I think this patch is more what I meant to do: * Change the /etc/fstab * Set network interfaces * Clear root password * Run a getty on hvc0
Also added a couple of necessary packages to EXTRA_PKGS in p2v-target.conf.in. Signed-off-by: Ben Lipton <[email protected]> --- instance-p2v-target/examples/hooks/grub | 59 -------------------- instance-p2v-target/hooks/clear-root-password | 21 +++++++ .../{examples => }/hooks/interfaces | 0 .../{examples/hooks/interfaces => hooks/ramboot} | 35 ++++-------- instance-p2v-target/hooks/xen-hvc0 | 24 ++++++++ .../{defaults => p2v-target.conf.in} | 9 ++- 6 files changed, 61 insertions(+), 87 deletions(-) delete mode 100755 instance-p2v-target/examples/hooks/grub create mode 100644 instance-p2v-target/hooks/clear-root-password copy instance-p2v-target/{examples => }/hooks/interfaces (100%) rename instance-p2v-target/{examples/hooks/interfaces => hooks/ramboot} (55%) create mode 100644 instance-p2v-target/hooks/xen-hvc0 rename instance-p2v-target/{defaults => p2v-target.conf.in} (94%) diff --git a/instance-p2v-target/examples/hooks/grub b/instance-p2v-target/examples/hooks/grub deleted file mode 100755 index c93dcf5..0000000 --- a/instance-p2v-target/examples/hooks/grub +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -# -# This is an example script that install and configure grub after installation. -# To use it put it in your CUSTOMIZE_DIR, make it executable, and edit EXTRAPKGS -# of your $sysconfdir/default/ganeti-instance-debootstrap. -# -# Xen, for etch/lenny i386: -# EXTRA_PKGS="linux-image-xen-686,libc6-xen" -# Xen, for etch/lenny amd64: -# EXTRA_PKGS="linux-image-xen-amd64" -# KVM: -# no extra packages needed besides the normal suggested ones -# -# Do not include grub in EXTRA_PKGS because it will cause error of debootstrap. - -set -e - -. common.sh - -CLEANUP=( ) - -trap cleanup EXIT - -if [ -z "$TARGET" -o ! -d "$TARGET" ]; then - echo "Missing target directory" - exit 1 -fi - -# install grub -LANG=C -chroot "$TARGET" apt-get -y --force-yes install grub grub-common - -# make /dev/sda -mknod $TARGET/dev/sda b $(stat -L -c "0x%t 0x%T" $BLOCKDEV) -CLEANUP+=("rm -f $TARGET/dev/sda") - -# make /dev/sda1 -mknod $TARGET/dev/sda1 b $(stat -L -c "0x%t 0x%T" $FSYSDEV) -CLEANUP+=("rm -f $TARGET/dev/sda1") - -# create grub directory -mkdir -p "$TARGET/boot/grub" - -# create device.map -cat > "$TARGET/boot/grub/device.map" <<EOF -(hd0) /dev/sda -EOF - -# execute update-grub -chroot "$TARGET" update-grub - -# install grub to the block device -grub-install --no-floppy --root-directory="$TARGET" "$BLOCKDEV" - -# execute cleanups -cleanup -trap - EXIT - -exit 0 diff --git a/instance-p2v-target/hooks/clear-root-password b/instance-p2v-target/hooks/clear-root-password new file mode 100644 index 0000000..417b62d --- /dev/null +++ b/instance-p2v-target/hooks/clear-root-password @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +# Make sure we're not working on the root directory +if [ -z "$TARGET" -o "$TARGET" = "/" ]; then + echo "Invalid target directory '$TARGET', aborting." 1>&2 + exit 1 +fi + +if [ "$(mountpoint -d /)" = "$(mountpoint -d "$TARGET")" ]; then + echo "The target directory seems to be the root dir, aborting." 1>&2 + exit 1 +fi + +# Disable root's password, as the switch to enable shadow by default +# has left root with a disabled password, preventing the initial login +echo "Disabling root's password" +chroot "$TARGET" passwd -d root + +exit 0 diff --git a/instance-p2v-target/examples/hooks/interfaces b/instance-p2v-target/hooks/interfaces similarity index 100% copy from instance-p2v-target/examples/hooks/interfaces copy to instance-p2v-target/hooks/interfaces diff --git a/instance-p2v-target/examples/hooks/interfaces b/instance-p2v-target/hooks/ramboot similarity index 55% rename from instance-p2v-target/examples/hooks/interfaces rename to instance-p2v-target/hooks/ramboot index 455c396..fee3c3e 100755 --- a/instance-p2v-target/examples/hooks/interfaces +++ b/instance-p2v-target/hooks/ramboot @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (C) 2009 Google Inc. +# Copyright (C) 2011 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,37 +17,24 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -# This is an example script that configures you /etc/network/interfaces after -# installation. By default its sets up the system to use dhcp. To use it just -# put it in your CUSTOMIZE_DIR and make it executable. +# This script modifies the /etc/fstab file of the instance OS to prevent +# mounting the hard disk over the tmpfs root. if [ -z "$TARGET" -o ! -d "$TARGET" ]; then echo "Missing target directory" exit 1 fi -if [ ! -d "$TARGET/etc/network" ]; then - echo "Missing target network directory" +if [ ! -f "$TARGET/etc/fstab" ]; then + echo "Missing target /etc/fstab" exit 1 fi -if [ -z "$NIC_COUNT" ]; then - echo "Missing NIC COUNT" - exit 1 -fi - -if [ "$NIC_COUNT" -gt 0 ]; then - - cat > $TARGET/etc/network/interfaces <<EOF -# This file describes the network interfaces available on your system -# and how to activate them. For more information, see interfaces(5). - -auto lo -iface lo inet loopback - -auto eth0 -iface eth0 inet dhcp +cat > $TARGET/etc/fstab <<EOF +# /etc/fstab: static file system information. +# +# <file system> <mount point> <type> <options> <dump> <pass> +tmpfs / tmpfs defaults 0 0 +proc /proc proc defaults 0 0 EOF - -fi diff --git a/instance-p2v-target/hooks/xen-hvc0 b/instance-p2v-target/hooks/xen-hvc0 new file mode 100644 index 0000000..5210767 --- /dev/null +++ b/instance-p2v-target/hooks/xen-hvc0 @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +# Make sure we're not working on the root directory +if [ -z "$TARGET" -o "$TARGET" = "/" ]; then + echo "Invalid target directory '$TARGET', aborting." 1>&2 + exit 1 +fi + +if [ "$(mountpoint -d /)" = "$(mountpoint -d "$TARGET")" ]; then + echo "The target directory seems to be the root dir, aborting." 1>&2 + exit 1 +fi + +# Fix the console information for xen-pvm mode +if [ "$HYPERVISOR" = "xen-pvm" ]; then + echo "xen-pvm hypervisor detected, adding getty on hvc0" + cat >> "$TARGET"/etc/inittab <<EOF +hvc0:2345:respawn:/sbin/getty 38400 hvc0 +EOF +fi + +exit 0 diff --git a/instance-p2v-target/defaults b/instance-p2v-target/p2v-target.conf.in similarity index 94% rename from instance-p2v-target/defaults rename to instance-p2v-target/p2v-target.conf.in index 72d41ac..f6456f9 100644 --- a/instance-p2v-target/defaults +++ b/instance-p2v-target/p2v-target.conf.in @@ -22,7 +22,7 @@ # SUITE: change suite to any of the ones supported by deboostrap; this # could be unstable, etch, etc.: -# SUITE="lenny" +# SUITE="squeeze" # EXTRA_PKGS: depending on the suite and architecture you are using, different # extra packages are needed for different hypervisors. For example: @@ -35,12 +35,13 @@ # EXTRA_PKGS="acpi-support-base,console-tools,udev,linux-image-686" # KVM, for lenny amd64: # EXTRA_PKGS="acpi-support-base,console-tools,udev,linux-image-amd64" -# + +# Additional packages required for p2v-target image +EXTRA_PKGS+=",rsync,openssh-server" # CUSTOMIZE_DIR: a directory containing scripts to customize the installation. # The scripts are executed using run-parts -# By default /etc/ganeti/instance-debootstrap/hooks -# CUSTOMIZE_DIR="/etc/ganeti/instance-debootstrap/hooks" +# CUSTOMIZE_DIR="@configdir@/hooks" # GENERATE_CACHE: if set to yes (the default), create new cache files; # any other value will disable the generation of cache files (but they -- 1.7.3.1
