{"id":47038,"date":"2024-08-12T15:57:44","date_gmt":"2024-08-12T15:57:44","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47038"},"modified":"2024-08-12T15:57:44","modified_gmt":"2024-08-12T15:57:44","slug":"separate-home-ubuntu","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/08\/separate-home-ubuntu\/","title":{"rendered":"Create Separate \/home Partition (e.g., on USB) for Ubuntu 24.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-35890\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/11\/file-manager-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This tutorial shows how to separate <code>\/home<\/code> from an existing Ubuntu file-system, to individual disk partition or even USB stick, while preserving all personal data.<\/p>\n<p>Linux can have separate <code>\/home<\/code> partition, which is useful for re-installing system, or even trying different Linux distributions without losing most of custom settings, configurations, downloads, etc.<\/p>\n<p>While installing Linux, there&#8217;s usually an option to create separate <code>\/home<\/code>. If you didn&#8217;t do that, then here&#8217;s step by step guide shows you how to do the trick afterward.<\/p>\n<p><!--more--><\/p>\n<p><b>NOTE: This tutorial is tested in Ubuntu 24.04 LTS, though it should work in most popular Linux Distributions, such as Debian, Fedora, Arch, and more.<\/b><\/p>\n<h3>Step 1. Create Disk Partition for \/home<\/h3>\n<p>First, launch <b>GNOME Disks<\/b>. Choose the destination disk drive from the left pane. If there&#8217;s enough free unallocated space in right, then choose it and go to next step to create a Ext4 file partition.<\/p>\n<p>If NOT, either format an existing partition or shrink it to make free room. In my case, I was going to use my USB stick for <code>\/home<\/code>, so I can take it anywhere and use even on different machines.<\/p>\n<p>However, the USB drive has NTFS file-system on it which is NOT recommended for Linux file system due to security reason. In the case, either <strong>shrink to make free space<\/strong>, while preserving existing data in the drive, or <strong>format to use full partition<\/strong> which will however remove all data on it.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/shrink-usbdrive.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47040\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/shrink-usbdrive-700x477.webp\" alt=\"\" width=\"610\" height=\"416\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/shrink-usbdrive-700x477.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/shrink-usbdrive-300x205.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/shrink-usbdrive-768x524.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/shrink-usbdrive.webp 1182w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Once you have enough free space on the disk drive, choose it and click on &#8220;+&#8221; to create partition on it. Then, choose format to <b>Ext4<\/b> file-system type, either with or without LUKS encryption as you want.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47041\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4-700x380.webp\" alt=\"\" width=\"610\" height=\"331\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4-700x380.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4-300x163.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4-768x417.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4-1536x834.webp 1536w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4-1320x717.webp 1320w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/create-ext4.webp 1602w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>When done, you need to copy the UUID of the partition you&#8217;re going to use it for <code>\/home<\/code>.<\/p>\n<p>If encryption enabled, then unlock and use the UUID of top half (device marked as <code>\/dev\/sdXY<\/code> or <code>\/dev\/nvmeXnYpZ<\/code>) for <code>\/etc\/crypttab<\/code>, and, the UUID of bottom half (marked as <code>\/dev\/mapper\/xxxxxxx<\/code>) for <code>\/etc\/fstab<\/code> in next step.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47042\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition-700x374.webp\" alt=\"\" width=\"610\" height=\"326\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition-700x374.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition-300x160.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition-768x410.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition-1536x821.webp 1536w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition-1320x705.webp 1320w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/encrypt-usb-partition.webp 1583w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 2: Copy existing user contents to the Separate Disk Partition<\/h3>\n<p>After created the separated partition, click unlock (if encrypted) and mount using either file manager or Gnome Disks.<\/p>\n<p>Then, open terminal (Ctrl+Alt+T) and run command to copy all existing users&#8217; contents into the new separated partition. The <code>-a<\/code> command option is required to preserve the ownership, timestamp, etc, information.<\/p>\n<pre>sudo cp -a \/home\/* \/media\/ji\/xxxxxxxx<\/pre>\n<p><b>NOTE: replace <code>\/media\/ji\/xxxxxxx<\/code> in command to your mount point. Check it either in Gnome Disk, file manager, or by running command <code>mount |grep \/media\/$USER<\/code>.<\/b><\/p>\n<p>Next, rename (move) the current <code>\/home<\/code> as backup:<\/p>\n<pre>sudo mv \/home \/home_backup<\/pre>\n<p><b>NOTE: after running this <code>mv<\/code> command, all personal folders will be inaccessible until reboot with new separate <code>\/home<\/code>. It&#8217;s better to close your apps, and stop any downloading before running this command.<\/b><\/p>\n<p>Finally, re-create an empty <code>\/home<\/code> directory as mount point for the new separate partition on every startup:<\/p>\n<pre>sudo mkdir \/home<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cp-home.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47045\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cp-home-700x299.webp\" alt=\"\" width=\"610\" height=\"261\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cp-home-700x299.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cp-home-300x128.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cp-home-768x328.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cp-home.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 3: Configure to let your system know the new \/home partition<\/h3>\n<p><b>1.<\/b> <code>\/etc\/fstab<\/code> is the configuration file to tell Linux to mount all the file partitions on start up.<\/p>\n<p>To edit the file, open terminal (Ctrl+Alt+T) run command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/fstab<\/pre>\n<p><i>Replace <code>gnome-text-editor<\/code> with your favorite editor, or use <code>nano<\/code> command line text editor that works in most Linux<\/i>.<\/p>\n<p>When it opens, add new line to tell it to mount the specified partition (via UUID) as separate <code>\/home<\/code>:<\/p>\n<pre>UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \/home ext4 defaults 0 2<\/pre>\n<p><b>NOTE: Replace the ID accordingly! Check it using &#8216;Gnome Disks&#8217;, and, if LUKS encryption enabled, use the UUID of bottom half marked as device \/dev\/mapper\/luks-xxxxxxx<\/b><\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/fstab-home.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47043\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/fstab-home-700x387.webp\" alt=\"\" width=\"610\" height=\"337\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/fstab-home-700x387.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/fstab-home-300x166.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/fstab-home-768x424.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/fstab-home.webp 954w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>For <code>nano<\/code> text editor, press Ctrl+S then Ctrl+X to save and exit.<\/p>\n<p><b>2.<\/b> If you enabled LUKS encryption for that partition, then open terminal (Ctrl+Alt+T) and run command to install the required management tool.<\/p>\n<pre>sudo apt install cryptsetup<\/pre>\n<p>Then, edit the <code>\/etc\/crypttab<\/code> file via command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/crypttab<\/pre>\n<p><i>Also replace <code>gnome-text-editor<\/code> with <code>nano<\/code> for non-GNOME desktop.<\/i><\/p>\n<p>Finally, add new line to tell your Linux to unlock it (will ask you to type password) on every startup.<\/p>\n<pre>home_crypt UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx none luks,retries=3<\/pre>\n<p>Here <code>home_crypt<\/code> specifies the mount point under <code>\/dev\/mapper<\/code>, you can change it to whatever as you want. And, <strong>replace the UUID according to the encrypted partition (the top half in GNOME Disk, marked as device \/dev\/sdXY or \/dev\/nvmeXnYpZ).<\/strong><\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crypttab-home.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47044\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crypttab-home-700x385.webp\" alt=\"\" width=\"610\" height=\"336\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crypttab-home-700x385.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crypttab-home-300x165.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crypttab-home-768x423.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/crypttab-home.webp 954w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>When done, save the file. And restart your computer to verify.<\/p>\n<h3>How to Restore<\/h3>\n<p>To restore the changes and use <code>\/home<\/code> inside your root partition, boot your Linux and login.<\/p>\n<p>Then, re-edit the <code>\/etc\/fstab<\/code> and <code>\/etc\/crypttab<\/code> files and remove the lines you added in the last step.<\/p>\n<p>Next, restart your computer. Press <code>Ctrl+Alt+F3<\/code>(or F4\/F5\/F6) to switch to TTY command line console, since the login screen may refuse to let you in without \/home directory content.<\/p>\n<p>In the TTY console, login with your username and password, then run the command to restore backup:<\/p>\n<pre>sudo rm -R \/home &amp;&amp; sudo mv \/home_backup \/home<\/pre>\n<p>If you have deleted the backup, and there&#8217;s nothing to restore, then you may choose to re-generate a clean user home by running command:<\/p>\n<pre>sudo mkhomedir_helper ji<\/pre>\n<p>In command replace <code>ji<\/code> with your username, and re-run this command again and again for other users if any.<\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to separate \/home from an existing Ubuntu file-system, to individual disk partition or even USB stick, while preserving all personal data. Linux can have separate \/home partition, which is useful for re-installing system, or even trying different Linux distributions without losing most of custom settings, configurations, downloads, etc. While installing Linux, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":35890,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-47038","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47038","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=47038"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47038\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/35890"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}