0

Everything in Linux-based systems is a file. Everytime I install Ubuntu, I choose a root partition. Now, I want to create a root filesystem, but in a file, for example ~/ubuntu.img. I've got another Linux distro (based on Ubuntu) as the main OS. Is there a way to install (s)ubiquity and select ~/ubuntu.img as the root filesystem? As far as I know, the installer mounts the root filesystem at /target and uses chroot. Maybe I can mount my root filesystem there and install manually?

I want to do this because:

  1. I don't want to install more than 1 OS and dual boot.
  2. My main OS doesn't support some packages or has some dependency issues when I want to compile some projects.

If I'm able to install Ubuntu this way, I'll use chroot to install packages inside the root filesystem image.

adazem009
  • 1,212

2 Answers2

0

I've managed to mount the image from this answer. You can use this link to download it.

For some reason I wasn't able to read the image directly using tools like parted, cfdisk or fdisk. I had to flash the image into a 16GB (or more) USB drive, and then copy the root partition using dd, or the GNOME Disk utility.

So, I copied the root partition to ~/ubuntu.img and set up the chroot environment:

cd # go to the directory where the root filesystem image is located
mkdir ubuntu
sudo mount -o loop ubuntu.img ubuntu
sudo mount -t proc /proc ./ubuntu/proc
sudo mount -t sysfs /sys ./ubuntu/sys
sudo mount -o bind /dev ./ubuntu/dev
sudo chroot ./ubuntu

I can even access USB devices from the chroot environment.

You've probably noticed that the internet connection works only partially - you can ping any server if you specify the IP address, but domains can't be resolved. This command should fix it:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

The downside of this method is that you always have to prepare the chroot environment if you need to access USB devices. But, that can be simplified by writing a shell script.

To clean up after you leave the chroot environment (and no processes are running there):

sudo umount ./ubuntu/{proc,sys,dev}
sudo umount ./ubuntu

I think there's a way to manually install Ubuntu on top of a base system. There are tools like debootstrap, but I didn't try that. Feel free to post another answer with that :)

adazem009
  • 1,212
0

What you suggest is essentially the idea behind a virtual machine. Why not simply use VirtualBox and install Ubuntu as a VirtualBox VM?

HuHa
  • 3,525