Multiple distros on one partition
June 5, 2008 5:22 PM   Subscribe

I have Ubuntu installed in a chroot. [How] can I boot into it?

My system is running Debian stable, with a kernel from unstable. I've got an Ubuntu hardy install (created with debootstrap) in a directory on the same partition. Currently, I'm able to easily run programs in the chroot using the schroot command.

It seems like I should be able to modify something in my initfs to chroot into hardy early in the boot process, but I'm not sure how/where I need to make this change. Resizing partitions and keeping different distros on different partitions is the obvious thing to do, but I'd prefer a solution that works for any number of distros (which I can then copy on and off of my system whenever I feel like it) with a single partition. Any suggestions?
posted by finite to Computers & Internet (7 answers total)
 
I don't know how to do what you want with your current setup. My suggestion for the future would be to use LVM and create/resize/delete logical volumes for new distros to your heart's content.
posted by PueExMachina at 5:38 PM on June 5, 2008


I'm a little confused. Part of what you want seems to be something like Solaris zones, which you can get in the Linux world courtesy of tools like OpenVZ or a Linux V-Server setup; this will let you have multiple Linux environments running at once.

As for being able to chroot instead of your main distro, no idea, I'm afraid.
posted by rodgerd at 6:19 PM on June 5, 2008


Response by poster: Sorry for the confusion, rodgerd. I'm already able (using schroot) to run Ubuntu programs while booted in Debian. What I'm trying to figure out how to do is to modify my initrd so that it will chroot into Ubuntu before starting any system services, so that I'll be running the Ubuntu versions of everything (except the kernel).

PueExMachina, I am using LVM (etch's installer sets it up), and resizing is what I'll do if I can't figure out how to do this with a single partition.

The reason I don't want multiple partitions is that I'd like to be able to untar N distros, boot into each (one at a a time) and test some things, and then be able to delete them when I'm done. Slicing my drive into partitions means that my free space is not all in one place, unless I repartition again, which is an unwanted hassle.

I suspect that a one-line patch (involving the chroot command) to some file in the initrd will do what I want, but I don't know where to do it.
posted by finite at 6:49 PM on June 5, 2008


Hm. Have you looked at maybe emulation like VMWare to do your testing? That's usually how I do my tests of various distros. And it makes it easy to pack up and archive the thing as there's just a handful of files to put into a tarball and stick somewhere. When you want it back, you just untar it and off you go..
posted by barc0001 at 7:31 PM on June 5, 2008


Best answer: Hmm, guessing: Make a script that runs init within a chroot, and tell the kernel to run that instead of init.

Make an executable script at /usr/local/bin/chrootinit and put in it
#!/bin/sh
exec /usr/sbin/chroot /path/to/root /sbin/init $*
And then at boot time, stop the boot loader and send the kernel the additional parameters "init=/usr/local/bin/chrootinit"

The first process is in Unix land is "init". If you tell the kernel to run a script that chroots and then runs the init inside, it should pick up where you intend.

Note 1, this should not be used as a security measure to keep people inside your chroot sandbox. One can break out, with effort.

Note 2, this assumes you do not have anything essential to run the script on another filesystem than the root filesystem. This is rare these days, but still possible.
posted by cmiller at 8:58 PM on June 5, 2008


But it's not much of a hassle. You can delete a logical volumes and extend another one to take the free space while your system is running (assuming you're using a filesystem that supports online growth like ext3).
posted by PueExMachina at 10:44 PM on June 5, 2008


Response by poster: Thanks, cmiller, that was exactly what I was looking for! And I didn't even need to modify the initrd, after all!

I had to add a few things to my chrootinit script: mount --bind /proc /var/ubuntu/proc, and the same for /sys, and /dev, and mount -oremount,rw / (not sure why ubuntu's init scripts didn't do that, but they didn't) ... and I still haven't gotten wireless working yet (due to missing kernel modules) ... but for the most part, it works!

mount --bind / /var/ubuntu/var/debian (before chrooting) gives access to the underlying debian system from within the ubuntu chroot, btw.
posted by finite at 12:40 PM on June 6, 2008


« Older I had to check the proper conjugation of "swim"...   |   Sometimes beauty really does come from within Newer »
This thread is closed to new comments.