Ubuntu LiveCD without a CDROM and with persistent mode
Translation of the original in Catalan. Read it in: CatalàCastellano
Last January I wrote about how to boot an Ubuntu LiveCD in persistent mode, that is, saving the configuration to a pendrive or hard disk so that the adjustments we make to the CD configuration are not lost. Well then, what we are dealing with now is doing the same but without the LiveCD. Let me explain, the goal is to have a read-only partition on our hard disk, or on another hard disk where the LiveCD is copied. Then we use another partition to save the modifications we make on the CD, that is, the persistent information. This allows us, in GRUB itself, to have recovery modes without having to insert the CD. Besides, we can always go back and have a basic configuration. And we can work exactly as if we had a LiveCD but without having it physically.
The solution is quite simple, perhaps the worst problem is that a configuration file called /scripts/casper has to be modified, and it is found inside the file /boot-live/initrd.gz, which makes modifying it a bit entertaining. Next I do a small cookbook of all the steps to follow.
-
We boot from the LiveCD.
-
We create a new partition on the disk of type vfat and we format it.
-
We mount the partition and create the directory /casper in it.
-
We copy the contents of the /casper directory of the Ubuntu LiveCD inside the new directory we have created on the partition.
-
Assuming that on the persistent partition we have GRUB installed to boot from the LiveCD but calling it from the hard disk, the configuration would be similar to this one:
default 0
timeout 30
hiddenmenu
color cyan/blue white/blue
# Calling LiveCD from hard drive
title mpti
root (hd0,0)
kernel /boot-live/vmlinuz boot=casper initrd=new-initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash vga=791 -- persistent
initrd /boot-live/new-initrd.gz
boot
# Calling LiveCD from hard drive in single user and persistent mode
title mpti persistent (recovery mode)
root (hd0,0)
kernel /boot-live/vmlinuz boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram ro single persistent
initrd /boot-live/new-initrd.gz
boot
# Calling LiveCD from hard drive without persistent and single user mode
title mpti w/o persistent (recovery mode)
root (hd0,0)
kernel /boot-live/vmlinuz boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram ro single
initrd /boot-live/new-initrd.gz
boot
-
Now it is time to modify the file /boot-live/new-initrd.gz, which is the one that contains the boot sequence we are interested in modifying. So, we go to the directory /boot-live.
-
To decompress the file new-initrd.gz we can do this:
mkdir new-initrd
cd new-initrd
gzip -dc /boot-live/new-initrd.gz | cpio -id
-
Inside /boot-live/new-initrd/scripts there is the file casper that we have to modify, so we edit it.
-
On line 257 there is the function is_usb_device that we have to leave as follows:
is_usb_device() {
# sysfs_path="${1#/sys}"
# if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-usb)"; then
return 0
# fi
# return 1
}
-
We save the configuration file and we create the file new-initrd again, like this:
# Fem una còpia l'antic new-initrd.gz per si les mosques
cd /boot-live
cp new-initrd.gz new-initrd.gz.old
# Creem el nou new-initrd.gz
cd new-initrd
find . | cpio --quiet --dereference -o -H newc | gzip -9 > ../new-initrd.gz
cd ..
rm -rf new-initrd
- Now we can reboot and remove the LiveCD, since everything should boot as if we had it inserted.
It is in the file casper where it is detected whether there is some LiveCD inserted from which the root file system will be mounted. The script looks in many places for a CD drive, it even looks for pendrives formatted as vfat with the contents of the CD, but before trying to mount them and looking inside them for the /casper directory and some file called *.squashfs it checks that the device is connected via USB.
So, the modification I have made only forces the USB check to always be true, so it will also try to mount the partitions of the possible connected hard disks or other similar ones. So, afterwards the only thing I do is create a vfat partition, create in it the directory it looks for and copy the file *.squashfs, which is where the squashfs file system is that contains the directory and file tree of the LiveCD.
Although I am happy with the result obtained, I would have liked to achieve the same result without having to modify the files of the initrd.gz, since that means that when updating Ubuntu, if there are modifications in the casper script, I will have to look at what has changed in order to update my system.
2 comments
Comments from the old blog, as they were written. Comments are closed.
M.Cara
Hola, la meva proposta, ya que he observat que parles catala seria mes luxosa, descarrega una vesio de CATIX 1.3 de linux en CATALA, es molt mes rapide que mandriva gaire bé marrisco a dir tan reapid com UBUNTU 7.04.
El Millor de tot es la velocitat de treball y el gran programari de aplicacions en Catala. Busca en GOOGLE
CATIX 1.3
Estic segur que despres de aixo no instalares altre linux
M.Cara
Ha tambe es pot instalar en un pendrive de 2 G de forma gairebe automatica, y funciona a la perfeció, (dispensa el meu Catalá, no practico gaire ultimament)