• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Convert a Directory to Partition in Linux

by admin

The goal of the post is to achieve moving the home directory into a newly added disk that has a dedicated Partition.

1. Add the new disk and create the necessary partition(for example sdb1).

2. Move the home folder into one of the partitions. To use a filesystem, it has to be mounted to the root filesystem at a mount point, the target directory such as /home.

3. First list the filesystem usage using the df command on the system.

# df -hl

4. Start by creating a new directory /srv/home where we can mount /dev/sdb1 for the time being.

# mkdir -p /srv/home
# mount /dev/sdb1 /srv/home

5. Move the content of /home into /srv/home (so they will be practically stored in /dev/sdb1) using rsync command or cp command.

# rsync -av /home/* /srv/home/

OR

# cp -aR /home/* /srv/home/

6. After that, we will find the difference between the two directories using the diff tool, if all is well, continue to the next step.

# diff -r /home /srv/home

7. Now delete all the old content in the /home as follows.

# rm -rf /home/*

8. Next unmount /srv/home.

# umount /srv/home

9. Finally, we have to mount the filesystem /dev/sdb1 to /home for the mean time.

# mount /dev/sdb1 /home
# ls -l /home
NOTE: After mounting the new /home it is advised to do a chmod 755 /home in case the default umask for directories has been changed in a system and /srv/home was created with different permissions.

10. The above changes will last only for the current boot, add the line below in the /etc/fstab to make the changes permanent.

11. Use following command to get the partition UUID.

# blkid /dev/sdb1
/dev/sdb1: UUID="[ID]" TYPE="ext4" PARTLABEL="primary"

12. Once you know the partition UUID, open /etc/fstab file add the following line.

UUID=[ID] /home ext4 defaults 0 2

13. Run the following command to see that /home directory has been successfully moved into a dedicated partition.

# df -hl

Filed Under: CentOS/RHEL, Linux

Some more articles you might also be interested in …

  1. arp-scan: Send ARP packets to hosts (specified as IP addresses or hostnames) to scan the local network
  2. cloud-init Command Examples in Linux
  3. flatpak: command not found
  4. “glab issue” Command Examples
  5. kill Command Examples in Linux
  6. Understanding multipath Utility to Configure DM-Multipath
  7. When to use rescan-scsi-bus.sh -i (LIP flag) in CentOS/RHEL
  8. git lfs: Work with large files in Git repositories
  9. cf: Command-line tool to manage apps and services on Cloud Foundry
  10. firewall-offline-cmd Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright