"target" is also the name used in the debian installer for the installation target while "prefix" is too ambiguous.
118 lines
2.9 KiB
Bash
Executable File
118 lines
2.9 KiB
Bash
Executable File
#!/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
|
|
|
|
TARGET=$1
|
|
|
|
#
|
|
# Source our common functions
|
|
#
|
|
|
|
if [ -e /usr/share/xen-tools/common.sh ]; then
|
|
. /usr/share/xen-tools/common.sh
|
|
else
|
|
. ./hooks/common.sh
|
|
fi
|
|
|
|
if [ "${pygrub}" ]; then
|
|
#
|
|
# Log our start
|
|
#
|
|
|
|
logMessage Script $0 starting
|
|
|
|
#
|
|
# Resolve the correct architecutre
|
|
#
|
|
|
|
if [ "${arch}" = "i386" ]; then
|
|
XEN_ARCH="686"
|
|
elif [ "${arch}" = "amd64" ]; then
|
|
XEN_ARCH="amd64"
|
|
elif [ -z "${arch}" ]; then
|
|
UNAME_ARCH=`uname -m`
|
|
if [ "${UNAME_ARCH}" = "i686" ]; then
|
|
XEN_ARCH="686"
|
|
elif [ "${UNAME_ARCH}" = "x86_64" ]; then
|
|
XEN_ARCH="amd64"
|
|
else
|
|
logMessage Unknown kernel architecture ${UNAME_ARCH}.
|
|
logMessage Please report this as bug to xen-tools-dev@xen-tools.org.
|
|
logMessage Script $0 failed
|
|
exit 1
|
|
fi
|
|
else
|
|
logMessage Unknown kernel architecture ${arch}
|
|
logMessage Script $0 failed
|
|
exit 1
|
|
fi
|
|
|
|
#
|
|
# Attempt to install a xen kernel, if that fails, then install a normal one
|
|
#
|
|
|
|
KERNEL_XEN_PKG="linux-image-xen-$XEN_ARCH"
|
|
KERNEL_PKG="linux-image-$XEN_ARCH"
|
|
|
|
logMessage Attempting to install the $KERNEL_XEN_PKG kernel image
|
|
if chroot ${TARGET} /usr/bin/apt-cache show $KERNEL_XEN_PKG > /dev/null 2>&1; then
|
|
logMessage Package $KERNEL_XEN_PKG is available - installing
|
|
installDebianPackage ${TARGET} initramfs-tools
|
|
installDebianPackage ${TARGET} $KERNEL_XEN_PKG
|
|
|
|
else
|
|
logMessage Package $KERNEL_XEN_PKG is not available
|
|
logMessage Attempting to install the $KERNEL_PKG kernel image
|
|
logMessage WARNING: This kernel may not have pvops
|
|
if chroot ${TARGET} /usr/bin/apt-cache show $KERNEL_PKG > /dev/null 2>&1; then
|
|
logMessage Package $KERNEL_PKG is available - installing
|
|
installDebianPackage ${TARGET} initramfs-tools
|
|
installDebianPackage ${TARGET} $KERNEL_PKG
|
|
else
|
|
logMessage Package $KERNEL_PKG is not available
|
|
logMessage pygrub set, but kernel could not be installed
|
|
logMessage Script $0 failed
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
DOMU_KERNEL=$(basename $(ls -1 ${TARGET}/boot/vmlinuz* | tail -n 1))
|
|
KERNEL_REV=$(echo $DOMU_KERNEL | sed "s/vmlinuz-//g")
|
|
DOMU_RAMDISK="initrd.img-$KERNEL_REV"
|
|
DOMU_ISSUE=$(sed -re "s/ *\\\.*//g" -e1q < ${TARGET}/etc/issue)
|
|
|
|
#
|
|
# Generate initrd if it does not exist
|
|
#
|
|
|
|
if [ -f ${TARGET}/boot/$DOMU_RAMDISK ]; then
|
|
logMessage initrd exists, skipping generation
|
|
else
|
|
logMessage initrd missing, generating
|
|
chroot ${TARGET} update-initramfs -c -k $KERNEL_REV
|
|
fi
|
|
|
|
#
|
|
# Generate a menu.lst for pygrub
|
|
#
|
|
|
|
generateDebianGrubMenuLst "${TARGET}" "$DOMU_ISSUE" "$DOMU_KERNEL" "$DOMU_RAMDISK"
|
|
|
|
|
|
else
|
|
logMessage pygrub not set, skipping kernel install
|
|
fi # if pygrub
|
|
|
|
#
|
|
# Log our finish
|
|
#
|
|
|
|
logMessage Script $0 finished
|