Difference between revisions of "Chroot notes"

From Noah.org
Jump to: navigation, search
m (Copy an existing root filesystem)
m (Copy an existing root filesystem)
Line 5: Line 5:
  
 
This script copies an existing rootfs to one that is to be used in a chroot environment. This copies '''everything''', so it should give you a full environment with everything you need to run anything that would run under the original rootfs. The copy rootfs should look and work exactly like the original. This is useful for creating new versions of rootfs images in embedded systems. This is not efficient if you just want to run a single program under a jail, but this eliminates any doubts and should always "just work".
 
This script copies an existing rootfs to one that is to be used in a chroot environment. This copies '''everything''', so it should give you a full environment with everything you need to run anything that would run under the original rootfs. The copy rootfs should look and work exactly like the original. This is useful for creating new versions of rootfs images in embedded systems. This is not efficient if you just want to run a single program under a jail, but this eliminates any doubts and should always "just work".
 +
 +
There are some fuzzy parts here. Copying /var from a running system is questionable.
  
 
<pre>
 
<pre>
Line 27: Line 29:
 
cp -a /usr .
 
cp -a /usr .
 
cp -a /var .
 
cp -a /var .
## # Enter the chroot jail, which should look exactly like the real rootfs.
+
## # Enter the chroot jail, which should look exactly like the original rootfs.
 
## chroot ${TARGET_DIR} /bin/bash -l
 
## chroot ${TARGET_DIR} /bin/bash -l
 
## # The /proc and /sys filesystems may need to be remounted inside the jail.
 
## # The /proc and /sys filesystems may need to be remounted inside the jail.

Revision as of 13:55, 7 September 2010


Copy an existing root filesystem

This script copies an existing rootfs to one that is to be used in a chroot environment. This copies everything, so it should give you a full environment with everything you need to run anything that would run under the original rootfs. The copy rootfs should look and work exactly like the original. This is useful for creating new versions of rootfs images in embedded systems. This is not efficient if you just want to run a single program under a jail, but this eliminates any doubts and should always "just work".

There are some fuzzy parts here. Copying /var from a running system is questionable.

#!/bin/sh
## mount /dev/sda1 /media/adhoc
## debootstrap jaunty /media/adhoc/rootfs/ http://ports.ubuntu.com/
## cd /media/adhoc/rootfs
TARGET_DIR=$1
cd ${TARGET_DIR}
cp -a /bin .
cp -a /boot .
cp -a /dev .
cp -a /etc .
cp -a /home .
cp -a /lib .
cp --preserve=all --no-dereference /media .
cp --preserve=all --no-dereference /mnt .
cp -a /opt .
cp -a /root .
cp -a /sbin .
cp --preserve=all --no-dereference /srv .
cp -a /usr .
cp -a /var .
## # Enter the chroot jail, which should look exactly like the original rootfs.
## chroot ${TARGET_DIR} /bin/bash -l
## # The /proc and /sys filesystems may need to be remounted inside the jail.
## mount -t proc proc /proc
## mount -t sysfs sysfs /sys