0

Quick question: Can I resize a filesystem without resizing the partition in advance? The question aims at growing, but information on shrinking might be useful for future reference too.

Here's the scenario:

  • SLES VM running on vSphere
  • Extend virtual disk to bigger size
  • The disk has a single partition but no LVM
  • Log into SLES VM and run the following commands:
    • Perform SCSI rescan: echo '1' > /sys/class/scsi_disk/<foobar>/device/rescan
    • Verify extended disk: fdisk -l
    • Resize filesystem: resize2fs /dev/foo
  • Result: Filesystem successfully resized

A colleague told me about this and did it, but I was sure that it have to resize the partition with fdisk or similar in advance as pointed out here.

1 Answer 1

1

You can (and should) certainly shrink a filesystem before shrinking the partition, though not necessarily - if you shrink the partition first, unless you create a new partition, nothing should write to the new empty space, but it still feels dangerous.

If you are talking about growing the filesystem, you can overwrite some space following the partition (e.g. with superblock copies). Again, it could work if nothing writes to the (officially) empty space before resizing the filesystem, but resize2fs will normally not grow beyond the size of the partition.

Note that your example looks like resizing the whole disk and using the filesystem in partitionless mode. In that case, shrinking the disk size before the filesystem might (and likely will) result in filesystem corruption, while growing the filesystem has to be done after you extend the disk size.

8
  • Shrinking the partition first means that any portion of the file system after the partition end will become inaccessible; so even if nothing writes to the empty space, you’re liable to run into problems (including not being able to shrink the file system). Dec 12, 2019 at 13:07
  • @StephenKitt Not if the kernel fails to reload the partition table - which is quite likely if the filesystem on the partition remains mounted (or you modify the partition table and do not tell the kernel - i.e. not by parted or fdisk, but a disk editor or something). Regardless, this is not something I would recommend. Dec 12, 2019 at 13:26
  • Right, it ends up relying on a few happy coincidences ;-). Dec 12, 2019 at 13:31
  • Hi @RadovanGarabík and thanks for your input. Sadly I knew the stuff you pointed out so I clarified my question a little. I am focused on growing and I am especially curious about the exact chain of commands as mentioned in the question.
    – Thorian93
    Dec 12, 2019 at 14:44
  • @Thorian93 Yes, if your disk really has a single partition, then you should resize it first. However, are you sure there is a partition? What exactly is your /dev/foo ? Chances are, you do not have any partitions and then of course, there is no partition to resize. Dec 12, 2019 at 15:59

You must log in to answer this question.

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