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:

  1. To check the current disk partition situation of the system, you can use the following command:
  2. Show information about disk space using human-readable format.
  3. Confirm if there is available unallocated disk space by using the following command:
  4. List all disks using fdisk command with root privileges.
  5. 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 (/).
  6. If there is no available unallocated disk space, you can consider using LVM (Logical Volume Manager) to expand the root directory disk space.
  7. Firstly, create a new physical volume (PV): sudo pvcreate /dev/sdX (where /dev/sdX is the available unallocated disk space).
  8. 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)

  9. 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)

  10. Finally, use the resize2fs command to adjust the file system size to occupy the new space.
  11. Please resize the filesystem using the following command: sudo resize2fs /dev//
  12. (其中,这是逻辑卷的名称)
    (其中,这是逻辑卷的名称)

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.

bannerAds