Saturday, October 01, 2022

Build a Turnkey "Deep Freeze"-Style Ubuntu System with Auto-Wiping Flash Storage

In a previous post, we discussed how to manually set up a Linux system that restores itself on every reboot, just like Faronics Deep Freeze.

Today, let's take it one step further: we'll customize an Ubuntu ISO so that:

  • It boots directly into a self-healing system,

  • It automatically sets up writable storage on a flash drive,

  • It wipes that flash drive every time you reboot.

No user intervention needed. Fully turnkey.


Prerequisites

Before we begin, you'll need:

  • ✅ A Linux system to prepare everything (Ubuntu preferred)

  • ✅ The Ubuntu 22.04 LTS ISO

  • ✅ A blank DVD or a bootable USB stick for burning

  • ✅ A second USB flash drive (at least 8GB) for temporary write space

  • ✅ Basic familiarity with the Linux terminal


Step 1: Set Up a Working Folder

First, install a few helper tools:

sudo apt update
sudo apt install squashfs-tools xorriso isolinux syslinux-utils

Now, set up a working folder:

mkdir ~/ubuntu-custom
cd ~/ubuntu-custom

Step 2: Extract the Ubuntu ISO

Download your Ubuntu ISO and extract it:

wget https://releases.ubuntu.com/22.04/ubuntu-22.04.4-desktop-amd64.iso

# Mount and copy contents
mkdir mnt
sudo mount -o loop ubuntu-22.04.4-desktop-amd64.iso mnt
rsync -a mnt/ extract-cd/
sudo umount mnt

You now have a modifiable copy of the ISO contents in extract-cd/.


Step 3: Add Our Auto-Wipe and Overlay Scripts

Inside extract-cd/, we'll embed a tiny custom startup script.

Create the directory if it doesn't exist:

mkdir -p extract-cd/casper/scripts

Now create the script:

nano extract-cd/casper/scripts/wipe-usb-overlay

Paste this:

#!/bin/bash
#
# Set up an OverlayFS using a flash drive, wiping it every boot

DEVICE=$(blkid | grep "TYPE=\"ext4\"" | grep -v "cdrom" | awk '{print $1}' | tr -d ':')  # crude but works
MOUNTPOINT=/media/usb

mkdir -p $MOUNTPOINT
mount $DEVICE $MOUNTPOINT

# Reformat USB flash drive
mkfs.ext4 -F $DEVICE

# Re-mount it fresh
mount $DEVICE $MOUNTPOINT

# Create upper and work directories for overlay
mkdir -p $MOUNTPOINT/upper
mkdir -p $MOUNTPOINT/work

# Mount overlay
mkdir -p /cow
mount -t overlay overlay -o lowerdir=/,upperdir=$MOUNTPOINT/upper,workdir=$MOUNTPOINT/work /cow

# Switch root to overlay
mount --bind /cow /

Save and close.

Make it executable:

chmod +x extract-cd/casper/scripts/wipe-usb-overlay

Step 4: Hook It Into Boot

Now, modify the boot sequence so Ubuntu will run this script automatically.

Edit extract-cd/casper/initrd by decompressing and editing:

cd extract-cd/casper
mkdir initrd
cd initrd
gzip -dc ../initrd | cpio -id

Now edit init (the master boot script):

nano init

Find a good spot after the root filesystem is mounted (you can search for mountroot) and insert:

# Custom wipe USB overlay setup
/scripts/wipe-usb-overlay

Then rebuild initrd:

find . | cpio --create --format='newc' | gzip > ../initrd
cd ..
rm -rf initrd

Step 5: Rebuild the ISO

Back in your main ubuntu-custom/ directory:

cd ~/ubuntu-custom
sudo mkisofs -D -r -V "UBUNTU_FREEZE" -cache-inodes -J -l \
  -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
  -boot-load-size 4 -boot-info-table -o ubuntu-deepfreeze.iso extract-cd

This creates ubuntu-deepfreeze.iso — your brand-new Deep Freeze-style Ubuntu image!


Step 6: Burn and Boot

  • Burn ubuntu-deepfreeze.iso to a DVD, or

  • Flash it to a USB stick using Rufus, dd, or balenaEtcher.

When you boot:

✅ Ubuntu will load fresh
✅ It will wipe and set up the USB flash drive automatically
✅ All system changes will disappear on reboot
✅ No user input is needed


Final Notes

Area Notes
Flash Drive Wear Consider using durable, higher-end flash drives
Security Add a UUID check if you want to verify the correct flash drive
Performance Booting from USB stick (read-only) is much faster than DVD

Conclusion

Now you have a true turnkey Deep Freeze system for Ubuntu —
no more worries about malware, user errors, broken settings, or clogged hard drives.

This setup is perfect for schools, labs, libraries, pop-up installations, and experiments.

All built with 100% free and open-source tools.
Linux is magic.