From 2d1f6ec282791c2165f896df1ebe78c2fb327199 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 24 Dec 2005 20:05:46 +0000 Subject: [PATCH] 2005-12-24 20:05:46 by steve The fstab is now prossed by a hook script, removing the code from xen-create-image. --- Makefile | 4 +- etc/hook.d/90-make-fstab | 53 +++++++++++++++++ xen-create-image | 125 +++++++++------------------------------ 3 files changed, 83 insertions(+), 99 deletions(-) create mode 100755 etc/hook.d/90-make-fstab diff --git a/Makefile b/Makefile index 5a52291..013bfbc 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ # -- # http://www.steve.org.uk/ # -# $Id: Makefile,v 1.26 2005-12-24 12:42:44 steve Exp $ +# $Id: Makefile,v 1.27 2005-12-24 20:05:46 steve Exp $ # @@ -62,7 +62,7 @@ diff: cvs diff --unified 2>/dev/null -install: +install: manpages mkdir -p ${prefix}/usr/bin cp xen-create-image ${prefix}/usr/bin cp xen-delete-image ${prefix}/usr/bin diff --git a/etc/hook.d/90-make-fstab b/etc/hook.d/90-make-fstab new file mode 100755 index 0000000..c170d27 --- /dev/null +++ b/etc/hook.d/90-make-fstab @@ -0,0 +1,53 @@ +#!/bin/sh +# +# This script is responsible for setting up /etc/fstab upon the +# new instance. +# +# This should be a simple job, but it is complicated by some of the +# differences between filesystems - some root filesystems will require +# the installation of new packages, and we have to handle that here. +# +# Steve +# -- +# $Id: 90-make-fstab,v 1.1 2005-12-24 20:05:46 steve Exp $ + + +prefix=$1 +hostname=$2 + + +# +# Options to mount the root filesystem with, we need to have +# different options for xfs. The default option works for ext2, +# ext3, and reiserfs. +# +options="errors=remount-ro" + +case "${fs}" in + xfs) + options="defaults" + ;; +esac + +# +# Now we have the options we can create the fstab. +# +cat < ${prefix}/etc/fstab +/dev/sda1 / $CONFIG{'fs'} ${options} 0 1 +/dev/sda2 none swap sw 0 0 +proc /proc proc defaults 0 0 +E_O_FSTAB + + +# +# Finally we can install any required packages for the given root +# filesystem +# +case "${fs}" in + xfs) + DEBIAN_FRONTEND=noninteractive chroot $prefix /usr/bin/apt-get --yes --force-yes install xfsprogs + ;; + reiserfs) + DEBIAN_FRONTEND=noninteractive chroot $prefix /usr/bin/apt-get --yes --force-yes install reiserfsprogs + ;; +esac diff --git a/xen-create-image b/xen-create-image index e3af8ac..e56891f 100755 --- a/xen-create-image +++ b/xen-create-image @@ -245,7 +245,8 @@ Show the version number and exit. xen-create-image --debootstrap='--include=screen,sudo,less' An alternative is to use the hook directory, described below, to - run a script which will install a package. + run a script which will install new packages upon the system for + you. =head1 HOOKS @@ -284,8 +285,8 @@ Show the version number and exit. =for example cut - The hook scripts are used extensively in this script, and provide - several of the base features. If you're looking at extending the + The hook scripts are used extensively by the xen-create-image + tool to setup the base system. If you're looking at extending the processing of the images it is recommended you examine the default hooks. @@ -299,7 +300,7 @@ Show the version number and exit. -- http://www.steve.org.uk/ - $Id: xen-create-image,v 1.65 2005-12-24 12:56:07 steve Exp $ + $Id: xen-create-image,v 1.66 2005-12-24 20:05:46 steve Exp $ =cut @@ -549,11 +550,13 @@ my $count = 1; my $total = $#files+1; foreach my $file ( @files ) { - my $t = "\r[$count/$total] : "; - if ( $file =~ /(.*)\/(.*)/ ) + my $name = $file; + if ( $name =~ /(.*)\/(.*)/ ) { - $t .= $2; + $name = $2; + } + my $t = "\r[$count/$total] : $name"; # # Print the status message and do the copy. @@ -582,17 +585,26 @@ $count = 1; $total = $#files + 1; foreach my $file ( @files ) { - my $t = "\r[$count/$total] : "; - if ( $file =~ /(.*)\/(.*)/ ) + my $name = $file; + if ( $name =~ /(.*)\/(.*)/ ) { - $t .= $2; + $name = $2; + } - + my $t = "\r[$count/$total] : $name"; + # # Print the status message and do the copy # printWideMessage( $t ); - File::Copy::cp( $file, "/var/cache/apt/archives" ); + + # + # But only copy if the image is new. + # + if ( ! -e "/var/cache/apt/archives/$name" ) + { + File::Copy::cp( $file, "/var/cache/apt/archives" ); + } $count += 1; } @@ -601,43 +613,6 @@ printWideMessage( "\rDone" ); -# -# Now setup the fstab -# -print "\n\nSetting up /etc/fstab\n"; - -# -# XFS requires different options for the fstab file. *sigh*. -# -my $options; -if ( $CONFIG{'fs'} eq "xfs" ) -{ - $options = "defaults"; -} -else -{ - $options = "errors=remount-ro"; -} - - -open( TAB, ">", $dir . "/etc/fstab" ); -print TAB< Install xfsprogs - reiser filesystem -> Install reiserfsprogs - -=cut - -sub installImagePackages -{ - my ( $prefix ) = ( @_ ); - - # - # Extra packages to install. - # - my $extra = ""; - - if ( $CONFIG{'fs'} eq "xfs" ) - { - $extra = "xfsprogs"; - } - elsif ( $CONFIG{'fs'} eq "reiserfs" ) - { - $extra = "reiserfsprogs"; - } - - # - # Install whatever we're supposed to. - # - if ( length( $extra ) ) - { - print "\n\nInstalling package into new system: $extra\n"; - runCommand( "DEBIAN_FRONTEND=noninteractive chroot $prefix /usr/bin/apt-get --yes --force-yes install $extra" ); - print "Done\n"; - } - -} - - - - - - - =head2 printWideMessage Print a message, ensuring the width is as wide as the console.