1

So, I'm working on a couple VMs for a high-profile site, and they have /home partitioned separately from / (root). The owner has asked me to merge the two partitions so that /home is not partitioned separately. I'm really bad with partitions, and Google has proved pretty useless for this. Doing a df -T on /home, I don't see anything for the filesystem, but I was told that it's partitioned separately. Likewise, the filesystem column for df -T / is also empty.

We're using CentOS 6.4.

Help would be appreciated.

2 Answers 2

1

Why won't you simply create a new drive, copy the current home folders to it, and attach it as the /home partition?

It seems like the immediate solution...

2
  • So I talked with the owner about it and we decided that we would add additional space to the server by adding more HDDs, and then we will simply move the entirety of the /home directory onto the other drive, delete the partition it was on, and then move the data back to /home. It's a shame that data on partitions is deleted when the partition is. Commented Dec 13, 2013 at 6:59
  • Partition manipulation needs backup before you do things - especially if you talk about a production webserver. Your solution is fine, but keep in mind that you will need to reboot server with either parted magic or some other live distro (in root terminal you could use resize2fs). This is needed so that you can delete the old /home and extend / to recover space. As for data - think partition is a bottle and data milk - once the bottle is broken milk is gone ;) - no other way about it. Good info on milk ibm.com/developerworks/library/l-resizing-partitions-1
    – r0berts
    Commented Dec 13, 2013 at 8:07
1

I assume that all your filesystems are ext4 (or ext3). With that, you can do it as follows:

  1. Check that you really have separate partitions. You can check /etc/fstab, use mount -v and df -h to confirm that you have separate / and /home partitions. Lets assume for simplicity that your / is mounted at /dev/sda1 and /home is mounted at /dev/sda2.
  2. Boot from some CD or USB media that has minimal Linux distribution with gparted. You could use any of UBCD, PartedMagic or simply Ubuntu or CentOS installation CD.
  3. After booting from non-primary hard drive, start gparted as root and resize your /home to be as small as possible (or as gparted lets you), move it further to the end of the drive, and enlarge / to be as big as possible. Note that if your / contains bootblocks (/boot directory which is not a separate partition), this may necessitate to run grub recovery (utility boot-repair is very good for that).
  4. Reboot into Linux, copy data from /home to /, as much as you can. Then repeat this process again from step 2, until your /home is almost empty, and has negligible size (maybe just few megabytes).
  5. Now, you can unmount partition /dev/sda2 from mountpount /home, and simply populate this now only a directory with content that you copied before. You probably would need to adjust /etc/fstab to not have line with /home anymore.
  6. Final result - / will be almost as big as whole drive and will contain all data from old / and /home partitions.
2
  • This is a live webserver. I don't want to be taking it offline for any extended period. Commented Dec 13, 2013 at 5:43
  • Then leave it alone, or use elaborate policy of symlinks here and there
    – mvp
    Commented Dec 13, 2013 at 5:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .