I have a 6Gb raw disk image with 1 ext4 partition on it. I have only 1Gb worth of data on it Is there a way to reposition/adjust ext4 datastructures such that I can truncate the disk at 1 GB or 1.2Gb and still retain all the relevant structures

I want to do a dd of the 1.2Gb truncated image on a target volume and still create the original 6GB disk with all the partition info & ext4 journals/superblocks valid

Is this possible?


To resize a ext2/3/4 volume, use resize2fs. You need to have the partition unmounted to shrink the filesystem. It will move your data (if needed), as well as any inodes, etc.

For example, if you wanted to shrink /dev/sda1 to 1073741824 bytes (one GiB), you'd run:

# fsck -f /dev/sda1
# resize2fs /dev/sda1 1073741824

After that completes, you'd then change the size of the partition to be 1073741824 bytes (or slightly larger if you insist on aligning to a "track" boundary)

You may find the -M option (make it as small as possible) useful as well.

You can also expand filesystems with resize2fs; if you omit the size, it'll expand it to fill the partition.

If you're just wanting to back up some files to move to another disk, you should use backup utilities like tar, afio, cpio, etc. Or alternatively, disk imaging programs like partclone or partimage (which will only need to copy used space). Or dedicated disk imaging systems like Clonezilla (which will typically use one of those imaging programs under the hood).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.