Expand Linux Root Directory: Step-by-Step
To enlarge the size of the Linux root directory, you can follow these steps:
- Make sure there is enough disk space available in the system before expanding the root directory. You can use the command df -h to check the disk usage.
- Create a new partition or logical volume, and mount it to a temporary directory. You can use tools like fdisk, parted, or lvcreate to complete this step.
- Create a file system on a new partition or logical volume, such as ext4. You can use the command “mkfs.ext4” to create the file system.
- Mount a new partition or logical volume to a temporary directory, such as /mnt/temp. The mount command can be used for this operation.
- Copy the contents of the root directory to a new partition or logical volume. You can use the cp command to copy the files.
- Copy all files and directories from the root directory to the temp directory in a preserved way.
- Switch to a new partition or logical volume, moving the root directory to the new partition or logical volume.
- Change root directory to /mnt/temp.
- Update the bootloader to use new partitions or logical volumes. Depending on the bootloader being used, different commands can be used for the update. For example, if GRUB bootloader is being used, the command ‘grub-install’ can be used for the update.
- Restart the system and perform validation. You can use the df -h command to verify if the root directory has been resized.
Please make sure to back up important data before making any partition or logical volume adjustments to prevent data loss.