1080*80 ad

Extending the Root Partition in Linux

How to Extend Your Linux Root Partition: A Step-by-Step Guide

Running out of disk space on your Linux system’s root partition is a common but critical issue. When the partition fills up, applications can fail, services can stop, and your entire system can become unstable. Fortunately, extending the root partition is a manageable task if you follow the right steps.

This guide will walk you through the process of safely and effectively increasing the size of your Linux root partition, covering both graphical and command-line methods suitable for different system setups.

Before You Begin: Critical Prerequisites

Before making any changes to your disk partitions, taking precautionary steps is essential to prevent data loss.

  • Create a full backup of your data. This is the most important step. Modifying partitions always carries a risk, and having a reliable backup is your only true safety net.
  • Identify your partition scheme. You need to know if your system uses a standard partition layout or Logical Volume Management (LVM). LVM is more flexible and common on server distributions like CentOS and RHEL, while standard partitions are often found on desktop setups. You can check this with the lsblk or df -T command.
  • Have a Linux Live USB or ISO ready. For modifying the root partition, you often cannot perform the operation while the operating system is running from it. Booting into a live environment (like an Ubuntu or GParted Live ISO) allows you to safely manipulate the inactive partitions.
  • Secure unallocated disk space. You can’t extend a partition into thin air. This space must come from either shrinking another partition on the same disk or by expanding the virtual disk in a virtual machine environment (like VMware or VirtualBox).

Method 1: Using GParted (The Graphical Approach)

For desktop users or those who prefer a visual interface, GParted is an excellent and powerful tool. This method requires booting from a live Linux environment that includes GParted.

  1. Boot from a Live USB: Restart your computer and boot from your GParted or Ubuntu Live USB. Select the “Try” option to enter the live desktop environment.
  2. Launch GParted: Open the GParted application from the system menu. It will scan your disks and display your current partition layout.
  3. Create Unallocated Space: Identify a partition adjacent to your root partition that you can shrink. Right-click on it, select “Resize/Move,” and drag the handle to reduce its size, creating unallocated space. The unallocated space must be directly next to the root partition you want to extend. If it’s not, you may need to move partitions, which can be time-consuming.
  4. Extend the Root Partition: Once you have adjacent unallocated space, right-click on your root partition (e.g., /dev/sda2).
  5. Select “Resize/Move”: Drag the partition’s handle to consume the unallocated space, thereby increasing its size.
  6. Apply the Changes: GParted queues all operations. To execute them, click the green checkmark icon to “Apply All Operations.” The process may take some time depending on the size of the data being moved.
  7. Reboot: Once complete, remove the Live USB and reboot your system.

Method 2: The Command-Line Approach for LVM Systems

If your server or workstation uses LVM, extending the root partition is incredibly flexible and can often be done on a running system. This is the preferred method for enterprise and virtualized environments.

Let’s assume your Volume Group is named ubuntu-vg and your Logical Volume for root is ubuntu-lv. You can find these names by running lvdisplay.

  1. Add Physical Space: First, ensure you have free space in your Volume Group. This can be achieved by:

    • Expanding the underlying virtual disk in your hypervisor (VMware, Proxmox, etc.).
    • Adding a new physical disk and adding it to the Volume Group with vgextend ubuntu-vg /dev/sdX.
  2. Rescan the Disk (If Expanded): If you expanded a virtual disk, you might need to tell the OS to recognize the new size. If your disk is /dev/sda and the partition is /dev/sda3, you can use a tool like growpart.

    # Install if needed: sudo apt install cloud-guest-utils
    sudo growpart /dev/sda 3 
    

    Then, tell LVM to recognize the larger physical volume:

    sudo pvresize /dev/sda3
    
  3. Extend the Logical Volume: Now you can extend the logical volume to use the newly available space. To add a specific amount of space (e.g., 20 GB):

    sudo lvextend -L +20G /dev/mapper/ubuntu--vg-ubuntu--lv
    

    Alternatively, to use all available free space in the Volume Group:

    sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
    
  4. Resize the Filesystem: The final, crucial step is to resize the filesystem to match the new logical volume size. The command depends on your filesystem type.

    • For ext4 filesystems (most common):
      bash
      sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
    • For XFS filesystems (common on RHEL/CentOS):
      bash
      sudo xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv

Verifying the Changes

After completing either method, the final step is to verify that the root partition has been successfully extended. Run the disk free command:

df -h /

The output should now reflect the new, larger size of your root filesystem, and the “Use%” should be lower. By successfully extending the partition, you have resolved the immediate space issue and restored your system to a stable, operational state.

Source: https://www.tecmint.com/increase-root-partition-linux/

900*80 ad

      1080*80 ad