Tuesday November 28, 2006 02:52
Development Platform The chroot Way
Posted by as Information Insemination
As opposed to some people, I prefer to use chroot rather than qemu ( or vmware, etc2, just name it) when doing my development, whenever possible. By this I don’t need to worry about damaging my system, and not having to deal with overheads introduced by virtualisation.
What I use for the purpose are my 40GB removable harddisk, and gentoo’s stage3 install package. Here’s how it goes;
shakir@herugrim ~ $ cat temp/bin/xxusbhd
#!/bin/bash
MOUNT=/mnt/usbhd
sudo mkdir $MOUNT
sudo mount -t reiserfs -o exec,rw /dev/`cat /proc/partitions | grep 39069680 | gawk ‘{ print $4 }’` $MOUNT
shakir@herugrim ~ $ temp/bin/xxusbhd
shakir@herugrim ~ $ cd /mnt/usbhd/chroot/uclinux/
shakir@herugrim /mnt/usbhd/chroot/uclinux $ cat /home/shakir/temp/bin/xxchroot.gentoo
#!/bin/bash
sudo mkdir -p usr/portage/distfiles
sudo mount –bind /usr/portage usr/portage
sudo mount –bind /home/gentoo/distfiles/ usr/portage/distfiles
sudo mount –bind /dev dev/
sudo mount –bind /proc proc/
sudo chroot . /bin/bash
sudo umount dev/
sudo umount proc/
sudo umount usr/portage/distfiles/
sudo umount usr/portage/
## Second check
echo "## Second check.. Please ignore the errors"
sudo umount dev/
sudo umount proc/
sudo umount usr/portage/distfiles/
sudo umount usr/portage/
shakir@herugrim /mnt/usbhd/chroot/uclinux $ /home/shakir/temp/bin/xxchroot.gentoo
herugrim / # ls -l
total 12
drwxr-xr-x 2 root root 3464 Aug 3 15:39 bin
drwxr-xr-x 2 root root 96 Aug 3 14:24 boot
drwxr-xr-x 14 root root 13280 Nov 28 08:37 dev
drwxr-xr-x 30 root root 2336 Nov 28 08:18 etc
drwxr-xr-x 2 root root 72 Aug 3 14:23 home
drwxr-xr-x 7 root root 3736 Nov 10 11:45 lib
drwxr-xr-x 4 root root 120 Aug 3 14:23 mnt
-rw-r–r– 1 root root 0 Nov 14 12:57 modules.dep
drwxr-xr-x 2 root root 72 Aug 3 14:23 opt
dr-xr-xr-x 79 root root 0 Nov 28 08:36 proc
drwx—— 2 root root 72 Aug 3 15:39 root
drwxr-xr-x 2 root root 3344 Aug 3 15:39 sbin
drwxr-xr-x 2 root root 72 Aug 3 14:23 sys
drwxrwxrwt 2 root root 80 Nov 28 08:18 tmp
drwxr-xr-x 18 root root 744 Nov 28 08:18 uClinux-dist
drwxr-xr-x 13 root root 368 Nov 9 12:17 usr
drwxr-xr-x 12 root root 288 Aug 3 15:38 var
herugrim / # exit
exit
## Second check.. Please ignore the errors
umount: dev/: not mounted
umount: proc/: not mounted
umount: usr/portage/distfiles/: not mounted
umount: usr/portage/: not mounted
shakir@herugrim /mnt/usbhd/chroot/uclinux $ cd
shakir@herugrim ~ $ cat temp/bin/xxusbhd.clean
#!/bin/bash
MOUNT=/mnt/usbhd
sudo umount $MOUNT
sudo rmdir $MOUNT
shakir@herugrim ~ $ /home/shakir/temp/bin/xxusbhd.clean
shakir@herugrim ~ $ ls /mnt/
cdrom cf floppy sdb1 sdc1 thumb windoze
shakir@herugrim ~ $
Terminal’s output copy-paste is a lazy but definitive way of explaining this (stress on the later
).. /home/shakir/temp/bin is actually already in my path, and so I just need to type my script’s name to execute it (please refer to my previous post).