{"id":14430,"date":"2022-01-28T05:49:29","date_gmt":"2022-01-28T05:49:29","guid":{"rendered":"https:\/\/linuxways.net\/?p=14430"},"modified":"2022-01-28T05:49:29","modified_gmt":"2022-01-28T05:49:29","slug":"how-to-convert-a-directory-to-a-partition-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-convert-a-directory-to-a-partition-in-linux\/","title":{"rendered":"How to Convert a Directory to a Partition in Linux"},"content":{"rendered":"<p>If you have opted for the default options during the installation of your operating system, chances are that all your folders lie in the same partition which is the root ( \/ ) partition. While this is perfectly okay, it presents a challenge when you want to reinstall your OS as you won&#8217;t be able to preserve your files and documents. The entire root system is wiped clean. Good practice demands that you create a separate home partition as well as boot and swap partitions so that you can reinstall your OS at ease.<\/p>\n<p>If you already have the home folder together with other folders in the same partition, worry not. In this guide, we demonstrate how you can migrate the home folder to another partition. We will demonstrate this using an external drive which we will back up the home directory and configure it as a partition.<\/p>\n<h2><strong>Step 1: Confirm the size of the home partition and external drive<\/strong><\/h2>\n<p>The first step is to confirm the size of your home directory.<\/p>\n<pre><strong>$ df -Th \/home<\/strong><\/pre>\n<p>In our case, our directory is 13G.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"141\" class=\"wp-image-14431\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-602.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-602.png 739w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-602-300x57.png 300w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/p>\n<p>The external drive should be greater in size than your home directory. We have a 16GB external drive which should be sufficient for the job.<\/p>\n<h2><strong>Step 2: Format external USB drive<\/strong><\/h2>\n<p>In the next step, we will format the external drive using the <strong>ext4 <\/strong>file format. First, we will unmount the drive.<\/p>\n<pre><strong>$ unmount \/dev\/sdb<\/strong><\/pre>\n<p>Then we will format it using <strong>ext4 <\/strong>file format.<\/p>\n<pre><strong>$ mkfs.ext4 \/dev\/sdb<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"367\" class=\"wp-image-14432\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-603.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-603.png 736w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-603-300x150.png 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/p>\n<h2><strong>Step 3: Create a directory for mounting the drive<\/strong><\/h2>\n<p>Next create a directory for mounting the external drive. In our case we have created the <strong>\/srv\/home<\/strong> directory.<\/p>\n<pre><strong>$ mkdir -p \/srv\/home<\/strong><\/pre>\n<p>Then , mount the external drive as follows.<\/p>\n<pre><strong>$ mount \/dev\/sdb \/srv\/home<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"199\" class=\"wp-image-14433\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-604.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-604.png 748w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-604-300x80.png 300w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/p>\n<p>To confirm that the drive has been mounted, use the command as shown<\/p>\n<pre><strong>$ df -Th | grep sdb<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"159\" class=\"wp-image-14434\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-605.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-605.png 737w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-605-300x65.png 300w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/strong><\/p>\n<h2><strong>Step 4: Copy the home directory to the mounted drive<\/strong><\/h2>\n<p>Next, transfer or copy all the files on your home directory to the <strong>\/srv\/home\/ <\/strong>mount point.<\/p>\n<pre><strong>$ rsync -av \/home\/* \/srv\/home\/<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"193\" class=\"wp-image-14435\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-606.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-606.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-606-300x79.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/strong><\/p>\n<p>This might take a while depending on the contents of your home directory especially in the Downloads directory. So, be patient as the copying process progresses.<\/p>\n<p>Once done, you will get a summary of the total size copied. In our case, the size of files transferred was 3GB.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"204\" class=\"wp-image-14436\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-607.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-607.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-607-300x84.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/strong><\/p>\n<p>You can verify the disk space usage as follows:<\/p>\n<pre><strong>$ df -Th | grep sdb<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"214\" class=\"wp-image-14437\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-608.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-608.png 738w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-608-300x87.png 300w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/p>\n<h2><strong>Step 5: Mount the filesystem<\/strong><\/h2>\n<p>NExt, delete all the files and folders under the home directory.<\/p>\n<pre><strong># rm -rf \/home\/*<\/strong><\/pre>\n<p>Then unmount the <strong>\/srv\/home<\/strong> mount point on which the <strong>\/dev\/sdb<\/strong> device is mounted.<\/p>\n<pre><strong># umount \/srv\/home<\/strong><\/pre>\n<p>Next, mount the external drive to the home folder.<\/p>\n<pre><strong># mount \/dev\/sdb \/home\/<\/strong><\/pre>\n<p>And list its contents to ensure that your folders are intact.<\/p>\n<pre><strong># ls -l \/home<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"324\" class=\"wp-image-14438\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-609.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-609.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-609-300x132.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/strong><\/p>\n<p>Then set the directory permissions as follows just in case the default umask has changed.<\/p>\n<pre><strong># chmod -R 755 \/home<\/strong><\/pre>\n<p><strong>NOTE:<\/strong><\/p>\n<p>The changes that we have made will not survive a reboot. To address this matter, we need to append some parameters to the <strong>\/etc\/fstab <\/strong>file.<\/p>\n<p>But first, let\u2019s get the UUID of our external volume. You can achieve this as follows:<\/p>\n<pre><strong>$ blkid \/dev\/sdb<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"123\" class=\"wp-image-14439\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-610.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-610.png 710w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-610-300x52.png 300w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/strong><\/p>\n<pre><strong>\/dev\/sdb: UUID=\"56bd886b-daa0-4bc4-add1-e0e2b64bff01\" TYPE=\"ext4\"<\/strong><\/pre>\n<p>Next, access the <strong>\/etc\/fstab <\/strong>file.<\/p>\n<pre><strong># vim \/etc\/fstab<\/strong><\/pre>\n<p>Then append the following parameters<\/p>\n<pre><strong>UUID=[ID] \/home ext4 defaults 0 2<\/strong><\/pre>\n<p>In our case, we have:<\/p>\n<pre><strong>UUID=\"56bd886b-daa0-4bc4-add1-e0e2b64bff01\" \/home ext4 defaults 0 2<\/strong><\/pre>\n<p>Save the file and reload the <strong>\/etc\/fstab <\/strong>file.<\/p>\n<pre><strong># mount -a<\/strong><\/pre>\n<p>Your home folder has now been migrated and accessible in a separate partition.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you have opted for the default options during the installation of your operating system, chances are that all your folders lie in the same partition which is&hellip;<\/p>","protected":false},"author":1,"featured_media":14538,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[878,35],"class_list":["post-14430","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-directory","tag-linux"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=14430"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14430\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14538"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}