Linux – Deep freeze like software for Fedora

fedorafilesystemslinuxsnapshot

For one of my labs, I need to maintain consistent file systems. So, I do not want any changes written to the file system after the system is shutdown. Currently, I am maintaining an operating system image and copying it manually after the lab session is over.

I am trying to figure out if there is any open source implementation of Deep Freeze software for Fedora based systems. I am trying to maintain a consistent file system so that any changes made will be lost when the system reboots.

From this link, I see there are similar software to Deep freeze, however, they are available for Debian based systems. I also came across LVM partitions which I did not understand much.

Suggest me some software that can be used in Fedora based systems or some other better solution.

Best Answer

You could set up aufs on the root partition and have the original image read only and all changes are stored in RAM. That way the students can make any changes they like (even as root), after a reboot a clean well defined system state is restored.

I did exactly this setup using Debian but the same should be possible without too much modification on Fedora as well. Since the clients were running diskless, I used PXE boot. Here are the basic steps, the instructions are mainly taken from Diskless Debian Linux booting via dhcp/pxe/nfs/tftp/aufs and Installing Debian using network booting.

The PXE boot server has the IP address 192.168.1.10 and it also serves as TFTP and NFS server. It uses aufs and the root filesystem is mounted read-only. Due to the aufs the clients have write access. All changes reside in memory and are wiped on reboot.

Install necessary packages

apt-get install isc-dhcp-server tftp-hpa nfs-kernel-server debootstrap syslinux

Configure DHCP server to serve a PXE boot image

cat >/etc/dhcp/dhcpd.conf <<EOF
next-server 192.168.1.10;  # address of the TFTP server
allow bootp;
allow booting;

subnet 192.168.1.0 netmask 255.255.255.0 {
  # clients get a dynamic IP address
  range dynamic-bootp 192.168.1.20 192.168.1.254;
  filename "pxelinux.0";
  option domain-name-servers 192.168.0.10;
  option broadcast-address 192.168.1.255;
  option routers 192.168.0.10;
}
EOF

This configures DHCP to use the TFTP server on address 192.168.1.10 and load the PXE boot image pxelinux.0.

Configure TFTP server

mkdir /srv/tftp

Configure NFS server.

The root file system is mounted read only via NFS.

mkdir /srv/nfsroot
cat >/etc/exports <<EOF
/srv/nfsroot 192.168.1.10/24(ro,no_root_squash,no_subtree_check)
EOF

Populate NFS directory with a Debian installation

debootstrap stable /srv/nfsroot <mirror>
# e.g.
debootstrap stable /srv/nfsroot \
  http://ftp.sunet.se/pub/Linux/distributions/debian/

Install kernel and initramfs tools:

chroot /srv/nfsroot apt-get update
chroot /srv/nfsroot apt-get install initramfs-tools linux-image-amd64

Configure its initramfs to generate NFS-booting initrds:

sed 's/BOOT=local/BOOT=nfs/' \
  -i /srv/nfsroot/etc/initramfs-tools/initramfs.conf

Load the aufs module:

echo aufs >> /srv/nfsroot/etc/initramfs-tools/modules

Configure aufs:

cat >/srv/nfsroot/etc/initramfs-tools/scripts/init-bottom/aufs <<EOF
modprobe aufs
mkdir /ro /rw /aufs
mount -t tmpfs tmpfs /rw -o noatime,mode=0755
mount --move $rootmnt /ro
mount -t aufs aufs /aufs -o noatime,dirs=/rw:/ro=ro
mkdir -p /aufs/rw /aufs/ro
mount --move /ro /aufs/ro
mount --move /rw /aufs/rw
mount --move /aufs /root
exit 0
EOF

Make the file executable:

chmod +x /srv/nfsroot/etc/initramfs-tools/scripts/init-bottom/aufs

Generate initrd:

chroot /srv/nfsroot update-initramfs -k $(uname -r) -u

Watch out if the kernel of the host and the chroot do not match. Replace $(uname -r) with the correct kernel if necessary.

Copy generated initrd, kernel image, and PXE bootloader to TFTP root and create folder for PXE config:

cp /srv/nfsroot/boot/initrd.img-* /srv/tftp/
cp /srv/nfsroot/boot/vmlinuz-*    /srv/tftp/
cp /usr/lib/syslinux/pxelinux.0   /srv/tftp/
mkdir /srv/tftp/pxelinux.cfg

The file pxelinux.0 is the PXELINUX bootstrap program.

Configure boot loader:

cat >/srv/tftp/pxelinux.cfg/default <<EOF
default Debian
prompt 1
timeout 10
label Debian
kernel vmlinuz-2.6.32-5-amd64  # <- use correct version!
append ro initrd=initrd.img-2.6.32-5-amd64 root=/dev/nfs ip=dhcp 
nfsroot=192.168.1.10:/srv/nfsroot
EOF

Change root password

chroot /srv/nfsroot passwd root

Restart services

invoke-rc.d isc-dhcp-server restart
invoke-rc.d tftpd-hpa restart
exportfs -ra
Related Question