Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.


  Search this Thread
Old 10-22-2010, 10:36 PM   #1
LQ Newbie
Registered: Jan 2010
Posts: 20

Rep: Reputation: 2
Chrooting a Linux distro inside another


This started out as a shoutout for help, but ended up being more of a HOWTO. Might as well since I couldn't readily find one online, although I didn't search long.

I wanted to run RPM related stuff on my friend's fast machine, which is running Ubuntu. I have a half-server/half-trashcan running Fedora 13, but is painfully slow to be compiling and building RPMs. So I wanted to run a chrooted Fedora inside his Ubuntu. Here's how I did it:
(These instructions should work for pretty much any other distros. Lines starting with # need to be done as root)

On the Fedora box, I created a 2 GB ext3 image:

$touch rootfs.ext3
$dd if=/dev/zero of=rootfs.ext3 bs=1k count=2M
$mke2fs -j rootfs.ext3
I then mounted it, and copied the Fedora's root filesystem on to it.
$mkdir rootfs
#mount -t ext3 -o loop rootfs.ext3 rootfs
$cp -r /bin /boot /etc /lib /sbin /srv /usr /var rootfs/        (you may copy /home as well if you want to copy your home files)
#umount rootfs
After copying the rootfs.ext3 file to the Ubuntu machine, I mounted it there, and remounted the special filesystems (/proc, /dev, /sys) inside it:

On the Ubuntu machine:

$mkdir rootfs
#mount -t ext3 -o loop rootfs.ext3 rootfs
#cd rootfs
#mount --bind /proc proc
#mount --bind /sys sys
#mount --bind /dev dev
#mount --bind /dev/pts dev/pts
#chroot . su -c zsh <MyFedoraUsername>               (Change "zsh" to "bash" if you use bash).
That's it. Any commands you run in here will execute with the Fedora files and libraries, and inside the Fedora jail.


I have found that "yum" was unable to connect to any of the repositories after doing this. I fixed that by changing all instances of "$releasever" in /etc/yum.repos.d/* to "13" (Since it was the rootfs of a Fedora13). This did the job:

#cd /etc/yum.repos.d
#for i in *; do sed -i $i -e "s/\$releasever/13/g"; done;
ROOT access inside the chroot:

I seem to be having a problem getting root access from inside the Fedora chroot. If I run "su", I get a "incorrect password" regardless of trying either password. The only way for me to currently get root access inside the chroot is to exit the chroot, then run:

#chroot . su -c zsh root
instead of

#chroot . su -c zsh <MyFedoraUsername>
If someone knows why that happens, or any other suggestions/tips I might have missed, please let me know and I'll try to make this a more complete HOWTO.

Last edited by bulls_i3; 10-23-2010 at 02:17 AM.
Old 10-25-2010, 02:05 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,986
Blog Entries: 14

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
Thanks for posting this.

Please mark the thread as "Solved" by going to thread tools. That way others will find it when looking for how to do it.
Old 10-27-2010, 05:07 PM   #3
Registered: Oct 2009
Distribution: Hackintosh, SlackWare
Posts: 267

Rep: Reputation: 30
Will this type of setup allow me to use devices whose drivers are in the chrooted environment from apps outside of the chroot.
You see. I got a canon MP240 all-in-one printer and so far the only linux drivers out there for it are designed for ubuntu only. And I wanted to know if it was possible to stuff a minimal, cli-only ubuntu with the canon drivers in it and have the printer recognized by all the apps running outside the chroot.
Old 10-28-2010, 03:51 AM   #4
LQ Newbie
Registered: Jan 2010
Posts: 20

Original Poster
Rep: Reputation: 2
By default, no.

But that's because applications, by default, look in /lib and /usr/lib. If your Ubuntu is jailed in /.ubuntu, then your apps that are outside of Ubuntu need to be told to look in /.ubuntu/lib and /.ubuntu/usr/lib.

I would imagine the simplest way of doing this would be to chroot a ubuntu, install the Canon drivers, then exit and symlink the canon drivers from /.ubuntu/usr/lib to /usr/lib.

Alternatively, you can just open the .deb file and copy the important files to the right location yourself.

PS I checked the Canon website and they make drivers in .deb and .rpm files. Link:


chroot, distro, jail, virtualization

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Chrooting into a Linux environment LXer Syndicated Linux News 0 06-29-2008 09:00 PM
Best Distro for a Dedicated Arcade Machine? (details inside) dryd kio Linux - Distributions 8 06-30-2006 10:15 PM
best distro for an old computer? (more details inside) mikewyatt Linux - Distributions 3 10-12-2004 07:12 PM
best distro....lot of details inside alaios Linux - Distributions 6 03-26-2004 01:54 PM > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 04:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration