0

Here is what I want to implement:

  1. Install a Linux distro into an image file, a.k.a., a linux installation inside an image file, just like a docker image. To make it easy, maybe we can just create a bootable image from a docker image. (Is it possible to create a bootable image from a docker image?) This kind of images can be tested with qemu, virtualbox, or something alike.
  2. Copy the prepared image into an external SSD, and then boot another computer with this image, just like Ventoy boot with ISO files.
  3. Different bootable images can share common disk spaces.

If it possible, I can prepare a bootable external SSD with multiple distros and shared data. Then, I can test different distros on different computers.

Is the above idea possible? And if possible, which is the best solution now?

Vivodo
  • 505

1 Answers1

1

The way I would do it, and its pretty easy:

  • Create the file image (requires 16GB disk space in ~/) :

    $ truncate -s $((16 * 1024 * 1024)) ~/Linux.img
    
  • Create a loopback device for the file (assuming /dev/loop0 is available) :

    # losetup /dev/loop0 ~/Linux.img
    

If /dev/loop0 doesn't exist or is in use, consult google for creating additional loopback devices or try /dev/loopN)

  • Create a GPT partition table (optional) :

    # fdisk /dev/loop0
    g
    <enter>
    

You can also create your desired partitions while still in fdisk, that is up to you how you'd like it laid out.

  • Update the kernel so that it knows about your new partitons (optional)

    # partprobe /dev/loop0
    

Now you should see /dev/loop0pN partitions in the /dev directory.

At this point you an apply filesystems and install your distro according to their documentation from within your host OS, or you can skip the optional steps and fire up a vm with the ~/Linux.img or /dev/loop0 as a disk and the distro iso as cdrom and install normally. Just make sure you unmount any filesystems in the image and losetup -d /dev/loop0 before you turn the VM on.

When you want to send the image to your SSD you can either use the whole SSD using dd to write to directly to the disk /dev/sdX.

If you optionally created a partition table in the ~/Linux.img file, you can dd that to a partition on the SSD and use partprobe to reveal the underlying partition table and its partitions within the physical SSD partition as /dev/sdXNpN device files.

To make it bootable on physical machines you will have to modify the initrd to partprobe and boot those nested partitions, archlinux has great documentation on how to modify initrd images. Every distro is different though so you'd have to adjust to each one individually.

Hydranix
  • 991