16

I have separate / and /home partitions, of which both use ext4 as their filesystem.
How can I merge them, and what is the easiest way?

  • 2
    I only know about using GParted and a live CD. Resize my /home, and then expand /. Move the /home files into the /, and finally delete the /home and expand /. – Apache Mar 29 '12 at 11:48
  • 1
    I would say copy/backup your entire /home to an external drive, reinstall Ubuntu with a single partition, then copy your home back in. – Marius Mar 29 '12 at 11:54
  • @Marius, it turns out, what I wrote works perfectly. (Which is what htorque said in his answer.) So I'll accept his. :) – Apache Mar 29 '12 at 12:33
14

I don't think there's an easier way. You need to copy the data from one partition to the other. You need to delete the old home partition and resize the root partition. That cannot be done on a running system, so a live CD or USB seems like as good as it gets.

  • Boot the live CD/USB.
  • Mount the root partition to /mnt/root.
  • Mount the home partition to /mnt/oldhome.
  • Copy the data using rsync:

    sudo rsync -avz --hard-links --numeric-ids /mnt/oldhome/ /mnt/root/home
    
  • Open /mnt/root/etc/fstab and delete the entry for your home partition.

  • Unmount the root and home partition and reboot the system. If everything works as expected you can reboot again into the live system and then:
  • Open Gparted.
  • Delete the old home partition, resize the root partition.

That should be it.

| improve this answer | |
  • 1
    There are a few improvements which can be made to that rsync command. First of all you will want a slash at the end of the from path, or you will end up with an oldhome, within the homefolder. You might also want to add --hard-links, in case you have any of those under /home. To be on the safe side --numer-ids won't hurt either, depending on what is in /etc/{passwd,group} on the Live CD. – andol Mar 29 '12 at 13:42
  • Also, do you really expect much benefit from compression when doing a local rsync? – andol Mar 29 '12 at 13:45
  • Thanks. I added those to the above mentioned rsync call. – qbi Mar 29 '12 at 13:46
  • @andol: Thanks, I was too sloppy with my answer. As for local compression: yes, I've seen a bit of a performance increase, so as long there's no performance hit, I tend to enable compression. – htorque Mar 29 '12 at 14:34
  • Good answer, but a few notes: --hard-links can be shortened to just -H, -z would not be desirable/effective on local filesystems, and --numeric-ids would not have any effect on a local filesystem (what's in /etc/passwd on other other drive would not have any effect when run locally). – thomasrutter Apr 15 '15 at 1:06
1

I dont know about the easiest or the best approach but here is how I would do it. I would just create folder in / and then copy all data from /home to it. Then I will reboot my system using live cd and delete the partition for /home and rename the folder that I created in / to home and then delete entry for /home in fstab. And the last step would be to resize my root partition to consume empty space created by deleting partition for /home.

| improve this answer | |
-1

I know this is an old question, but for anyone like me who are looking for a good solution this tutorial: MERGE (OR RESIZE) THE /HOME PARTITION ON CENTOS 7 worked great for me!

Just don't forget to do chown -R <USER> /path/to/new/home for all end users. System/program users are fine as well as root, but any users you set up will need that command.

The other benefit of this is that you don't need to use the install media, you can just do it from a root terminal, so if your server is of site you'll still be able to do this!

| improve this answer | |
  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Kevin Bowen Jun 15 at 23:19
  • Also OP has only ext4 partitions whilst the example in the link uses xfs. – mook765 Jun 16 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.