To create a new partition in an already partitioned system you should start with a livecd, then use
gparted to shrink the
sda1 partition (that I assume take all the space on the disk, excluded the swap), then create a new partition in the free space created.
It can be of course done on the command line, but GParted take care of many details that it is difficult to track.
After create the partition, you should move the content of your current home on the new partition, then modify
/etc/fstab to mount the new partition on
Here's one way to actually move the files from sda1 to sda2. All this is done as root:
- Take a backup. Have you tried restoring your backups? They're not backups until you do. And make sure that they're stored on a different machine (that isn't mounted), or on an external drive that is currently detached. The point is,
rm -Rf / shouldn't delete them. Nor should
mkfs on the wrong partition.
- Read all the steps and make sure you fully understand them before starting. Except for take a backup. You should do that immediately if you haven't already.
- Make a filesystem on sda2. Something like
mkfs.ext4 /dev/sda2 (assuming you're fine with ext4, which is probably what you're currently using on sda1).
sda2 to somewhere that isn't /home. For example, you could
mkdir /mnt/new_home and then
mount -text4 /dev/sda2 /mnt/new_home
- Make sure no users are logged in—otherwise they may be trying to change their files as you do this.
- Copy the files. First, confirm that /home doesn't have anything hidden (only dot entries should be
..) by doing
ls -l /home. If it does, you need to copy the separately (
* will not match them, and
.* doesn't do what you want):
cp -a /home/* /mnt/new_home/
- Stop now if there are any errors copying.
- Unmount sda2:
umount /mnt/new_home. Do it now to make sure you don't accidentally nuke the wrong one.
- This is the point of no return.
rm -Rf /home/*. Absolutely, positively, do not try
/home/.* here. Also, make sure not to accidentally add a space in that path. You should be at least a little afraid wile typing this command, it is a scary command, and you should tripple-check you've entered it correctly (otherwise, you'll be needing that backup).
- If there are any dot-files or folders in /home, remove them by name. Remember, you must not ever run
rm -Rf .*. That'd match
.., which means parent directory, ultimately leading to complete filesystem destruction (though some versions of
rm may refuse to do this, you shouldn't depend on that).
/etc/fstab and add an entry for your new sda2 partition, like this:
/dev/sda2 /home ext4 relatime,user_xattr,errors=remount-ro 0 2. You may use different flags if you like, those are the ones I use. Also, that
pass number (2) assumes that you've only got two filesystems on sda, which seems very likely since this is sda2.
- Finally, mount your new home
mount /home. This should run without errors, and your files should be there. If you get errors, check your fstab line. If you get a warning about files under the mount point being hidden, you didn't delete everything in the last few steps: unmount
/home and delete the remainder. If files are missing, see the first step.