Skip to content

chroots

Alkis Georgopoulos edited this page Nov 4, 2019 · 2 revisions

Chroots

The older LTSP 5 had a tool called ltsp-build-client that administrators could use to create chroots, and another tool called ltsp-chroot to manage them.

The new LTSP doesn't provide them anymore, as nowadays numerous alternatives to manage chroots exist.

Here's a quick tutorial to create a minimal chroot. Replace focal, which is the name of Ubuntu 20.04, with whatever version you prefer.

cd /srv/ltsp
debootstrap focal focal
chroot focal
apt install --no-install-recommends linux-generic initramfs-tools
echo focal > /etc/hostname
passwd
exit

Then put the following line in /etc/exports.d/local.conf:

/srv/ltsp/focal	*(rw,async,crossmnt,no_subtree_check,no_root_squash,insecure)

You might want to restrict "*" there to the server IP so that only KVM has read-write access to that chroot. Then run exportfs -ra to export it via NFS.

Booting the chroot with KVM

At that point you should be able to boot the chroot with KVM and maintain it without caring about chroot restrictions like bind-mounting directories, prohibiting services from starting etc. If your server is headless, run:

kvm -m 1024 -nographic -serial mon:stdio -kernel /srv/ltsp/focal/boot/vmlinuz -initrd /srv/ltsp/focal/boot/initrd.img -append "rw root=/dev/nfs nfsroot=192.168.67.1:/srv/ltsp/focal console=ttyS0"

While if your server has a normal GUI, run:

kvm -m 1024 -kernel /srv/ltsp/focal/boot/vmlinuz -initrd /srv/ltsp/focal/boot/initrd.img -append "rw root=/dev/nfs nfsroot=192.168.67.1:/srv/ltsp/focal"

Then login as root and install whatever packages you need, for example apt install ubuntu-desktop.

Booting the chroot with a client

An alternative way is to boot the chroot in NFS read-write mode from a client. This has the advantage that it can work with different architectures, e.g. armhf chroots and x86 server, or with a GUI client and a headless server. To do that, you'd need to add the following to /srv/tftp/ltsp/ltsp.ipxe.

Below "Other options:"

item --key n nfs-rw               nfs-rw

And then below "goto ${img}":

:nfs-rw
set img focal
set cmdline rw root=/dev/nfs nfsroot=${srv}:/srv/ltsp/${img},tcp,timeo=600,rsize=4096,wsize=4096
kernel /ltsp/${img}/vmlinuz initrd=initrd.img ${cmdline}
initrd /ltsp/${img}/initrd.img
boot || goto failed
You can’t perform that action at this time.