Tuesday, February 27, 2018

如何在Ubuntu 16.04 desktop 透過PXE安裝Ubuntu?

在開始之前,請先準備與安裝相關的service在Ubuntu desktop 16.04 LTS:

準備:
1. Download Ubuntu desktop ISO
2. Download PXE bootloader

安裝:
1. DHCP Server
$ sudo apt-get install isc-dhcp-server
2. TFTP Server
$ sudo apt-get install tftpd-hpa inetutils-inetd
3. NFS Server
$ sudo apt-get install nfs-kernel-server
配置:
1. DHCP Server:
$ sudo vi /etc/dhcp/dhcpd.conf
 subnet 192.168.1.0 netmask 255.255.255.0 {
 range 192.168.1.200 192.168.1.253;
 option domain-name-servers 8.8.8.8;
 option routers 192.168.1.1;
 option broadcast-address 192.168.1.255;
 default-lease-time 600;
 max-lease-time 7200;
 next-server 192.168.1.254;
 filename "pxelinux.0";

 }
 $ sudo systemctl restart isc-dhcp-server
 2. TFTP Server:
$ sudo vi /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
RUN_DAEMON="yes"
OPTIONS="-l -s /var/lib/tftpboot"
$ sudo vi /etc/xinetd.conf
tftp    dgram   udp    wait    root    /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot
$ sudo systemctl restart tftpd-hpa 
3. PXE bootloader:
$ tar -xJf syslinux-6.03.tar.xz
$ cd syslinux-6.03
$ sudo cp bios/core/pxelinux.0 /var/lib/tftpboot
$ sudo cp bios/com32/lib/libcom32.c32 /var/lib/tftpboot
$ sudo cp bios/com32/libutil/libutil.c32 /var/lib/tftpboot
$ sudo cp bios/com32/elflink/ldlinux/ldlinux.c32 /var/lib/tftpboot
$ sudo cp bios/com32/menu/vesamenu.c32 /var/lib/tftpboot
$ mkdir /var/lib/tftpboot/pxelinux.cfg
$ sudo vi /var/lib/tftpboot/

pxelinux.cfg/default 
DEFAULT vesamenu.c32
MENU TITLE Network boot
LABEL ubuntu-mate-16.04.2-desktop-amd64
  MENU LABEL ubuntu-mate-16.04.2-desktop-amd64
  KERNEL vmlinuz.efi
  APPEND initrd=initrd.lz root=/dev/nfs boot=casper netboot=nfs nfsroot=192.168.1.254:/var/nfs/ubuntu_desktop splash -- 
* Remember to copy vmlinuz.efi and initrd.lz to the folder /var/lib/tftpboot from Ubuntu ISO.
* 補充: 針對18.04要修改一下設定檔如下:
  APPEND initrd=./u18/initrd_ubuntu18.04.lz root=/dev/nfs boot=casper netboot=nfs nfsroot=192.168.1.254:/var/nfs/ubuntu18.04 splash toram --


4. NFS file Server:
$ sudo mount -o loop ubuntu-16.04.3-desktop-amd64.iso /mnt/
$ sudo mkdir -p /var/nfs/ubuntu_desktop
$ sudo cp -rf /mnt/* /var/nfs/ubuntu_desktop/
$ sudo vi /etc/exports

/var/nfs/ubuntu_desktop *(ro,sync)
$ sudo systemctl restart nfs-kernel-server
$ showmount -e localhost 
Export list for localhost:
/var/nfs/ubuntu_desktop *

Boot from Network boot:















Done!

No comments: