From 294b6f20bd8018e0b65bc7ab327ce1500f1bdfe8 Mon Sep 17 00:00:00 2001 From: Adam Podogrocki Date: Mon, 3 Dec 2018 11:16:08 +0100 Subject: [PATCH] Create repartitioned Mender compliant image from Yocto image for qemu x86-64 Issues: MEN-2207 Changelog: Title Signed-off-by: Adam Podogrocki --- rpi3-convert-stage-3.sh => convert-stage-3.sh | 8 +- mender-convert | 83 ++++++++++++++++--- mender-convert-functions.sh | 12 ++- qemux86_64-convert-stage-2.sh | 21 +++++ 4 files changed, 107 insertions(+), 17 deletions(-) rename rpi3-convert-stage-3.sh => convert-stage-3.sh (53%) create mode 100755 qemux86_64-convert-stage-2.sh diff --git a/rpi3-convert-stage-3.sh b/convert-stage-3.sh similarity index 53% rename from rpi3-convert-stage-3.sh rename to convert-stage-3.sh index 763be39..e657395 100755 --- a/rpi3-convert-stage-3.sh +++ b/convert-stage-3.sh @@ -8,9 +8,11 @@ build_log=$output_dir/build.log { log "Error: extracted rootfs partition not found. Aborting."; exit 1; } sudo dd if=${output_dir}/rootfs.img of=/dev/mapper/${rootfs_mapping} bs=8M >> "$build_log" 2>&1 - -# dd sets the original label, make sure label follows Mender naming convention. -sudo e2label /dev/mapper/${rootfs_mapping} "primary" +sync +# Check Linux ext4 file system just in case. +sudo fsck.ext4 -fp /dev/mapper/${rootfs_mapping} >> "$build_log" 2>&1 +# Make sure the rootfs partition's label follows Mender naming convention. +sudo tune2fs -L "primary" /dev/mapper/${rootfs_mapping} >> "$build_log" 2>&1 log "\tDone." diff --git a/mender-convert b/mender-convert index 9c44f7c..7f725f6 100755 --- a/mender-convert +++ b/mender-convert @@ -176,7 +176,7 @@ declare -a rootfs_partition_ids=("primary" "secondary") declare -a mender_disk_mappings declare -a raw_disk_mappings #Supported devices -declare -a supported_devices=("beaglebone" "raspberrypi3") +declare -a supported_devices=("beaglebone" "raspberrypi3" "qemux86_64") do_raw_disk_image_shrink_rootfs() { log "$step/$total Shrinking raw disk image root filesystem..." @@ -309,6 +309,10 @@ do_raw_disk_image_create_partitions() { \n\t\troot filesystem size: $((${mender_disk_sizes[prootfs_size]} * $sector_size)) bytes\ \n\t\tdata partition size: $((${mender_disk_sizes[pdata_size]} * $sector_size)) bytes" + if [ -v mender_disk_sizes[pswap_size] ]; then + log "\t\tswap partition size: $((${mender_disk_sizes[pswap_size]} * $sector_size)) bytes" + fi + create_test_config_file $device_type $partition_alignment $mender_disk_image_size \ $sector_size mender_disk_sizes @@ -335,6 +339,9 @@ do_raw_disk_image_create_partitions() { "raspberrypi3") do_make_sdimg_raspberrypi3 ;; + "qemux86_64") + do_make_sdimg_qemux86_64 + ;; esac rc=$? @@ -383,11 +390,11 @@ do_make_sdimg_beaglebone() { do_make_sdimg_raspberrypi3() { log "$step/$total Setting boot partition..." ((step++)) - local image_boot_part=$(fdisk -l ${raw_disk_image} | grep FAT32) + local raw_boot_part=$(fdisk -l ${raw_disk_image} | grep FAT32) - local boot_part_start=$(echo ${image_boot_part} | awk '{print $2}') - local boot_part_end=$(echo ${image_boot_part} | awk '{print $3}') - local boot_part_size=$(echo ${image_boot_part} | awk '{print $4}') + local boot_part_start=$(echo ${raw_boot_part} | awk '{print $2}') + local boot_part_end=$(echo ${raw_boot_part} | awk '{print $3}') + local boot_part_size=$(echo ${raw_boot_part} | awk '{print $4}') log "\tExtracting boot partition from raw disk image." extract_file_from_image ${raw_disk_image} ${boot_part_start} \ @@ -399,18 +406,18 @@ do_make_sdimg_raspberrypi3() { log "$step/$total Setting root filesystem partition..." ((step++)) - local image_rootfs_part=$(fdisk -l ${raw_disk_image} | grep Linux) + local raw_rootfs_part=$(fdisk -l ${raw_disk_image} | grep Linux) - local rootfs_part_start=$(echo ${image_rootfs_part} | awk '{print $2}') - local rootfs_part_end=$(echo ${image_rootfs_part} | awk '{print $3}') - local rootfs_part_size=$(echo ${image_rootfs_part} | awk '{print $4}') + local rootfs_part_start=$(echo ${raw_rootfs_part} | awk '{print $2}') + local rootfs_part_end=$(echo ${raw_rootfs_part} | awk '{print $3}') + local rootfs_part_size=$(echo ${raw_rootfs_part} | awk '{print $4}') log "\tExtracting root filesystem partition from raw disk image." extract_file_from_image ${raw_disk_image} ${rootfs_part_start} \ ${rootfs_part_size} "rootfs.img" stage_3_args="$output_dir ${mender_disk_mappings[1]}" - ${tool_dir}/rpi3-convert-stage-3.sh ${stage_3_args} || ret=$? + ${tool_dir}/convert-stage-3.sh ${stage_3_args} || ret=$? [[ $ret -ne 0 ]] && { return $ret; } mount_mender_disk ${mender_disk_mappings[@]} @@ -430,6 +437,56 @@ do_make_sdimg_raspberrypi3() { return 0 } +do_make_sdimg_qemux86_64() { + log "$step/$total Setting boot partition..." + ((step++)) + + local raw_boot_part=$(fdisk -l ${raw_disk_image} | grep 'Microsoft' | sed s/*//) + + local boot_part_start=$(echo ${raw_boot_part} | awk '{print $2}') + local boot_part_end=$(echo ${raw_boot_part} | awk '{print $3}') + local boot_part_size=$(echo ${raw_boot_part} | awk '{print $4}') + + log "\tExtracting boot partition from raw disk image." + extract_file_from_image ${raw_disk_image} ${boot_part_start} \ + ${boot_part_size} "boot.vfat" + + stage_2_args="$output_dir ${mender_disk_mappings[0]}" + ${tool_dir}/qemux86_64-convert-stage-2.sh ${stage_2_args} || ret=$? + [[ $ret -ne 0 ]] && { return $ret; } + + log "$step/$total Setting root filesystem partition..." + ((step++)) + local raw_rootfs_part=$(fdisk -l ${raw_disk_image} | grep 'Linux filesystem') + + local rootfs_part_start=$(echo ${raw_rootfs_part} | awk '{print $2}') + local rootfs_part_end=$(echo ${raw_rootfs_part} | awk '{print $3}') + local rootfs_part_size=$(echo ${raw_rootfs_part} | awk '{print $4}') + + log "\tExtracting root filesystem partition from raw disk image." + extract_file_from_image ${raw_disk_image} ${rootfs_part_start} \ + ${rootfs_part_size} "rootfs.img" + + stage_3_args="$output_dir ${mender_disk_mappings[1]}" + ${tool_dir}/convert-stage-3.sh ${stage_3_args} || ret=$? + [[ $ret -ne 0 ]] && { return $ret; } + + mount_mender_disk ${mender_disk_mappings[@]} + + # Add mountpoints. + sudo install -d -m 755 ${sdimg_primary_dir}/boot/efi + sudo install -d -m 755 ${sdimg_primary_dir}/data + + log "$step/$total Setting file system table..." + ((step++)) + set_fstab $device_type + + [[ $keep != "-k" ]] && { rm -f $output_dir/boot.vfat\ + $output_dir/syslinux.cfg $output_dir/rootfs.img; } + + return 0 +} + do_install_mender_to_mender_disk_image() { log "$step/$total Installing Mender to Mender disk image..." ((step++)) @@ -798,21 +855,21 @@ case "$1" in do_raw_disk_image_create_partitions || rc=$? [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; } log "A new Mender disk image with partition layout to support Mender has been successfully created!" - log "You can find the output Mender disk image at:\n\t${mender_disk_image}." + log "You can find the output Mender disk image at:\n\t${mender_disk_image}" ;; install-mender-to-mender-disk-image) total=1 do_install_mender_to_mender_disk_image || rc=$? [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; } log "The Mender client has been successfully installed to the Mender disk image." - log "You can find the output Mender disk image at:\n\t${mender_disk_image}." + log "You can find the output Mender disk image at:\n\t${mender_disk_image}" ;; install-bootloader-to-mender-disk-image) total=1 do_install_bootloader_to_mender_disk_image || rc=$? [[ $rc -ne 0 ]] && { log "Check $build_log for details."; exit 1; } log "A bootloader configuration supporting dual A/B rootfs updates has been installed to the Mender disk image!" - log "You can find the output Mender disk image at:\n\t${mender_disk_image}." + log "You can find the output Mender disk image at:\n\t${mender_disk_image}" ;; mender-disk-image-to-artifact) total=1 diff --git a/mender-convert-functions.sh b/mender-convert-functions.sh index 1c1875b..63b7ae5 100755 --- a/mender-convert-functions.sh +++ b/mender-convert-functions.sh @@ -196,7 +196,7 @@ set_mender_disk_alignment() { local rvar_vfat_storage_offset=$3 case "$1" in - "beaglebone") + "beaglebone" | "qemux86_64") local lvar_partition_alignment=${PART_ALIGN_8MB} local lvar_vfat_storage_offset=$lvar_partition_alignment ;; @@ -697,6 +697,11 @@ set_fstab() { mountpoint="/uboot" blk_device=mmcblk0p ;; + "qemux86_64") + mountpoint="/boot/efi" + blk_device=hda + data_id=5 + ;; esac # Add Mender specific entries to fstab. @@ -717,6 +722,11 @@ set_fstab() { /dev/${blk_device}${data_id} /data auto defaults 0 0 EOF" + if [ "$device_type" == "qemux86_64" ]; then + # Add entry referring to swap partition. + sudo tee -a ${sysconfdir}/fstab <<< "/dev/hda6 swap swap defaults 0 0" 2>&1 >/dev/null + fi + log "\tDone." } diff --git a/qemux86_64-convert-stage-2.sh b/qemux86_64-convert-stage-2.sh new file mode 100755 index 0000000..ffad07f --- /dev/null +++ b/qemux86_64-convert-stage-2.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +output_dir=$1 +boot_mapping=$2 +build_log=$output_dir/build.log + +[ ! -f $output_dir/boot.vfat ] && \ + { log "Error: extracted boot partition not found. Aborting."; exit 1; } + +# Make a copy of Linux kernel arguments and modify. +mcopy -on -i ${output_dir}/boot.vfat -s ::EFI/BOOT/grub.cfg ${output_dir}/grub.cfg +sed -i 's/\b[ ]root=[^ ]*/ root=\/dev\/hda2/' ${output_dir}/grub.cfg + +# Update Linux kernel command arguments with our custom configuration +mcopy -o -i ${output_dir}/boot.vfat -s ${output_dir}/grub.cfg ::EFI/BOOT/grub.cfg + +sudo dd if=${output_dir}/boot.vfat of=/dev/mapper/${boot_mapping} bs=1M >> "$build_log" 2>&1 + +log "\tDone." + +exit 0