Browse Source

work with sparse images where possible

This speeds up the conversion quite a lot, meaning that it will skip
copying large blocks of 'zero' data back and forth.

Converting a 2018-11-13-raspbian-stretch-lite.img went from 8m10s to
4m45s on my machine.

Changelog: None

Signed-off-by: Mirza Krak <mirza.krak@northern.tech>
1.1.x
Mirza Krak 6 years ago
parent
commit
3d601712d6
  1. 2
      convert-stage-3.sh
  2. 2
      mender-convert
  3. 7
      mender-convert-functions.sh
  4. 2
      qemux86_64-convert-stage-2.sh
  5. 2
      rpi-convert-stage-2.sh

2
convert-stage-3.sh

@ -7,7 +7,7 @@ build_log=$output_dir/build.log
[ ! -f ${output_dir}/rootfs.img ] && \
{ 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
sudo dd if=${output_dir}/rootfs.img of=/dev/mapper/${rootfs_mapping} bs=8M conv=sparse >> "$build_log" 2>&1
sync
# Check Linux ext4 file system just in case.
sudo fsck.ext4 -fp /dev/mapper/${rootfs_mapping} >> "$build_log" 2>&1

2
mender-convert

@ -297,7 +297,7 @@ do_raw_disk_image_create_partitions() {
calculate_mender_disk_size $sector_size ${partition_alignment} \
mender_disk_sizes mender_disk_image_size
log "\tCreating Mender disk image:\
log "\tCreating blank Mender disk image:\
\n\t\timage size: ${mender_disk_image_size} bytes\
\n\t\tboot partition size: $((${mender_disk_sizes[pboot_size]} * $sector_size)) bytes\
\n\t\troot filesystem size: $((${mender_disk_sizes[prootfs_size]} * $sector_size)) bytes\

7
mender-convert-functions.sh

@ -396,10 +396,9 @@ unmount_partitions() {
create_mender_disk() {
local lfile=$1
local lsize=$2
local bs=$(( 1024*1024 ))
local count=$(( ${lsize} / ${bs} ))
dd if=/dev/zero of=${lfile} bs=${bs} count=${count}>> "$build_log" 2>&1
# Generates a sparse image
dd if=/dev/zero of=${lfile} seek=${lsize} bs=1 count=0 >> "$build_log" 2>&1
}
# Takes following arguments:
@ -738,7 +737,7 @@ set_fstab() {
extract_file_from_image() {
log "\tStoring data in $4."
local cmd="dd if=$1 of=${output_dir}/$4 skip=$2 bs=512 count=$3"
local cmd="dd if=$1 of=${output_dir}/$4 skip=$2 bs=512 count=$3 conv=sparse"
$(${cmd}>> "$build_log" 2>&1)
}

2
qemux86_64-convert-stage-2.sh

@ -14,7 +14,7 @@ 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
sudo dd if=${output_dir}/boot.vfat of=/dev/mapper/${boot_mapping} bs=1M conv=sparse >> "$build_log" 2>&1
log "\tDone."

2
rpi-convert-stage-2.sh

@ -18,7 +18,7 @@ mcopy -on -i ${output_dir}/boot.vfat -s ::config.txt ${output_dir}/config.txt
echo -e '\nenable_uart=1\n' >> ${output_dir}/config.txt
mcopy -o -i ${output_dir}/boot.vfat -s ${output_dir}/config.txt ::config.txt
sudo dd if=${output_dir}/boot.vfat of=/dev/mapper/${boot_mapping} bs=1M >> "$build_log" 2>&1
sudo dd if=${output_dir}/boot.vfat of=/dev/mapper/${boot_mapping} bs=1M conv=sparse >> "$build_log" 2>&1
log "\tDone."

Loading…
Cancel
Save