feat(disk_layout): follow new CoreOS partition layout

As outlined here we need a new partition layout, this patch makes the
necessary changes:
https://groups.google.com/forum/#!topic/coreos-dev/bA7gwGGoTng

The first big change is making all of the scripts obey partition numbers
based on labels in the disk_layout.json. This makes it much easier to
change later on.

The second big change is in the layout itself. The json file was updated
to reflect the document above.

And finally the grub boot configuration needed for pv-grub and pygrub
were added to the create_legacy_bootloader_templates.sh library utlity.

Everything seems to work and boot now.
This commit is contained in:
Brandon Philips 2013-05-09 17:43:50 -07:00
parent be7a09d64d
commit 4057d5590d
12 changed files with 189 additions and 423 deletions

View File

@ -83,8 +83,6 @@ DEFINE_string image "chromiumos_base.img" \
"Full path to the chromiumos image to make bootable."
DEFINE_string arch "x86" \
"Architecture to make bootable for: arm, x86, or amd64"
DEFINE_string usb_disk "/dev/sdb3" \
"Path syslinux should use to do a usb boot."
DEFINE_boolean cleanup_dirs ${FLAGS_TRUE} \
"Whether the mount dirs should be removed on completion."
@ -190,6 +188,8 @@ make_image_bootable() {
--image "$(basename ${image})" -r "${FLAGS_rootfs_mountpoint}" \
-s "${FLAGS_statefulfs_mountpoint}"
legacy_offset_size_export ${image}
# The rootfs should never be mounted rw again after this point without
# re-calling make_image_bootable.
sudo mount -o remount,ro "${FLAGS_rootfs_mountpoint}"
@ -226,6 +226,7 @@ make_image_bootable() {
-noI -noF -ef ${SCRIPTS_DIR}/exclude-list -wildcards ${squash_sort_flag}
root_dev=$squashfs_img
fi
# Builds the kernel partition image. The temporary files are kept around
# so that we can perform a load_kernel_test later on the final image.
${SCRIPTS_DIR}/build_kernel_image.sh \
@ -259,8 +260,8 @@ make_image_bootable() {
fi
local rootfs_hash_size=$(stat -c '%s' ${FLAGS_rootfs_hash})
local rootfs_fs_size=$(get_filesystem_size ${FLAGS_image_type} 3)
local rootfs_partition_size=$(get_partition_size ${FLAGS_image_type} 3)
local rootfs_fs_size=$(get_filesystem_size ${FLAGS_image_type} ${NUM_ROOTFS_A})
local rootfs_partition_size=$(get_partition_size ${FLAGS_image_type} ${NUM_ROOTFS_A})
local rootfs_hash_pad=$(( rootfs_partition_size - rootfs_fs_size ))
info "Appending rootfs.hash (${rootfs_hash_size} bytes) to the root fs"
if [[ ${rootfs_hash_size} -gt ${rootfs_hash_pad} ]]
@ -272,7 +273,7 @@ make_image_bootable() {
# Unfortunately, mount_gpt_image uses mount and not losetup to create the
# loop devices. This means that they are not the correct size. We have to
# write directly to the image to append the hash tree data.
local hash_offset="$(partoffset ${image} 3)"
local hash_offset="$(partoffset ${image} ${NUM_ROOTFS_A})"
if [ $FLAGS_enable_squashfs -eq $FLAGS_TRUE ]; then
rootfs_file_size=$(stat -c '%s' ${root_dev})
hash_offset=$((hash_offset + (${rootfs_file_size} / 512)))
@ -294,41 +295,21 @@ make_image_bootable() {
sudo cp "${FLAGS_output_dir}/vmlinuz_hd.vblock" \
"${FLAGS_statefulfs_mountpoint}"
local koffset="$(partoffset ${image} 2)"
sudo dd if="${FLAGS_output_dir}/vmlinuz.image" of="${image}" \
conv=notrunc bs=512 seek=${koffset} status=none
# Update the bootloaders. The EFI system partition will be updated.
local kernel_part=
local usb_disk="${FLAGS_usb_disk}"
# We should update the esp in place in the image.
local bootloader_to="${image}"
local esp_offset="$(partoffset ${image} 12)"
local esp_offset="$(partoffset ${image} ${NUM_ESP})"
esp_offset=$((esp_offset * 512)) # sectors to bytes
local esp_size="$(partsize ${image} 12)"
local esp_size="$(partsize ${image} ${NUM_ESP})"
esp_size=$((esp_size * 512)) # sectors to bytes
local bootloader_to_flags="--to_offset=${esp_offset} --to_size=${esp_size}"
if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
# Use the kernel partition to acquire configuration flags.
kernel_part="--kernel_partition='${FLAGS_output_dir}/vmlinuz.image'"
# Install syslinux on the EFI System Partition.
kernel_part="${kernel_part} --install_syslinux"
elif [[ "${FLAGS_arch}" = "arm" ]]; then
# These flags are not used for ARM update_bootloaders.sh
kernel_part=""
fi
# Update partition 12
${SCRIPTS_DIR}/update_bootloaders.sh \
--arch=${FLAGS_arch} \
--to="${bootloader_to}" \
--from="${FLAGS_rootfs_mountpoint}"/boot \
--vmlinuz="${FLAGS_rootfs_mountpoint}"/boot/vmlinuz \
--usb_disk="${usb_disk}" \
${bootloader_to_flags} \
$kernel_part
${bootloader_to_flags}
# We don't need to keep these files around anymore.
sudo rm "${FLAGS_rootfs_hash}" "${FLAGS_output_dir}/vmlinuz.image" \
@ -342,7 +323,7 @@ make_image_bootable() {
if [ $FLAGS_enable_squashfs -eq $FLAGS_TRUE ]; then
# copy the squashfs image to the partition
info "copy the squashfs to the partition"
local part_offset="$(partoffset ${image} 3)"
local part_offset="$(partoffset ${image} ${NUM_ROOTFS_A})"
sudo dd bs=512 if="${squashfs_img}" of="${image}" \
seek=${part_offset} conv=notrunc status=none
sudo rm "${squashfs_img}"

View File

@ -29,8 +29,8 @@ DEFINE_string disk_layout "default" \
"The disk layout type to use for this image."
DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \
"Install standard backdoor credentials for testing"
DEFINE_string usb_disk /dev/sdb3 \
"Path syslinux should use to do a usb boot. Default: /dev/sdb3"
DEFINE_string usb_disk /dev/sdb4 \
"Path syslinux should use to do a usb boot. Default: /dev/sdb4"
DEFINE_string enable_serial "" \
"Enable serial port for printks. Example values: ttyS0"

View File

@ -71,22 +71,26 @@ create_base_image() {
trap "cleanup_mounts && delete_prompt" EXIT
cleanup_mounts &> /dev/null
local root_fs_label="ROOT-A"
local root_fs_num=$(get_num ${image_type} ${root_fs_label})
local root_fs_img="${BUILD_DIR}/rootfs.image"
local root_fs_bytes=$(get_filesystem_size ${image_type} 3)
local root_fs_label=$(get_label ${image_type} 3)
local root_fs_bytes=$(get_filesystem_size ${image_type} ${root_fs_num})
local stateful_fs_label="STATE"
local stateful_fs_num=$(get_num ${image_type} ${stateful_fs_label})
local stateful_fs_img="${BUILD_DIR}/stateful.image"
local stateful_fs_bytes=$(get_filesystem_size ${image_type} 1)
local stateful_fs_label=$(get_label ${image_type} 1)
local stateful_fs_bytes=$(get_filesystem_size ${image_type} ${stateful_fs_num})
local stateful_fs_uuid=$(uuidgen)
local esp_fs_label="EFI-SYSTEM"
local esp_fs_num=$(get_num ${image_type} ${esp_fs_label})
local esp_fs_img="${BUILD_DIR}/esp.image"
local esp_fs_bytes=$(get_filesystem_size ${image_type} 12)
local esp_fs_label=$(get_label ${image_type} 12)
local esp_fs_bytes=$(get_filesystem_size ${image_type} ${esp_fs_num})
local oem_fs_label="OEM"
local oem_fs_num=$(get_num ${image_type} ${oem_fs_label})
local oem_fs_img="${BUILD_DIR}/oem.image"
local oem_fs_bytes=$(get_filesystem_size ${image_type} 8)
local oem_fs_label=$(get_label ${image_type} 8)
local oem_fs_bytes=$(get_filesystem_size ${image_type} ${oem_fs_num})
local oem_fs_uuid=$(uuidgen)
local fs_block_size=$(get_fs_block_size)

View File

@ -135,7 +135,6 @@ create_boot_desc() {
--image_type=${image_type}
--arch="${ARCH}"
--keys_dir="${DEVKEYSDIR}"
--usb_disk="${FLAGS_usb_disk}"
--boot_args="${FLAGS_boot_args}"
--nocleanup_dirs
--verity_algorithm=sha1

View File

@ -294,16 +294,12 @@ def WriteLayoutFunction(options, sfile, func_name, image_type, config):
sfile.write('$GPT add -i %d -b $CURR -s %s -t %s -l %s $1 && ' % (
partition['num'], str(partition['var']), partition['type'],
partition['label']))
if partition['type'] == 'efi':
sfile.write('$GPT boot -p -b $2 -i %d $1\n' % partition['num'])
# Increment the CURR counter ready for the next partition.
sfile.write('CURR=$(( $CURR + %s ))\n' % partition['var'])
# Set default priorities on kernel partitions
sfile.write('$GPT add -i 2 -S 0 -T 15 -P 15 $1\n')
sfile.write('$GPT add -i 4 -S 0 -T 15 -P 0 $1\n')
sfile.write('$GPT add -i 6 -S 0 -T 15 -P 0 $1\n')
sfile.write('$GPT boot -p -b $2 -i 12 $1\n')
sfile.write('$GPT show $1\n')
sfile.write('}\n')
@ -458,6 +454,27 @@ def GetLabel(options, image_type, layout_filename, num):
return 'UNTITLED'
def GetNum(options, image_type, layout_filename, label):
"""Returns the number for a given label.
Args:
options: Flags passed to the script
image_type: Type of image eg base/test/dev/factory_install
layout_filename: Path to partition configuration file
label: Label of the partition you want to read from
Returns:
Number of selected partition, or '-1' if there is no number
"""
partitions = GetPartitionTableFromConfig(options, layout_filename, image_type)
partition = GetPartitionByLabel(partitions, label)
if 'num' in partition:
return partition['num']
else:
return '-1'
def DoDebugOutput(options, image_type, layout_filename):
"""Prints out a human readable disk layout in on-disk order.
@ -526,6 +543,10 @@ def main(argv):
'usage': ['<image_type>', '<partition_config_file>', '<partition_num>'],
'func': GetLabel,
},
'readnum': {
'usage': ['<image_type>', '<partition_config_file>', '<label>'],
'func': GetNum,
},
'debug': {
'usage': ['<image_type>', '<partition_config_file>'],
'func': DoDebugOutput,

View File

@ -69,7 +69,7 @@ if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
# Build configuration files for pygrub/pvgrub
GRUB_DIR="${FLAGS_to}/grub"
GRUB_DIR="${FLAGS_to}/boot/grub"
sudo mkdir -p "${GRUB_DIR}"
cat <<EOF | sudo dd of="${GRUB_DIR}/menu.lst.A" 2>/dev/null
@ -77,11 +77,11 @@ timeout 0
title CoreOS A
root (hd0,0)
kernel /boot/vmlinuz.A ${common_args} root=HDROOTA cros_legacy
kernel /syslinux/vmlinuz.A ${common_args} root=HDROOTA cros_legacy
title CoreOS B
root (hd0,0)
kernel /boot/vmlinuz.B ${common_args} root=HDROOTB cros_legacy
kernel /syslinux/vmlinuz.B ${common_args} root=HDROOTB cros_legacy
EOF
info "Emitted ${GRUB_DIR}/menu.lst.A"
@ -105,72 +105,36 @@ TIMEOUT 0
# the actual target
include /syslinux/default.cfg
# chromeos-usb.A
include /syslinux/usb.A.cfg
# chromeos-hd.A / chromeos-vhd.A
# coreos.A
include /syslinux/root.A.cfg
# chromeos-hd.B / chromeos-vhd.B
# coreos.B
include /syslinux/root.B.cfg
EOF
info "Emitted ${SYSLINUX_DIR}/syslinux.cfg"
if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then
# To change the active target, only this file needs to change.
cat <<EOF | sudo dd of="${SYSLINUX_DIR}/default.cfg" 2>/dev/null
DEFAULT chromeos-vusb.A
# To change the active target, only this file needs to change.
cat <<EOF | sudo dd of="${SYSLINUX_DIR}/default.cfg" 2>/dev/null
DEFAULT coreos.A
EOF
else
# To change the active target, only this file needs to change.
cat <<EOF | sudo dd of="${SYSLINUX_DIR}/default.cfg" 2>/dev/null
DEFAULT chromeos-usb.A
EOF
fi
info "Emitted ${SYSLINUX_DIR}/default.cfg"
cat <<EOF | sudo dd of="${SYSLINUX_DIR}/usb.A.cfg" 2>/dev/null
label chromeos-usb.A
menu label chromeos-usb.A
kernel vmlinuz.A
append ${common_args} root=${FLAGS_usb_disk} i915.modeset=1 cros_legacy
label chromeos-vusb.A
menu label chromeos-vusb.A
kernel vmlinuz.A
append ${common_args} ${verity_common} root=${ROOTDEV} \
i915.modeset=1 cros_legacy dm="DMTABLEA"
EOF
info "Emitted ${SYSLINUX_DIR}/usb.A.cfg"
# Different files are used so that the updater can only touch the file it
# needs to for a given change. This will minimize any potential accidental
# updates issues, hopefully.
cat <<EOF | sudo dd of="${SYSLINUX_DIR}/root.A.cfg" 2>/dev/null
label chromeos-hd.A
menu label chromeos-hd.A
label coreos.A
menu label coreos.A
kernel vmlinuz.A
append ${common_args} root=HDROOTA i915.modeset=1 cros_legacy
label chromeos-vhd.A
menu label chromeos-vhd.A
kernel vmlinuz.A
append ${common_args} ${verity_common} root=${ROOTDEV} \
i915.modeset=1 cros_legacy dm="DMTABLEA"
EOF
info "Emitted ${SYSLINUX_DIR}/root.A.cfg"
cat <<EOF | sudo dd of="${SYSLINUX_DIR}/root.B.cfg" 2>/dev/null
label chromeos-hd.B
menu label chromeos-hd.B
label coreos.B
menu label coreos.B
kernel vmlinuz.B
append ${common_args} root=HDROOTB i915.modeset=1 cros_legacy
label chromeos-vhd.B
menu label chromeos-vhd.B
kernel vmlinuz.B
append ${common_args} ${verity_common} root=${ROOTDEV} \
i915.modeset=1 cros_legacy dm="DMTABLEB"
EOF
info "Emitted ${SYSLINUX_DIR}/root.B.cfg"

View File

@ -88,18 +88,6 @@ EOF
sudo chmod a+rx "${path}"
fi
# If python is installed on stateful-dev, fix python symlinks.
local python_path="/usr/local/bin/python2.6"
if [ -e "${root_fs_dir}${python_path}" ]; then
info "Fixing python symlinks for developer and test images."
local python_paths="/usr/bin/python /usr/local/bin/python \
/usr/bin/python2 /usr/local/bin/python2"
for path in ${python_paths}; do
sudo rm -f "${root_fs_dir}${path}"
sudo ln -s ${python_path} "${root_fs_dir}${path}"
done
fi
info "Developer image built and stored at ${image_name}"
cleanup_mounts

View File

@ -104,6 +104,14 @@ get_label() {
cgpt_py readlabel "${image_type}" "${DISK_LAYOUT_PATH}" ${part_id}
}
get_num() {
local image_type=$1
local label=$2
get_disk_layout_path
cgpt_py readnum "${image_type}" "${DISK_LAYOUT_PATH}" ${label}
}
check_valid_layout() {
local image_type=$1
get_disk_layout_path
@ -194,22 +202,34 @@ build_gpt() {
sudo=sudo
fi
local root_fs_label="ROOT-A"
local root_fs_num=$(get_num ${image_type} ${root_fs_label})
local stateful_fs_label="STATE"
local stateful_fs_num=$(get_num ${image_type} ${stateful_fs_label})
local esp_fs_label="EFI-SYSTEM"
local esp_fs_num=$(get_num ${image_type} ${esp_fs_label})
local oem_fs_label="OEM"
local oem_fs_num=$(get_num ${image_type} ${oem_fs_label})
# Now populate the partitions.
info "Copying stateful partition..."
$sudo dd if="$stateful_img" of="$outdev" conv=notrunc bs=512 \
seek=$(partoffset ${outdev} 1) status=none
seek=$(partoffset ${outdev} ${stateful_fs_num}) status=none
info "Copying rootfs..."
$sudo dd if="$rootfs_img" of="$outdev" conv=notrunc bs=512 \
seek=$(partoffset ${outdev} 3) status=none
seek=$(partoffset ${outdev} ${root_fs_num}) status=none
info "Copying EFI system partition..."
$sudo dd if="$esp_img" of="$outdev" conv=notrunc bs=512 \
seek=$(partoffset ${outdev} 12) status=none
seek=$(partoffset ${outdev} ${esp_fs_num}) status=none
info "Copying OEM partition..."
$sudo dd if="$oem_img" of="$outdev" conv=notrunc bs=512 \
seek=$(partoffset ${outdev} 8) status=none
seek=$(partoffset ${outdev} ${oem_fs_num}) status=none
# Pre-set "sucessful" bit in gpt, so we will never mark-for-death
# a partition on an SDCard/USB stick.

View File

@ -7,74 +7,17 @@
"layouts":{
"base":[
{
"num": 11,
"label":"RWFW",
"type":"firmware",
"blocks":"16384"
},
{
"num": 6,
"label":"KERN-C",
"type":"kernel",
"blocks":"1"
},
{
"num": 7,
"label":"ROOT-C",
"type":"rootfs",
"blocks":"1"
},
{
"num": 9,
"type":"reserved",
"label":"reserved",
"blocks":"1"
},
{
"num": 10,
"type":"reserved",
"label":"reserved",
"blocks":"1"
},
{
"type":"blank",
"blocks":"4028"
"num": 1,
"label":"EFI-SYSTEM",
"type":"efi",
"blocks":"262144"
},
{
"num": 2,
"label":"KERN-A",
"type":"kernel",
"label":"BOOT-B",
"type":"reserved",
"blocks":"32768"
},
{
"num": 4,
"label":"KERN-B",
"type":"kernel",
"blocks":"32768"
},
{
"num": 8,
"label":"OEM",
"type":"data",
"blocks":"32768"
},
{
"type":"blank",
"blocks":"131072"
},
{
"num": 12,
"label":"EFI-SYSTEM",
"type":"efi",
"blocks":"32768"
},
{
"num": 5,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"4194304",
"fs_blocks":"262144"
},
{
"num": 3,
"label":"ROOT-A",
@ -83,7 +26,38 @@
"fs_blocks":"262144"
},
{
"num": 1,
"num": 4,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"4194304",
"fs_blocks":"262144"
},
{
"num": 5,
"label":"ROOT-C",
"type":"rootfs",
"blocks":"1"
},
{
"num": 6,
"label":"OEM",
"type":"data",
"blocks":"32768"
},
{
"num": 7,
"type":"reserved",
"label":"reserved",
"blocks":"1"
},
{
"num": 8,
"type":"reserved",
"label":"reserved",
"blocks":"1"
},
{
"num": 9,
"label":"STATE",
"type":"data",
"blocks":"2097152",
@ -99,7 +73,7 @@
"fs_blocks":"262144"
},
{
"num": 5,
"num": 4,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"1"
@ -108,9 +82,9 @@
"factory_install": [
{
"num": 1,
"label":"STATE",
"type":"data",
"blocks":"286720"
"label":"EFI-SYSTEM",
"type":"efi",
"blocks":"65536"
},
{
"num": 3,
@ -120,111 +94,38 @@
"fs_blocks":"102400"
},
{
"num": 5,
"num": 4,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"1"
},
{
"num": 12,
"label":"EFI-SYSTEM",
"type":"efi",
"blocks":"65536"
"num": 9,
"label":"STATE",
"type":"data",
"blocks":"286720"
}
],
"vm": [
{
"num": 1,
"num": 3,
"label":"ROOT-A",
"type":"rootfs",
"blocks":"2097152",
"fs_blocks":"262144"
},
{
"num": 4,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"2097152",
"fs_blocks":"262144"
},
{
"num": 9,
"label":"STATE",
"type":"data",
"blocks":"6291456"
},
{
"num": 3,
"label":"ROOT-A",
"type":"rootfs",
"blocks":"2539520",
"fs_blocks":"262144"
},
{
"num": 5,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"2539520",
"fs_blocks":"262144"
}
],
"recovery": [
{
"num": 1,
"label":"STATE",
"type":"data",
"blocks":"4096"
},
{
"num": 3,
"label":"ROOT-A",
"type":"rootfs",
"blocks":"2539520",
"fs_blocks":"262144"
},
{
"num": 5,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"4096"
}
],
"2gb-rootfs": [
{
"num": 3,
"label":"ROOT-A",
"type":"rootfs",
"blocks":"4569600",
"fs_blocks":"512000"
},
{
"num": 5,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"1"
}
],
"2gb-rootfs-updatable": [
{
"num": 1,
"label":"STATE",
"type":"data",
"blocks":"6291456"
},
{
"num": 3,
"label":"ROOT-A",
"type":"rootfs",
"blocks":"4569600",
"fs_blocks":"512000"
},
{
"num": 5,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"4569600",
"fs_blocks":"512000"
}
],
"4gb-rootfs": [
{
"num": 3,
"label":"ROOT-A",
"type":"rootfs",
"blocks":"8729600",
"fs_blocks":"1024000"
},
{
"num": 5,
"label":"ROOT-B",
"type":"rootfs",
"blocks":"1"
}
]
}

View File

@ -100,6 +100,9 @@ else
SRC_IMAGE="${FLAGS_from}/${CHROMEOS_IMAGE_NAME}"
fi
locate_gpt
legacy_offset_size_export ${SRC_IMAGE}
# Memory units are in MBs
TEMP_IMG="$(dirname "${SRC_IMAGE}")/vm_temp_image.bin"
@ -120,15 +123,14 @@ pushd "${TEMP_DIR}" >/dev/null
popd >/dev/null
# Fix the kernel command line
TEMP_ESP="${TEMP_DIR}"/part_12
TEMP_OEM="${TEMP_DIR}"/part_8
TEMP_ROOTFS="${TEMP_DIR}"/part_3
TEMP_STATE="${TEMP_DIR}"/part_1
TEMP_KERN="${TEMP_DIR}"/part_2
TEMP_ESP="${TEMP_DIR}"/part_${NUM_ESP}
TEMP_OEM="${TEMP_DIR}"/part_${NUM_OEM}
TEMP_ROOTFS="${TEMP_DIR}"/part_${NUM_ROOTFS_A}
TEMP_STATE="${TEMP_DIR}"/part_${NUM_STATEFUL}
if [ -n "${FLAGS_state_image}" ]; then
TEMP_STATE="${FLAGS_state_image}"
else
STATEFUL_SIZE_BYTES=$(get_filesystem_size "${FLAGS_disk_layout}" 1)
STATEFUL_SIZE_BYTES=$(get_filesystem_size "${FLAGS_disk_layout}" ${NUM_STATEFUL})
STATEFUL_SIZE_MEGABYTES=$(( STATEFUL_SIZE_BYTES / 1024 / 1024 ))
original_image_size=$(stat -c%s "${TEMP_STATE}")
if [ "${original_image_size}" -gt "${STATEFUL_SIZE_BYTES}" ]; then
@ -143,49 +145,36 @@ fi
TEMP_PMBR="${TEMP_DIR}"/pmbr
dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1
TEMP_MNT=$(mktemp -d)
# Setup the bootloader configs to be correct for the image type
TEMP_ESP_MNT=$(mktemp -d)
TEMP_STATE_MNT=$(mktemp -d)
cleanup() {
safe_umount "${TEMP_MNT}"
safe_umount "${TEMP_ESP_MNT}"
safe_umount "${TEMP_STATE_MNT}"
rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" "${TEMP_STATE_MNT}"
rmdir "${TEMP_ESP_MNT}"
}
trap cleanup INT TERM EXIT
mkdir -p "${TEMP_MNT}"
enable_rw_mount "${TEMP_ROOTFS}"
sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}"
mkdir -p "${TEMP_ESP_MNT}"
enable_rw_mount "${TEMP_ESP}"
sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}"
# 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"
# HACKBP: this will need to move from STATE to BOOT
# with the new partition layout
BOOT_DIR=${TEMP_STATE_MNT}/boot
SYSLINUX_DIR=${TEMP_ESP_MNT}/syslinux
BOOT_DIR=${TEMP_ESP_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
# Assume that if we are booting syslinux we are fully virtualized
sudo sed -i -e "s%HDROOTA%/dev/sda${NUM_ROOTFS_A}%g" ${SYSLINUX_DIR}/root.A.cfg
sudo sed -i -e "s%HDROOTB%/dev/sda${NUM_ROOTFS_B}%g" ${SYSLINUX_DIR}/root.B.cfg
# 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
sudo sed -i -e "s%HDROOTA%/dev/xvda${NUM_ROOTFS_A}%g" ${GRUB_DIR}/menu.lst
sudo sed -i -e "s%HDROOTB%/dev/xvda${NUM_ROOTFS_B}%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
sudo sed -i -e "s%HDROOTA%/dev/sda${NUM_ROOTFS_A}%g" ${GRUB_DIR}/menu.lst
sudo sed -i -e "s%HDROOTB%/dev/sda${NUM_ROOTFS_B}%g" ${GRUB_DIR}/menu.lst
fi
cat ${GRUB_DIR}/menu.lst
cat ${GRUB_DIR}/menu.lst ${SYSLINUX_DIR}/root.A.cfg
# Unmount everything prior to building a final image
trap - INT TERM EXIT
@ -200,24 +189,13 @@ rm "${PARTITION_SCRIPT_PATH}"
# Copy into the partition parts of the file
dd if="${TEMP_ROOTFS}" of="${TEMP_IMG}" conv=notrunc bs=512 \
seek=$(partoffset ${TEMP_IMG} 3)
seek=$(partoffset ${TEMP_IMG} ${NUM_ROOTFS_A})
dd if="${TEMP_STATE}" of="${TEMP_IMG}" conv=notrunc bs=512 \
seek=$(partoffset ${TEMP_IMG} 1)
dd if="${TEMP_KERN}" of="${TEMP_IMG}" conv=notrunc bs=512 \
seek=$(partoffset ${TEMP_IMG} 2)
seek=$(partoffset ${TEMP_IMG} ${NUM_STATEFUL})
dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \
seek=$(partoffset ${TEMP_IMG} 12)
seek=$(partoffset ${TEMP_IMG} ${NUM_ESP})
dd if="${TEMP_OEM}" of="${TEMP_IMG}" conv=notrunc bs=512 \
seek=$(partoffset ${TEMP_IMG} 8)
# Make the built-image bootable and ensure that the legacy default usb boot
# uses /dev/sda instead of /dev/sdb3.
# NOTE: The TEMP_IMG must live in the same image dir as the original image
# to operate automatically below.
${SCRIPTS_DIR}/bin/cros_make_image_bootable $(dirname "${TEMP_IMG}") \
$(basename "${TEMP_IMG}") \
--usb_disk /dev/sda3 \
--force_developer_mode
seek=$(partoffset ${TEMP_IMG} ${NUM_OEM})
echo Creating final image
# Convert image to output format

View File

@ -102,18 +102,20 @@ get_usb_partitions() {
[ ${FLAGS_read_only} -eq ${FLAGS_TRUE} -o \
${FLAGS_safe} -eq ${FLAGS_TRUE} ] && safe_flag="-o ro -t ext2"
sudo mount ${safe_flag} "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}"
sudo mount ${ro_flag} "${FLAGS_from}1" "${FLAGS_stateful_mountpt}"
sudo mount ${safe_flag} "${FLAGS_from}4" "${FLAGS_rootfs_mountpt}"
sudo mount ${ro_flag} "${FLAGS_from}10" "${FLAGS_stateful_mountpt}"
if [[ -n "${FLAGS_esp_mountpt}" ]]; then
sudo mount ${ro_flag} "${FLAGS_from}12" "${FLAGS_esp_mountpt}"
sudo mount ${ro_flag} "${FLAGS_from}2" "${FLAGS_esp_mountpt}"
fi
}
get_gpt_partitions() {
local filename="${FLAGS_image}"
legacy_offset_size_export "${FLAGS_from}/${FLAGS_image}"
# Mount the rootfs partition using a loopback device.
local offset=$(partoffset "${FLAGS_from}/${filename}" 3)
local offset=$(partoffset "${FLAGS_from}/${filename}" ${NUM_ROOTFS_A})
local ro_flag=""
local safe_flag=""
@ -139,7 +141,7 @@ get_gpt_partitions() {
fi
# Mount the stateful partition using a loopback device.
offset=$(partoffset "${FLAGS_from}/${filename}" 1)
offset=$(partoffset "${FLAGS_from}/${filename}" ${NUM_STATEFUL})
if ! sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
"${FLAGS_from}/${filename}" "${FLAGS_stateful_mountpt}" ; then
error "mount failed: options=${ro_flag} offset=$(( offset * 512 ))" \
@ -147,9 +149,9 @@ get_gpt_partitions() {
return 1
fi
# Mount the stateful partition using a loopback device.
# Mount the esp partition using a loopback device.
if [[ -n "${FLAGS_esp_mountpt}" ]]; then
offset=$(partoffset "${FLAGS_from}/${filename}" 12)
offset=$(partoffset "${FLAGS_from}/${filename}" ${NUM_ESP})
if ! sudo mount ${ro_flag} -o loop,offset=$(( offset * 512 )) \
"${FLAGS_from}/${filename}" "${FLAGS_esp_mountpt}" ; then
error "mount failed: options=${ro_flag} offset=$(( offset * 512 ))" \

View File

@ -20,8 +20,8 @@ assert_inside_chroot
DEFINE_string arch "x86" \
"The boot architecture: arm or x86. (Default: x86)"
# TODO(wad) once extlinux is dead, we can remove this.
DEFINE_boolean install_syslinux ${FLAGS_FALSE} \
"Controls whether syslinux is run on 'to'. (Default: false)"
DEFINE_boolean install_syslinux ${FLAGS_TRUE} \
"Controls whether syslinux is run on 'to'. (Default: true)"
DEFINE_string from "/tmp/boot" \
"Path the legacy bootloader templates are copied from. (Default /tmp/boot)"
DEFINE_string to "/tmp/esp.img" \
@ -32,18 +32,6 @@ DEFINE_integer to_size -1 \
"Size in bytes of 'to' to use if it is a file. -1 is ignored. (Default: -1)"
DEFINE_string vmlinuz "/tmp/vmlinuz" \
"Path to the vmlinuz file to use (Default: /tmp/vmlinuz)"
# The kernel_partition and the kernel_cmdline each are used to supply
# verified boot configuration: dm="".
DEFINE_string kernel_partition "/tmp/vmlinuz.image" \
"Path to the signed kernel image. (Default: /tmp/vmlinuz.image)"
DEFINE_string kernel_cmdline "" \
"Kernel commandline if no kernel_partition given. (Default: '')"
DEFINE_string kernel_partition_offset "0" \
"Offset to the kernel partition [KERN-A] (Default: 0)"
DEFINE_string kernel_partition_sectors "0" \
"Kernel partition sectors (Default: 0)"
DEFINE_string usb_disk /dev/sdb3 \
"Path syslinux should use to do a usb boot. Default: /dev/sdb3"
# Parse flags
FLAGS "$@" || exit 1
@ -56,74 +44,6 @@ part_index_to_uuid() {
cgpt show -i "$index" -u "$image"
}
# If not provided by chromeos-common.sh, this will update all of the
# boot loader files (both A and B) with the data pulled
# from the kernel_partition. The default boot target should
# be set when the rootfs is stuffed.
if ! type -p update_x86_bootloaders; then
update_x86_bootloaders() {
local old_root="$1" # e.g., /dev/sd%D%P or %U+1
local kernel_cmdline="$2"
local esp_fs_dir="$3"
local template_dir="$4"
local to="$5"
# Pull out the dm="" values
dm_table=
if echo "$kernel_cmdline" | grep -q 'dm="'; then
dm_table=$(echo "$kernel_cmdline" | sed -s 's/.*dm="\([^"]*\)".*/\1/')
fi
# Maintain cros_debug flag in developer and test images.
cros_flags="cros_legacy"
if echo "$kernel_cmdline" | grep -q 'cros_debug'; then
cros_flags="cros_legacy cros_debug"
fi
root_a_uuid="PARTUUID=$(part_index_to_uuid "$to" 3)"
root_b_uuid="PARTUUID=$(part_index_to_uuid "$to" 5)"
# Rewrite grub table
grub_dm_table_a=${dm_table//${old_root}/${root_a_uuid}}
grub_dm_table_b=${dm_table//${old_root}/${root_b_uuid}}
sed -e "s|DMTABLEA|${grub_dm_table_a}|g" \
-e "s|DMTABLEB|${grub_dm_table_b}|g" \
-e "s|cros_legacy|${cros_flags}|g" \
"${template_dir}"/efi/boot/grub.cfg |
sudo dd of="${esp_fs_dir}"/efi/boot/grub.cfg status=none
sed -e "s|/dev/\\\$linuxpartA|${root_a_uuid}|g" \
-e "s|/dev/\\\$linuxpartB|${root_b_uuid}|g" \
"${template_dir}"/efi/boot/grub.cfg |
sudo dd of="${esp_fs_dir}"/efi/boot/grub.cfg status=none
# Rewrite syslinux DM_TABLE
syslinux_dm_table_usb=${dm_table//${old_root}/${root_a_uuid}}
sed -e "s|DMTABLEA|${syslinux_dm_table_usb}|g" \
-e "s|cros_legacy|${cros_flags}|g" \
"${template_dir}"/syslinux/usb.A.cfg |
sudo dd of="${esp_fs_dir}"/syslinux/usb.A.cfg status=none
syslinux_dm_table_a=${dm_table//${old_root}/HDROOTA}
sed -e "s|DMTABLEA|${syslinux_dm_table_a}|g" \
-e "s|cros_legacy|${cros_flags}|g" \
"${template_dir}"/syslinux/root.A.cfg |
sudo dd of="${esp_fs_dir}"/syslinux/root.A.cfg status=none
syslinux_dm_table_b=${dm_table//${old_root}/HDROOTB}
sed -e "s|DMTABLEB|${syslinux_dm_table_b}|g" \
-e "s|cros_legacy|${cros_flags}|g" \
"${template_dir}"/syslinux/root.B.cfg |
sudo dd of="${esp_fs_dir}"/syslinux/root.B.cfg status=none
# Copy the vmlinuz's into place for syslinux
sudo cp -f "${template_dir}"/vmlinuz "${esp_fs_dir}"/syslinux/vmlinuz.A
sudo cp -f "${template_dir}"/vmlinuz "${esp_fs_dir}"/syslinux/vmlinuz.B
# The only work left for the installer is to pick the correct defaults
# and replace HDROOTA and HDROOTB with the correct /dev/sd%D%P/%U+1
}
fi
ESP_DEV=
if [[ ! -e "${FLAGS_to}" ]]; then
error "The ESP doesn't exist"
@ -185,9 +105,9 @@ if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
# 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
sudo mkdir -p "${ESP_FS_DIR}"/boot/grub
sudo cp -r "${FLAGS_from}"/boot/grub/. "${ESP_FS_DIR}"/boot/grub
sudo cp -r "${FLAGS_from}"/boot/grub/menu.lst.A "${ESP_FS_DIR}"/boot/grub/menu.lst
# Prepopulate the syslinux directories too and update for verified boot values
# after the rootfs work is done.
@ -199,20 +119,8 @@ if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
sudo cp -f "${FLAGS_vmlinuz}" "${ESP_FS_DIR}"/syslinux/vmlinuz.B
# Extract kernel flags
kernel_cfg=
kernel_cfg="cros_debug"
old_root="%U+1"
if [[ -n "${FLAGS_kernel_cmdline}" ]]; then
info "Using supplied kernel_cmdline to update templates."
kernel_cfg="${FLAGS_kernel_cmdline}"
elif [[ -n "${FLAGS_kernel_partition}" ]]; then
info "Extracting the kernel command line from ${FLAGS_kernel_partition}"
kernel_cfg=$(dump_kernel_config "${FLAGS_kernel_partition}")
fi
update_x86_bootloaders "${old_root}" \
"${kernel_cfg}" \
"${ESP_FS_DIR}" \
"${FLAGS_from}" \
"${FLAGS_to}"
# Install the syslinux loader on the ESP image (part 12) so it is ready when
# we cut over from rootfs booting (extlinux).