歡迎您光臨本站 註冊首頁

如何遠程安裝Linux

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0
由ITAA gotolab 作
本文介紹了在不需要光碟機和軟碟機的情況下,如何通過PXE協議快速安裝Linux的原理和步驟,這對於提高安裝Linux的效率非常有幫助;同時,PXE協議也可以作為無盤linux技術,用於引導遠程的Linux啟動.
1. 引言
一般情況下,我們都是利用軟碟機或光碟機引導Linux后,再通過本地的光碟機安裝Linux.但是,這種安裝方法在以下的幾種情況下就不能適用:
  1. 無軟碟機和光碟機:很多公司為了節省成本,計算機一般都不帶光碟機或軟碟機,這樣就無法通過本地安裝Linux;
  2. 非標準的軟碟機和光碟機:雖然筆記本都會配置光碟機,但是並不一定都是標準的IDE設備,有些是通過USB介面,有些是通過1394介面(例如Samsung的Q10).在Linux安裝時所引導的Linux內核一般都不會帶這些介面的驅動,所以也無法通過本地安裝Linux;
  3. 另外,在一些場合,如機房中,有大量的計算機需要同時安裝Linux,如果通過光碟機的方式一個個安裝,不僅效率低,也不利於維護.
筆者在工作過程中,就遇到過第二種情況.一台Samsung的Q10筆記本需要安裝Redhat Linux 8.0,但是通過光碟機引導后發現,安裝程序無法訪問光碟.針對這個問題,筆者經過查閱資料和摸索,找到了在Q10上安裝Linux的方法.在下面的討論中,如不做特別聲明,都將以Q10為例,介紹如何通過PXE Bootrom來遠程安裝Linux.
2. 基本原理
1) 什麼是PXE
PXE(Pre-boot Execution Environment)是由英特爾設計的協議,它可以使計算機通過網路啟動.協議分為client和server兩端,PXE client在網卡的ROM中,當計算機引導時,BIOS把PXE client調入內存執行,並顯示出命令菜單,經用戶選擇后,PXE client將放置在遠端的操作系統通過網路下載到本地運行.


3. 步驟
有了前面的背景知識,接下來就可以正式操作了,下面按照順序給出了操作步驟:
1) 配置DHCP Server
選用ISC dhcp-3.0,DHCP Server的配置文件是/etc/dhcpd.conf,配置文件的內容如下:
   option space PXE;   option PXE.mtftp-ip               code 1 = ip-address;     option PXE.mtftp-cport            code 2 = unsigned integer 16;   option PXE.mtftp-sport            code 3 = unsigned integer 16;   option PXE.mtftp-tmout            code 4 = unsigned integer 8;   option PXE.mtftp-delay            code 5 = unsigned integer 8;   option PXE.discovery-control      code 6 = unsigned integer 8;   option PXE.discovery-mcast-addr   code 7 = ip-address;   class "pxeclients" {       match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";       option vendor-class-identifier "PXEClient";       vendor-option-space PXE;       # At least one of the vendor-specific PXE options must be set in       # order for the client boot ROMs to realize that we are a PXE-compliant       # server.  We set the MCAST IP address to 0.0.0.0 to tell the boot ROM       # that we can't provide multicast TFTP (address 0.0.0.0 means no       # address).       option PXE.mtftp-ip 0.0.0.0;       # This is the name of the file the boot ROMs should download.       filename "pxelinux.0";       # This is the name of the server they should get it from.       next-server 192.168.0.1;   }   ddns-update-style interim;   ignore client-updates;   default-lease-time 1200;   max-lease-time 9200;   option subnet-mask 255.255.255.0;   option broadcast-address 192.168.0.255;   option routers 192.168.0.254;   option domain-name-servers 192.168.0.1,192.168.0.2;   option domain-name "mydomain.org";   subnet 192.168.0.0 netmask 255.255.255.0 {   range 192.168.0.10 192.168.0.100;   }    host q10 {   hardware ethernet 00:00:F0:6B:38:5B;   	fixed-address 192.168.0.22;   }   


dhcpd.conf配置文件中幾個關鍵部分說明如下:host q10{…}定義了筆記本Q10網卡的MAC地址與IP地址的對應關係,表明DHCP Server為Q10分配一個固定的IP:192.168.0.22;filename ""指定bootstrap的文件名;netx-server指定TFTP Server的地址.其它的配置請讀者參考DHCP Server的手冊.
2) 配置TFTP server
選用tftp-hpa,TFTP Server的配置文件是/etc/xinetd.d/tftp,配置文件的內容如下:
   	   service tftp   {           socket_type             = dgram           protocol                = udp           wait                    = yes           user                    = root           server                  = /usr/sbin/in.tftpd           server_args             = -u nobody -s /tftpboot           disable                 = no           per_source              = 11           cps                     = 100 2   	}   	

這裡制定了/tftpboot為TFTP Server的根目錄位置.
3) 配置bootstrap
bootstrap文件在dhcpd.conf中被指定為pxelinux.0文件,放置在/tftpboot.Linux內核以及Linux根文件系統也放置在/tftpboot.pxelinux.0在執行過程中,要讀配置文件,所有的配置文件都放在/tftpboot/pxelinux.cfg/目錄下.由於PXElinux具有為不同的PXE Client提供不同的Linux內核以及根文件系統的功能,所以要通過不同的配置文件名來區分出不同的PXE Client的需求.比如一個PXE Client由DHCP Server分配的IP地址為192.168.0.22,那麼相對應的配置文件名為/tftpboot/pxelinux.cfg/C0A80016(註:C0A80016為IP地址192.168.0.22的十六進位表示).如果找不到,就按照順序C0A80016-> C0A8001-> C0A800-> C0A80-> C0A8-> C0A-> C0-> C->default查找配置文件.


[火星人 ] 如何遠程安裝Linux已經有403次圍觀

http://coctec.com/docs/linux/show-post-54240.html