Wednesday, March 25, 2009

Testing read/write union filesystem in my EeePC 4G

These 2 days, I have been testing on mounting the union filesystem (aufs) with both partitions sda1 and sda2 as read/write to install, upgrade and remove programs with my EeePC 4G.

What I want is to uninstall Open Office 2 from sda1 and install updates from Asus without wasting the precious disk space of my 4 GB SSD. With the read/write initramfs image I have modified, both sda1 and sda2 are mounted read/write in the union filesystem. So, when I uninstall Open Office 2, all files originally residing from sda1 will be deleted. And while upgrading programs with Asus Updates, the new version will be installed to sda2 while the old version in sda1 will be deleted. I intend to install Open Office 3 for docx support, and as I expect a possibility to upgrade in the future, I intend to keep it in sda2.

The original plan was to shrink sda1 after all the updates to recover the disk space there. This is because with the union filesystem mounting sda1 as read only, there is no way to make use of the free disk space I have gained removing so many programs in sda1. However, an second thought told me that working like this, I won't be able to F9 restore to factory default any more because many important system files will now be residing in sda2. So instead, I merged changes from sda2 to sda1 following this wiki instructions: merging the first two partitions.

Unfortunately something went wrong and I ended up with a broken system. I am not sure where I've made the mistake. May be the wiki instruction is only for unionfs but not entirely correct for aufs. Or may be it is just some typing mistake. Anyway, I will need to restore from USB and try it all over again. But next time, I will probably use my old approach: Boot without unionfs to install the updates.

For those who are interested to test this, here is how I made the read/write initramfs image. [NB. You can also download the read-write initramfs image I have compiled here: initramfs-rw-eeepc.img]


1) Modify the initramfs image as per this wiki instruction: Rebuilding initramfs, make the following changes to the init script:
#change this line from ro to rw
mount -t ext2 -o rw $ROOT /mnt-system

#Add mount options=rw to this line
mount -t aufs -o br:/mnt-user=rw:/mnt-system=rw+nolwh none /mnt
2) Re-pack the initramfs
find | cpio -H newc -o | gzip -9 > ../initramfs-rw-eeepc.img
3) Edit /boot/grub/menu.lst and add this entry:
title Boot with rw aufs
root (0x80,0)
kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1
initrd /boot/initramfs-rw-eeepc.img
4) Boot into rescue mode and copy the modified initramfs image and grub menu.lst to sda1.

Like this, I press F9 at reboot, and select the new entry to boot into the read/write union filesystem. I verified this with the "mount" command:
rootfs on / type rootfs (rw)
/dev/sda1 on / type ext2 (rw)
none on / type aufs (rw,xino=/.aufs.xino,br:/=rw:/=rw+nolwh)
...
Then I uninstalled openoffice2 with apt-get, removing 17 packages and free up 300 MB disk space:
sudo apt-get remove openoffice*
After installing all those Asus updates, and merging the change to sda1, I ended up with 275MB free space in sda1 (original should be something like 75 MB).
/dev/sda1             2.3G  1.9G  275M  88% /home/user/sda1
/dev/sda2 1.4G 444M 905M 33% /home/user/sda2
Please note that you cannot see this from within the union filesystem. I have to boot from USB and mount the 2 partitions to verify their disk usage.

No comments:

Post a Comment