How to expand the disk space of the root directory in Linux?
To expand the root directory (/) disk space of Linux, you can follow these steps:
- To check the current disk partition situation of the system, you can use the following command:
- Show information about disk space using human-readable format.
- Confirm if there is available unallocated disk space by using the following command:
- List all disks using fdisk command with root privileges.
- If there is available unallocated disk space, you can use tools like GParted to adjust the disk partitions and allocate the unallocated space to the root directory (/).
- If there is no available unallocated disk space, you can consider using LVM (Logical Volume Manager) to expand the root directory disk space.
- Firstly, create a new physical volume (PV): sudo pvcreate /dev/sdX (where /dev/sdX is the available unallocated disk space).
- Next, add the new physical volume to the volume group (VG) by running the command: sudo vgextend
/dev/sdX (where
is the name of the volume group) - Finally, expand the logical volume (LV) of the volume group to new space by using the following command: sudo lvextend -l +100%FREE /dev/
/ (Where
is the name of the logical volume) - Finally, use the resize2fs command to adjust the file system size to occupy the new space.
- Please resize the filesystem using the following command: sudo resize2fs /dev/
/ - (其中,这是逻辑卷的名称)
(其中,这是逻辑卷的名称)
After completing the above steps, the disk space in the root directory should have been expanded. You can use the df -h command again to verify.