1
0
mirror of synced 2026-02-02 06:20:56 +00:00

1. Added pygrub support to the ubuntu scripts

- Hardy still not working
2. Added karmic support
	- Working fully
3. Edited Makefile to install karmic hooks
This commit is contained in:
Dmitry Nedospasov
2010-04-17 14:41:18 +02:00
parent a82f8754df
commit 0ecc697a82
21 changed files with 1464 additions and 11 deletions

View File

@@ -165,21 +165,18 @@ install-hooks:
-cd ${prefix}/usr/lib/xen-tools/ && ln -s debian.d testing.d
mkdir -p ${prefix}/usr/lib/xen-tools/gentoo.d/
cp -R hooks/gentoo/*-* ${prefix}/usr/lib/xen-tools/gentoo.d
mkdir -p ${prefix}/usr/lib/xen-tools/edgy.d/
mkdir -p ${prefix}/usr/lib/xen-tools/dapper.d/
cp -R hooks/dapper/*-* ${prefix}/usr/lib/xen-tools/dapper.d/
mkdir -p ${prefix}/usr/lib/xen-tools/edgy.d/
cp -R hooks/edgy/*-* ${prefix}/usr/lib/xen-tools/edgy.d/
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d feisty.d
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d gutsy.d
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d hardy.d
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d intrepid.d
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d jaunty.d
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d karmic.d
-cd ${prefix}/usr/lib/xen-tools/ && ln -s edgy.d lucid.d
mkdir -p ${prefix}/usr/lib/xen-tools/dapper.d/
cp -R hooks/dapper/*-* ${prefix}/usr/lib/xen-tools/dapper.d/
mkdir -p ${prefix}/usr/lib/xen-tools/edgy.d/
cp -R hooks/edgy/*-* ${prefix}/usr/lib/xen-tools/edgy.d/
mkdir -p ${prefix}/usr/lib/xen-tools/dapper.d/
cp -R hooks/dapper/*-* ${prefix}/usr/lib/xen-tools/dapper.d/
mkdir -p ${prefix}/usr/lib/xen-tools/karmic.d/
cp -R hooks/karmic/*-* ${prefix}/usr/lib/xen-tools/karmic.d/
-cd ${prefix}/usr/lib/xen-tools/ && ln -s karmic.d lucid.d
cp hooks/common.sh ${prefix}/usr/lib/xen-tools

90
hooks/edgy/80-install-kernel Executable file
View File

@@ -0,0 +1,90 @@
#!/bin/sh
#
# If the pygrub flag is set, this script will install the necessary
# packages to boot the VM from the dom0 via pygrub. This script installs
# the kernel and modules and generates a grub menu.lst in the newly
# created maschine.
#
# Dmitry Nedospasov
# --
# http://nedos.net
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
if [ ${pygrub} ]; then
#
# Log our start
#
logMessage Script $0 starting
#
# The type of kernel that we will be installing
#
# linux_kernel_type="desktop"
#
linux_kernel_type="xen"
linux_kernel_package="linux-image-${linux_kernel_type}"
logMessage "Installing the ${linux_kernel_package} kernel image"
if chroot ${prefix} /usr/bin/apt-cache show ${linux_kernel_package} >/dev/null 2>/dev/null; then
logMessage "Package '${linux_kernel_package}' is available - installing"
installDebianPackage ${prefix} initramfs-tools
installDebianPackage ${prefix} ${linux_kernel_package}
# Force initrd if none exists
echo ${prefix}/boot/initrd* | grep -q 2\\.6
if [ $? -ne 0 ]; then
chroot ${prefix} update-initramfs -c -k `ls -1
${prefix}/lib/modules/ | head -n 1`
fi
# Generate grub menu.lst
LNZ=`basename \`ls -1 ${prefix}/boot/vmlinuz*|tail -n 1\``
RD=`basename \`ls -1 ${prefix}/boot/initrd*|tail -n 1\``
mkdir -p ${prefix}/boot/grub
cat - <<-EOF > ${prefix}/boot/grub/menu.lst
default 0
timeout 2
title Ubuntu
root (hd0,0)
kernel /boot/$LNZ root=/dev/xvda2 ro
initrd /boot/$RD
title Ubuntu (Single-User)
root (hd0,0)
kernel /boot/$LNZ root=/dev/xvda2 ro single
initrd /boot/$RD
EOF
else
logMessage "Package '${linux_kernel_package}' is not available"
fi
#
# Install the module-init-tools package.
#
installDebianPackage ${prefix} module-init-tools
else
logMessage pygrub not set, skipping kernel install
fi # if pygrub
#
# Log our finish
#
logMessage Script $0 finished

View File

@@ -31,7 +31,9 @@ fi
#
logMessage Script $0 starting
if [ ${pygrub} ]; then
logMessage "pygrub set, skipping module install"
else
#
# The name of the package containing the correct modules.
#
@@ -71,12 +73,12 @@ else
cp -au /lib/modules/$(uname -r) ${prefix}/lib/modules
fi
#
# Install the module-init-tools package.
#
installDebianPackage ${prefix} module-init-tools
fi # if pygrub
#
# Log our finish

54
hooks/karmic/01-disable-daemons Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/sh
#
# This script ensures that daemons will not be started inside our
# chroot() installation.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Make sure we have a directory.
#
if [ ! -d "${prefix}/usr/sbin" ]; then
mkdir -p "${prefix}/usr/sbin"
logMessage "created missing directory: ${prefix}/usr/sbin"
fi
#
# Add the script.
#
echo '#!/bin/sh' > ${prefix}/usr/sbin/policy-rc.d
echo 'exit 101' >> ${prefix}/usr/sbin/policy-rc.d
chmod 755 ${prefix}/usr/sbin/policy-rc.d
#
# Log our finish
#
logMessage Script $0 finished.

45
hooks/karmic/05-shadowconfig-on Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/sh
#
# This script enforces the use of a shadow password file.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Enable the shadow passwords if the command is found.
#
if [ -x ${prefix}/sbin/shadowconfig ]; then
chroot ${prefix} /sbin/shadowconfig on
else
logMessage "/sbin/shadowconfig not found. skipping."
fi
#
# Log our finish
#
logMessage Script $0 finished.

38
hooks/karmic/15-disable-hwclock Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
#
# This script disables the hardware clock.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Disable the startup scripts from all runlevels.
#
chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove
#
# Log our finish
#
logMessage Script $0 finished.

106
hooks/karmic/20-setup-apt Executable file
View File

@@ -0,0 +1,106 @@
#!/bin/sh
#
# This script sets up the /etc/apt/sources.list for APT.
#
# Steve
# --
#
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# You will probably need DNS to run "apt-get update"
#
cp /etc/resolv.conf ${prefix}/etc
#
# Attempt to auto-magically detect the use of a Proxy for apt-get, and
# replicate that setup in our new guest.
#
#
# Process any of the present apt-conf setup lines.
#
for i in /etc/apt/apt.conf $(run-parts --list /etc/apt/apt.conf.d) ; do
#
# If the file exists. (Need this in case the literal glob fails.)
#
if [ -e $i ] ; then
#
# Save the matching line(s) to the proxy guess file.
#
logMessage The use of a proxy detected.
grep -v '^//' $i | grep -i HTTP::Proxy >>${prefix}/etc/apt/apt.conf.d/proxy-guess
fi
done
cat <<E_O_APT > ${prefix}/etc/apt/sources.list
#
# /etc/apt/sources.list
#
#
# ${dist}
#
deb ${mirror} ${dist} main restricted universe multiverse
deb-src ${mirror} ${dist} main restricted universe
deb ${mirror} ${dist}-updates main restricted universe multiverse
deb-src ${mirror} ${dist}-updates main restricted universe
deb http://security.ubuntu.com/ubuntu ${dist}-security main restricted universe
deb-src http://security.ubuntu.com/ubuntu ${dist}-security main restricted universe
E_O_APT
#
# Now that the sources have been setup make sure the system is up to date.
#
chroot ${prefix} /usr/bin/apt-get update
#
# Now fixup TLS on non-64bit systems.
#
if [ "`uname -m`" = "x86_64" ]; then
logMessage "Ignoring TLS since we're a 64 bit host."
else
logMessage "Installing libc6-xen"
installDebianPackage ${prefix} libc6-xen
fi
#
# Log our finish
#
logMessage Script $0 finished

40
hooks/karmic/25-generate-locale Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/sh
#
# This script generates a default en_US.UTF-8 locale.
#
# Ward
# --
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Install the English language pack.
#
# NOTE: Failure to support your favourite language is *not* a bug.
#
installDebianPackage ${prefix} language-pack-en
#
# Log our finish
#
logMessage Script $0 finished

58
hooks/karmic/30-disable-gettys Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/sh
#
# This script comments out all virtual terminals which aren't on the
# first console - that must remain so that 'xm console ...' works
# correctly.
#
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Remove the links for upstart
#
rm ${prefix}/etc/init/tty[!1].conf
#
# Are we using an alternative serial device?
#
if [ ! -z "${serial_device}" ]; then
serial_device=`basename ${serial_device}`
# Let the user know.
logMessage "Replacing default serial device (tty1) with ${serial_device}"
# replace existing device.
mv ${prefix}/etc/init/tty1.conf ${prefix}/etc/init/${serial_device}.conf
sed -i -e s/tty1/${serial_device}/ ${prefix}/etc/init/${serial_device}.conf
[ -f ${prefix}/etc/inittab ] && sed -i -e s/tty1/${serial_device}/ ${prefix}/etc/inittab
# make sure that it is allowed to login.
echo $serial_device >> ${prefix}/etc/securetty
fi
#
# Log our finish
#
logMessage Script $0 finished

181
hooks/karmic/35-setup-users Executable file
View File

@@ -0,0 +1,181 @@
#!/usr/bin/perl -w
#
# This script attempts to copy all user accounts from the host to
# the guest. It does this by copying all user accounts which are not
# already present.
#
# NOTE: Unless '--accounts' was specified upon the 'xen-create-image'
# command line we don't do this.
#
# Steve
# --
# http://www.steve.org.uk/
use strict;
use Env;
my $prefix = shift;
die "Prefix must be given" unless defined( $prefix );
die "Prefix must be a directory" unless ( -d $prefix );
#
# Exit unless the 'accounts' variable is set.
#
exit unless ( $ENV{'accounts'} );
#
# Make sure we have $prefix/etc
#
die "Prefix is missing /etc : $prefix" unless ( -d $prefix . "/etc" );
#
# Read all accounts from the installed /etc/passwd on the guest.
#
my %present;
if ( -e $prefix . "/etc/passwd" )
{
%present = readAccounts( $prefix . "/etc/passwd" );
}
#
# Now read the accounts on the host.
#
my %host = readAccounts( "/etc/passwd" );
#
# For each account not present on new installation then add it
#
foreach my $account ( sort keys( %host ) )
{
if ( ! $present{ $account } )
{
print "Adding: $account\n";
addAccount( $account );
#
# Find any groups the user is member of on the host
# and add them on the guest system
#
addGroups( $account );
}
}
#
# Read the accounts which are already present on the guest image.
#
sub readAccounts
{
my ( $file ) = ( @_ );
my %found;
open( EXISTING, "<", $file );
foreach my $line ( <EXISTING> )
{
#
# Record the userid + username
#
if ( $line =~ /^([^:]+):([^:]+):([^:]+)/ )
{
my $user = $1;
my $pass = $2;
my $uid = $3;
$found{$user} = 1;
}
}
close( EXISTING );
return( %found );
}
#
# Add the passwd + shadow accounts for the given user.
#
sub addAccount
{
my ( $user ) = ( @_ );
#
# passwd file.
#
open( PASSWD, "<", "/etc/passwd" );
foreach my $line ( <PASSWD> )
{
chomp( $line );
if ( $line =~ /^\Q$user\E:/ )
{
#
# Add the line
#
open( OUTY, ">>", $prefix . "/etc/passwd" );
print OUTY $line . "\n";
close( OUTY );
}
}
close( PASSWD );
#
# shadow file.
#
open( SHADOW, "<", "/etc/shadow" ) or die "Failed to open : $!";
foreach my $line ( <SHADOW> )
{
chomp( $line );
if ( $line =~ /^\Q$user\E:/ )
{
#
# Add the line
#
open( OUTY, ">>", $prefix . "/etc/shadow" );
print OUTY $line . "\n";
close( OUTY );
}
}
close( SHADOW );
}
#
# Find the groups a user is member of on the host, and add them to
# those groups on the new guest.
#
sub addGroups
{
my( $username ) = ( @_ );
#
# Get the groups.
#
my $groups = `groups $username`;
# split off the usernmame.
if ( $groups =~ /^([^:]+):(.*)/ )
{
$groups = $2;
print "User: $username is member of the groups: $groups\n";
}
foreach my $g ( split( / /, $groups ) )
{
# Make sure the group exists.
system( "chroot $prefix /usr/sbin/addgroup $g" );
# add the user to it.
system( "chroot $prefix /usr/sbin/adduser $username $g" );
}
}

145
hooks/karmic/40-setup-networking Executable file
View File

@@ -0,0 +1,145 @@
#!/bin/sh
#
# This script sets up the /etc/network/interface file for the new
# image.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Make sure we have an /etc/network directory.
#
mkdir -p ${prefix}/etc/network
#
# A function to setup DHCP for our new image.
#
setupDynamicNetworking ()
{
#
# The host is using DHCP.
#
cat <<E_O_DHCP > ${prefix}/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
# post-up ethtool -K eth0 tx off
#
# The commented out line above will disable TCP checksumming which
# might resolve problems for some users. It is disabled by default
#
E_O_DHCP
}
#
# A function to setup static IP addresses for our new image.
#
setupStaticNetworking ()
{
#
# broadcast address?
#
bcast='';
if [ ! -z "${broadcast}" ]; then
bcast=" broadcast ${broadcast}"
fi
#
# We have a static IP address
#
cat <<E_O_STATIC >${prefix}/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address ${ip1}
gateway ${gateway}
netmask ${netmask}
${bcast}
# post-up ethtool -K eth0 tx off
#
# The commented out line above will disable TCP checksumming which
# might resolve problems for some users. It is disabled by default
#
E_O_STATIC
interface=1
count=2
while [ "${count}" -le "${ip_count}" ]; do
value=\$ip${count}
value=`eval echo $value`
logMessage Adding etho:${interface}
cat <<E_O_STATIC >>${prefix}/etc/network/interfaces
auto eth0:${interface}
iface eth0:${interface} inet static
address ${value}
netmask ${netmask}
# post-up ethtool -K eth0 tx off
E_O_STATIC
count=`expr $count + 1`
interface=`expr $interface + 1`
done
}
#
# Call the relevant function
#
if [ -z "${dhcp}" ]; then
logMessage "Setting up static networking"
setupStaticNetworking
else
logMessage "Setting up DHCP networking"
setupDynamicNetworking
fi
#
# Log our finish
#
logMessage Script $0 finished

118
hooks/karmic/50-setup-hostname Executable file
View File

@@ -0,0 +1,118 @@
#!/bin/sh
#
# This script places the new systems hostname into a couple of files within
# the new image.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Setup the mailname + hostname files.
#
echo ${hostname} | sed 's/^\([^\.]*\)\..*/\1/' > ${prefix}/etc/hostname
echo ${hostname} > ${prefix}/etc/mailname
#
# Fixup the /etc/hosts file upon the new image for
# machines with static IPs
#
if [ -z "${dhcp}" ]; then
# Non-IPv6 stuff.
grep -v '\(::\|IPv6\)' /etc/hosts > ${prefix}/etc/hosts
# New entry.
echo "${ip1} ${hostname}" >> ${prefix}/etc/hosts
echo " " >> ${prefix}/etc/hosts
# IPv6 stuff.
grep '\(::\|IPv6\)' /etc/hosts >> ${prefix}/etc/hosts
else
#
# Stub /etc/hosts for DHCP clients.
#
cat >> ${prefix}/etc/hosts <<EOF
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
EOF
fi
#
# Allow the host system to know the IP address of our new guest.
#
if [ -z "${dhcp}" ]; then
if ( grep ${hostname} /etc/hosts > /dev/null ) ; then
logMessage Host already has IP address for the host ${hostname}.
else
#
# Short host name.
#
name=`echo ${hostname} | awk -F. '{print $1}'`
if [ -z "${nohosts}" ]; then
logMessage Adding ${hostname} and ${name} to /etc/hosts on the host
echo "${ip1} ${hostname} ${name}" >> /etc/hosts
#
# If we've updated the /etc/hosts file on the host machine
# and there is an installation of dnsmasq installed then
# reload it.
#
# This will let the local LAN clients lookup the new address.
#
if [ -x /usr/sbin/dnsmasq ] ; then
if [ -e /var/run/dnsmasq.pid ]; then
logMessage Allowing DNSMasq to restart.
kill -s HUP `cat /var/run/dnsmasq.pid`
fi
fi
fi
fi
fi
#
# Log our finish
#
logMessage Script $0 finished

58
hooks/karmic/60-copy-host-files Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/sh
#
# Copy files from a 'skel' directory, if present, into the
# new images
#
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Copy "required" files from our host.
#
cp /etc/timezone ${prefix}/etc
#
# If the host has sudo then copy the configuration file, and install
# the package
#
if [ -e /etc/sudoers ]; then
logMessage Installing SUDO too.
#
# Copy file and fixup permissions.
#
cp /etc/sudoers ${prefix}/etc
chown root:root ${prefix}/etc/sudoers
chmod 440 ${prefix}/etc/sudoers
#
# Install sudo
#
installDebianPackage ${prefix} sudo
fi
#
# Log our finish
#
logMessage Script $0 finished

49
hooks/karmic/65-copy-user-files Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
#
# Copy files from a 'skel' directory, if present, into the
# new images
#
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Copy everything from the skel directory into the new instance
# if that directory exists.
#
if [ -d /etc/xen-tools/skel ]; then
logMessage Copying files from /etc/xen-tools/skel
(cd /etc/xen-tools/skel; tar -cf - . ) | (cd ${prefix}/; tar -xpf -)
logMessage Finished
else
logMessage skel directory, /etc/xen-tools/skell, not present ignoring.
fi
#
# Log our finish
#
logMessage Script $0 finished

42
hooks/karmic/70-install-ssh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/sh
#
# This script installs OpenSSH upon the new system.
#
# It must make sure that the server is not running before it exits
# otherwise the temporary mounted directory will not be unmountable.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Install ssh
#
installDebianPackage ${prefix} ssh
#
# Log our finish
#
logMessage Script $0 finished

62
hooks/karmic/75-fixup-securetty Executable file
View File

@@ -0,0 +1,62 @@
#!/bin/sh
#
# This script ensures /etc/securetty upon the new guests has the new
# Xen console devices in it
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# If the file doesn't exist exit early.
#
if [ ! -e ${prefix}/etc/securetty ]; then
logMessage /etc/securetty not found.
exit
fi
#
# Do both the devices.
#
for i in xvc0 hvc0 ; do
#
# Only append if not presnt.
#
if ( grep $i ${prefix}/etc/securetty > /dev/null ) ; then
logMessage Host already has $i entry
else
echo $i >> ${prefix}/etc/securetty
fi
done
#
# Log our finish
#
logMessage Script $0 finished.

90
hooks/karmic/80-install-kernel Executable file
View File

@@ -0,0 +1,90 @@
#!/bin/sh
#
# If the pygrub flag is set, this script will install the necessary
# packages to boot the VM from the dom0 via pygrub. This script installs
# the kernel and modules and generates a grub menu.lst in the newly
# created maschine.
#
# Dmitry Nedospasov
# --
# http://nedos.net
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
if [ ${pygrub} ]; then
#
# Log our start
#
logMessage Script $0 starting
#
# The type of kernel that we will be installing
#
# linux_kernel_type="desktop"
#
linux_kernel_type="server"
linux_kernel_package="linux-image-${linux_kernel_type}"
logMessage "Installing the ${linux_kernel_package} kernel image"
if chroot ${prefix} /usr/bin/apt-cache show ${linux_kernel_package} >/dev/null 2>/dev/null; then
logMessage "Package '${linux_kernel_package}' is available - installing"
installDebianPackage ${prefix} initramfs-tools
installDebianPackage ${prefix} ${linux_kernel_package}
# Force initrd if none exists
echo ${prefix}/boot/initrd* | grep -q 2\\.6
if [ $? -ne 0 ]; then
chroot ${prefix} update-initramfs -c -k `ls -1
${prefix}/lib/modules/ | head -n 1`
fi
# Generate grub menu.lst
LNZ=`basename \`ls -1 ${prefix}/boot/vmlinuz*|tail -n 1\``
RD=`basename \`ls -1 ${prefix}/boot/initrd*|tail -n 1\``
mkdir -p ${prefix}/boot/grub
cat - <<-EOF > ${prefix}/boot/grub/menu.lst
default 0
timeout 2
title Ubuntu
root (hd0,0)
kernel /boot/$LNZ root=/dev/xvda2 ro
initrd /boot/$RD
title Ubuntu (Single-User)
root (hd0,0)
kernel /boot/$LNZ root=/dev/xvda2 ro single
initrd /boot/$RD
EOF
else
logMessage "Package '${linux_kernel_package}' is not available"
fi
#
# Install the module-init-tools package.
#
installDebianPackage ${prefix} module-init-tools
else
logMessage pygrub not set, skipping kernel install
fi # if pygrub
#
# Log our finish
#
logMessage Script $0 finished

86
hooks/karmic/80-install-modules Executable file
View File

@@ -0,0 +1,86 @@
#!/bin/sh
#
# Install modules from the host system into the new image, and
# ensure that 'module-init-tools' is setup.
#
# This is most likely required if you're using a custom kernel
# for your Xen system. But even if it isn't required it can't
# really do anything bad; just waste a bit of space.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
if [ ${pygrub} ]; then
logMessage "pygrub set, skipping module install"
else
#
# The name of the package containing the correct modules.
#
linux_modules_package="linux-modules-$(uname -r)"
#
# Attempt to install that package. This will either work on an Etch
# system, or fail on a Sarge/custom kernel.
#
if [ -n "${modules}" -a -d "${modules}" ]; then
#
# Modules path was specified during install
#
logMessage "Copying modules from ${modules}"
mkdir -p ${prefix}/lib/modules
cp -au ${modules} ${prefix}/lib/modules
elif chroot ${prefix} /usr/bin/apt-cache show ${linux_modules_package} >/dev/null 2>/dev/null; then
logMessage "Package '${linux_modules_package}' is available - installing"
#
# If it worked then we can install the package.
#
installDebianPackage ${prefix} ${linux_modules_package}
else
#
# Fall back to copying over modules from the host to the new
# system.
#
logMessage "Package '${linux_modules_package}' is not available"
logMessage "Copying modules from /lib/modules/$(uname -r)"
mkdir -p ${prefix}/lib/modules
cp -au /lib/modules/$(uname -r) ${prefix}/lib/modules
fi
#
# Install the module-init-tools package.
#
installDebianPackage ${prefix} module-init-tools
fi # if pygrub
#
# Log our finish
#
logMessage Script $0 finished

109
hooks/karmic/90-make-fstab Executable file
View File

@@ -0,0 +1,109 @@
#!/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
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Find the root device.
#
# 1. default to sda.
#
# 2. If --ide is specified use hda.
#
# 3. Otherwise use a named $disk_device
#
device=sda
if [ "${ide}" ]; then
device=hda
else
if [ ! -z "${disk_device}" ]; then
device=`basename $disk_device`
fi
fi
logMessage "Root device is /dev/$device"
#
# Now we have the options we can create the fstab.
#
has_xfs=0
has_reiserfs=0
cat <<E_O_FSTAB > ${prefix}/etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0
E_O_FSTAB
for part in `seq 1 ${NUMPARTITIONS}`; do
eval "PARTITION=\"\${PARTITION${part}}\""
OLDIFS="${IFS}"
IFS=:
x=0
for partdata in ${PARTITION}; do
eval "partdata${x}=\"${partdata}\""
x=$(( $x+1 ))
done
IFS="${OLDIFS}"
case "${partdata2}" in
xfs)
has_xfs=1
;;
reiserfs)
has_reiserfs=1
;;
esac
if [ "${partdata2}" = "swap" ]; then
echo "/dev/${device}${part} none swap sw 0 0" >> ${prefix}/etc/fstab
else
echo "/dev/${device}${part} ${partdata3} ${partdata2} ${partdata4} 0 1" >> ${prefix}/etc/fstab
fi
done
#
# Finally we can install any required packages for the given root
# filesystem
#
if [ $has_xfs -eq 1 ]; then
installDebianPackage ${prefix} xfsprogs
fi
if [ $has_reiserfs -eq 1 ]; then
installDebianPackage ${prefix} reiserfsprogs
fi
#
# Log our finish
#
logMessage Script $0 finished

38
hooks/karmic/99-clean-image Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
#
# This script cleans the newly created image's apt-get archive.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Clean the APT package cache for Debian GNU/Linux.
#
chroot ${prefix} /usr/bin/apt-get clean
#
# Log our finish
#
logMessage Script $0 finished

45
hooks/karmic/99-enable-daemons Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/sh
#
# This script removes the file which prevents daemons from running.
#
# Steve
# --
# http://www.steve.org.uk/
prefix=$1
#
# Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
. /usr/lib/xen-tools/common.sh
else
. ./hooks/common.sh
fi
#
# Log our start
#
logMessage Script $0 starting
#
# Remove the script if present.
#
if [ -x "${prefix}/usr/sbin/policy-rc.d" ]; then
rm -f "${prefix}/usr/sbin/policy-rc.d"
logMessage "Removed: ${prefix}/usr/sbin/policy-rc.d"
fi
#
# Log our finish
#
logMessage Script $0 finished