Custom ubuntu based livecd - cesetxeberria/pxeserver GitHub Wiki

Prepare the server

First of all we have to prepare our PXE server using one of these bootloaders

We also need to configure it as a nfs server.

Now we need to get 3 files: a kernel (vmlinuz), an initramfs (initrd.img) and a squashed installation (filesystem.squashfs).

Prepare the files

If you prefer to use an official iso, see here.

Install debootstrap and squashfs-tools. As we are installing the newest ubuntu release (Focal Fossa) and current debian stable release is older, we need to use debootstrap from focal.

apt-get install squashfs-tools
wget -c http://es.archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_1.0.118ubuntu1_all.deb
dpkg -i debootstrap_1.0.123_all.deb

Create a new folder for the custom system, with a subfolder named "live" inside. Go to the newly created directory (not the subfolder).

mkdir -p /home/tftp/livecds/customubuntu/live
cd /home/tftp/livecds/customubuntu

Use debootstrap to create a new ubuntu installation.

debootstrap --arch=amd64 \
 --components=main,restricted,universe,multiverse --merged-usr \
focal live/squashfs-root http://es.archive.ubuntu.com/ubuntu/

Keep in mid that this is a one-line command, it's written like this for readability. It will create an ubuntu "Focal Fossa" installation, for amd64 architecture inside "live/squashfs-root" directory. Rest of the options are pretty self-explanatory, read the manual if you have doubts.

After finishing with debootstrap, enter the new system with chroot

LANG=C.UTF-8 chroot ./live/squashfs-root

First part of the command (LANG=C.UTF-8) isn't mandatory but can help if you want to create a system with different locale settings than yours.

Inside a chroot is preferable to mount some special filesystems

mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none dev/pts

Configure locale, keyboard, console settings and local time.

dpkg-reconfigure locales
dpkg-reconfigure keyboard-configuration
dpkg-reconfigure tzdata

Customize this file to prevent systemd from storing journal in hard disk.

sed -i.bak 's/#Storage=auto/Storage=volatile/g' /etc/systemd/journald.conf

Now install minimum packages and execute tasksel, to select the rest of packages to install. grub*- means we don't want to install grub.

apt-get install linux-image-generic grub*- live-boot tasksel
tasksel --new-install

I don't know why, the live system doesn't get a good dns configuration. So I add some openNIC dnss manually.

nano /etc/systemd/resolved.conf

DNS=193.183.98.66 151.80.222.79

Clean all the temporary files created by apt

apt-get clean
apt-get autoclean
apt-get autoremove
rm -rf /var/cache/apt/archives/*.deb
rm -rf /var/cache/apt/archives/partial/*
rm -rf /var/cache/debconf/*-old
rm -rf /var/lib/apt/lists/*

Umount the previously mounted special filesystems

umount -df /dev/pts
umount -df /sys
umount -df /proc

Create a new user and add it to the "sudo" group, so it can become root. Then exit the chroot

adduser username
adduser username sudo
exit

Remember to replace "username" with your own user name.

Get initrd.img and vmlinuz files from the new system. Compress the filesystem using mksquash and delete the uncompressed folder.

cp live/squashfs-root/vmlinuz .
cp live/squashfs-root/initrd.img .
mksquashfs live/squashfs-root live/filesystem.squashfs
rm -R live/squashfs-root

Add the livecd entry to your boot menu.

Using pxelinux

nano /home/tftp/syslinux/bios/pxelinux.cfg/default

label Custom Ubuntu live
 menu clear
 kernel /livecds/customubuntu/vmlinuz
 initrd /livecds/customubuntu/initrd.img
 append panic=10 ro boot=live root=/dev/nfs nfsroot=192.168.1.54:/home/tftp/livecds/customubuntu swap
 ipappend 2 

Remember that 192.168.1.54 is just an example. You must use the ip of your own nfs server. Last line (ipappend 2) is very important. When Ubuntu boots, it tries to get an ip address using dhcp, but as we are booting from pxe he already has one. With this line we are telling the system to keep it.

Using grub

nano /home/tftp/grub/grub.cfg

menuentry "Custom Ubuntu live" {
 linux /livecds/customubuntu/vmlinuz panic=10 ro boot=live root=/dev/nfs nfsroot=192.168.1.54:/home/tftp/livecds/customubuntu ksdevice=bootif
 initrd /livecds/customubuntu/initrd.img
}

Remember that 192.168.1.54 is just an example. You must use the ip of your own nfs server. Last part of the first command (ksdevice=bootif) is very important. When Ubuntu boots, it tries to get an ip address using dhcp, but as we are booting from pxe he already has one. With this line we are telling the system to keep it.

Using ipxe

nano /home/tftp/default.ipxe

:customubuntulive
kernel /livecds/customubuntu/vmlinuz
initrd /livecds/customubuntu/initrd.img
imgargs vmlinuz initrd=initrd.img panic=10 ro boot=live root=/dev/nfs nfsroot=192.168.1.54:/home/tftp/livecds/customubuntu ksdevice=bootif      
boot ||
goto MENU

Remember that 192.168.1.54 is just an example. You must use the ip of your own nfs server. Last part of the first command (ksdevice=bootif) is very important. When Ubuntu boots, it tries to get an ip address using dhcp, but as we are booting from pxe he already has one. With this line we are telling the system to keep it.