3

I have a disk mounted to VM without as a whole. I created a file system on that disk. It has no partitions. Now, I resized the disk from 100G to 200G. Do I need to do anything else to let the file system to make full use of the disk size?

For file systems on some disk partition, we need to update the size of the partition that holds the file system. But I'm not sure do we need to do anything in my above senario.

1
  • 3
    You didn't mention what file system you're using, but yes, you can make certain file systems expand to use the whoe space. For ext2/3/4 for example use resize2fs.
    – Pourko
    Apr 1, 2021 at 3:26

2 Answers 2

12

You will need to verify that the kernel has recognized the new size, by e.g. running fdisk -l /dev/<device> or cat /sys/block/<device>/size and checking that the total size matches the new size instead of the old one. If you are using paravirtualized drivers in a VM, most of them will handle this automatically.

But if the old size is still displayed, echo 1 > /sys/block/<device>/device/rescan can be used to tell the kernel that the size of the device has changed.

Once the kernel knows the new size of the whole device, there is no partition table to edit in your case, so you can proceed directly to extending the filesystem, using a filesystem-dependent tool.

For ext2/ext3/ext4 filesystems, you can use resize2fs /dev/<device>, no matter if the filesystem is currently mounted or not.

For XFS, the filesystem must be mounted to extend it, and the command will be xfs_growfs <mount point pathname>.

Other filesystem types have their own rules and extension tools.

If your distribution includes fsadm, it provides an unified method for resizing ext2/ext3/ext4 filesystems, ReiserFS and XFS (hopefully it will be extended to cover other filesystem types in the future). The command would be fsadm resize /dev/<device>.

4
  • 1
    fsadm can resize a file system without the user having to figure out what the file system type is (on file systems it supports — the Ext family, ReiserFS and XFS). Apr 1, 2021 at 5:26
  • @StephenKitt Good point, added.
    – telcoM
    Apr 1, 2021 at 5:45
  • This is great answer. Thanks! But I have further questions here. Is there any difference between resize2fs the FS while it is currently mounted or not? And will resizing the FS in my case possibly cause any data loss? Apr 1, 2021 at 14:50
  • If you extend the filesystem a really large amount (like to 100x original size), resize2fs might not be able to do it while the FS is mounted, and it will tell you so without doing anything. Likewise if the filesystem is not in a 100% error-free state, it will tell you to unmount and run a fsck first. Taking a backup before any major changes is always smart, but in my experience resize2fs has been very reliable.
    – telcoM
    Apr 1, 2021 at 17:32
-1

If the disk is completely empty (no partitions, filesystems etc.), you won't need to do anything. Otherwise you'll need to use a program like fdisk to resize the partitions and the filesystems inside them.

Also, you can't have a filesystem without a partition, unless whatever OS you're using writes to random locations, but then it won't boot.

4
  • You can have a file system without a partition; mke2fs /dev/sdX works just fine. Apr 1, 2021 at 5:25
  • Doesn't mke2fs reformat the whole device?
    – kettle
    Apr 1, 2021 at 5:40
  • Yes, I meant it as an example of a command one could use to create a file system without a partition. Apr 1, 2021 at 6:18
  • This answer is factually incorrect. It makes no difference to the filesystem if it's on a partition or on the whole disk, or on a regular file for that matter. You just give it a block of something, and it will draw a file system on it. Nothing forces you to use partitions.
    – Pourko
    Apr 1, 2021 at 8:32

You must log in to answer this question.

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