Browse Source

Create repartitioned Mender compliant image from Yocto image for qemu x86-64

Issues: MEN-2207

Changelog: Title

Signed-off-by: Adam Podogrocki <a.podogrocki@gmail.com>
1.1.x
Adam Podogrocki 6 years ago
parent
commit
294b6f20bd
  1. 8
      convert-stage-3.sh
  2. 83
      mender-convert
  3. 12
      mender-convert-functions.sh
  4. 21
      qemux86_64-convert-stage-2.sh

8
rpi3-convert-stage-3.sh → 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."

83
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

12
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."
}

21
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
Loading…
Cancel
Save