![]() ![]() Let's request a new (free) loopback device: sudo losetup -f Let's enable enable the loopback: sudo modprobe loop We do this using the loopback-functionality of Linux. This is why we first need to create a device for the image. GParted operates on devices, not simple files like images. In order to shrink the image, GParted is going to be used along the first part of the answer. GParted is an application typically used to manage partition tables and filesystems. img you want to shrink ( myimage.img in this example) The secret is to use standard Linux tools and instruments: GParted, fdisk and truncate. Having a myimage.img bigger then the hardware support (if it is smaller there should be no problem however, using the same strategy, you can better fit the image in the hardware support). For example: umount /dev/sdc1Ĭreate a copy of the whole sd card with all the partitions unmounted dd if=/dev/sdc of=/path/to/file/myimage.img Unmount all partitions of the device you want to copy on your pc. Use lsblk to see which devices are available and if their partitions are mounted Following the full solution in order to not lose the answer.Ī preliminary step consists in cloning the SD card in your PC: The key information was the use of the command truncate. I re-propose the same answer here, it can be useful. I originally posted the same answer here, on StackExchange Ask Ubuntu. # qemu-img convert -f raw -O vmdk foo.img foo.vmdkīut if it's going to be written to a real disk again, you have to convert it back to a raw image. # qemu-img convert -f raw -O qcow2 foo.img foo.qcow Note that this still requires you to prepare the image by cleaning the free space using the above method. qcow2 for Qemu, VDI for VirtualBox, or VMDK for VMware. with a virtual machine – is to convert the raw image to one of the image formats used by virtualization software e.g. ![]() Note that the output device (sda) must be of sufficient size to fit the original image, otherwise data will be lost or corrupted.Īn alternative method, if you want to keep using the image – e.g. This will uncompress it 'live': # cat | gunzip | dd of=/dev/sda Note that you must uncompress the image when writing it back to disk. Even at lowest compression levels, a long series of zeros will compress well: # ls -s Then compress it with a tool like gzip or xz. # losetup -find -partscan foo.imgĭd if=/dev/zero of=/mnt/filler conv=fsync bs=1Mĭd: error writing ‘/mnt/filler’: No space left on device Otherwise, an easy way to achieve this is to create a huge file on the disk, containing only null bytes, then delete it. This works on loop devices in a similar way to TRIM on SSDs unused areas are replaced with zeros and the underyling. With recent kernels (3.2 or later), it's easiest to do so by mounting each partition of the loop image, then issuing a discard using fstrim on the mountpoint. First make sure the free space is actually empty, and doesn't contain leftovers of deleted files. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |