Ubuntu – Install Ubuntu on a loop device

loop-devicemountsystem-installationubiquity

I used grub2 to boot the Ubuntu ISO file from my hard disk (without burning it to a DVD or a flash drive), but I don't want to install Ubuntu to a partition on my hard disk; instead I want to install it to a disk image (.img)file.

So, I created an .img file (using dd) and then I mounted the .img file through multiple ways:

  1. Using kpartx (which mounts to /dev/mapper devices).

  2. Using losetup (which mounts to /dev/loopX devices).

But when I run the Ubuntu installer (ubuquity) the installer doesn't seem to recognize the loop device as a hard disk, so I only get /dev/sdXX device and can't see loop devices!

Now, I didn't try to mount the image using the mount command, but I'm sure it will show the same issue, because as far as I know that losetup uses mount to mount the files.

So I have two questions:

  1. Is there a way to make ubiquity detect "loop devices" as hard disks?

  2. Can I mount .img files to /dev/sdXX devices (instead of the normal /dev/loopX)?

Best Answer

I have written a blog post about this.

Basically you just need to create a virtual block device at /dev/sdX, and mount your LOFS on it. Then you can run the installer and install Ubuntu on it. But please note that you cannot install GRUB directly on it (and there is no point to do so).

Related Question