Moving Folders under /home/me to new drive

So - I have a new computer, and the hard drive config is 2 SSDs (240 GB) - 1 for / and 1 for /home;
it also has a 1 TB 7200RPM drive… that is currently empty

What I’d like to do is split my home folder so that some of it (like . and Documents, etc) stay on the SSD, while I move others (Downloads, Music, other folders I put under Home) on the 1TB drive…

How can I do this?

Hi @MusicalCoder, There’s many many ways to do this. But…

One of the reasons for a separate ~/home is to carry it to the next install since it has all your settings and personal stuff. Splitting it up can certainly be done but transplanting it in the future means a lot more fiddling.

I suggest something like this and it is exactly what I do…

Mount the big drive in something like the /mnt directory. You’ll be able to access it there and can then make directories /mnt/Downloads, /mnt/Music, etc. Bookmarks can get to these very quickly.

Permanently mounting the 1TB drive in /mnt is usually done with a line added to /etc/fstab.

NOW…

If you really want ~/Downloads to actually use /mnt/Downloads you are a few commands away from making this happen with a symbolic link. This link would replace the current ~/Downloads and, except that it’ll be called a link-to-folder instead of a folder, you won’t see any difference.

Sound feasible?

1 Like

Sounds good -

How do I go about this?!

I’m not sure I can create a big detailed Howto, let’s see how far we get…

Does the drive have 1 big partition? I use GParted and suggest making it EXT4.

Chances are this partition will be /dev/sdc1 but these days it’s best to use the partition’s UUID. GParted has it or use sudo blkid. A UUID is absolutely unique and created with the partition. It looks like this:

2656ee22-b3ae-4db7-b21f-8a56e95f0aeb

When you have your UUID, this is the line added to the bottom of /etc/fstab (as root):

UUID=2656ee22-b3ae-4db7-b21f-8a56e95f0aeb /mnt ext4 defaults 0 1

Except use YOUR UUID, not my example.

When you reboot, the drive should be at /mnt.

How far did we get? I left out a lot of detail.

First - Thanks for your time in this!!!

Drive has 1 XFS partition (i’m a fan of that)

Followed your instructions and used the UUID in etc/fstab -

so now when I run lsblk i get:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb      8:16   0 223.6G  0 disk 
└─sdb1   8:17   0 223.6G  0 part /home
sr0     11:0    1  1024M  0 rom  
sdc      8:32   0 931.5G  0 disk 
└─sdc1   8:33   0 931.5G  0 part /mnt
sda      8:0    0 223.6G  0 disk 
├─sda2   8:2    0   216G  0 part /
└─sda1   8:1    0   7.6G  0 part [SWAP]

So I’m thinking I’m where I need to be so far…

Do I just delete the folders I want to move (since their empty - fresh install) - make them on /mnt, and then use ln -s to recreate them on Home? And will that still be the default for the system (Downloads, Pictures, etc)??

Oh good, I can probably convey better with the commands…

First, you may need to do this for your regular user permissions. It needs to be done after mounting, not before:

sudo chmod 777 /mnt

I’ll assume you want to keep a 1-to-1 correspondence. Let’s start with ~/Downloads.

Move everything in ~/Downloads to /mnt/Downloads. You want it empty and what you had there safe. If it’s already empty, ignore this. :slight_smile:

rmdir ~/Downloads
ln -s /mnt/Downloads ~/Downloads

That’s all there is to it. Check out some files - you should see them in both /mnt/Downloads and ~/Downloads.

Thank you so very much - I have completed this, and also added Music & Videos, and then also created my own Work directory and linked it!!

You’re faaaast!! :grin:

I was trying to think of any scenario that might not like a link to a folder but it seems highly unlikely. You can see the path is maintained completely. I hope it works out for you!

I’m not sure this is the best way to go about this.
I’m not an expert on drive management but looking at the output of the “mount” command on my machine:

/dev/sdb1 on /media/ouroumov/Ubuntu-MATE 17.04 amd64 type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)

It seems to me this hints that passing as mount option (in fstab) uid=1000,gid=1000 (default admin user id / group id) might do the trick.
Can someone confirm?

I’m pretty sure you’re right. I’m sloppy with permissions on my 1-user local box.

Well - the funny thing is doing it with sudo chmod 777 /mnt must have worked because I get the same 3 things when I run mount…

