feat(image_to_vm): setup grub/menu.lst for xen

xen requires a /boot/grub/menu.lst for pygrub and pvgrub on partition 1.
Put it on the stateful partition for now and come back around and fix
this up when we redo the partition layout.
This commit is contained in:
Brandon Philips 2013-05-03 18:34:45 -07:00
parent edf40e1863
commit be7a09d64d
2 changed files with 37 additions and 3 deletions

View File

@ -34,7 +34,7 @@ DEFINE_boolean factory_install $FLAGS_FALSE \
# behavior from image_to_usb.sh # behavior from image_to_usb.sh
DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image"
DEFINE_string format "qemu" \ DEFINE_string format "qemu" \
"Output format, either qemu, vmware or virtualbox" "Output format, either xen, qemu, vmware or virtualbox"
DEFINE_string from "" \ DEFINE_string from "" \
"Directory containing rootfs.image and mbr.image" "Directory containing rootfs.image and mbr.image"
DEFINE_string disk_layout "vm" \ DEFINE_string disk_layout "vm" \
@ -145,10 +145,12 @@ dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1
TEMP_MNT=$(mktemp -d) TEMP_MNT=$(mktemp -d)
TEMP_ESP_MNT=$(mktemp -d) TEMP_ESP_MNT=$(mktemp -d)
TEMP_STATE_MNT=$(mktemp -d)
cleanup() { cleanup() {
safe_umount "${TEMP_MNT}" safe_umount "${TEMP_MNT}"
safe_umount "${TEMP_ESP_MNT}" safe_umount "${TEMP_ESP_MNT}"
rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" safe_umount "${TEMP_STATE_MNT}"
rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" "${TEMP_STATE_MNT}"
} }
trap cleanup INT TERM EXIT trap cleanup INT TERM EXIT
mkdir -p "${TEMP_MNT}" mkdir -p "${TEMP_MNT}"
@ -160,6 +162,31 @@ sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}"
# Modify the unverified usb template which uses a default usb_disk of sdb3 # Modify the unverified usb template which uses a default usb_disk of sdb3
sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg" sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg"
# HACKBP: this will need to move from STATE to BOOT
# with the new partition layout
BOOT_DIR=${TEMP_STATE_MNT}/boot
GRUB_DIR=${BOOT_DIR}/grub
mkdir -p "${TEMP_STATE_MNT}"
enable_rw_mount "${TEMP_STATE}"
sudo mount -o loop "${TEMP_STATE}" "${TEMP_STATE_MNT}"
sudo mkdir -p "${GRUB_DIR}"
sudo cp -R "${TEMP_ESP_MNT}"/grub/. ${GRUB_DIR}
sudo cp -R "${TEMP_ESP_MNT}"/syslinux/vmlinuz.* "${BOOT_DIR}"
cat ${GRUB_DIR}/menu.lst
# Update the menu.lst to be right for xen pygrub/pv-grub or just guess for
# everything else.
if [ "${FLAGS_format}" = "xen" ]; then
sudo sed -i -e 's%HDROOTA%/dev/xvda3%g' ${GRUB_DIR}/menu.lst
sudo sed -i -e 's%HDROOTB%/dev/xvda5%g' ${GRUB_DIR}/menu.lst
else
sudo sed -i -e 's%HDROOTA%/dev/sda3%g' ${GRUB_DIR}/menu.lst
sudo sed -i -e 's%HDROOTB%/dev/sda5%g' ${GRUB_DIR}/menu.lst
fi
cat ${GRUB_DIR}/menu.lst
# Unmount everything prior to building a final image # Unmount everything prior to building a final image
trap - INT TERM EXIT trap - INT TERM EXIT
cleanup cleanup
@ -194,7 +221,8 @@ ${SCRIPTS_DIR}/bin/cros_make_image_bootable $(dirname "${TEMP_IMG}") \
echo Creating final image echo Creating final image
# Convert image to output format # Convert image to output format
if [ "${FLAGS_format}" = "virtualbox" -o "${FLAGS_format}" = "qemu" ]; then if [ "${FLAGS_format}" = "virtualbox" -o "${FLAGS_format}" = "qemu" \
-o "${FLAGS_format}" = "xen" ]; then
if [ "${FLAGS_format}" = "virtualbox" ]; then if [ "${FLAGS_format}" = "virtualbox" ]; then
sudo VBoxManage convertdd "${TEMP_IMG}" "${FLAGS_to}/${FLAGS_vbox_disk}" sudo VBoxManage convertdd "${TEMP_IMG}" "${FLAGS_to}/${FLAGS_vbox_disk}"
else else

View File

@ -183,6 +183,12 @@ if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
sudo cp "${FLAGS_from}/efi/boot/grub.cfg" \ sudo cp "${FLAGS_from}/efi/boot/grub.cfg" \
"${ESP_FS_DIR}/efi/boot/grub.cfg" "${ESP_FS_DIR}/efi/boot/grub.cfg"
# Copy over the grub configurations for cloud machines and the
# kernel into both the A and B slot
sudo mkdir -p "${ESP_FS_DIR}"/grub
sudo cp -r "${FLAGS_from}"/grub/. "${ESP_FS_DIR}"/grub
sudo cp -r "${FLAGS_from}"/grub/menu.lst.A "${ESP_FS_DIR}"/grub/menu.lst
# Prepopulate the syslinux directories too and update for verified boot values # Prepopulate the syslinux directories too and update for verified boot values
# after the rootfs work is done. # after the rootfs work is done.
sudo mkdir -p "${ESP_FS_DIR}"/syslinux sudo mkdir -p "${ESP_FS_DIR}"/syslinux