slitaz-doc-wiki-data view pages/en/guides/chroot.txt @ rev 7

Add pages/en folder.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Feb 26 12:17:18 2011 +0000 (2011-02-26)
parents
children
line source
1 ====== Chroot =======
3 This guide explain how to setup a chroot to cook packages in a separate environment. The chroot can be built on a USB or HDD device to save RAM when using a live session. There is also a script which removes any packages installed during cooking on exit in order to keep the chroot light and also checks the build_depends.
5 ===== With Tazdev =====
7 Over time the SliTaz developers created tools for the automation of various tasks. The slitaz-dev-tools package provides the tazdev utility and its configuration file /etc/slitaz/tazdev.conf; it can create a chroot to use:
9 <code>
10 # tazpkg get-install slitaz-dev-tools
11 # tazdev gen-chroot
12 # tazdev chroot
13 </code>
15 By default the chroot is created in ///home/slitaz/cooking/chroot// and is slitaz-based. For more info and available commands you can use 'tazdev usage' and/or take a look at the configuration file.
17 ===== Create the chroot =====
18 <file>
19 #!/bin/sh
20 mkdir /home/chroot
21 # You can mount a device to /home/chroot
22 # with mountbox or mount
23 tazpkg get-install busybox --root="/home/chroot"
24 echo "No" | tazpkg get-install bash --root="/home/chroot"
25 tazpkg get-install slitaz-toolchain --root="/home/chroot"
26 tazpkg get-install tazwok --root="/home/chroot"
27 tazpkg get-install tazpkg --root="/home/chroot"
28 tazpkg get-install lzma --root="/home/chroot"
29 mkdir /home/chroot/home/slitaz</file>
31 Note, you can keep these lines in a script file if needed. Just add #!/bin/sh to the first line and make executable with:
32 <code># chmod +x script_file</code>
34 ===== Add a script file to automate some actions =====
36 <code># cat > /home/chroot/chroot_script.sh << "EOF"</code>
37 <file>
38 #!/bin/sh
39 /bin/sh --login
40 for pkg in $(cat /var/log/tazpkg.log | grep -v Removed | sed 's/\(.*\)\(- Installed - \)\(.*\)\( (.*\)/\3/'); do
41 echo "y" | tazpkg remove $pkg
42 done
43 rm /var/log/tazpkg.log
45 EOF
46 </file>
47 <code># chmod +x "/home/chroot/chroot_script.sh"</code>
49 Note, /bin/sh --login logs you into the chrooted environment. The commands after that auto-remove any packages added when cooking on exit. You can hack this file to execute various automated actions when entering and exiting the chroot.
51 ===== Add a script to mount and umount chroot =====
53 <code># cat > /usr/bin/tazchroot << "EOF"</code>
54 <file>
55 #!/bin/sh
56 cat /etc/resolv.conf > /home/chroot/etc/resolv.conf
57 if [ ! -d "/home/chroot/proc/1" ]; then
58 echo "Mounting virtual filesystems..."
59 mount -t proc proc /home/chroot/proc
60 mount -t sysfs sysfs /home/chroot/sys
61 mount -t devpts devpts /home/chroot/dev/pts
62 mount -t tmpfs shm /home/chroot/dev/shm
63 mount /home/slitaz /home/chroot/home/slitaz
64 chroot /home/chroot ./chroot_script.sh
65 until [ "$ps" = "2" ]; do
66 echo "Waiting for the end of all other chroot processes..."
67 ps=$(ps | grep `basename $0` | grep -v grep | grep -v basename | wc -l)
68 sleep 1
69 done
70 umount /home/chroot/home/slitaz
71 umount /home/chroot/dev/shm
72 umount /home/chroot/dev/pts
73 umount /home/chroot/sys
74 umount /home/chroot/proc
75 else
76 echo "The chroot is already mounted"
77 fi
78 EOF
79 </file>
80 <code># chmod +x /usr/bin/tazchroot</code>
82 Note, this script mounts ///home/slitaz// in your chroot, so you can use tazwok as if it was in your normal environment.
84 ----
85 \\
86 ^ Page Review Section ^^
87 |Quality| Good |
88 |Review| Minor Updates |
89 |Priority| Medium |
90 |Problems| add a [[http://forum.slitaz.org|forum post link]]|
91 |::: | OR add a [[http://labs.slitaz.org/issues |lab issue tracker link ]]|
92 |How to Improve| Suggest briefly|
93 |::: | |
95 \\
96 ----