
Moving a /home directory in Linux
The /home directory on a Linux machine performs the same function as the Users directory under Windows – within this directory is a sub-directory per user of the machine and within that user’s sub-directory are more sub-directories that are both visible – say the Documents, Downloads or Pictures folders) and “invisible” (in the sense that they will not normally appear with a normal directory display command or inside graphical file managers unless command options or specific menu options are set) folders that contain configuration files for applications the user runs and cache directories containing local copies of files (say downloaded from the Internet) that are held locally to save having to repeatedly download them via a potentially slow link.
A very basic primer on the Linux file system
Every filing system needs a start point from which you can navigate to other locations (directories, folders or files). Every Linux system has but one start point called the “root” of the file system (not to be confused with the root user login) written as “/”
– Windows has a start point on each separate drive known to the system written as “\”,
so the start point (root) of the filing system on drive C: of a Windows system is known as “C:\”
– if it has a second drive called “D:” then that drive’s root will be called “D:\”
.
One of the great powers of Linux (thanks to its roots in UNIX) is that EVERYTHING is nothing more than a file to the operating system. And there is only a single root – regardless of the number of disks or remote storage locations connected to the system.
“Everything is a file” allows a simple command to direct all incoming traffic from a network adapter to the screen – or to another file or an output device. While the full wonders of this concept are outside the scope of this article and the entire idea can seem strange and confusing to people moving to Linux from other operating systems it is a very powerful concept. I only raise it here to allow understanding of a couple of things that might otherwise confuse you.
Unlike (say) Windows, when Linux is installed it divides its boot drive into sections (technically “partitions”) each of which has a specific purpose – so a partition called “boot” is created which – as you might expect – contains the software stack – the kernel and device drivers – the operating system needs when it boots. The reasons these partitions are created is to ensure that they each have a minimum, appropriate size that cannot then be written into by other file operations. Both the root partition “/” and /home – that appear as ordinary directories within a working Linux system – are partitions of fixed size. The “fixed size” is important – being created as partitions they cannot grow any larger than the space allocated to them … unless that allocation is somehow changed or they somehow get moved somewhere else.
I hear readers asking “How do these partitions become ‘ordinary’ directories once Linux is up and running?” The answer is that the are mounted on to mountpoints (which are themselves ordinary, normally empty, directories somewhere in or below the root (“/”) path. Anyone following along will be asking “How does the root path get mounted” – the answer to which is “In the same way as every other partition that gets mounted – by the Linux boot process – just before anything else so that they can all be mounted within this root path.
All clear? Anyone still swimming in mud is recommended to head off and read a Linux primer on-line or any of the hundreds of good books on learning Linux. Or just accept what I’m writing and move on for now.We are straying too far into Linux workings now. My only intent in explaining the process of mounting a partition to a mountpoint is to explain why the /home directory has only a fixed amount of space – that is some fraction of the size of the boot drive for a “standard” Linux installation.
This article is not going to describe details of the mount function or mountpoints or how they get used – other than providing the instructions necessary to complete the task of this article’s title. You will find copious information on the subject with a simple web search or (perhaps better) by reading any Linux primer book. Just take care and pay attention to the warnings here about the dangers of diving in to areas of an operating system not fully understood – unaided.
Linux (as ever) provides several ways to move, relocate or resize the /home directory. Here, I am going to describe one of the simplest that will also introduce some techniques that will prove useful in many other areas – as well. I hope, help clear the fog of confusion that greets anybody arriving fresh to a new (to them) operating system.
Why move the /home directory or any part of it?
WARNING! As ever before embarking on any procedure that could result in data loss make sure you have at least one (preferably two or more) backups of the data you are about to operate on or the complete machine BEFORE starting. You have been warned!
A common problem that crops up after people install Linux on a relatively small boot disk – perhaps a small SSD these days – is that the /home directory – in which all their data files are stored – becomes full or so large that the operating system starts to slow down.
Frustration arises when the machine has other disk storage (ie; other SSDs or HDD drives) with high, unused capacity where the files (eg; a large collection of photographs or music) could be stored without taking space on the drive used to boot the machine.
Another good reason is that, for backup and maintenance purposes it is usually a good idea to separate a system’s software components from the data. This allows each component to be backed up separately so that a disaster in the data storage area is no more than a shrug of the shoulders (just restore from backup) equally a software update or configuration change that has caused problems is another shrug of the shoulders – just restore the previous (presumably working) configuration from backup.
When software and data become mixed problems arise that can easily be avoided.
Does the /home directory need to be moved at all?
The simple answer is “no”.
Just as with any OS such as Windows you can add drives (of whatever kind) to a Linux system, prepare and mount those drives then create a Photos or Music directory on that drive. But, you are now (just as happens with operating systems like Windows) scattering files across your storage and MUST engage with Linux’s arcane and potentially confusing file ownership and permissions systems if you intend those files to be available to you alone.
If you want to place files somewhere they can be shared with a group of people they should definitely be placed outside your home directory path in this way.
But if you have a folder of Private_Financial_Files or Secret_Business_Plans and want to make sure they stay reasonably within your view alone then your home directory is where they should go – as creating a new directory generally inherits the ownership and permissions of its parent.
Ergo, if you want to keep files “where they belong” and your filing system neat and tidy as you need to add files your home directory grows and you may eventually run out of space on a machine that has plenty of unused storage elsewhere. This is particularly true of a machine that is used by several users – say a pair of partners and some children. Linux makes it trivially easy to add users to a given system – each of those users is given their own private home directory …. but all those home directories share the same amount of fixed space allocated to /home when Linux was installed. So, if the children download a couple of multi-GN games and the parents download a few multi-GB movies a situation can quickly develop where somebody gets told “No space left”.
How to identify a full or filling home directory and how to deal with it
All the examples given here are going to use the Linux command line and assume you are logged in as root and are the only current user of the system – for the reasons stated below – it is a very bad idea to move potentially critical files while they are being used by the operating system – root has its own “home” directory for this specific purpose.
There is a simple command to display the names, mountpoints and sizes of all storage connected to a Linux machine:
“# df -h”
The command is df and the argument -h tells the command to display its output in “human readable form” – in this case as MB or GB rather than the number of disk blocks used or available (which is far from easy to interpret information – even if you know the number of blocks on a particular drive or partition).
Here is the output of running the df -h command on my workstation:
Filesystem Size Used Avail Use% Mounted on dev/tmpfs 16G 0 16G 0% /dev
tmpfs 16G 136M 16G 1% /dev/shm
tmpfs 16G 2.0M 16G 1% /run
/dev/nvme0n1p5 69G 23G 43G 35% /
tmpfs 16G 9.7M 16G 1% /tmp
/dev/nvme0n1p8 106G 61M 101G 1% /ws1
/dev/nvme0n1p2 976M 249M 661M 28% /boot
/dev/nvme0n1p1 599M 21M 579M 4% /boot/efi
/dev/nvme1n1p1 916G 556G 314G 64% /ws2
/dev/nvme0n1p3 147G 38G 102G 27% /homegp_local
/dev/sda1 1.8T 118G 1.6T 7% /localstore/dev/nvme0n1p4 98G 5.0G 88G 6% /var
tmpfs 3.2G 44K 3.2G 1% /run/user/709000001
anafiles.anadigi.loc:/raid1/home/george 4.5T 1.2T 3.3T 27% /home/george
The first column “Filesystem” gives us the name of the device or disk partition that has been mounted. The next three columns show the maximum “Size” of space available to that device, the amount of space already “Used” and the amount remaining “Avail[able]”.
Then comes a very useful column – “Use%” which shows proportion of space already used on that device.
Finally comes “Mounted on” which specifies the mountpoint … which is the most relevant factor here.
You may see when researching or viewing articles on the web or older books abut Linux a general piece of advice that a storage device (disk, partition, “thing that the operating system creates”) should be considered fully used when it “Use%” exceeds ~70%. In my experience this advice no longer applies – I have occasionally experienced situations where, during my experimental wanderings, I have managed to fill one or more storage devices to 100% capacity …. and Linux just carries on humming along nicely. Quite reasonably it will write no more files to the full device but it does no harm to files that are already stored.
How to interpret the df -h
output? Simple, really!
Quickly cast your eye down the “Use%” column checking for devices that are nearing 100% full. These should gain your urgent attention. But, in general, the column you want to look at is “Mounted on”. I have left – on the final line shown, my home directory “mounted on “/home/george” which shows that it contains enough files to occupy 1.2 Terabytes of shared storage that currently offers “4.5 T” (4.5 Terabytes) leaving 3.3T free for use. This is a somewhat usual (and certainly artificial) situation due to the nature of the shared storage used around here by all the workstations and devices in use around the house. In a more normal Linux installation a typical output might look like:
/dev/nvme0n1p9 100G 98G 2G 98% /home
indicating that the /home directory on the machine is very close to becoming full to bursting and something should be done urgently as, if the /home
directory becomes full, users will very definitely start to experience problems using the machine.
Remember, everything in Linux is a file so you can examine these mountpoints using the directory paths given. For example, to look inside the /tmp directory (where Linux and its applications stores temporary files that come and go as the OS is used simply type:
“# ls -lh /tmp”
ls
is the standard Linux directory listing command, the argument -lh
specifying that you want to see the output in “long form” – ie; columnar output with details of file ownership, permissions and size – the h
specifying that you want the size in (that’s right) human readable form (eg; bytes, KB, MB, GB etc) rather than nonsensical blocks.
An example of (a very) partial output from my workstation:
# ls -al /tmp
total 1716K
drwxrwxrwt 32 root root 820 Oct 17 12:24 .
dr-xr-xr-x. 30 root root 4096 May 23 16:24 ..
drwx------ 2 george george 60 Oct 17 07:00 .esd-709000001
drwxrwxrwt 2 root root 40 Oct 17 07:00 .font-unix
drwxr-xr-x 2 george george 40 Oct 17 07:02 hsperfdata_george
drwxrwxrwt 2 root root 60 Oct 17 07:00 .ICE-unix
You can see from the file ownership that temporary files are written by both applications running within a user session and by the operating system itself (shown as owned by root).
Just because you can see inside a directory does NOT mean that you should change or delete files without FULLY knowing what you are doing. Especially when logged in as root (but sometimes even as a “mere mortal” user) you are capable of doing enormous damage with just one simple command. For example the command “# rm -rf /dev” will wipe out every device in and connected to your machine. Just 9 characters typed and cue full system restore. Drop the “dev” from the command and you will wipe every single file from the system.
Remember – with great power comes great responsibility.
ESPECIALLY when logged in as root or using sudo or similar mechanisms to assume root’s powers be VERY careful what you type!
What to do when the /home directory is full or becoming full
The answer is to move the /home directory to another disk – freeing space on the boot drive and restoring speed to the machine.There are other reasons why you might want to move all or part of the /home directory and I will touch on and describe, briefly, how to accomplish this.Faced with this situation there are a couple of actions you might take:
- If you know enough “Linux” you might selectively move the contents of individual directories. The basic technique described here can be used to do this too – for example, I run an “enterprise class” environment here with centralised storage – which means that disk accesses (of which there can be thousands by applications such as web browsers or email clients) are limited to a maximum transfer rate of 100MB/s (megabytes per second) by the Gigabit network – regardless of the speed (transfer rate abilities) of the machines so all the directories that get “hammered” in this way are located on a local fast SSD. In the context of this article’s discussion (freeing up space) it remains a way to achieve that too – this time choosing just the directories (commonly, for example, most people’s – usually hidden – configuration and cache folders) to alternate storage.
- Move the entire /home directory and all its contents to a new drive. This is the main subject of this article though I will show the tools needed to identify which locations are using up most space and they can be moved using the same technique I set out.
IMPORTANT NOTE: You should be logged in as root – ie; not an ordinary user – when moving all or any part of the home folder otherwise your Linux login session will crash or cause considerable problems when the home folder is moved. For Debian and other variant users who are used to using sudo to temporarily gain root privileges this is not enough by prefixing a command with sudo (eg; sudo apt install xxxapp)– follow the instructions from step 1 carefully!
To the basic procedure.
What is going to happen is that the /home directory (and all the files and directories of all the machine’s users) will be moved to another drive
I am starting from the assumption that the machine has been installed in a ‘standard’ way – ie;
- the operating system and all its essential directories (mount points) including
/home
are on the boot drive (ie; the drive or partition used to boot the operating system) and - there is a another disk (HDD or SSD does not matter but it must be a disk that is permanently available to the machine – NOT a plugin USB drive, for example has been prepared and mounted as /store which is currently essentially empty or has plenty of space. Obviously, change
/store
or whatever mountpoint you have used to mount your large disk. - The existing
/home
directory will show up as a separate (fixed maximum size) disk partition with the“df -h”
command.
I will show command line prefixes “$” and “#” to show respectively where a command should be typed as the user or root respectively. DO NOT type these prefixes or the “” I use to surround command lines! Take care to note and use the correct case in commands or arguments to them – Linux differentiates between “-r” and “-R”!
All the procedures about to be described are carried out on the command line – NOT in a GUI.
Moving /home in its entirety
- Ensure that all ordinary users are logged out of the machine. Make sure that no other users log in to the machine until this entire procedure is completed.
- Obtain a plain, command line interface. DO NOT log in to a graphical interface as root! On most modern Linux installations this is best accomplished from the usual graphical login screen by
- pressing the key combination “Ctrl-Alt-F2” (as ever, without the “”) which means hold down the Control (Ctrl) AND Left-Alt keys then press the F2 function key
- you should be presented with a plain, full-screen with traditional Linux login prompt.
- On some Linux versions or some GUI types you may have to use a higher function key to obtain a plain text session – try Ctrl-Alt-F4 etc. until you see a plain text screen with a login prompt.
- Log in to Linux as root – then, when prompted, enter root’s password (the password you created when installing the system or have subsequently created/changed). Once logged in you will be in root’s “home” directory which significantly is NOT inside the /home directory used by mere mortal users. You can check this by typing the command
"# pwd"
which should produce the result"/root"
. Note that the“#”
prompt character indicates that you are acting as (in this case, logged in as)root
. - Create a NEW home directory on the 2TB HDD with the command
"# mkdir /store/home"
If necessary copy the permissions and ownership settings from the existing/home
directory. The new directory should look like this if you enter the command"# ls -al /store"
drwxr-xr-x 3 root root 0 Sep 12 06:48 home
Note owner and group are'root'
and permissions are'rwxr_xr_x'
(octal 755).If your listing differs enter the following commands (the upper case “-R” is important – this is Linux not Windows!):"# chown -R root:root /store/home"
"# chmod -R 755 /store/home" - Assuming you have been using the machine (so the existing /home directory on the SSD will contain user files you wish to preserve) copy them to the HDD with the command
"# cp -arv /home/ /store/home/"
Note the lower case"-r"
in this instance. the“-arv”
options here cause:-a archive (preserve the ownership and permissions of all files)
-r recursive (copy all subdirectories)
-v verbose (show each file or directory name as it is copied) - When the copy finishes make sure all the files have been copied by (quick and simple) entering
"# ls -alh /store/home"
which should list the home directory entries for each user of the machine with appropriate ownership and permissions – eg; my home directory might show as:drwxrws--- 135 george admins 326 Oct 14 07:40 george
followed by"# ls -alh /store/home/{username}"
where{username}
is the login ID of a “mere mortal” (ie; normal, not-root) user of the system – in my case “george”. If you are a worrier and want to check everything has been copied over enter these commands:
"# tree /home > oldhome.listing"
"# tree /store/home > newhome.listing"
"# diff oldhome.listing newhome.listing"
Thediff
command should produce no output.As soon as you are satisfied you have copied the user data and config files move on. You can delete the now redundant listing files with the command"# rm *listing"
- Now take a deep breath because here comes the scary part …
- Unmount the existing /home directory with the command
"#umount /home"
This will cause no problems as long as you logged in asroot
because though you are (temporarily) removing access to the/home
directory the operating system is making no use of it as no normal users are logged in.
Remember – everything in Linux is a file – though as normally installed home exists as a separate disk partition, here we are changing it to be a normal file directory within the standard root (“”) path. - Now, make sure you are comfortable using a simple text editor. All modern Linux types should have the easier-to-use
'nano'
editor installed avoiding the need to use old techie editors like'vi'
or'emacs'
. If the following nano command does not work (reports that the commandnano
is not recognised) install nano with"# apt -y install nano"
[Debian / Ubuntu / Mint ]
or“# dnf -y install nano”
{Centos / Fedora / RHEL ]
or“yum -y install nano”
(older versions of CentOS / Fedora / RHEL) - The list of partitions, disks and remote file stores that are mounted at boot time is contained in the file “/etc/fstab”. Make a backup copy of the fstab file (one mistake editing this file and your system becomes toast – proceed at your peril – and make sure you have a backup so that you can recover the position easily using recovery mode at boot time. Backup the file with the command
"# cp /etc/fstab /etc/fstab.SAVE"
- Edit the fstab file with the command
"# nano /etc/fstab"
Look for the line that mounts your existing /home partition – which will look something like this:UUID=f56445af-8ff6-42be-a7e6-07997aab3d84 /home ext4 defaults 1 2
Note: older kernels do not use UUID partition/device identifiers so you may see a path such as/dev/sda4
instead of aUUID
…. it doesn’t matter how the partition is identified just look for the mountpoint"/home"
. - Position the cursor ON THE LINE defining
/home
and pressF9
to delete the line. If you mistakenly delete the wrong line(s) don’t panic – just hitF2
followed by"n"
(without the “”) to exit nano without altering the file … then start the edit again. If you get really confused and have accidentally saved a damaged fstab file COPY the saved version you made in step 10 back with the command“# cp /etc/fstab.SAVE /etc/fstab”
then start again from step 11 - Within nano, press
F3
followed by [Return
] or [Enter
] to save the file thenF2
to exit nano. - Remount all drives/paths with the command
"# mount -a"
… then list the root directory with"# ls -al /"
to confirm that the/home
directory is no longer present. - Now … create a link in the
root
directory to your new home directory sitting on the HDD at/store /home
with the command"#ln -s /store/home /home"
- a link in any UNIX based OS (such as Linux) is a ‘redirect’ – it tells the OS to go elsewhere when it tries to access a given file or directory – here we are telling the operating system to go to
/store/home
whenever it looks for/home
- Check the link. First type the command
"# ls -al /home"
which will provide something like:
lrwxrwxrwx 1 root root 7 Jan 28 2020 /home -> store/home
Note the leading'l'
before the permissions field signifying that this entry is a link – also given away by the->
pointing to the link destination.If you are wondering how to get to your files just type the command"# ls -al /home/"
… NOTE the trailing"/"
. The contents of your newly located/home
directory should now appear – identical to the original/home
directory. - You can now reclaim the space used by the old
/home
directory using a disk management tool as described in other articles in this series (eg; graphical tools with names such as “Disks” or “Disk Management in menus or programs such as “gparted
” or “kparted
” according the the desktop interface you have chosen. I cannot give specific instructions here (and have no need to as the mechanism for reclaiming the space from the old/home
partition depends on the layout of existing partitions relative to one another on the original boot drive and the file system type(s) used. Whatever disk management tools are available to you will be well documented on-line Anaconda usually places the/home
partition as the last on the boot drive or at least immediately following the root("/"
) partition which makes the job of reclaiming the space relatively easy by (quick description) deleting the old/home
partition and then expanding the root or“/”
partition to use the space newly freed. You can see partition layouts most easily with the ‘lsblk
‘ command – here is the output from the workstation I am currently using:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
└─sda1 8:1 0 1.8T 0 part /localstore
sr0 11:0 1 1024M 0 rom
nvme0n1 259:0 0 465.8G 0 disk
├─nvme0n1p1 259:1 0 600M 0 part /boot/efi
├─nvme0n1p2 259:3 0 1G 0 part /boot
├─nvme0n1p3 259:4 0 150G 0 part /homegp_local
├─nvme0n1p4 259:5 0 100G 0 part /var
├─nvme0n1p5 259:6 0 70G 0 part /
├─nvme0n1p6 259:7 0 20G 0 part /home
├─nvme0n1p7 259:8 0 16G 0 part
│ └─fedora_localhost--live-swap 253:0 0 16G 0 lvm [SWAP]
└─nvme0n1p8 259:9 0 108.2G 0 part /ws1
nvme1n1 259:2 0 931.5G 0 disk
└─nvme1n1p1 259:10 0 931.5G 0 part /ws2
which shows that the machine has a 2TB HDD (shown as 1.8T usable due to the differences between the way disk manufacturers “pad” their wares by defining 1KB as 1,000 bytes where operating systems (and computers in general) define 1KB as the binary based powers-of-two value of 1,024) HDD listed as “sda
” containing one partition "/localstore"
and two NVME type SSDs … you can see the root ("/"
) and /home
partitions on drive nvme0n1
partitions 4 and 5 … significantly adjacent to each other and in a usefully correct order. In my case the local /home
partition is not used as the bulk of the 1.2TB of files contained in my home directory are stored on the central file store – but I left a small /home
partition which allows me to log in should all the fancy centralised storage and authority stuff ever fail.
Note that my root ("/"
) partition is only 70GB in size yet despite having a VERY full set of applications and tools installed it is only 35% full.
You can, of course, just decide to leave the original home partition in place as a backup (though of poor quality) or just wait until your Linux skills give you more confidence to go playing around with live partitions. Not a bad course to choose unless you really need the space back now.
Moving individual home directories
Sometimes you may not wish to move the entire /home directory – containing all user files and the entire contents of each user account.
There are several possible reasons why you might want to be more selective, including:
- A single user account is becoming too large so must be moved but the only other local storage you have is a relatively slow HDD compared to the fast SSD used for the main boot drive – hence the performance hit can be confined to only that user who is taking up most space without impacting other users.
- In a more complex environment (such as the centralised login and storage used here) all disk access to the home directory is V_E_R_Y slow compared to even a 10 year old HDD, restricted as it is by the maximum speed of the network connection. In my case, the central file store use can sustain read/write speeds in excess of 550MB/s (550megabytes/second) and though the server has multiple LAN connections usually only one at a time is available to a client so a single Gigabit network link can provide a maximum of 1,000Mb/s (1,000megabits/second ~= 100MB/s or 100 megabytes/second). Compare this to even a modern HDD installed on a SATA connection inside a machine which might produce 100MB/s and all seems well … until you realise that the shared storage is serving multiple clients simultaneously and may be simultaneously performing backup or file system synchronisation with a replica or backup server and delivered speeds might tumble. So, you might want to place directories such as cache directories and other frequently hit workspaces on a fast, local SSD to maintain speed of the client machine. NOTE: If you do this you should take care that the backup process of the client machine takes the, now local, directories into account.
Who or what is using all the space?
A simple command – “du
” (standing for “disk usage”) – can be used to identify where large amounts of space are being used.
Following our example, we know the /home
directory contains 98GB of files – but we do not know where this space is being used. Let’s assume we have three user of the machine – david, sally and tom.
The simple command:
“# du -hd1 /home”
where “du
” is the command and two options are being passed to it – the -h
again means human readable output and “d1
” tells the process to summarise its finding to only ONE depth of subdirectory. Finally, we are telling du
to start its search in the /home
directory. The du
process can take quite some time (several minutes on a fast machine with lots of files – far longer on a slower machine) so be patient and let it do its work.
This command might produce an output like this:
3G /home/david
5G /home/sally
90G /home/tom
98G /home
We now know that user ‘tom’ is using the majority of the space.
We could decide to move just tom’s home directory to other storage or we might want to look deeper into where the space is being used with a command:
“# du -hd1 /home/tom”
which repeats the process – but this time starting in and confined to tom’s home directory. The output (again limited to just one directory deep) will show all the directories in tom’s home directory with a summary of how much space each sub-directory is using. A quick look at this output might reveal that tom is storing 85GB of files in his Music directory.
If necessary, you can repeat this process to explore deeper into the file hierarchy by specifying longer and longer file paths – eg
“# du -hd1 /home/tom/Music”
might reveal that tom has a large Jazz collection OR we can simply increase the number of directory levels reported with, for example,
“# du hd3 /home/tom”
which will show summaries for tom’s Music directory and the Jazz and Rock subdirectories as well.
Selectively moving directories
The process of moving individual user or functional directories is the same as for moving an entire /home directory – the only difference is that you are increasingly the granularity of which sub-directors to move.
Assume as before we have a second large disk mounted as /store and that we already have a /store/home directory in place.
Pursuing our example, let’s move user tom’s entire home directory:
“# df -h /store”
which will produce an output identical to our previous use of the df
command but restricted to just the /store
mountpoint – allowing us to check that the /store
directory has enough space to store all 90GB of files that we have previously identified are in user tom’s home directory
“# mv /home/tom /store/home/tom”
NOTE this time we are using the mv
(move) command which will first copy the directory /home/tom
and all the files and all sub-directories it contains to its new location at /store/home/tom
(creating the new sub-directory /tom
under /store/home
as necessary) and then deleting the original /home/tom
directory
.So, as tom now has no home directory, we give him one using the simple link command we learned earlier:
“# ln -s /store/home/tom /home/tom”
Now, when user tom next logs in he see nothing changed – other than if he checks the amount of disk space available to him it will have grown from 2GB to whatever spare size you have in the /store
directory.
Bring on the Jazz!
Moving just tom’s Music directory
Look back at what was just done. Just three commands:
(1) we checked our intended new location for tom’s home had enough space to accommodate his files,
(2) moved tom’s entire home directory to that new location and
(3) created a link to the new location from the old location (which was no longer there) so that Linux will follow the link and use the new location to find or create whatever files are usually stored in tom’s home directory.
Exactly the same, simple, three-step process can be used to move (for example) just tom’s Music directory to a new location.
BUT … a word of caution. This simple process is easy to learn and easy to follow. But if you use it too often and at too granular level you will quickly end up in “link hell” as directories are displaced from where they are expected to be to another (potentially) random place in the storage pool. There is also no such thing as a free lunch as thers is a (small) performance penalty to pay for causing Linux to follow a link and, while this normally causes no noticeable problem you should be careful when using links to relocate heavily used directories such as a user’shome directory – with all its hidden config and cache directories and files (which may exist in the thousands) as every file access will first look in the original parent directory location then need to follow the link to the new location and can only then begin its search for the file being sought.
Refer to my description above why, on my workstation, heavily used directories are located on a local (to the machine) fast SSD while the majority of my (somewhat large) home directory is held on the central, shared file storage.
Summary
You should now know
- how to relocate your /home directory from the original boot drive to the drive where you have space for all your data and be able to fill it up with terabytes (or whatever size you have) of whatever files you need.
- how to move just one user’s home directory to a new location
- how to relocate individual directories or files
Finishing up and testing
Having moved whatever directory or directories you want or need you can just log out of the command line interface by hitting Ctrl-D
followed by Ctrl-ALt-F1
to regain the graphical interface session or reboot the machine while still logged in using the
"# reboot"
command. I suggest the latter as this tests that everything comes to life normally.Then log back in (using the graphical interface if that is what you usually use) and check that everything is working exactly as before.