Moving /home with LVM
There are quite a few ways to do what you want, but the way I'd recommend is:
- 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.
- Prepare the PV(s) for use by LVM with the
pvcreate
command, as insudo pvcreate /dev/sdb1
. - Add the new PV(s) to your existing volume group (VG) with
vgextend
, as insudo vgextend ubuntu--vg /dev/sdb1
. - Type
sudo pvdisplay
to show statistics on your PVs, including their sizes. - Create a new logical volume (LV) with
lvcreate
, as insudo 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
). - Type
sudo pvdisplay
again to verify that you've created an LV that's an appropriate size. If not, you can resize it withlvresize
or delete it withlvremove
and try again. - Create a filesystem on your LV, as in
sudo mkfs -t ext4 /dev/mapper/ubuntu--vg-home
. - Mount the new LV somewhere convenient, as in
sudo mount /dev/mapper/ubuntu--vg-home /mnt
. - Copy your
/home
directory withtar
,cp
,rsync
, or whatever tool you prefer. - Edit
/etc/fstab
to mount the new LV at/home
. - Rename your current
/home
to some other name (say,/home-orig
) and create a new empty/home
directory to serve as a mount point. - Reboot and hope it works.
- 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.
Related videos on Youtube
tonysdg
Updated on September 18, 2022Comments
-
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 almost 7 yearsI'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!