Skip to Content

DRBL-Ubuntu

使用 Ubuntu 建立 DRBL(Diskless Remote Boot in Linux)
Step 0 : 環境需求
Step 1 : tftp server 的設定
Step 2 : nfs 分享目錄
Step 3 : PXE 設定檔
Step 4 : DHCP Server
Step 5 : The PXE clients

Step 0 : 環境需求
Ubuntu 有它的 LiveCD (LiveCD 為一種不需安裝可直接由光碟執行 Linux 的方式),除了透過光碟來開啟 Linux 外,我們還可以透過 PXE + NFS 的方式執行 LiveCD 的內容,方式就是將光碟的內容放在 NFS 所分享的目錄 Client 再透過 PXE 開機.所需的環境需求如下.

  • 一台具有 DHCP 與 tftp server (eg: IP 192.10.0.1)
  • 一台具有 PXE 開機功能網路卡的 Client(請先確定 PXE 功能已經在 BIOS 下開啟,並設為第一開機順位)

作業系統我選擇的是 RedHat Enterprise Linux 4 版本

Step 1 : tftp server 的設定
1. 編輯 “/etc/xinetd.d/tftp” 並將 server 開啟

[root@benjr ~]# vi /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
CPUS = 100 2
flags = IPv4
}

將 disable 設定成為 no 即可.或者你可以用下面的指令將 tftp 功能開啟

[root@benjr ~]# chkconfig tftp on

2.啟動 tftp servicee

[root@benjr ~]# service xinetd restart


Step 2 :
nfs 分享目錄
1.複製 ubuntu 光碟所有的內容 (這邊我是用 Ubuntu 8.1.0 Desktop 為範例) ,下載點為 http://www.ubuntu.com/getubuntu/download

[root@benjr ~]# mkdir /var/ftp/ubuntu
[root@benjr ~]# mount -o loop ubuntu8.1.0.iso /mnt/cdrom
[root@benjr ~]# cp -rf /mnt/cdrom/* /var/ftp/ubuntu

編輯 "/etc/exports" 並將 /var/ftp/ubuntu 分享出來(因為我們把光碟內的檔案放在此目錄下)

[root@benjr ~]# vi /etc/exports
/var/ftp/ubuntu 192.10.0.0/24(async,no_root_squash,no_subtree_check,ro)

並確定 nfs 的服務已經開啟

[root@benjr ~]# chkconfig nfs on
[root@benjr ~]# service nfs start


Step 3 : PXE 設定檔
1.將開機所需的 kernel 和 initrd 檔案複製到 "/tftpboot/linux-install/ubuntu 目錄下.

[root@benjr ~]# mkdir /tftpboot/linux-install/ubuntu
[root@benjr ~]# cp /var/ftp/ubuntu/casper/vmlinuz /tftpboot/linux-install/ubuntu/
[root@benjr ~]#
cp /var/ftp/ubuntu/casper/initrd.gz /tftpboot/linux-install/ubuntu/

2.編輯 /tftpboot/linux-install/pxelinux.cfg/default (這個檔案定義了與PXE的Clients可以經由按鍵來選擇安裝的系統)

[root@benjr ~]# vi /tftpboot/linux-install/pxelinux.cfg/default
default 0
timeout 2000
F1 msgs/boot.msg
F2 msgs/expert.msg
prompt 1
display msgs/boot.msg
label 0
localboot 1
label ubuntu
  kernel ubuntu/vmlinuz
  append boot=casper netboot=nfs nfsroot=192.10.0.1:/var/ftp/ubuntu initrd=/ubuntu/initrd.gz --

設定檔說明:

  • default 0
  • 如果使用者不選擇安裝哪一種OS這邊就可以設定預設安裝哪一個OS,default 0的意是就是使用label 0的設定.

  • timeout 2000
  • 預設安裝生效時間為2000ms(200秒).

  • F1 msgs/boot.msg
  • F2 msgs/expert.msg
  • 這邊是用來定義F1至F12功能鍵所要顯示的內容.

  • prompt 1
  • 效果不明????

  • display msgs/boot.msg
  • 一開機進入PXE所顯示的第一個提示訊息.

  • label 0
  • localboot 1
  • 這裡定義了使用機器系統上的硬碟來直接開機.

  • label ubuntu
  •   kernel ubuntu/vmlinuz
      append boot=casper netboot=nfs nfsroot=192.10.0.1:/var/ftp/ubuntu initrd=ubuntu/initrd.gz --
    這就是要開啟的 OS 定義.

3.編輯 /tftpboot/linux-install/msgs/boot.msg (這個檔案就是Clients經由PXE開機時所看到的提示訊息)

[root@benjr ~]# vi /tftpboot/linux-install/msgs/boot.msg
ubuntu8.1.0 Install

4.編輯 /etc/rc.d/rc.local 必須加入下面這一行

[root@benjr ~]# vi /etc/rc.d/rc.local
route add -host 255.255.255.255 eth0


Step 4 : DHCP Server

編輯 /etc/dhcpd.conf

[root@benjr ~]# vi /etc/dhcpd.conf
# ddns-update-style interim;
ddns-update-style none;
ignore client-updates;
allow booting;
allow bootp;
class "pxeclients" {
match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.10.0.1;
filename "linux-install/pxelinux.0";
}
subnet 192.10.0.0 netmask 255.255.255.0 {
range 192.10.0.150 192.10.0.180;
option broadcast-address 192.10.0.255;
option routers 192.10.0.1;
option subnet-mask 255.255.255.0;option domain-name-servers 192.10.0.1;
}

這個項目 option domain-name-servers 192.10.0.1 為非必要選項,如果你有設定就不用再指定 DNS 位址.但是相對應的 DNS(Bind Server)也要設定.並確定 DHCP 的服務已經開啟

[root@benjr ~]# chkconfig dhcpd on
[root@benjr ~]# service dhcpd start

其中的 next-server 就是你的tftp server所在的位置.我這邊的例子使用192.10.0.1.至於其他有關於DHCP的設定說明起自行參考DHCP的官方網站http://www.isc.org.

在整個 DHCP 設定檔中,最重要的就是 filename "linux-install/pxelinux.0",整個網路開機顯示畫面,流程控制都由 pxelinux.0 來管理,關於更多有關於 pxelinux.0 ,請參考 PXELinux 的官方網頁  http://syslinux.zytor.com/

Step 5 : The PXE clients
1. 將具有 PXE 功能網路卡的 client 開機.
2. 並從 PXE 開機
3. 在 Boot 鍵入 ubuntu 開啟 ubuntu 作業系統.

參考文件:
https://wiki.ubuntu.com/LiveCDNetboot

回應

Ubuntu Desktop 10.10

最近重做 Ubuntu Desktop 10.10 版本做成透過 PXE 的 Live CD ,按著上面所說的步驟系統開到一半就停下來.顯示一個從來沒看過的訊息 "Please provide a name for this Disc, such as ‘Debian 5.0.3 Disk1′"
上網爬文一下原來在 Ubuntu Desktop 10.10 有一個隱藏目錄 .disk 是必須的檔案需要複製到 PXE 所分享的目錄.
http://www.linuxreaders.com/2010/06/24/pxe-boot-ubuntu-10-04/

PS:後來覺得很怪為什麼 Linux 下的 cp 並不能複製以 "." 開頭的隱藏目錄,幾乎試過所有的參數都不行.