Remove the home Partition and Reallocating Space to the root

Remove the home Partition and Reallocating Space to the root
Remove the home Partition and Reallocating Space to the root

Remove the home Partition and Reallocating Space to the root - Hi everyone, welcome to our blog, Kitsake. How are you all doing today? I hope you are all well and blessed with good health and smooth work.

This time, I will share a trick that might be beneficial for your work or simply for knowledge. What trick is that? Yes, it's about How to Remove the Home Partition and Reallocate Space to the Root on RHEL 8.

Remove the home Partition
Remove the home Partition

Introduction

Perhaps you have encountered a situation where the home partition in your Linux system is too large or even unused. In such cases, you can utilize that space and merge it with the root partition. To learn ow, you can follow this tutorial.

Understanding the Setup

Before proceeding, let's take a moment to understand the typical partition setup in a Linux system. The home partition usually stores user-specific data, such as documents, downloads, and settings. The root partition contains the operating system and its files.

Over time, the home partition might fill up, while the root partition remains relatively empty. By merging both partitions, you can ensure more efficient use of disk space.

Precautions and Backups

Before attempting any major changes to your system's partitions, it's essential to back up your data. While the process we'll be following is generally safe, unexpected errors can occur. Make sure you have a recent backup of your important files to avoid data loss.

Step-by-Step Guide

Step 1: Backup file to the in-home partition

Back up the contents of the files within the home partition by archiving the path first and saving it to the /tmp directory.
# cd / ; tar -czvf /tmp/home.tgz home

Step 2: Capture before change

Before executing, I also make it a habit to capture before and after changes so that they can be used as a work report when needed. 

Here, I simply use the command to view the partitions as follows:

# df -h
view the partitions
view the partitions

Step 3: umount home partition

Let's go ahead and unmount the home partition after we have backed it up previously. This is because this partition is the one that we will later merge its size into the root partition.

# umount /home
# df -h

unmount home partition
unmount home partition

Step 4: Display information about a logical volume

Here, we will retrieve data from the logical volume, specifically the LV Path for root and home, which we will use in the following command.

# lvdisplay

Display information about a logical volume
Display information about a logical volume

Step 5: Remove logical volume(s) from the system

# lvremove /dev/rhel/home

After extending it, type the vgs or vgdisplay commands for a more detailed overview of the VG. The vgs command shows only the in with a few lines.

# vgs
# df -h
Remove logical volume(s) from the system
Remove logical volume(s) from the system

Step 6: Add space to a logical volume

Moving on to the next step, here's the point: adding the size that we have removed from the home partition and incorporating it into the root partition.

# lvextend -l +100%FREE /dev/rhel/root
# df -h

Add space to a logical volume
Add space to a logical volume
# cat /etc/fstab
/etc/fstab
/etc/fstab

In this step, we are implementing what we have executed earlier, and we can immediately see the result of adding the size of the home partition to the root partition.

# xfs_growfs /dev/rhel/root
# df -h

xfs_growfs
xfs_growfs

Step 7: Remove / Disable Auto Mount After Reboot

Do not forget the configuration file for fstab, as it contains settings for auto-mounting the partitions from the home partition. Our task is to disable that job so that it does not run upon restart.

# vi /etc/fstab
# systemctl daemon-reload
Edit configuration file fstab
Edit configuration file fstab

Step 8: Restothe re file the in home partition

The final step is to restore the home files that we have backed up in the first sep, so that user data in the home partition returns to its state before this reallocation activity.

# tar -xzvf /tmp/home.tgz -C /

Yes, you have successfully completed the tutorial on 'How to Remove the Home Partition and Reallocate Space to the Root on RHEL 8.' Pretty easy, right? But remember, whenever you make changes, always remember to back up your data first.

FAQs

Q1: Is it safe to remove the home partition?

Yes, it's safe as long as you follow the steps carefully and have a backup of your data. However, always exercise caution while working with partitions.

Q2: Can I use this guide for any Linux distribution?

Yes, this guide applies to most Linux distributions, but the partition paths may vary slightly. Adjust the commands accordingly.

Maybe that's all I can share with you guys, hopefully this article will be useful.

Thank You.

Bangkit Ade Saputra
Bangkit Ade Saputra At the end of the day, my job involves people. we're complicated, we're always changing, we have millions of things going on in our lives, and changing jobs is always a big decision.

Post a Comment for "Remove the home Partition and Reallocating Space to the root"