Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

Question:

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

share|improve this question
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
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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