Use lsblk to see which devices are available and if their partitions are mounted
#.img file size reducer full#
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.
#.img file size reducer software#
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. Uncompress and extract the contents of the image in the /boot/ directory: xz -dc /dev/null | cpio -o -c -R root:root | xz -9 -format=lzma > /boot/new.First make sure the free space is actually empty, and doesn't contain leftovers of deleted files. | cpio -o -c -R root:root | gzip -9 > /boot/new.img Still in the working directory, find all files and add them to a new boot image file: find. Uncompress and extract the contents of the image in the /boot/ directory: zcat /boot/initrd-$(uname -r).img | cpio -idmv Select the appropriate instructions below to extract or repack the correct image type for your system. boot/initramfs-2.6.86_64.img: LZMA compressed data However, there may also be an XZ/LZMA-format image which displays as: # file /boot/initramfs-$(uname -r).img boot/initramfs-2.6.86_64.img: gzip compressed data The most common is a gzip-format image which displays as: # file /boot/initramfs-$(uname -r).img
You may also specify a specific file, such as: file /boot/initramfs-2.6.86_64.img The $(uname -r) will use the file for the current kernel version. Use the file command on the initramfs/initrd to identify the compression format: file /boot/initramfs-$(uname -r).img This will be the location where the initramfs/initrd contents will be viewed, edited, and re-compressed if required: mkdir /tmp/initrd
#.img file size reducer how to#
Note: For RHEL7 and RHEL8, refer to How to extract the contents of initramfs image on RHEL7? Issue