I'm currently trying to expand the alloted hard drive space on this server. When I do a fdisk -l
I get the following
/home/api# fdisk -l
Disk /dev/loop0: 99.22 MiB, 104030208 bytes, 203184 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 55.48 MiB, 58159104 bytes, 113592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 99.15 MiB, 103964672 bytes, 203056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop3: 69.9 MiB, 73277440 bytes, 143120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop4: 55.46 MiB, 58142720 bytes, 113560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop5: 70.39 MiB, 73797632 bytes, 144136 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 800 GiB, 858993459200 bytes, 1677721600 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: A078CCF8-9233-43B5-AF50-32ABC1E5FB18
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 167770111 167766016 80G Linux filesystem
/dev/sda3 167770112 1677721566 1509951455 720G Linux filesystem
Disk /dev/mapper/virtual--machines-lvol0: 719.102 GiB, 773089918976 bytes, 1509941248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
But when I run the command resize2fs -r /dev/sda3
I get the following error
/home/api# lvextend -r -l+100%FREE /dev/virtual-machines/lvol0
fsadm: Cannot get FSTYPE of "/dev/mapper/virtual--machines-lvol0".
Filesystem check failed.
Any help would be appreciated.
The answer
Your issue is most likely due to not having an FS created on the LV you're trying to extend.
If you're trying to extend
/dev/virtual-machines/lvol0
, I suggest you make sure it has an FS first by running:lsblk -f /dev/virtual-machines/lvol0
If the column FSTYPE shows nothing, then you have to create an FS. To create an ext4 FS run:
mkfs.ext4 /dev/virtual-machines/lvol0
This will create an FS on the full extent of that LV, so no need to do a resize after that. However, if later you were to add an extra Physical Volume to your Volume Group, you can then extend your Logical Volume with the command you used to try and do so, though I prefer the following syntax for cases like this one:
lvextend -r /dev/virtual-machines/lvol0 /dev/sdaX
This adds all space from the specified PV to the LV. Just in case clarification is needed:
-r
: Also resizes the FS./dev/sdaX
: This is the newly added PV, which has to be in the same VG as the other PVs of this LV.
Some final comments
- You said that you run the command
resize2fs -r /dev/sda3
but you showed the output for the commandlvextend -r -l+100%FREE /dev/virtual-machines/lvol0
. I just looked past by it and assumed it was a mistake.- When working with Logical Volumes, you should not manage the FS directly on the "physical" partitions (
/dev/sda3
, in this case); only work on the LV itself.- Please also note that, when working with LVM, your partitions should be of type "Linux LVM". I run some tests and didn't encounter any issue with using partition type "Linux" instead of "Linux LVM", I even changed back and forth from one to the other without losing any data or having any negative impact whatsoever on a running system but, just in case, I suggest you use the corresponding partition type to avoid any possible issues.
In case you need to know how to change a partition type, assuming that the partition of interest is
/dev/sda3
:fdisk /dev/sda
(you'll be taken to the fdisk tool).p
to print the partition table and check its current status.t
to change the type of a partition.3
to select partition number 3. If you only have one partition (number 1), said partition will be automatically selected.l
to list all available partition types and look for the one corresponding to "Linux LVM".Enter
.p
to check your changes.w
. If having any doubts and want to revert the whole process, you may quit without saving by pressingq
.