Partially moving /home to a new partition, leaving some content behind
I have a partition and directory structure that looks like:
small partition:
/
usr
var
... # etc.
large partition:
/home
shared
other_stuff
large_folder
user_1
...
user_2
...
medium partition:
(empty)
The other partitions are too small to hold the large_folder
by itself, never mind the rest of /home
. Note that shared
does not correspond to a user; it's just an ordinary folder I created under /home
, mainly so that the large_folder
contents would be on the large partition.
Now with the benefit of hindsight (my reasons for creating the empty partition were ill considered, and also considering reasoning given in https://unix.stackexchange.com/questions/70700), I want to rearrange things like so:
small partition:
/
usr
var
... # etc.
large partition:
/large_folder
medium partition:
/home
shared
other_stuff
user_1
...
user_2
...
That is: move everything except the large_folder
's contents to the medium partition and have the system recognize this as the new home
mount point, while promoting the large_folder
to the top level of the large partition.
What's the simplest way to do this? Is it possible without scratch space on a separate drive?
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
Karl Knechtel | (no comment) | Nov 26, 2024 at 20:46 |
There are two key ideas here:
-
Moving data between partitions entails copying it onto the new one and then deleting it from the original - just like copying between different physical drives. However, of course, the deletion can be postponed arbitrarily; not deleting leaves a potentially useful backup.
-
The new partition needs to be the mount point for
/home
, while the original should also be auto-mounted somewhere in order to have access to the files.
The natural choice is/home/shared/large_folder
, since fundamentally the contents are still user data.
The following approach is adapted from what I actually did (some steps were needlessly clumsy, and the real situation was actually more complex than I described) and from general advice in Ubuntu's guide to moving /home
onto a new partition starting from the root partition.
- Log out all users, then log in as
user_1
(a sudoer) from a terminal (to avoid having any GUI processes running that might write touser_1
's config files during the copy) - Copy user folders to the medium partition
- Mount the empty
medium_partition
and create empty folders for the mount point:
(wheremkdir -p /media/user_1 mount /dev/sdXN /media/user_1/medium_partition mkdir -p /media/user_1/medium_partition/shared/large_folder
sdXN
is the actual device name, which can be inferred fromlsblk
output) Usechmod
andchown
as necessary to make the createdshared
andlarge_folder
folders match the existing ones on the large partition. - Copy the shared folder and user folders:
sudo cp -a /home/user_n/ /media/user_1/medium_partition/ sudo cp -a /home/shared/other_stuff /media/user_1/medium_partition/shared
- Unmount the partition
- Mount the empty
- Reconfigure permanent mount points:
- Locate and back up
/etc/fstab
, then edit (requires sudo):- On the line with
/home
, change that to/home/shared/large_folder
(i.e., change the mount point for thelarge_partition
) - Determine the UUID for the
medium_partition
(I looked it up ingnome-disks
; it could also be done viablkid /dev/sdXN
) - Above the old
/home
entry, add a new one:
(filling in the actual UUID. If you use a different filesystem thanUUID=01234567-89ab-cdef-0123-456789abcdef /home ext4 defaults 0 2
ext4
, change that too)
- On the line with
- Locate and back up
- Reboot, or
sudo mount -a
, and verify that everything works.
The large_partition will now look like:
/home/shared/large_folder
shared
other_stuff
large_folder
user_1
...
user_2
...
Therefore, we now want to move the contents of the large_folder
up to the root of the partition (i.e. directly into /home/shared
):
mv /home/shared/large_folder/shared/large_folder/* /home/shared/large_folder
(Of course, this can just as well be done with a GUI)
and then the rest of that partition contains backups which can be dealt with as one pleases (archiving somewhere else, renaming the folders to avoid confusion, or just deleting it eventually).
0 comment threads