I have a script that help me to backup my root partition to another partition on the same disk during initramfs stage when a specific variable is detected in /proc/cmdline.
What the script did is simple, while it is backing up the image, it will calculate sha256sum of sections written to the backup partition. After the backup is complete, it will run sha256sum on the backup partition to verify everything is the same as the original root partition and move on.
The script is working fine, however the speed is very slow, it feels like everything is running on single thread. Running the same script when Pi already booted into rootfs feels a lot faster.
This is the code snippet that I'm using to backup the root partition and calculating the checksum in initramfsInitially I've tried writing the whole disk instead of chopping it into pieces, it was painfully slow. The latter method is slightly faster.
Anything that I can do on the initramfs side that can make the dd process faster?
What the script did is simple, while it is backing up the image, it will calculate sha256sum of sections written to the backup partition. After the backup is complete, it will run sha256sum on the backup partition to verify everything is the same as the original root partition and move on.
The script is working fine, however the speed is very slow, it feels like everything is running on single thread. Running the same script when Pi already booted into rootfs feels a lot faster.
This is the code snippet that I'm using to backup the root partition and calculating the checksum in initramfs
Code:
# Backup to another partition by section, using tee to redirect # the output of first dd that read from rootfs to sha256sum and # another dd that write to another partitiondd if=${SRC_PARTITION} skip=${COUNT} bs=${NEW_BLOCK_SIZE} count=1 status=none | tee \ >(sha256sum | awk '{print $1}' > "/tmp/${SRC_PARTUUID}_${COUNT}.txt") \ >(dd of=${DST_PARTITION} seek=${COUNT} bs=${NEW_BLOCK_SIZE} count=1 iflag=fullblock oflag=append conv=notrunc status=none) | \ cat >/dev/null# Calculate the sha256sum of specific section for verificationDST_CHKSUM=$(dd if=${DST_PARTITION} skip=${COUNT} bs=${NEW_BLOCK_SIZE} count=1 status=none | sha256sum | awk '{print $1}')Anything that I can do on the initramfs side that can make the dd process faster?
Statistics: Posted by rasp14 — Mon May 26, 2025 2:35 am