0

System is a CentOS 7.

I have a logical volume mounted at /.

While setting up the server I forgot to give /home an own logical volume.

Now I want to move everything in /home to its own logical volume.

What is the best process to do so? Does lvm have a built-in way to do so?

My current way of doing things would be:

Taking it offline

  • Take the server offline (so web-applications running on it are not reachable during the operation)
  • mv /home /old-home (to prevent file changes during the operation)
  • Reboot the server, so any process that had an open file-handle in /home gives up the handle and can't start until /home is available again

Moving the data

  • Create new logical volume (lv)
  • Mount new lv at /mnt/new-lv
  • cp -r all contents from /home to /mnt/new-lv
  • Mount new lv at /home

Checking the result

  • Switch the server back online and test the application
  • Keep /old-home for a while as emergency backup if everyhing looks allright
  • rm -rf /old-home at some point later

But maybe there is a less manual way? Or a way that avoides downtime?

edit 1: Add the new lv to /etc/fstab so it automatically starts with the system.

edit 2: The system in question is a virtual system in our hoster's datacenter, so afaik booting into alternative OS modes (like rescue/minimal) is not an option.

3

Here's what I would've done:

  1. Create the LV for home
  2. Format the LV with the desired file system
  3. Reboot with a Live or System Rescue CD
  4. Mount /
  5. Rename /home to /home-old
  6. Mount /home
  7. Make the necessary changes to /etc/fstab
  8. Copy the data with rsync -av /home-old/* /home/
  9. To check: diff -r /home-old /home

If all looks good, reboot the server to it's own OS and you should be good to go.

Cheers, OJ

| improve this answer | |
  • Booting into minimal/rescue OS is a good idea. I would actually like your approach much more than mine. Sadly I forgot to specify that it's a virtual system in a hoster's datacenter. So as far as I know I can't boot the system into alternative modes. Sorry for not mentioning earlier, I will specify that as an edit. This does not make your approach any less viable though! – Worp Oct 8 '19 at 7:01
  • Well, if you cannot boot it up in alternative ways, you will have to do what you outlined. I'd shut down all connections for other users with iptables and kill all processes (or ask the users to disconnect if you're such inclined :-)) Then I'd shut down any and all services with open handles in the /home or subdirectories. Finally use lsof to find any stragglers. Then rename the folder to /home-old, mount the new LV and move the data as per instructions above. After changing the fstab to point to the new location you should be good to go without a reboot (remember to check later). – OnkelJ Oct 11 '19 at 7:31
  • Roger that =) I will happily mark your answer as answer as the comment confirms what I had already thought about! Thank you sir! – Worp Oct 16 '19 at 17:10

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.