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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. vim: command not found
  2. light: command not found
  3. which: command not found
  4. Introduction to sed (Stream Editor) : Useful sed Command Examples
  5. lsinitramfs: Listing the contents of the initrd file system.
  6. chfn Command Examples in Linux
  7. mimetype: command not found
  8. CentOS / RHEL 7 : Beginners guide to systemd
  9. pkgmk Command Examples in Linux
  10. How to Install apt-utils with apt-get?

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright