Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Partially moving /home to a new partition, leaving some content behind

+1
−0

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?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+0
−0

There are two key ideas here:

  1. 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.

  2. 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 to user_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:
      mkdir -p /media/user_1
      mount /dev/sdXN /media/user_1/medium_partition
      mkdir -p /media/user_1/medium_partition/shared/large_folder
      
      (where sdXN is the actual device name, which can be inferred from lsblk output) Use chmod and chown as necessary to make the created shared and large_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
  • 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 the large_partition)
      • Determine the UUID for the medium_partition (I looked it up in gnome-disks; it could also be done via blkid /dev/sdXN)
      • Above the old /home entry, add a new one:
        UUID=01234567-89ab-cdef-0123-456789abcdef /home           ext4    defaults        0       2
        
        (filling in the actual UUID. If you use a different filesystem than ext4, change that too)
  • 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).

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »