November 10, 2006
Gentoo as an OS Inside a Chroot
Gentoo Linux might be the most versatile Linux distribution on the market. Many give it low marks because it forces you to compile everything. However, that feature provides the flexibility that you simply don't get with other operating systems.
I was growing tired recompiling LAMPS stacks on a few Redhat machines I maintain, and I decided there was a better way. I am now harnessing the power of Portage, Gentoo's package management tool, to build and maintain the custom LAMPS stacks.
The solution is simple: install Gentoo as a chroot'd operating system under a master operating system. This is much like running a virtual server, but the child operating system interacts directly with the parent's kernel, so there is practically no overhead. In case you didn't know, 'chroot' is a command on Linux that allows you to change the root directory of a process and all of its children. Basically, it allows you to sandbox a series of processes. It is commonly used to create "jail" environments where processes can execute without affecting files, directories outside of that program's directory. In our case, we install an operating system as a chroot'd program.
Creating a chroot'd Gentoo is a simple process:
- Download a stage 3 Gentoo archive and Portage snapshot
- Unpack the stage 3 and portage snapshot in a directory (/chroot/gentoo for example)
- Run
rm -Rf dev/*in the newly created directory - Mount proc and /dev in the new chroot via
mount -t proc none /chroot/gentoo/proc && mount -o bind /dev /chroot/gentoo/dev - Perform some minor steps to set up Gentoo
- Chroot to the new environment by running
chroot /chroot/gentoo /bin/bash - Enjoy
You now have a fully-functional Gentoo operating system on your machine. Use it to compile programs with ease. It is worth noting that if you intend to run daemon processes via /etc/init.d/ scripts in the child system, you need to go through some loops. I typically avoid Gentoo's init scripts and just use it to compile programs. It is so much easier than compiling programs manually.
Trackback
You can ping this entry by using http://blog.case.edu/gps10/mt-tb.cgi/11070 .
Comments
I wish there was a portage in Suse - I miss that. I do not miss recompiling everything and having dependencies break when I overlooked certain (sometimes dumb) things. I miss being able to keep all my LAMP applications up-to-date and secure. I hope some day someone will add a YAST repository with all the common PHP apps I use (wordpress, gallery2, phpcalendar, etc).