93 lines
2.2 KiB
Bash
Executable File
93 lines
2.2 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
|
|
|
|
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
|
|
DOMU_KERNEL=$(basename $(ls -1 ${prefix}/boot/vmlinuz* | tail -n 1))
|
|
DOMU_RAMDISK=$(basename $(ls -1 ${prefix}/boot/initrd*|tail -n 1))
|
|
DOMU_ISSUE=$(head -n 1 ${prefix}/etc/issue | awk -F '\' '{ print $1 }' | sed 's/[ \t]*$//')
|
|
|
|
mkdir -p ${prefix}/boot/grub
|
|
cat << E_O_MENU > ${prefix}/boot/grub/menu.lst
|
|
default 0
|
|
timeout 2
|
|
|
|
title $DOMU_ISSUE
|
|
root (hd0,0)
|
|
kernel /boot/$DOMU_KERNEL root=/dev/xvda2 ro elevator=noop
|
|
initrd /boot/$DOMU_RAMDISK
|
|
|
|
title $DOMU_ISSUE (Single-User)
|
|
root (hd0,0)
|
|
kernel /boot/$DOMU_KERNEL root=/dev/xvda2 ro single elevator=noop
|
|
initrd /boot/$DOMU_RAMDISK
|
|
|
|
E_O_MENU
|
|
|
|
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
|