Since we don't have a tool to do this and many newcomers want to learn how to do this, here's a "How To."
Since /home is in use (and thus can't be manipulated easily) if you are logged in as any user, this "How To" includes instructions on how to create a password for root and log in as root. Also included at the end is how to remove the root password correctly, if you wish to do so.
These examples work for single or multiple users. This "How To" does not include instructions on doing this with an encrypted home.
There are two most common ways you may want to move /home: From the root partition to a separate partition or from a separate partition to the root partition. Some of the steps are different or in a different order, so both examples are given.
In this "How To" dev/sdb1 is assumed to be the new home partition, and that it exists and ext4 is the filesystem. Adjust the location to suit your needs as necessary. The partition location can be on the same drive, or separate drives. I do not recommend using a USB device for a separate /home unless it is the same device your install resides on or unless you intend for your system to be un-bootable when the USB device is removed. This "How To" will not cover using a USB device. ext4 is used only because it is the most common filesystem at this time. Any filesystem will work and the instructions are the same.
Pre-steps - Before we begin:
Since these commands require root privileges and your user cannot be logged in, this must be done from a terminal. While you're still logged into your desktop, open a terminal (konsole) and give your root user a password:
sudo passwd root
Follow the prompts and log out when you're done. Then hit CRTL-ATL-F2 and log into the text console using the username "root" and the new password you just created. You should see the prompt as a "#" and you're now ready to proceed.
To move /home from the root partition to a separate partition, steps are:
Step 1: Move the current home
mv /home /old_home
Step 2: Make a location for the new home partition, and then mount it there:
mkdir /home
mount /dev/sdb1 /home
Step 3: Copy all the files and folders, then verify it worked:
rsync -aXS --progress /old_home/. /home/.
diff -r /old_home /home
You may see some errors from the diff operation. These should be due to symbolic links that may not match up until after reboot. If you see other errors, stop and figure out why they are occurring before you reboot (to revert to your previous setup at this point, redo the mv command from step 1 in reverse: mv /old_home /home).
Step 4: Edit fstab so the new home is used at next boot:
nano /etc/fstab
add this line at the bottom:
and add an extra carriage return (blank line) after it, and save (CRTL-x will save and exit if you answer "y" at the overwrite prompt). If you prefer, you may use the filesystem UUID or Label in place of the device name. Now, mount the new home:
mount /home
Step 5: Log in as your user:
Hit CTRL-ALT-F7 and you should be able to log in as usual and see no differences from your previous session. If you do, you may have not copied all your files over or the fstab edit may have been done incorrectly. Don't panic, all your old files are still there in /old_home. Once you are satisfied that all is well, proceed to step six.
Step 6: Remove old home and (optionally) remove root password (terminal commands):
Removes old_home:
sudo rm -rf /old_home
Removes root password:
sudo usermod -p '!' root
Done.
To move a separate home partition to the root partition, steps are:
Step 1: Unmount and re-mount the current home:
mkdir /old_home
umount /dev/sdb1
mount /dev/sdb1 /old_home
Step 2: Copy all the files and folders, then verify it worked:
rsync -aXS --progress /old_home/. /home/.
diff -r /old_home /home
You may see some errors from the diff operation. These should be due to symbolic links that may not match up until after reboot. If you see other errors, stop and find out why they are occurring before you reboot.
Step 3: Edit fstab so the old home is not used at next boot:
nano /etc/fstab
Edit the line containing /home by placing a leading # in front of it making it a remark line. This is easier to recover from if need be. Then save the edit (CRTL-x will save and exit if you answer "y" at the overwrite prompt).
Or, you can use this nifty one-liner to do the edit for you in a single step:
sed -i '/[[:space:]]\/home[[:space:]]/s/^/#/' /etc/fstab
Step 4: Log back in as your user:
CTRL-ATL-F7 should return you to the log in screen. You should be able to log in as usual and see no differences from your previous session. If you do, you may have not copied all your files over or the fstab edit may have been done incorrectly. Don't panic, all your old files are still there in /old_home. Once you are satisfied that all is well, proceed to step 5.
Step 5: Remove old home and (optionally) remove root password:
Open a terminal and do these to remove old_home:
sudo umount /old_home
sudo rmdir /old_home
Remove root password:
sudo usermod -p '!' root
Your old home and all its files still reside on /dev/sdb1. You can now reformat to wipe it clean or keep it as a backup location.
Done.
Since /home is in use (and thus can't be manipulated easily) if you are logged in as any user, this "How To" includes instructions on how to create a password for root and log in as root. Also included at the end is how to remove the root password correctly, if you wish to do so.
Warning: ***THE USUAL CAVEATS AND WARNINGS*** Mis-typing something as root can cause problems. Playing around with your home without a backup is foolishness. Don't do either. It's also always a very good idea to have a bootable USB or DVD handy in case things get mucked up so you can do a recovery.
These examples work for single or multiple users. This "How To" does not include instructions on doing this with an encrypted home.
There are two most common ways you may want to move /home: From the root partition to a separate partition or from a separate partition to the root partition. Some of the steps are different or in a different order, so both examples are given.
In this "How To" dev/sdb1 is assumed to be the new home partition, and that it exists and ext4 is the filesystem. Adjust the location to suit your needs as necessary. The partition location can be on the same drive, or separate drives. I do not recommend using a USB device for a separate /home unless it is the same device your install resides on or unless you intend for your system to be un-bootable when the USB device is removed. This "How To" will not cover using a USB device. ext4 is used only because it is the most common filesystem at this time. Any filesystem will work and the instructions are the same.
Pre-steps - Before we begin:
Since these commands require root privileges and your user cannot be logged in, this must be done from a terminal. While you're still logged into your desktop, open a terminal (konsole) and give your root user a password:
sudo passwd root
Follow the prompts and log out when you're done. Then hit CRTL-ATL-F2 and log into the text console using the username "root" and the new password you just created. You should see the prompt as a "#" and you're now ready to proceed.
Warning: DO NOT LOG IN TO THE GUI AS ROOT: This is unsafe and may cause all kinds of havoc - just don't do it.
To move /home from the root partition to a separate partition, steps are:
1. Relocate the current home folder.
2. Mount a new partition for use as /home.
3. Duplicate (and verify) all the /home contents into the new partition.
4. Create an fstab entry for the new /home location and mount the new home.
5. Log in to verify function.
6. Remove the old home.
Step 1: Move the current home
mv /home /old_home
Step 2: Make a location for the new home partition, and then mount it there:
mkdir /home
mount /dev/sdb1 /home
Step 3: Copy all the files and folders, then verify it worked:
rsync -aXS --progress /old_home/. /home/.
diff -r /old_home /home
You may see some errors from the diff operation. These should be due to symbolic links that may not match up until after reboot. If you see other errors, stop and figure out why they are occurring before you reboot (to revert to your previous setup at this point, redo the mv command from step 1 in reverse: mv /old_home /home).
Step 4: Edit fstab so the new home is used at next boot:
nano /etc/fstab
add this line at the bottom:
Code:
/dev/sdb1 /home ext4 defaults 0 1
mount /home
Step 5: Log in as your user:
Hit CTRL-ALT-F7 and you should be able to log in as usual and see no differences from your previous session. If you do, you may have not copied all your files over or the fstab edit may have been done incorrectly. Don't panic, all your old files are still there in /old_home. Once you are satisfied that all is well, proceed to step six.
Step 6: Remove old home and (optionally) remove root password (terminal commands):
Removes old_home:
sudo rm -rf /old_home
Removes root password:
sudo usermod -p '!' root
Done.
To move a separate home partition to the root partition, steps are:
1. Unmount the current home folder and re-mount it elsewhere.
2. Duplicate all the /home contents into the home folder and verify the contents.
3. Remove the fstab entry for /home.
4. Log in to verify function.
5. Remove old_home.
Step 1: Unmount and re-mount the current home:
mkdir /old_home
umount /dev/sdb1
mount /dev/sdb1 /old_home
Step 2: Copy all the files and folders, then verify it worked:
rsync -aXS --progress /old_home/. /home/.
diff -r /old_home /home
You may see some errors from the diff operation. These should be due to symbolic links that may not match up until after reboot. If you see other errors, stop and find out why they are occurring before you reboot.
Step 3: Edit fstab so the old home is not used at next boot:
nano /etc/fstab
Edit the line containing /home by placing a leading # in front of it making it a remark line. This is easier to recover from if need be. Then save the edit (CRTL-x will save and exit if you answer "y" at the overwrite prompt).
Or, you can use this nifty one-liner to do the edit for you in a single step:
sed -i '/[[:space:]]\/home[[:space:]]/s/^/#/' /etc/fstab
Step 4: Log back in as your user:
CTRL-ATL-F7 should return you to the log in screen. You should be able to log in as usual and see no differences from your previous session. If you do, you may have not copied all your files over or the fstab edit may have been done incorrectly. Don't panic, all your old files are still there in /old_home. Once you are satisfied that all is well, proceed to step 5.
Step 5: Remove old home and (optionally) remove root password:
Open a terminal and do these to remove old_home:
sudo umount /old_home
sudo rmdir /old_home
Remove root password:
sudo usermod -p '!' root
Your old home and all its files still reside on /dev/sdb1. You can now reformat to wipe it clean or keep it as a backup location.
Done.
Comment