I have Linux (Debian Jessie) installed on a hard drive. Drive - sda1, ext4fs, and sda2 - swap

I have a /chroot folder. There is installed another system, in /chroot folder.


How to tell the bootmanager, to boot not the primary system (main, Debian Jessie), but system in /chroot? Probably, change /menu.lst and /chroot/etc/fstab? (vmlinuz root=/dev/sda1/chroot?)

Or another variant of question: is it possible, to have linux installed not into root directory of partition, but in folder? (/another_linux/bin, /another_linux/home, /another_linux/etc, ...)

  • 1
    vmlinuz root=/dev/sda1/chroot won't work. One probably could simulate this with a method similar to what is used in initrd. See e.g. here. You mount /new_root as described there, then instead of cd /new_root do cd /new_root/chroot and continue. – n.m. Aug 6 '13 at 18:06

This cannot be done by the bootloader or kernel. The parameter to the kernel root option such as in root=/dev/sda1 looks like a standard Unix pathname, but such pathnames are interpreted according to currently mounted filesystem. At the time the root option is interpreted, there are no mounted filesystems. Well, almost none. At kernel initialization time there is an instance of a minimal ramfs filesystem called rootfs mounted as the root for the initial process running start_kernel(). The actual interpretation of the root option parameter is done in a routine called name_to_dev_t(). One of the supported syntaxes is the /dev/name format, where the name is interpreted by doing a temporary mount of the sysfs filesystem in the rootfs root, and looking for a block device entry matching name under /sys/block. This process is explained in more detail here.

The setup as described would need to be done by first booting into a minimal environment such as one provided by an initrd, mount the real root filesystem from /dev/sda1 at a temporary mountpoint, e.g. /mnt/rootfs, then change the root directory to /mnt/rootfs/chroot using pivot_root(8).

This is somewhat similar to how the root filesystems for LinuX Containers (LXC) are setup. LXC is an operating system-level virtualization implementation for Linux. Operating system-level virtualization is commonly used in virtual hosting environments as a lightweight alternative to full virtualization managed by a hypervisor. In operating system-level virtualization, a single operating system kernel is shared among multiple isolated user-space instances. Each instance, often called container, jail, Virtual Private Server (VPE) or Virtual Environment (VE), is essentially a separate operating system installation housed in a directory of its own on the host system.


I came across the same issue and ended up writing this to make it work painlessly across different systems (debian, ubuntu currently):

Run make_chroot_initrd script to create a new chroot-enabled initrd image from the existing one:

#  ./make_chroot_initrd /chroot/trusty/boot/initrd.img-3.13.0-32-generic
making new initrd: /chroot/trusty/boot/initrd.img-3.13.0-32-generic.chroot

The new image will be exactly the same, except now it can handle a chroot= boot parameter.

With grub2 as bootloader you can add an entry to /boot/grub/grub.cfg:
(or perhaps better /etc/grub.d/40_custom)

menuentry "ubuntu trusty, (linux 3.13.0-32) (chroot)" {
    insmod ext2                       # or whatever you're using ...
    set root='(hd0,7)'                # partition containing the chroot
    set chroot='/chroot/trusty'       # chroot path
    linux   $chroot/boot/vmlinuz-3.13.0-32-generic root=/dev/sda7 chroot=$chroot rw
    initrd  $chroot/boot/initrd.img-3.13.0-32-generic.chroot

(change files/partitions to match yours)

System-wide install

Once you're happy with it you can make the changes permanent
(until initramfs-tools package gets upgraded).
In the chrooted system:

# cd /usr/share/initramfs-tools
# cp -pdrv .  ../initramfs-tools.orig       # backup
# patch -p1 < path_to/boot_chroot/initrd.patch
# rm *.orig */*.orig
# update-initramfs -u

From now on regular initrd image will support chroot booting.
No need to use a separate initrd.chroot which may get out of sync with it then.

See boot_chroot for details.


Yes, you can do the trick using Btrfs subvolumes.

First you need to convert ext4 to btrfs as described here.

Convert your chroot to subvilume if it is not yet:

 sudo mv /path/to/chroot /path/to/chroot-tmp
 sudo btrfs subvol create /path/to/chroot
 sudo mv /path/to/chroot-tmp/* /path/to/chroot
 sudo mv /path/to/chroot-tmp/* /path/to/chroot -r # for directories

Now you have subvolume named path/to/chroot. You can check it with sudo btrfs subvol list /

Now you can create boot to subvolume record in grub. Just add rootflags=subvol=path/to/chroot to linux kernel load string in grub menu item or use this to probe automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.