Unix & Linux Asked by Malano on October 30, 2021
I’m working on low level memory writing of linux filesystem for embedded purpose. I created the partition image using following procedure:
dd if=/dev/null of=example.img bs=1M seek=4096
mkfs.ext4 -F example.img
mkdir /mnt/example.img
mount -t ext4 -o loop exmaple.img /mnt/exampleimg
cp -r rootfs/* /mnt/exampleimg/
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.
I cannot modify partition size afterwards using on target linux, because this is the partition of root filesystem on which Linux is working.
This is not true when extending a file system. The manual for resize2fs says:
If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.).
So you can create a much smaller image, copy it onto the device then use resize2fs to extend the file system:
resize2fs /dev/mmcblok0
There is an alternative method that's dependent on the hardware you're using. It's complicated so I can give an outline for the technique, but I'll avoid writing out exact steps to use this technique.
The technique there is to create an image with a re-configured bootloader.
This is designed to run directly from an sd card. The bootloader starts up Linux, telling it to directly run a script (rather than the regular /sbin/init
). The script then:
Answered by Philip Couling on October 30, 2021
Do everything like you do (i.e. create a small image, copy it as is) but the last step would be
resize2fs -p /dev/mmcblok0
Answered by Artem S. Tashkinov on October 30, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP