4

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)?

1 Answers1

2

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).

Kong Chun Ho
  • 406
  • 4
  • 12
  • To avoid link rot, please summarize the steps here. – Oxwivi Jun 16 '17 at 12:44
  • @Oxwivi The summarized steps already written in the second paragraph of this answer. – Kong Chun Ho Jun 16 '17 at 18:21
  • Do you think it is possibile to install grub on USB stick addressing a loopback file on the internal disk (so we can avoid to modify the original Windows bootloader)? – Antonio Petricca Mar 01 '18 at 09:19
  • @AntonioPetricca Of course. You can install GRUB on your USB stick, making it acting like some sort of a "bootloader stick" which boots some partitions/LOFS on the internal disk. – Kong Chun Ho Mar 02 '18 at 10:27