I’m working on low level memory writing of linux filesystem for embedded purpose. I created the partition image using following procedure:
- Create an empty image file ex for 4GiB.
dd if=/dev/null of=example.img bs=1M seek=4096 - Add a filesystem to it (ext4)
mkfs.ext4 -F example.img - Mount it on local machine
mkdir /mnt/example.imgmount -t ext4 -o loop exmaple.img /mnt/exampleimg - Copy the filesystem to mounted partition image
cp -r rootfs/* /mnt/exampleimg/ - Unmount the image
umount /mnt/exampleimg
After writing created image to first sector of the partition I need to replace, everything work, and I have access to data, the problem is, I need to copy whole 16GB partition, while the data on it, is only 2GB, and it took a lot of time.
I created smaller image with the same data, and it works, but I cannot exceed the fixed size of the partition image. System see the partition size is still big (fdisk -l /dev/mmcblok0, and sectors count in /sys/class/block/mmcblkop2/size), probably because the partition table has not been changed, but in case of copying file bigger than free space on the image(not real size of partition) I get cp: write error: No space left on device.
I cannot modify partition size afterwards using on target linux, because this is the partition of root filesystem on which Linux is working. Is there any way to create image with fake size/ with no unnecessary limits? I would like to get image of 16GB partition with data, while image size is smaller than 16GB.
ddbe reading from/dev/zerorather than/dev/null? Is that a typo?partclone? I think that if you do apartclonebackup of the filesystem image to stdout and then pipe that in to anotherpartcloneinstance to do a "restore" of the block device, then you'd only copy used blocks rather than the entire filesystem. The catch is you'd have to determine the partition size and create the partition yourself prior to restoring from the "backup".