Hello.
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.
Problem:
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:
Code:
$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.
Code:
$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:
Code:
$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.
YUM NOTE:
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:
Code:
#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:
Code:
#chroot . su -c zsh root
instead of
Code:
#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.