0

I have an vmware ext4 file system that non-lvm, non-partitioned file system that resides on a virtual 300GB disk. In other words, there is no partition and the file system was probably created by:

mkfs.ext4 /dev/sdd1

The disk is barely used (1%) but I would like to keep the data on it. Is there a safe way to shrink it? I was thinking of resizing the disk in Vmware from 300 to 100 and running resize2fs /dev/sdd1 but am not certain if I will not lose anything on it.

Any pieces of advice would be highly appreciated.

P.

  • 4
    For that to work at all you would need to shrink the filesystem first. Shrinking the device before the filesystem would most probably bork it. – Mat Apr 8 '14 at 9:51
  • If there is no partition then there should be no 1 following /dev/sdd. – psusi Apr 8 '14 at 14:23
1

Your question is inconsistent: if there's a partition, the filesystem was created by a command like mkfs.ext4 /dev/sdd1. If there's no partition, the filesystem was created by a command line mkfs.ext4 /dev/sdd. Check the output of df /path/to/some/directory/on/that/filesystem to see which one it is.

Either way, you can call resize2fs to shrink the filesystem. This is independent of any use of LVM. You can only shrink the filesystem while it's unmounted, so if it's your root filesystem, you need to do that from a rescue system. Note that the disk letter might be different in the rescue system, e.g. sdb instead of sdd.

After shrinking the filesystem to the desired size, if it's on a partition, you need to shrink the partition. You can use fdisk for that, but it's a bit delicate: you need to delete and recreate the partition, making sure that you don't change its start location. You can also use parted, which combines filesystem resizing and partition resizing, but it's also cumbersome to use because you need to compute the target start address.

After this, you can shrink the size of the disk image in VMware. Make sure that the filesystem (and partition, if applicable) fit inside the disk image; if there's a partition, remember that the partition table uses an extra 512B at the beginning.

| improve this answer | |
  • Thanks for this; Not sure why I have written "non partitioned" as there is a partition there obviously. I'll edit the question. The fdisk was what I was looking for, cheers for that again. I have shrinked the partition by recreating it via fdisk. – Peter Apr 9 '14 at 15:13

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.