# HG changeset patch # User Paul Boddie # Date 1306446942 -7200 # Node ID 5f0c57a96935c3aab5224864b1ba2d74d41e2952 # Parent 790947f9014bb0938fed6103ab386289ff972dc6 Added a device-mounting option for conventional chroot installations. Introduced extensive quoting throughout the scripts. diff -r 790947f9014b -r 5f0c57a96935 README.txt --- a/README.txt Sun May 30 19:47:11 2010 +0200 +++ b/README.txt Thu May 26 23:55:42 2011 +0200 @@ -42,7 +42,8 @@ * Removed specific apt- and dpkg-related scripts, replacing them with the general -do scripts. * Added --root options to certain scripts in order to support normal chroot - installations. + installations. Added --dev option for bind mounting of /dev in normal + chroot installations. * Added support for UML instance construction from distribution installations, along with networking support and a uml-net script. @@ -223,6 +224,29 @@ otherwise, this can potentially damage the main operating system installation on your computer. +Using the Host's Device Filesystem +---------------------------------- + +In root mode, the /dev filesystem on the host can be mounted by using the +--dev option with user-do: + +sudo user-do --root --dev + +Note that care must be taken not to delete the contents of this directory +within the installation while the above command is running. + +Enabling Audio in Root Mode +--------------------------- + +Together with the --root and --dev options, audio can be enabled for +applications within an installation by adding users to the audio group in +/etc/group. In addition, it may be necessary to run an audio manager daemon +depending on the system used to manage the audio on the host. + +For example, the artsd package may need installing in order to make the +corresponding artsdsp program available to applications within the package +manager. + Constructing UML Instances -------------------------- diff -r 790947f9014b -r 5f0c57a96935 uml-do --- a/uml-do Sun May 30 19:47:11 2010 +0200 +++ b/uml-do Thu May 26 23:55:42 2011 +0200 @@ -11,15 +11,15 @@ exit 1 fi -if [[ ! $1 ]]; then +if [ ! "$1" ]; then echo "$0 " exit 1 fi -export IMAGE=$UMLROOT/rootfs -export SWAPIMAGE=$UMLROOT/swap -export UML_MEMORY=$1 -export THIS_DIR=`dirname $0` +export IMAGE="$UMLROOT/rootfs" +export SWAPIMAGE="$UMLROOT/swap" +export UML_MEMORY="$1" +export THIS_DIR="`dirname $0`" # Discard the memory argument. @@ -27,12 +27,12 @@ # Test for networking. -if [[ $1 == '--net' ]]; then +if [ "$1" == '--net' ]; then export UML_NETWORKING="$NETDEVICE=tuntap,$TUNDEVICE,fe:fd:0:0:0:1,$HOSTADDRESS" - xhost +$GUESTADDRESS + xhost +"$GUESTADDRESS" shift 1 fi # Now we start the virtual machine... -$THIS_DIR/linux ubd0=$IMAGE ubd1=$SWAPIMAGE mem=$UML_MEMORY $UML_NETWORKING $* +"$THIS_DIR/linux" ubd0="$IMAGE" ubd1="$SWAPIMAGE" mem="$UML_MEMORY" "$UML_NETWORKING" $* diff -r 790947f9014b -r 5f0c57a96935 uml-net --- a/uml-net Sun May 30 19:47:11 2010 +0200 +++ b/uml-net Thu May 26 23:55:42 2011 +0200 @@ -11,18 +11,18 @@ exit 1 fi -if [[ $1 == "--start" ]]; then +if [ "$1" == "--start" ]; then chgrp adm /dev/net/tun - tunctl -u $2 -t $TUNDEVICE - ifconfig $TUNDEVICE $HOSTADDRESS up + tunctl -u "$2" -t "$TUNDEVICE" + ifconfig "$TUNDEVICE" "$HOSTADDRESS" up bash -c "echo 1 > /proc/sys/net/ipv4/ip_forward" - iptables -t nat -I POSTROUTING -o $NETDEVICE -j MASQUERADE - iptables -I FORWARD -i $TUNDEVICE -j ACCEPT - iptables -I FORWARD -o $TUNDEVICE -j ACCEPT + iptables -t nat -I POSTROUTING -o "$NETDEVICE" -j MASQUERADE + iptables -I FORWARD -i "$TUNDEVICE" -j ACCEPT + iptables -I FORWARD -o "$TUNDEVICE" -j ACCEPT -elif [[ $1 == "--stop" ]]; then +elif [ "$1" == "--stop" ]; then iptables -t nat -D POSTROUTING 1 iptables -D FORWARD 1 iptables -D FORWARD 1 - tunctl -d $TUNDEVICE + tunctl -d "$TUNDEVICE" fi diff -r 790947f9014b -r 5f0c57a96935 uml-postsetupfs --- a/uml-postsetupfs Sun May 30 19:47:11 2010 +0200 +++ b/uml-postsetupfs Thu May 26 23:55:42 2011 +0200 @@ -12,33 +12,33 @@ fi # Ensure that images have been set up. -if [ ! -e $UMLROOT ]; then +if [ ! -e "$UMLROOT" ]; then echo "No UML instances set up at $UMLROOT." exit 1 fi -export IMAGE=$UMLROOT/rootfs +export IMAGE="$UMLROOT/rootfs" -if [ ! -e $IMAGE ]; then +if [ ! -e "$IMAGE" ]; then echo "No image set up at $IMAGE." exit 1 fi -export IMAGEDIR=$UMLROOT/rootfsdir +export IMAGEDIR="$UMLROOT/rootfsdir" -if [ ! -e $IMAGEDIR ]; then - mkdir $IMAGEDIR +if [ ! -e "$IMAGEDIR" ]; then + mkdir "$IMAGEDIR" fi echo "Initialising device files..." -chroot $PACKAGEROOT /bin/bash -c 'mount -t proc proc /proc; cd /dev; ./MAKEDEV generic; umount /proc' +chroot "$PACKAGEROOT" /bin/bash -c 'mount -t proc proc /proc; cd /dev; ./MAKEDEV generic; umount /proc' echo "Accessing the image..." -mount -o loop $IMAGE $IMAGEDIR || exit 1 +mount -o loop "$IMAGE" "$IMAGEDIR" || exit 1 echo "Copying the filesystem into the image..." -cp -a $PACKAGEROOT/* $IMAGEDIR +cp -a "$PACKAGEROOT/"* "$IMAGEDIR" echo "Unmounting the image..." -umount $IMAGEDIR -rmdir $IMAGEDIR +umount "$IMAGEDIR" +rmdir "$IMAGEDIR" diff -r 790947f9014b -r 5f0c57a96935 uml-setupdev --- a/uml-setupdev Sun May 30 19:47:11 2010 +0200 +++ b/uml-setupdev Thu May 26 23:55:42 2011 +0200 @@ -17,9 +17,9 @@ for ((i=0; i<8; i++)) do let=$(echo $i|tr '0-7' 'a-z') - mknod $PACKAGEROOT/dev/ubd$let b 98 $[16 * $i] + mknod "$PACKAGEROOT/dev/ubd$let" b 98 $[16 * $i] for ((p=1; p<=16; p++)) do - mknod $PACKAGEROOT/dev/ubd$let$p b 98 $[16 * $i + $p] + mknod "$PACKAGEROOT/dev/ubd$let$p" b 98 $[16 * $i + $p] done done else diff -r 790947f9014b -r 5f0c57a96935 uml-setupfs --- a/uml-setupfs Sun May 30 19:47:11 2010 +0200 +++ b/uml-setupfs Thu May 26 23:55:42 2011 +0200 @@ -12,7 +12,7 @@ fi # Ensure arguments have been provided. -if [[ ! $1 || ! $2 ]]; then +if [[ ! "$1" || ! "$2" ]]; then echo "$0 " exit 1 fi @@ -20,18 +20,18 @@ # Make the UML instance directory if not already present. echo "Making the UML instance directory at $UMLROOT..." -if [ ! -e $UMLROOT ]; then - mkdir $UMLROOT +if [ ! -e "$UMLROOT" ]; then + mkdir "$UMLROOT" fi -export IMAGE=$UMLROOT/rootfs -export IMAGESIZE=$1 -export SWAPIMAGE=$UMLROOT/swap -export SWAPSIZE=$2 +export IMAGE="$UMLROOT/rootfs" +export IMAGESIZE="$1" +export SWAPIMAGE="$UMLROOT/swap" +export SWAPSIZE="$2" echo "Making the filesystem with size ${IMAGESIZE}GB..." -dd if=/dev/zero of=$IMAGE bs=1024 count=1 seek=$((${IMAGESIZE}*1024*1024-1024)) -mkfs.ext3 $IMAGE +dd if=/dev/zero of="$IMAGE" bs=1024 count=1 seek=$((${IMAGESIZE}*1024*1024-1024)) +mkfs.ext3 "$IMAGE" echo "Making the swap file with size ${SWAPSIZE}MB..." -dd if=/dev/zero of=$SWAPIMAGE bs=1M count=$SWAPSIZE +dd if=/dev/zero of="$SWAPIMAGE" bs=1M count="$SWAPSIZE" diff -r 790947f9014b -r 5f0c57a96935 user-do --- a/user-do Sun May 30 19:47:11 2010 +0200 +++ b/user-do Thu May 26 23:55:42 2011 +0200 @@ -1,5 +1,5 @@ #!/bin/bash -# Usage: user-enter [ --root ] [ ] +# Usage: user-do [ --root [ --dev ] ] [ ] # Configuration: if [ -e userinstall-defaults ]; then @@ -11,13 +11,28 @@ exit 1 fi -if [[ $1 == '--root' ]]; then +if [[ "$1" == '--root' ]]; then shift 1 - mount -o bind /proc $PACKAGEROOT/proc - mount -o bind /sys $PACKAGEROOT/sys - chroot $PACKAGEROOT $* - umount $PACKAGEROOT/proc - umount $PACKAGEROOT/sys + mount -o bind /proc "$PACKAGEROOT/proc" + mount -o bind /sys "$PACKAGEROOT/sys" + if [[ "$1" == '--dev' ]]; then + shift 1 + if [ -e "$PACKAGEROOT/dev.orig" ]; then + echo "Devices may already be defined for the installation." + else + mv "$PACKAGEROOT/dev" "$PACKAGEROOT/dev.orig" + mkdir "$PACKAGEROOT/dev" + mount -o bind /dev "$PACKAGEROOT/dev" + fi + fi + chroot "$PACKAGEROOT" $* + umount "$PACKAGEROOT/proc" + umount "$PACKAGEROOT/sys" + if [ -e "$PACKAGEROOT/dev.orig" ]; then + umount "$PACKAGEROOT/dev" + rmdir "$PACKAGEROOT/dev" + mv "$PACKAGEROOT/dev.orig" "$PACKAGEROOT/dev" + fi else - fakeroot fakechroot $FAKECHROOT_OPTIONS chroot $PACKAGEROOT $* + fakeroot fakechroot $FAKECHROOT_OPTIONS chroot "$PACKAGEROOT" $* fi diff -r 790947f9014b -r 5f0c57a96935 user-path --- a/user-path Sun May 30 19:47:11 2010 +0200 +++ b/user-path Thu May 26 23:55:42 2011 +0200 @@ -11,4 +11,4 @@ exit 1 fi -echo $PACKAGEROOT/$1 +echo "$PACKAGEROOT/$1" diff -r 790947f9014b -r 5f0c57a96935 user-postsetup --- a/user-postsetup Sun May 30 19:47:11 2010 +0200 +++ b/user-postsetup Thu May 26 23:55:42 2011 +0200 @@ -1,5 +1,5 @@ #!/bin/bash -# Usage: user-postsetup [ --root ] [ ] +# Usage: user-postsetup [ --root [ --dev ] ] [ ] # Configuration: if [ -e userinstall-defaults ]; then @@ -11,51 +11,51 @@ exit 1 fi -if [[ $1 && $1 == '--root' ]]; then +if [[ "$1" && "$1" == '--root' ]]; then export AS_ROOT=' --root' - export COUNTRY=$2 -else - export COUNTRY=$1 + shift 1 fi -export THIS_DIR=`dirname $0` +export COUNTRY="$1" + +export THIS_DIR="`dirname $0`" echo "Copying host DNS configuration..." -cp /etc/resolv.conf $PACKAGEROOT/etc/ +cp /etc/resolv.conf "$PACKAGEROOT/etc/" echo "Copying filesystems configuration..." -cp /etc/fstab $PACKAGEROOT/etc/ +cp /etc/fstab "$PACKAGEROOT/etc/" echo "Copying network configuration..." -cp /etc/hosts $PACKAGEROOT/etc/ -cp /etc/network/interfaces $PACKAGEROOT/etc/network/ +cp /etc/hosts "$PACKAGEROOT/etc/" +cp /etc/network/interfaces "$PACKAGEROOT/etc/network/" echo "Copying package repository configuration..." -if [[ $USERINSTALL_CODENAME == $DISTRIB_CODENAME ]]; then - cp /etc/apt/sources.list $PACKAGEROOT/etc/apt/ -elif [ -e $USERINSTALL_CODENAME/sources.list ]; then - cp $USERINSTALL_CODENAME/sources.list $PACKAGEROOT/etc/apt/ +if [ "$USERINSTALL_CODENAME" == "$DISTRIB_CODENAME" ]; then + cp /etc/apt/sources.list "$PACKAGEROOT/etc/apt/" +elif [ -e "$USERINSTALL_CODENAME/sources.list" ]; then + cp "$USERINSTALL_CODENAME/sources.list" "$PACKAGEROOT/etc/apt/" else echo "Attempting to generate a repository definition for $USERINSTALL_CODENAME." - $THIS_DIR/user-makesources $PACKAGEROOT/etc/apt/sources.list $COUNTRY + "$THIS_DIR/user-makesources" "$PACKAGEROOT/etc/apt/sources.list" "$COUNTRY" fi -if [[ $AS_ROOT ]]; then +if [ "$AS_ROOT" ]; then echo "Mounting filesystems..." - $THIS_DIR/user-do$AS_ROOT mount -t proc proc /proc + "$THIS_DIR/user-do$AS_ROOT" mount -t proc proc /proc fi echo "Updating package details and upgrading..." -$THIS_DIR/user-do$AS_ROOT apt-get update -$THIS_DIR/user-do$AS_ROOT apt-get upgrade +"$THIS_DIR/user-do$AS_ROOT" apt-get update +"$THIS_DIR/user-do$AS_ROOT" apt-get upgrade -if [[ $AS_ROOT ]]; then +if [ "$AS_ROOT" ]; then echo "Configuring a root installation..." - $THIS_DIR/user-do$AS_ROOT apt-get install locales console-data - $THIS_DIR/user-do$AS_ROOT dpkg-reconfigure locales - $THIS_DIR/user-do$AS_ROOT dpkg-reconfigure tzdata - $THIS_DIR/user-do$AS_ROOT dpkg-reconfigure console-data + "$THIS_DIR/user-do$AS_ROOT" apt-get install locales console-data + "$THIS_DIR/user-do$AS_ROOT" dpkg-reconfigure locales + "$THIS_DIR/user-do$AS_ROOT" dpkg-reconfigure tzdata + "$THIS_DIR/user-do$AS_ROOT" dpkg-reconfigure console-data echo "Unmounting filesystems..." - $THIS_DIR/user-do$AS_ROOT umount /proc + "$THIS_DIR/user-do$AS_ROOT" umount /proc fi diff -r 790947f9014b -r 5f0c57a96935 user-setup --- a/user-setup Sun May 30 19:47:11 2010 +0200 +++ b/user-setup Thu May 26 23:55:42 2011 +0200 @@ -11,7 +11,7 @@ exit 1 fi -if [[ $1 == "--help" ]]; then +if [ "$1" == "--help" ]; then echo "Usage: user-setup [ --root ] [ ]" echo echo "Examples:" @@ -23,18 +23,18 @@ exit 1 fi -if [[ $1 && $1 == '--root' ]]; then +if [[ "$1" && "$1" == '--root' ]]; then export AS_ROOT=' --root' - export MIRROR=$2 + export MIRROR="$2" else - export MIRROR=$1 + export MIRROR="$1" fi -if [[ $AS_ROOT ]]; then - debootstrap --include=gnupg,$KEYRING $USERINSTALL_CODENAME $PACKAGEROOT $MIRROR +if [ "$AS_ROOT" ]; then + debootstrap --include="gnupg,$KEYRING" "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" else - fakeroot fakechroot $FAKECHROOT_OPTIONS debootstrap --variant=fakechroot --include=gnupg,$KEYRING \ - $USERINSTALL_CODENAME $PACKAGEROOT $MIRROR + fakeroot fakechroot $FAKECHROOT_OPTIONS debootstrap --variant=fakechroot --include="gnupg,$KEYRING" \ + "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" fi echo diff -r 790947f9014b -r 5f0c57a96935 user-to-uml --- a/user-to-uml Sun May 30 19:47:11 2010 +0200 +++ b/user-to-uml Thu May 26 23:55:42 2011 +0200 @@ -13,35 +13,35 @@ echo "Removing any linked /dev entry..." if [ -h "$PACKAGEROOT/dev" ]; then - rm $PACKAGEROOT/dev - mkdir $PACKAGEROOT/dev + rm "$PACKAGEROOT/dev" + mkdir "$PACKAGEROOT/dev" fi cp /dev/MAKEDEV $PACKAGEROOT/dev echo "Removing any linked /proc entry..." if [ -h "$PACKAGEROOT/proc" ]; then - rm $PACKAGEROOT/proc - mkdir $PACKAGEROOT/proc + rm "$PACKAGEROOT/proc" + mkdir "$PACKAGEROOT/proc" fi echo "Using a special fstab..." if [ -e "$PACKAGEROOT/etc/fstab" ]; then if [ ! -e "$PACKAGEROOT/etc/fstab.orig" ]; then - mv $PACKAGEROOT/etc/fstab $PACKAGEROOT/etc/fstab.orig + mv "$PACKAGEROOT/etc/fstab" "$PACKAGEROOT/etc/fstab.orig" fi fi -cp `dirname $0`/UML/fstab $PACKAGEROOT/etc/fstab +cp "`dirname $0`/UML/fstab" "$PACKAGEROOT/etc/fstab" # Tweak the inittab to only use tty0 and add it to securetty. echo "Reconfiguring the console settings..." if [ ! -e "$PACKAGEROOT/etc/inittab.orig" ]; then - cp $PACKAGEROOT/etc/inittab $PACKAGEROOT/etc/inittab.orig - grep -v "getty" $PACKAGEROOT/etc/inittab.orig > $PACKAGEROOT/etc/inittab - echo "# We launch just one console for UML:" >> $PACKAGEROOT/etc/inittab - echo "c0:1235:respawn:/sbin/getty 38400 tty0 linux" >> $PACKAGEROOT/etc/inittab + cp "$PACKAGEROOT/etc/inittab" "$PACKAGEROOT/etc/inittab.orig" + grep -v "getty" "$PACKAGEROOT/etc/inittab.orig" > "$PACKAGEROOT/etc/inittab" + echo "# We launch just one console for UML:" >> "$PACKAGEROOT/etc/inittab" + echo "c0:1235:respawn:/sbin/getty 38400 tty0 linux" >> "$PACKAGEROOT/etc/inittab" - echo "# UML modification: use tty0 or vc/0" >> $PACKAGEROOT/etc/securetty - echo "tty0" >> $PACKAGEROOT/etc/securetty - echo "vc/0" >> $PACKAGEROOT/etc/securetty + echo "# UML modification: use tty0 or vc/0" >> "$PACKAGEROOT/etc/securetty" + echo "tty0" >> "$PACKAGEROOT/etc/securetty" + echo "vc/0" >> "$PACKAGEROOT/etc/securetty" fi diff -r 790947f9014b -r 5f0c57a96935 userinstall-defaults --- a/userinstall-defaults Sun May 30 19:47:11 2010 +0200 +++ b/userinstall-defaults Thu May 26 23:55:42 2011 +0200 @@ -16,5 +16,5 @@ # Configuration details for building and using a personal package manager. -export PACKAGEROOT=$HOME/.userinstall +export PACKAGEROOT="$HOME/.userinstall" export KEYRING=$(echo $USERINSTALL_ID | tr '[:upper:]' '[:lower:]')-keyring diff -r 790947f9014b -r 5f0c57a96935 userinstall-defaults-uml --- a/userinstall-defaults-uml Sun May 30 19:47:11 2010 +0200 +++ b/userinstall-defaults-uml Thu May 26 23:55:42 2011 +0200 @@ -12,7 +12,7 @@ # Configuration details for building a UML instance. -export UMLROOT=$HOME/.userinstall-uml +export UMLROOT="$HOME/.userinstall-uml" # Optional settings. # Guest: the address used inside the UML instance