Portable OS with Qemu (partially success)

LiveUSB is too nice, especially for recovery. KNOPPIX or Puppy Linux can also be used as OS temporary to do the work and save the file. However, LiveUSB is too distro dependent. Thus, I am wondering how to prepare a portable OS by virtualisation through Qemu.

The advantages of this idea is to

  • allow the user to install any OS, meaning that the user can install any packages to do any work.
  • have an OS in an FAT32 formatted pendrive where the OS can have the size exceeds 4G.
  • be portable as a portable application.

However, there are some disadvantages.

  • Qemu virtualisation without KVM in Windows is slow.
  • Pre-compiled Qemu may not up-to-date and some DLLs may be missing.
  • Compilation of Qemu may needed.
  • Only the OS which has LVM support can work.

Since Qemu is open source and cross platform, assuming that Qemu can work on any OS, then this method is theoretically worked. However, there are several things need to be considered when preparing the OS image(s).

Firstly, because FAT32 does not allow file size exceeds 4G. Therefore, we need to use qemu-img to create several disk images less than 4G. However, Qemu can only load 4 images as the harddisk at most, i.e., -hda, -hdb, -hdc, -hdd. Thus, it will have the difficulty to prepare an OS more than 16G (4 x 4G). Yet, based on this page, it is possible to solve this problem. As a result, I solved this problem by options such as

qemu-system-i386 -m 1024 -hda hd001.img -usb -usbdevice disk:hd002.img \
-usbdevice disk:hd003.img \
-usbdevice disk:hd004.img \
-usbdevice disk:hd005.img \
-usbdevice disk:hd006.img

By using -usb and -usbdevice, Qemu can have more than 4 disk images.

Secondly, and luckily, Linux supports LVM. By using LVM, we can just combine these virtual hard disks together and use as a single large hard disk virtually in LVM. Then we can partition this LVM hard drive as any way we want. Before preparing LVM hard drive (physical volume), please see the next important point.

Thirdly, the partition for boot. I tried to create /boot in the LVM physical volume, it failed to boot from GRUB2. Therefore, my solution is separate the /boot as one standard partition, then the others remain in LVM physical volume.

Fourthly, GRUB2 is needed.

As a result, I can boot into the portable OS using Qemu in a FAT32 from a Linux OS. Everything works fine in Linux. However, I still not yet figure out booting this portable OS from Windows using Qemu. Thus, this method is partially success.