I like to use VMs when doing things which might put stuff all over the filesystem or needs root access to install. But at a few gigabytes each they quickly take up space. I managed to use the live CD image as a base, which is compressed and can be shared among virtual machines.
Create a virtual machine with a hard disk of your choosing. Boot the Ubuntu live CD in it.
Create a partition on the virtual hard disk for persistence, and make it bootable.
Format it, give it a label:
$ sudo bash # mkfs.ext2 /dev/sda1 -L overlay
# mount /dev/sda1 /mnt
# mkdir /mnt/boot
# cp -p /cdrom/casper/vmlinuz.efi /mnt/boot
We need to edit
/etc/casper.confinside the initrd (Edit: You don't need to do this; see the end of the post):
# cd /tmp # mkdir i # cd i # lzcat /cdrom/casper/initrd.lz | cpio -i
now put in /tmp/i/etc/casper.conf (I found out the variables by looking through
/usr/share/initramfs-tools/scripts/casper, which is run by the kernel command line's
# This file should go in /etc/casper.conf # Supported variables are: # USERNAME, USERFULLNAME, HOST, BUILD_SYSTEM, FLAVOUR export USERNAME="user" export USERFULLNAME="Live session user" export HOST="vm" export BUILD_SYSTEM="Ubuntu" # USERNAME and HOSTNAME as specified above won't be honoured and will be set to # flavour string acquired at boot time, unless you set FLAVOUR to any # non-empty string. export FLAVOUR="Ubuntu" export PERSISTENT="Yes" export root_persistence="overlay"
You can customize your username and host name in this file too. Note
root_persistenceis the label we specified in step 3. Now compress the initramfs:
# cd /tmp/i # find . | cpio --quiet --dereference -o -H newc | lzma -7 > /mnt/boot/initrd.lz
Now for a bootloader which uses the above stuff. Install the extlinux package. I grabbed the .deb from the package search.
# mkdir /mnt/boot/extlinux # extlinux -i /mnt/boot/extlinux
Put this in
DEFAULT linux LABEL linux KERNEL /boot/vmlinuz.efi APPEND boot=casper initrd=/boot/initrd.lz noprompt
The hard disk is probably missing the master boot record code, so write that.
# dd if=/usr/lib/syslinux/mbr.bin of=/dev/sda
Edit: It turns out you don't need to change
Instead, all of the options in
root_persistence can be sp
ecified on the kernel command line - simply add them (without the quotes) to
ex tlinux.conf, like this:
APPEND boot=casper initrd=/boot/initrd.lz noprompt username=user hostname=host
You also need to label your hard disk partition