1

I used dd on a drive of mine that I am building my Linux distribution on. I have an issue, how do I prep that iso (of a 256GB drive (so I have a 256GB ISO image file)) to be of a smaller size (get rid of the empty space).

3
  • Does a sparse file count as "being of a smaller size"? Commented Feb 1, 2020 at 23:15
  • Do you have specific reason for removing empty space? Please tell us what you are trying to achieve exactly. DD makes bit by bit copies of a disk drive. Removing those might create issues afaik.
    – Natsu Kage
    Commented Feb 1, 2020 at 23:18
  • 1
    Related: Clone only space in use from hard disk. I understand you want something similar after using dd. Do you also want the resulting image to fit into smaller disks? Or just to take less space where you store it? What is the partition layout of the source drive (and thus of the image)? Commented Feb 1, 2020 at 23:37

1 Answer 1

1

You might attach the image using losetup and use any partition tool to resize partitions. After that, you can safely truncate the image.

For a tutorial, you can refer to: https://softwarebakery.com/shrinking-images-on-linux

From the link above:

# modprobe loop
# losetup -f
# losetup /dev/loop0 myimage.img
# partprobe /dev/loop0

Now you can resize partitions on disk (eg. using gparted /dev/loop0), keeping the empty space at the end. Then close the loop image:

# losetup -d /dev/loop0

and use truncate to truncate the file at a specific size.

1
  • I'll try this, sounds like it could work
    – nerd7473
    Commented Feb 2, 2020 at 3:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .