There's no direct way to swap two devices, but this isn't what you need anyway. Keep
home to the desired smaller size, and enlarge
root using the space that was freed up.
Depending on the filesystems, you may or may not need to unmount them to resize them. Ext4 filesystems can be enlarged while mounted, but not shrunk; use the command
resize2fs. Btrfs filesystems can be resized in either direction while mounted.
To shrink an LVM logical volume, use
lvreduce. Make sure that you don't accidentally shrink it smaller than the filesystem — this is the one step here where an incorrect manipulation can cause data loss (and it's very likely to do so if you get the number wrong). Be careful, with LVM, lowercase suffixes (
g, …) use powers of 1024, but uppercase suffixes (
G, …) use powers of 1000. To enlarge an LVM logical volume, use
For example, with ext4:
resize2fs /dev/mapper/home 5G
lvreduce -L 5g /dev/mapper/home # note lowercase g
lvextend 2t /dev/mapper/root
Note that if
/home is really 2TB and is 1% full, it won't fit in 5GB. Adjust sizes accordingly.
Alternatively, you may want to move the database to a filesystem of its own. It's often a good idea to use separate volumes for the operating system and for large datasets, because they can have different storage policies (regarding redundancy, performance, backups, etc.). If that server is only a database server, it would make sense for it to have two filesystems:
/ (including the
/home directories which don't contain much more than the administrators' configuration files) and