# HG changeset patch # User Paul Boddie # Date 1310510591 -7200 # Node ID ca9bfaf0c7bf96ec756ce3c5172b207a01953f63 # Parent 5c388118c8fc46cd198cfbb23fa7c273dac81fdb Made it possible to make a UML image from a root install. Changed root operations to invoke sudo internally where appropriate or to invoke other scripts using a --root option. Moved the root user-do functionality into a separate script. Added some help texts. Fixed echo statements to use standard error for messages. diff -r 5c388118c8fc -r ca9bfaf0c7bf README.txt --- a/README.txt Tue Jul 12 00:47:20 2011 +0200 +++ b/README.txt Wed Jul 13 00:43:11 2011 +0200 @@ -101,7 +101,7 @@ sudo mount -o loop /home/me/downloads/kubuntu-7.04-alternate-i386.iso /tmp/cdrom user-setup file:///tmp/cdrom -An URI must be specified as the "mirror" location, not a normal filename. +A URL must be specified as the "mirror" location, not a normal filename. Once the installation is complete, some post-installation is necessary: @@ -211,12 +211,12 @@ option which sets up a package manager for a user with root privileges. To set up such an installation, the following commands can be used: -sudo user-setup --root -sudo user-postsetup --root +user-setup --root +user-postsetup --root Entering the installation is done using the user-do script: -sudo user-do --root +user-do --root Note that in root mode, the /proc and /sys filesystems are mounted within the installation. Care must be taken not to delete the contents of these @@ -230,7 +230,7 @@ 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 +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. @@ -289,3 +289,8 @@ to allocate to the instance: uml-do 512M + +Specifying the --net option allows networking to be used by the instance, if +set up as described above: + +uml-do 512M --net diff -r 5c388118c8fc -r ca9bfaf0c7bf uml-do --- a/uml-do Tue Jul 12 00:47:20 2011 +0200 +++ b/uml-do Wed Jul 13 00:43:11 2011 +0200 @@ -12,7 +12,7 @@ PROGNAME=`basename "$0"` -if [ ! "$1" ]; then +if [ ! "$1" ] || [ "$1" = '--help' ]; then echo "Usage: $PROGNAME [ --net ]" 1>&2 exit 1 fi diff -r 5c388118c8fc -r ca9bfaf0c7bf uml-make-image --- a/uml-make-image Tue Jul 12 00:47:20 2011 +0200 +++ b/uml-make-image Wed Jul 13 00:43:11 2011 +0200 @@ -10,14 +10,26 @@ exit 1 fi +if [ "$1" = '--help' ]; then + echo "Usage: `basename $0` [ --root ] " 1>&2 + exit 1 +fi + +if [ "$1" = '--root' ]; then + shift 1 + AS_USER="sudo" +else + AS_USER= +fi + if [ ! "$1" ]; then - echo "Need a root image size in GB." 1>&2 - exit 1 + echo "Need a root image size in GB." 1>&2 + exit 1 fi if [ ! "$2" ]; then - echo "Need a swap image size in MB." 1>&2 - exit 1 + echo "Need a swap image size in MB." 1>&2 + exit 1 fi IMAGESIZE=$1 @@ -25,13 +37,13 @@ THISDIR=`dirname "$0"` if [ ! -e "$PACKAGEROOT" ]; then - echo "A package root must first be made using user-setup." 1>&2 - exit 1 + echo "A package root must first be made using user-setup." 1>&2 + exit 1 fi if [ ! "$IMAGEDIR" ]; then - echo "An image directory must be defined." 1>&2 - exit 1 + echo "An image directory must be defined." 1>&2 + exit 1 fi echo "Making the filesystem with size ${IMAGESIZE}GB..." @@ -43,5 +55,5 @@ # Image population activities. -"$THISDIR/uml-access-image" "$THISDIR/uml-populate-image" -"$THISDIR/uml-access-image" "$THISDIR/uml-make-network" +"$AS_USER" "$THISDIR/uml-access-image" "$THISDIR/uml-populate-image" +"$AS_USER" "$THISDIR/uml-access-image" "$THISDIR/uml-make-network" diff -r 5c388118c8fc -r ca9bfaf0c7bf uml-make-network --- a/uml-make-network Tue Jul 12 00:47:20 2011 +0200 +++ b/uml-make-network Wed Jul 13 00:43:11 2011 +0200 @@ -17,7 +17,7 @@ fi if [ ! -e "$IMAGEDIR/etc/hosts" ]; then - echo "Creating hosts file..." + echo "Creating hosts file..." 1>&2 echo "$GUESTADDRESS $GUESTNAME" > "$IMAGEDIR/etc/hosts" echo "127.0.0.1 localhost" >> "$IMAGEDIR/etc/hosts" echo "$HOSTADDRESS $HOSTNAME" >> "$IMAGEDIR/etc/hosts" @@ -30,7 +30,7 @@ fi if [ ! -e "$IMAGEDIR/etc/network/interfaces" ]; then - echo "Creating network configuration..." + echo "Creating network configuration..." 1>&2 echo "auto lo" > "$IMAGEDIR/etc/network/interfaces" echo "iface lo inet loopback" >> "$IMAGEDIR/etc/network/interfaces" echo "iface eth0 inet static" >> "$IMAGEDIR/etc/network/interfaces" diff -r 5c388118c8fc -r ca9bfaf0c7bf uml-populate-image --- a/uml-populate-image Tue Jul 12 00:47:20 2011 +0200 +++ b/uml-populate-image Wed Jul 13 00:43:11 2011 +0200 @@ -25,23 +25,35 @@ echo "Installing the package root..." 1>&2 cp -a "$PACKAGEROOT/"* "$IMAGEDIR"/ -echo "Removing any linked /dev entry..." 1>&2 if [ -h "$IMAGEDIR/dev" ]; then + echo "Removing linked /dev entry..." 1>&2 rm "$IMAGEDIR/dev" fi +if [ -e "$IMAGEDIR/dev" ]; then + echo "Moving existing /dev directory..." 1>&2 + mv "$IMAGEDIR/dev" "$IMAGEDIR/dev.old" +fi + if [ ! -e "$IMAGEDIR/dev" ]; then + echo "Making /dev directory..." 1>&2 mkdir "$IMAGEDIR/dev" fi cp "/dev/MAKEDEV" "$IMAGEDIR/dev" -echo "Removing any linked /proc entry..." 1>&2 if [ -h "$IMAGEDIR/proc" ]; then + echo "Removing any linked /proc entry..." 1>&2 rm "$IMAGEDIR/proc" fi +if [ -e "$IMAGEDIR/proc" ]; then + echo "Moving existing /proc directory..." 1>&2 + mv "$IMAGEDIR/proc" "$IMAGEDIR/proc.old" +fi + if [ ! -e "$IMAGEDIR/proc" ]; then + echo "Making /proc directory..." 1>&2 mkdir "$IMAGEDIR/proc" fi diff -r 5c388118c8fc -r ca9bfaf0c7bf user-do --- a/user-do Tue Jul 12 00:47:20 2011 +0200 +++ b/user-do Wed Jul 13 00:43:11 2011 +0200 @@ -1,5 +1,4 @@ #!/bin/sh -# Usage: user-do [ --root [ --dev ] ] [ ] # Configuration: if [ -e userinstall-defaults ]; then @@ -7,39 +6,18 @@ elif [ -e /etc/default/userinstall ]; then . /etc/default/userinstall else - echo "No defaults found for userinstall." + echo "No defaults found for userinstall." 1>&2 exit 1 fi -if [ "$1" = '--root' ]; then +THISDIR=`dirname "$0"` + +if [ "$1" = '--help' ]; then + echo "Usage: `basename $0` [ --root [ --dev ] ] [ ]" + exit 1 +elif [ "$1" = '--root' ]; then shift 1 - mount -o bind /proc "$PACKAGEROOT/proc" - mount -o bind /sys "$PACKAGEROOT/sys" - if [ "$1" = '--dev' ]; then - DEV=$1 - shift 1 - if [ -e "$PACKAGEROOT/dev.orig" ]; then - echo "Devices may already be defined for the installation." - else - if [ -e "$PACKAGEROOT/dev" ]; then - mv "$PACKAGEROOT/dev" "$PACKAGEROOT/dev.orig" - fi - if [ ! -e "$PACKAGEROOT/dev" ]; then - mkdir "$PACKAGEROOT/dev" - fi - mount -o bind /dev "$PACKAGEROOT/dev" - fi - fi - chroot "$PACKAGEROOT" $* - umount "$PACKAGEROOT/proc" - umount "$PACKAGEROOT/sys" - if [ "$DEV" ]; then - umount "$PACKAGEROOT/dev" - rmdir "$PACKAGEROOT/dev" - if [ -e "$PACKAGEROOT/dev.orig" ]; then - mv "$PACKAGEROOT/dev.orig" "$PACKAGEROOT/dev" - fi - fi + sudo "$THISDIR/user-do-root" $* else fakeroot fakechroot $FAKECHROOT_OPTIONS chroot "$PACKAGEROOT" $* fi diff -r 5c388118c8fc -r ca9bfaf0c7bf user-do-root --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user-do-root Wed Jul 13 00:43:11 2011 +0200 @@ -0,0 +1,39 @@ +#!/bin/sh + +# Configuration: +if [ -e userinstall-defaults ]; then + . "$PWD/userinstall-defaults" +elif [ -e /etc/default/userinstall ]; then + . /etc/default/userinstall +else + echo "No defaults found for userinstall." 1>&2 + exit 1 +fi + +mount -o bind /proc "$PACKAGEROOT/proc" +mount -o bind /sys "$PACKAGEROOT/sys" +if [ "$1" = '--dev' ]; then + DEV=$1 + shift 1 + if [ -e "$PACKAGEROOT/dev.orig" ]; then + echo "Devices may already be defined for the installation." 1>&2 + else + if [ -e "$PACKAGEROOT/dev" ]; then + mv "$PACKAGEROOT/dev" "$PACKAGEROOT/dev.orig" + fi + if [ ! -e "$PACKAGEROOT/dev" ]; then + mkdir "$PACKAGEROOT/dev" + fi + mount -o bind /dev "$PACKAGEROOT/dev" + fi +fi +chroot "$PACKAGEROOT" $* +umount "$PACKAGEROOT/proc" +umount "$PACKAGEROOT/sys" +if [ "$DEV" ]; then + umount "$PACKAGEROOT/dev" + rmdir "$PACKAGEROOT/dev" + if [ -e "$PACKAGEROOT/dev.orig" ]; then + mv "$PACKAGEROOT/dev.orig" "$PACKAGEROOT/dev" + fi +fi diff -r 5c388118c8fc -r ca9bfaf0c7bf user-path --- a/user-path Tue Jul 12 00:47:20 2011 +0200 +++ b/user-path Wed Jul 13 00:43:11 2011 +0200 @@ -7,7 +7,7 @@ elif [ -e /etc/default/userinstall ]; then . /etc/default/userinstall else - echo "No defaults found for userinstall." + echo "No defaults found for userinstall." 1>&2 exit 1 fi diff -r 5c388118c8fc -r ca9bfaf0c7bf user-postsetup --- a/user-postsetup Tue Jul 12 00:47:20 2011 +0200 +++ b/user-postsetup Wed Jul 13 00:43:11 2011 +0200 @@ -1,5 +1,4 @@ #!/bin/sh -# Usage: user-postsetup [ --root [ --dev ] ] [ ] # Configuration: if [ -e userinstall-defaults ]; then @@ -7,12 +6,15 @@ elif [ -e /etc/default/userinstall ]; then . /etc/default/userinstall else - echo "No defaults found for userinstall." + echo "No defaults found for userinstall." 1>&2 exit 1 fi -if [[ "$1" && "$1" = '--root' ]]; then - export AS_ROOT=' --root' +if [ "$1" = '--help' ]; then + echo "Usage: `basename $0` [ --root ] [ ]" 1>&2 +elif [ "$1" = '--root' ]; then + AS_ROOT="$1" + AS_USER="sudo" shift 1 fi @@ -20,42 +22,47 @@ THIS_DIR=`dirname "$0"` -echo "Copying host DNS configuration..." -cp /etc/resolv.conf "$PACKAGEROOT/etc/" +if [ ! "$PACKAGEROOT" ] || [ "$PACKAGEROOT" = '/' ]; then + echo "The package root must be specified and not be set to / (the system root)." 1>&2 + exit 1 +fi -echo "Copying filesystems configuration..." -cp /etc/fstab "$PACKAGEROOT/etc/" +echo "Copying host DNS configuration..." 1>&2 +"$AS_USER" cp /etc/resolv.conf "$PACKAGEROOT/etc/" + +echo "Copying filesystems configuration..." 1>&2 +"$AS_USER" cp /etc/fstab "$PACKAGEROOT/etc/" -echo "Copying network configuration..." -cp /etc/hosts "$PACKAGEROOT/etc/" -cp /etc/network/interfaces "$PACKAGEROOT/etc/network/" +echo "Copying network configuration..." 1>&2 +"$AS_USER" cp /etc/hosts "$PACKAGEROOT/etc/" +"$AS_USER" cp /etc/network/interfaces "$PACKAGEROOT/etc/network/" -echo "Copying package repository configuration..." +echo "Copying package repository configuration..." 1>&2 if [ "$USERINSTALL_CODENAME" = "$DISTRIB_CODENAME" ]; then - cp /etc/apt/sources.list "$PACKAGEROOT/etc/apt/" + "$AS_USER" cp /etc/apt/sources.list "$PACKAGEROOT/etc/apt/" elif [ -e "$USERINSTALL_CODENAME/sources.list" ]; then - cp "$USERINSTALL_CODENAME/sources.list" "$PACKAGEROOT/etc/apt/" + "$AS_USER" 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" + echo "Attempting to generate a repository definition for $USERINSTALL_CODENAME." 1>&2 + "$AS_USER" "$THIS_DIR/user-makesources" "$PACKAGEROOT/etc/apt/sources.list" "$COUNTRY" fi if [ "$AS_ROOT" ]; then - echo "Mounting filesystems..." - "$THIS_DIR/user-do"$AS_ROOT mount -t proc proc /proc + echo "Mounting filesystems..." 1>&2 + "$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 +echo "Updating package details and upgrading..." 1>&2 +"$THIS_DIR/user-do" $AS_ROOT apt-get update +"$THIS_DIR/user-do" $AS_ROOT apt-get upgrade 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 + echo "Configuring a root installation..." 1>&2 + "$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 + echo "Unmounting filesystems..." 1>&2 + "$THIS_DIR/user-do" $AS_ROOT umount /proc fi diff -r 5c388118c8fc -r ca9bfaf0c7bf user-setup --- a/user-setup Tue Jul 12 00:47:20 2011 +0200 +++ b/user-setup Wed Jul 13 00:43:11 2011 +0200 @@ -1,5 +1,4 @@ #!/bin/sh -# Usage: user-setup [ --root ] [ ] # Configuration: if [ -e userinstall-defaults ]; then @@ -7,37 +6,43 @@ elif [ -e /etc/default/userinstall ]; then . /etc/default/userinstall else - echo "No defaults found for userinstall." + echo "No defaults found for userinstall." 1>&2 exit 1 fi if [ "$1" = "--help" ]; then - echo "Usage: user-setup [ --root ] [ ]" - echo - echo "Examples:" - echo - echo "user-setup" - echo "user-setup file:///tmp/$USERINSTALL_CODENAME/" - echo "user-setup http://ftp.xx.debian.org/debian/" - echo "user-setup --root http://ftp.xx.debian.org/debian/" + echo 1>&2 < ] + +Examples: + +user-setup +user-setup file:///tmp/$USERINSTALL_CODENAME/ +user-setup http://ftp.xx.debian.org/debian/ +user-setup --root http://ftp.xx.debian.org/debian/ +EOF exit 1 +elif [ "$1" = '--root' ]; then + AS_ROOT="$1" + shift 1 fi -if [[ "$1" && "$1" = '--root' ]]; then - export AS_ROOT=' --root' - export MIRROR="$2" -else - export MIRROR="$1" +if [ ! "$PACKAGEROOT" ] || [ "$PACKAGEROOT" = '/' ]; then + echo "The package root must be specified and not be set to / (the system root)." 1>&2 + exit 1 fi +MIRROR="$1" + if [ "$AS_ROOT" ]; then - debootstrap --include="gnupg,$KEYRING" "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" + sudo debootstrap --include="gnupg,$KEYRING" "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" else fakeroot fakechroot $FAKECHROOT_OPTIONS debootstrap --variant=fakechroot --include="gnupg,$KEYRING" \ "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" fi -echo -echo "Don't forget to run the following before installing packages:" -echo -echo "user-postsetup$AS_ROOT [ ]" +echo 1>&2 < ] +EOF diff -r 5c388118c8fc -r ca9bfaf0c7bf userinstall-defaults-uml --- a/userinstall-defaults-uml Tue Jul 12 00:47:20 2011 +0200 +++ b/userinstall-defaults-uml Wed Jul 13 00:43:11 2011 +0200 @@ -6,7 +6,7 @@ elif [ -e /etc/default/userinstall ]; then . /etc/default/userinstall else - echo "No defaults found for userinstall." + echo "No defaults found for userinstall." 1>&2 exit 1 fi