I. Feature Description
When configuring Linux, insufficient space reserved for the root directory may cause programs to fail to start. While changing the data storage directory can resolve this issue, there are situations where such changes are not feasible due to various reasons. In such cases, expanding the root directory space becomes necessary.
II. Operation Steps
- First, use the
df -hcommand to check the disk space usage in the system.
df -h

From the above image, it can be seen that the root directory has only 20G of space, with 5.6G currently in use. We will attempt to expand it to 36G.
-
Using the
lsblkcommand, we observe that the sda disk has 48G of space, but only 20G is allocated to the root directory. Next, we will allocate the remaining 16G to the root directory.
-
Run the
growpart /dev/sdb3command to expand the sdb3 partition.
-
Use the
lvmcommand to expand the root directory.
-
Step 1: Enter the lvm interactive mode.

-
Step 2: Use the
pvdisplaycommand to display all PVs (Physical Volumes). The Free PE (Free Physical Extents) value of 2815 indicates that expansion is possible.
-
Step 3: Use the
vgdisplaycommand to display all VGs (Volume Groups).
-
Step 4: Use the
lvdisplaycommand to display all LVs (Logical Volumes). Currently, it is 20G.
-
Step 5: Use the
lvextend -l +2815 /dev/ubuntu-vg/ubuntu-lvcommand to expand the root directory. (lvextend -l: number of blocks, check the remaining PE count via vgdisplay; -r: recursive; -L: specify exact size)
-
Step 6: Check the LV again; the size has been updated.

-
Step 7: Exit lvm.
-
Use the
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lvcommand to expand the file system.
-
Use the
df -hcommand to verify that the root directory space has been expanded to 31G.
III. FAQ
Question 1: When using the resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv command in the final step, an error occurs: resize2fs: Bad magic number in super-block while trying to open /dev/mapper/ubuntu--vg-ubuntu--lv.
Answer 1: The XFS file system cannot be expanded using the resize2fs command. Use the xfs_growfs command instead for expansion.