# HG changeset patch # User Paul Boddie # Date 1269131339 -3600 # Node ID 31111194d6e64636ab7bbc5ec330b2d07c93ced9 # Parent 967f05c9320ffa85749dc2d373467510ea762731 Split various initialisation steps into separate files. Added repository configuration assistance and a script for entering the chroot. Adopted distinct USERINSTALL variables which can be tested against the DISTRIB variables for configuration purposes. Added UML instance initialisation and configuration. diff -r 967f05c9320f -r 31111194d6e6 README.txt --- a/README.txt Sat Jan 16 22:12:19 2010 +0100 +++ b/README.txt Sun Mar 21 01:28:59 2010 +0100 @@ -31,13 +31,16 @@ debootstrap Tested with 0.3.3.2ubuntu3 on Ubuntu Hoary 5.04, 1.0.7~feisty1 on Ubuntu Feisty 7.04, 1.0.20~hardy1 on Ubuntu Hardy -New in userinstall 0.1.1 (Changes since userinstall 0.1) --------------------------------------------------------- +New in userinstall 0.2 (Changes since userinstall 0.1) +------------------------------------------------------ * Fixed an argument parsing error in the user-setup script. * Adopted lsb-release environment variables instead of new ones like - DISTNAME. + DISTNAME, exposing derivatives of these variables by default. * Added explicit keyring package installation. + * Added scripts for configuring and entering the chroot. + * Added support for UML instance construction from distribution + installations. Configuration ------------- @@ -45,26 +48,30 @@ If the system defaults are not to be used, or if userinstall is not installed as a system package, the userinstall-defaults file supplied with the distribution may be edited to specify the nature and location of the personal -package manager. After commenting out or removing this line... +package manager. -source /etc/lsb-release +The following settings can be edited: -...the following settings can be edited: - -DISTRIB_ID This should reflect the distribution being used or, in - special cases, a different distribution. Examples include - Debian and Ubuntu. +USERINSTALL_ID This should reflect the distribution being used or, in + special cases, a different distribution. Examples + include Debian and Ubuntu. -DISTRIB_CODENAME This should reflect the version of the distribution being - used and need only be altered in special situations (such as - the creation of a sandbox for testing other distributions). - Examples of codenames include hardy and jaunty for Ubuntu - and lenny and squeeze for Debian. Note that the setup - process may not work with different distributions due to - library incompatibilities. +USERINSTALL_CODENAME This should reflect the version of the distribution + being used and need only be altered in special + situations (such as the creation of a sandbox for + testing other distributions). -PACKAGEROOT The location of the personal package manager in the - filesystem. + Examples of codenames include hardy and jaunty for + Ubuntu and lenny and squeeze for Debian. Note that the + setup process may not work with different distributions + due to library incompatibilities. + +PACKAGEROOT The location of the personal package manager in the + filesystem. + +See the /etc/lsb-release file for example values describing your own system, +with the DISTRIB prefix used instead of the USERINSTALL prefix for each of the +settings. If a completely new userinstall-defaults file is created, it is essential that the above variables be defined so that the scripts know where to create or to @@ -95,6 +102,19 @@ An URI must be specified as the "mirror" location, not a normal filename. +Once the installation is complete, some post-installation is necessary: + +user-postsetup + +If a different distribution is being used for the package manager than that +being run on the system, it might be necessary to specify a country code so +that the configuration of package repositories can be performed successfully. +For example, for repositories mirrored in the United Kingdom (UK): + +user-postsetup uk + +At this point, the package manager should be ready to use. + Adding Package Repositories to the Package Manager -------------------------------------------------- @@ -180,3 +200,55 @@ export LD_LIBRARY_PATH=`./user-path /usr/lib` export PYTHONPATH=`./user-path /usr/lib/python2.5/site-packages/` export PYTHONPATH=${PYTHONPATH}:`./user-path /var/lib/python-support/python2.5` + +Entering the Package Manager +---------------------------- + +It is also possible to administer the package manager from within the +installation: + +user-enter + +This should provide a "root" prompt which can then be used to issue commands +within the package manager environment. For example: + +apt-get update + +Constructing UML Instances +-------------------------- + +For some applications, it can be desirable to provide a completely isolated +environment for package installation and testing. This can be performed using +the User Mode Linux (UML) software. + +To convert a package manager installation into a UML instance, start with the +uml-postsetup script which changes the installation's configuration in a +number of areas: + +uml-postsetup + +Then, as a privileged user, run the user-setupdev script to initialise some +UML-specific device files: + +sudo uml-setupdev + +Since UML needs to see its filesystems as images, not directories within an +existing filesystem, the uml-setupfs script needs to create these image files. +For example, to create a root filesystem 1GB in size, along with a swap file +512MB in size: + +uml-setupfs 4 512 + +Again, as a privileged user, these images are then populated with the package +manager contents as follows: + +uml-postsetupfs + +NOTE: Add Linux build process. + +Entering or Starting UML Instances +---------------------------------- + +To enter a UML instance, use the uml-enter script: + +uml-enter diff -r 967f05c9320f -r 31111194d6e6 UML/fstab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UML/fstab Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,7 @@ +# /etc/fstab: static file system information. +# +# +proc /proc proc defaults 0 0 +/dev/ubda / ext3 defaults,errors=remount-ro 0 1 +/dev/ubdb none swap sw 0 0 +/dev/ubdc /mnt/cdrom iso9660 defaults 0 0 diff -r 967f05c9320f -r 31111194d6e6 uml-enter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uml-enter Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,18 @@ +#!/bin/bash +# Usage: uml-enter + +# Configuration: +if [ -e userinstall-defaults-uml ]; then + source userinstall-defaults-uml +elif [ -e /etc/default/userinstall-uml ]; then + source /etc/default/userinstall-uml +else + echo "No defaults found for userinstall (UML)." + exit 1 +fi + +export IMAGE=$UMLROOT/rootfs +export SWAPIMAGE=$UMLROOT/swap + +# Now we start the virtual machine... +`dirname $0`/linux ubd0=$IMAGE ubd1=$SWAPIMAGE mem=$1 diff -r 967f05c9320f -r 31111194d6e6 uml-postsetup --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uml-postsetup Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,45 @@ +#!/bin/bash +# Usage: uml-postsetup + +# Configuration: +if [ -e userinstall-defaults ]; then + source userinstall-defaults +elif [ -e /etc/default/userinstall ]; then + source /etc/default/userinstall +else + echo "No defaults found for userinstall." + exit 1 +fi + +echo "Removing any linked /dev entry..." +if [ -h "$PACKAGEROOT/dev" ]; then + 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 +fi + +echo "Using a special fstab..." +if [ -e "$PACKAGEROOT/etc/fstab" ]; then + mv $PACKAGEROOT/etc/fstab $PACKAGEROOT/etc/fstab.orig +fi +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.save" ]; then + cp $PACKAGEROOT/etc/inittab $PACKAGEROOT/etc/inittab.save + grep -v "getty" $PACKAGEROOT/etc/inittab.save > $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 +fi diff -r 967f05c9320f -r 31111194d6e6 uml-postsetupfs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uml-postsetupfs Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,44 @@ +#!/bin/bash +# Usage: uml-postsetupfs + +# Configuration: +if [ -e userinstall-defaults-uml ]; then + source userinstall-defaults-uml +elif [ -e /etc/default/userinstall-uml ]; then + source /etc/default/userinstall-uml +else + echo "No defaults found for userinstall (UML)." + exit 1 +fi + +# Ensure that images have been set up. +if [ ! -e $UMLROOT ]; then + echo "No UML instances set up at $UMLROOT." + exit 1 +fi + +export IMAGE=$UMLROOT/rootfs + +if [ ! -e $IMAGE ]; then + echo "No image set up at $IMAGE." + exit 1 +fi + +export IMAGEDIR=$UMLROOT/rootfsdir + +if [ ! -e $IMAGEDIR ]; then + mkdir $IMAGEDIR +fi + +echo "Accessing the image..." +mount -o loop $IMAGE $IMAGEDIR || exit 1 + +echo "Copying the filesystem into the image..." +cp -a $PACKAGEROOT/* $IMAGEDIR + +echo "Initialising device files..." +chroot $PACKAGEROOT /bin/bash -c 'mount -t proc proc /proc; cd /dev; MAKEDEV generic; umount /proc' + +echo "Unmounting the image..." +umount $IMAGEDIR +rmdir $IMAGEDIR diff -r 967f05c9320f -r 31111194d6e6 uml-setupdev --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uml-setupdev Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,29 @@ +#!/bin/bash +# From UMLconfig... + +# Configuration: +if [ -e userinstall-defaults ]; then + source userinstall-defaults +elif [ -e /etc/default/userinstall ]; then + source /etc/default/userinstall +else + echo "No defaults found for userinstall." + exit 1 +fi + +echo "Creating special UML devices..." +if [ ! -e "$PACKAGEROOT/dev/ubda" ]; then + if [ -e "$PACKAGEROOT/dev" ]; then + for ((i=0; i<8; i++)) + do + let=$(echo $i|tr '0-7' 'a-z') + 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] + done + done + else + echo "/dev not found!" + exit 1 + fi +fi diff -r 967f05c9320f -r 31111194d6e6 uml-setupfs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uml-setupfs Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,37 @@ +#!/bin/bash +# Usage: uml-setupfs + +# Configuration: +if [ -e userinstall-defaults-uml ]; then + source userinstall-defaults-uml +elif [ -e /etc/default/userinstall-uml ]; then + source /etc/default/userinstall-uml +else + echo "No defaults found for userinstall (UML)." + exit 1 +fi + +# Ensure arguments have been provided. +if [[ ! $1 || ! $2 ]]; then + echo "$0 " + exit 1 +fi + +# Make the UML instance directory if not already present. + +echo "Making the UML instance directory at $UMLROOT..." +if [ ! -e $UMLROOT ]; then + mkdir $UMLROOT +fi + +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 + +echo "Making the swap file with size ${SWAPSIZE}MB..." +dd if=/dev/zero of=$SWAPIMAGE bs=1M count=$SWAPSIZE diff -r 967f05c9320f -r 31111194d6e6 user-enter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user-enter Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,14 @@ +#!/bin/bash +# Usage: user-enter + +# Configuration: +if [ -e userinstall-defaults ]; then + source userinstall-defaults +elif [ -e /etc/default/userinstall ]; then + source /etc/default/userinstall +else + echo "No defaults found for userinstall." + exit 1 +fi + +fakeroot fakechroot chroot $PACKAGEROOT diff -r 967f05c9320f -r 31111194d6e6 user-makesources --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user-makesources Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +templates = { + + "Debian" : """ +deb http://ftp.%(country)s.debian.org/debian %(codename)s main +deb-src http://ftp.%(country)s.debian.org/debian %(codename)s main + +deb http://security.debian.org/ %(codename)s/updates main +deb-src http://security.debian.org/ %(codename)s/updates main +""", + + "Ubuntu" : """ +deb http://%(country)s.archive.ubuntu.com/ubuntu/ %(codename)s main universe +deb-src http://%(country)s.archive.ubuntu.com/ubuntu/ %(codename)s main universe + +deb http://%(country)s.archive.ubuntu.com/ubuntu/ %(codename)s-security main universe +deb-src http://%(country)s.archive.ubuntu.com/ubuntu/ %(codename)s-security main universe + +deb http://%(country)s.archive.ubuntu.com/ubuntu/ %(codename)s-updates main universe +deb-src http://%(country)s.archive.ubuntu.com/ubuntu/ %(codename)s-updates main universe +""" + + } + +if __name__ == "__main__": + import os, sys + + if len(sys.argv) < 2: + print "Need a filename for the generated file." + sys.exit(1) + + elif len(sys.argv) < 3: + print "Need a country to generate source lists." + sys.exit(1) + + filename, country = sys.argv[1:3] + distribution = os.environ["USERINSTALL_ID"] + codename = os.environ["USERINSTALL_CODENAME"] + + try: + template = templates[distribution] + except KeyError: + print "Distribution %s not supported." % distribution + sys.exit(1) + + f = open(filename, "w") + try: + f.write(template % {"codename" : codename, "country" : country}) + finally: + f.close() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 967f05c9320f -r 31111194d6e6 user-path --- a/user-path Sat Jan 16 22:12:19 2010 +0100 +++ b/user-path Sun Mar 21 01:28:59 2010 +0100 @@ -1,5 +1,5 @@ #!/bin/bash -# Usage: user-dirpath +# Usage: user-path # Configuration: if [ -e userinstall-defaults ]; then diff -r 967f05c9320f -r 31111194d6e6 user-postsetup --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user-postsetup Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,32 @@ +#!/bin/bash +# Usage: user-postsetup [ ] + +# Configuration: +if [ -e userinstall-defaults ]; then + source userinstall-defaults +elif [ -e /etc/default/userinstall ]; then + source /etc/default/userinstall +else + echo "No defaults found for userinstall." + exit 1 +fi + +echo "Copying host DNS configuration..." +cp /etc/resolv.conf $PACKAGEROOT/etc/ + +echo "Copying filesystems configuration..." +cp /etc/fstab $PACKAGEROOT/etc/ + +echo "Copying network configuration..." +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/ +else + echo "Attempting to generate a repository definition for $USERINSTALL_CODENAME." + `dirname $0`/user-makesources $PACKAGEROOT/etc/apt/sources.list $1 +fi diff -r 967f05c9320f -r 31111194d6e6 user-setup --- a/user-setup Sat Jan 16 22:12:19 2010 +0100 +++ b/user-setup Sun Mar 21 01:28:59 2010 +0100 @@ -17,12 +17,12 @@ echo "Examples:" echo echo "user-setup" - echo "user-setup file:///tmp/$DISTRIB_CODENAME/" + echo "user-setup file:///tmp/$USERINSTALL_CODENAME/" echo "user-setup http://ftp.xx.debian.org/debian/" exit 1 fi -fakeroot fakechroot --use-system-libs debootstrap --variant=fakechroot --include=gnupg,$KEYRING $DISTRIB_CODENAME $PACKAGEROOT $1 +fakeroot fakechroot --use-system-libs debootstrap --variant=fakechroot --include=gnupg,$KEYRING $USERINSTALL_CODENAME $PACKAGEROOT $1 echo echo "Don't forget to run the following before installing packages:" echo diff -r 967f05c9320f -r 31111194d6e6 userinstall-defaults --- a/userinstall-defaults Sat Jan 16 22:12:19 2010 +0100 +++ b/userinstall-defaults Sun Mar 21 01:28:59 2010 +0100 @@ -2,7 +2,13 @@ source /etc/lsb-release +# If not using the same distribution inside the userinstall, replace these +# definitions: + +export USERINSTALL_ID=$DISTRIB_ID +export USERINSTALL_CODENAME=$DISTRIB_CODENAME + # Configuration details for building and using a personal package manager. export PACKAGEROOT=$HOME/.userinstall -export KEYRING=$(echo $DISTRIB_ID | tr '[:upper:]' '[:lower:]')-keyring +export KEYRING=$(echo $USERINSTALL_ID | tr '[:upper:]' '[:lower:]')-keyring diff -r 967f05c9320f -r 31111194d6e6 userinstall-defaults-uml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/userinstall-defaults-uml Sun Mar 21 01:28:59 2010 +0100 @@ -0,0 +1,15 @@ +#!/bin/bash + +# Main configuration: +if [ -e userinstall-defaults ]; then + source userinstall-defaults +elif [ -e /etc/default/userinstall ]; then + source /etc/default/userinstall +else + echo "No defaults found for userinstall." + exit 1 +fi + +# Configuration details for building a UML instance. + +export UMLROOT=$HOME/.userinstall-uml