/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,noquota)
/dev/sdb1 on /home type xfs (rw,relatime,attr2,inode64,noquota)
/dev/sdc1 on /mnt type xfs (rw,relatime,attr2,inode64,noquota)

(sda1 is swap - 8GB)

The big difference to grasp is the permissions change to /mnt while the 1TB is mounted there changes the 1TB drive / permissions and not the original permissions of /mnt. If you were to sudo umount /mnt the permissions of /mnt revert to what they were.

In the end, your 1TB drive’s root directory is open to everyone, even when transplanted into the next machine. This may make some gasp. :unamused: At least that’s the way I think of it. Anyone?

Well, to be fair that’s always the case, regardless of permissions.
The only exception is if the files are encrypted.
Now I’m wondering if $HOME folder encryption can work across symlinks.

I have a similar setup, but slightly mofied to “scale better” in case I want to add another disk or another regular user at some point in the future. I’m a lazy, old man so I try to avoid extra work when ever I can. And yes, I try to keep things neat and organized. It helps with automation, as well.

The main difference is not to mount disks directly to /mnt but create a mountpoint under /mnt for each disk. That way you don’t have to change the permissions of /mnt directory itself and adding new disks is easy.

For similar reasons all regular users will have their own directory on the disk with permissions set to 700 (drwx------) so they cannot peek into other users’ directories.

Both /mnt and /mnt/data (disk mount point used in this example) are owned by root:root, permissions 0755/drwxr-xr-x .

Example: I have a disk I want to dedicate for Downloads etc.

I create a mountpoint for it under /mnt and add it to /etc/fstab:

$ sudo mkdir /mnt/data
$ sudo nano /etc/fstab

\# /mnt/data - /dev/sda4
UUID=<UUID-here> /mnt/data      ext4    rw,noatime,errors=remount-ro   0    0

I save and reboot.

After reboot I should see the disk mounted in /mnt/data. It has one directory (lost+found) in it, owned by root. I create a directory for user samuvuo, change it to be owned by samuvuo and change directory permissions to 700, so that only user samuvuo can access it (root has almighty powers anyway):

$ sudo mkdir /mnt/data/samuvuo
$ sudo chown samuvuo:samuvuo /mnt/data/samuvuo
$ sudo chmod 700 /mnt/data/samuvuo

I have some downloads already in the ~/Downloads directory, so I move it with its contents to the new location and create a symbolic link (shortcut) to the new location and place it in my home directory:

$ mv -v ~/Downloads /mnt/data/samuvuo/
$ ln -s /mnt/data/samuvuo/Downloads ~/Downloads

That should be it. (Although to be perfectly honest I move only directories that have little content. For larger directories or ones with really important files I use cp -avi or rsync, verify that all files got copied to the new place and only then remove the original.)

If I want to add another regular user and want their Downloads on the separate disk as well , I just repeat the steps for the new user (“otheruser”):

$ sudo mkdir /mnt/data/otheruser
$ sudo chown otheruser:otheruser /mnt/data/otheruser
$ sudo chmod 700 /mnt/data/otheruser
$ sudo mv /home/otheruser/Downloads /mnt/data/otheruser/
$ sudo ln -s /mnt/data/otheruser/Downloads /home/otheruser/Downloads
$ sudo chown otheruser:otheruser /home/otheruser/Downloads

The last step is purely cosmetic: the shortcut in user otheruser’s home directory is owned by root:root, but it can still be deleted by user otheruser.

Let’s say I want to add another disk, this time for media (Music and Videos). I just repeat the steps for adding a disk:

$ sudo mkdir /mnt/media
$ sudo nano /etc/fstab

\# /mnt/media - /dev/sda5
UUID=<UUID-here> /mnt/media      ext4    rw,noatime,errors=remount-ro   0    0

After reboot:

$ sudo mkdir /mnt/media/samuvuo
$ sudo chown samuvuo:samuvuo /mnt/media
$ sudo chmod 700 /mnt/media/samuvuo
$ mv ~/Music /mnt/media/samuvuo/
$ mv ~/Videos /mnt/media/samuvuo/
$ ln -s /mnt/media/samuvuo/Music ~/Music
$ ln -s /mnt/media/samuvuo/Videos ~/Videos
4 Likes