Moving /home with LVM

14,011

There are quite a few ways to do what you want, but the way I'd recommend is:

  1. Partition the new disk. It can be one big LVM partition or you can set aside one or more non-LVM partitions for other purposes. I sometimes create multiple LVM partitions (aka physical volumes, or PVs) so that I can remove one or more of them from the LVM configuration in the future, should the need arise. Note that I do not recommend putting PV data structures directly on the disk without partitions, as shown in the LVM answer you reference. Although this is legal, it can lead to confusion because hard disks are usually partitioned.
  2. Prepare the PV(s) for use by LVM with the pvcreate command, as in sudo pvcreate /dev/sdb1.
  3. Add the new PV(s) to your existing volume group (VG) with vgextend, as in sudo vgextend ubuntu--vg /dev/sdb1.
  4. Type sudo pvdisplay to show statistics on your PVs, including their sizes.
  5. Create a new logical volume (LV) with lvcreate, as in sudo lvcreate -L 900G -n home ubuntu--vg /dev/sdb1. Note that I've specified a syntax that enables you to set a size (via -L) and the PV on which the LV will be created (/dev/sdb1).
  6. Type sudo pvdisplay again to verify that you've created an LV that's an appropriate size. If not, you can resize it with lvresize or delete it with lvremove and try again.
  7. Create a filesystem on your LV, as in sudo mkfs -t ext4 /dev/mapper/ubuntu--vg-home.
  8. Mount the new LV somewhere convenient, as in sudo mount /dev/mapper/ubuntu--vg-home /mnt.
  9. Copy your /home directory with tar, cp, rsync, or whatever tool you prefer.
  10. Edit /etc/fstab to mount the new LV at /home.
  11. Rename your current /home to some other name (say, /home-orig) and create a new empty /home directory to serve as a mount point.
  12. Reboot and hope it works.
  13. If it all looks good, delete the old /home-orig directory.

Steps 8-11 are very similar to equivalent steps in the procedure outlined in the wiki page you reference, so I've gone light on the details for those steps.

Note that, although I've done this sort of thing myself many times, the example commands I've shown are based on my reading of the relevant man pages, so I may have missed some detail. I recommend you review the man pages and, if you get an error, adjust once you figure out what's wrong. Also, I find Ubuntu's default LVM naming confusing, so I may have misinterpreted that detail, and you may need to adjust.

Once you're done with this, you'll have unused space in your PV on your SSD. You can expand your root (/) LV into this space, expand the /home LV to span both disks, create another LV for some special purpose, etc.

A variant of this procedure might be to leave your current /home LV where it is, create a new LV on the new disk, and begin using the new LV as spillover space. You note that your computer is a multi-user server, so this might be awkward, but there might be reasons to do this -- for instance, if just one or two users are consuming the lion's share of the disk space, you could move just their home directories to the new space or give them directories on the new space (with mount points or symbolic links to make access easier) and instruct them to move their big files to the new space. This approach would have the advantage of not negatively impacting other users, since the new hard disk storage space is likely to be noticeably slower than the old SSD storage space.

Share:
14,011

Related videos on Youtube

tonysdg
Author by

tonysdg

Updated on September 18, 2022

Comments

  • tonysdg
    tonysdg over 1 year

    I currently have Ubuntu 16.04 Server installed on a machine with a small 96-GB SSD. That's no longer enough space for all of the users on the server, so I'd like to add a 1-TB HDD and move the /home folder to a new partition on this 1-TB drive explicitly.

    Originally, I had planned on doing this using the instructions here. However, on closer review of the system, I discovered that LVM is enabled:

    Filesystem                   Size  Used Avail Use% Mounted on
    udev                          63G     0   63G   0% /dev
    tmpfs                         13G  9.5M   13G   1% /run
    /dev/mapper/ubuntu--vg-root   98G   76G   18G  82% /
    tmpfs                         63G     0   63G   0% /dev/shm
    tmpfs                        5.0M     0  5.0M   0% /run/lock
    tmpfs                         63G     0   63G   0% /sys/fs/cgroup
    /dev/sda2                    473M  111M  338M  25% /boot
    /dev/sda1                    512M  136K  512M   1% /boot/efi
    tmpfs                         13G     0   13G   0% /run/user/1001
    

    Based on what I've read so far, I need to add the new drive to the ubuntu-vg volume group (as in steps 2-3 of this answer). But I'm unsure of how to proceed after this -- should I continue with steps 4-5? Or is there another way of explicitly moving just /home to the 1-TB HDD and leaving / on the SSD?

  • tonysdg
    tonysdg almost 7 years
    I'm not terribly concerned about negatively impacting other users (it's a research group, we all know each other, they can yell at me if they want haha), so I'm guessing this will be the way I go about it. I'll read up a bit more, give this a shot, and accept if it's what I use in the end. Thanks!