Add another HDD to GPT and LVM

I have Rocky Linux 9 and right now I have

df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                 12G     0   12G   0% /dev/shm
tmpfs                4.7G  8.8M  4.7G   1% /run
efivarfs             256K   28K  223K  12% /sys/firmware/efi/efivars
/dev/mapper/rl-root  220G  3.4G  217G   2% /
/dev/sdb2            960M  273M  688M  29% /boot
/dev/sdb1            599M  7.1M  592M   2% /boot/efi
tmpfs                2.4G     0  2.4G   0% /run/user/0

I add another HDD to this server and I see

lsblk 
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   240G  0 disk 
sdb           8:16   0   240G  0 disk 
├─sdb1        8:17   0   600M  0 part /boot/efi
├─sdb2        8:18   0     1G  0 part /boot
└─sdb3        8:19   0 238.4G  0 part 
  ├─rl-root 253:0    0 219.8G  0 lvm  /
  └─rl-swap 253:1    0   1.6G  0 lvm  [SWAP]
sr0          11:0    1  1024M  0 rom  

I see too

fdisk -l
Disk /dev/sdb: 240 GiB, 257698038272 bytes, 503316481 sectors
Disk model: Virtual disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B133D9B5-CF8F-4786-BE67-B0734B59F71D

Device       Start       End   Sectors   Size Type
/dev/sdb1     2048   1230847   1228800   600M EFI System
/dev/sdb2  1230848   3327999   2097152     1G Linux filesystem
/dev/sdb3  3328000 503316447 499988448 238.4G Linux LVM


Disk /dev/sda: 240 GiB, 257698037760 bytes, 503316480 sectors
Disk model: Virtual disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/rl-root: 219.81 GiB, 236017680384 bytes, 460972032 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/rl-swap: 1.6 GiB, 1719664640 bytes, 3358720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

I want add this

sda

to this disk and after that add it to

/dev/mapper/rl-root

and I want have 480GB after that

You need to create a physical volume (PV), add it to your volume group (VG), expand the logical volume (LV) and grow the file system.

  • Create a partition table and an empty partition. gdisk /dev/sda. Once in interactive mode, hit o to create a GPT partition table, than hit n to create an empty partition: just go with the defaults and use 8E00 as partition type (it stands for LVM). Hit w to commit the changes to the disk. This step could be omitted and you could create the PV on the raw disk, but I prefer to create a partition table for consistency - it may look weird and confuse some admins or tools. If you prefer to omit this step, just run below commands on /dev/sda instead of /dev/sda1.
  • Create the PV with pvcreate /dev/sda1. You can verify it by pvdisplay /dev/sda1.
  • Find out the name of your VG by running vgdisplay. Than run vgextend <name of your vg> /dev/sda1. Verify with vgdisplay.
  • Expand your LV by the amount you need. lvextend -L +50G /dev/mapper/rl-root (adjust the size on -L to your needs).
    Consider not commiting the whole disk now, if you do not need it. xfs cannot be shrunk and if you should want to create another partition at some point in the future you will not be able to.
  • Grow the file system with xfs_growfs /.

You need to run the commands as root or with sudo. Be aware that the disk will be wiped by writing a new partition table. So be sure you run the commands on the right disk. If possible, do a backup because any operations on the disks come with some risk.

3 Likes

And keep doing them in the future too. After all, if either HDD fails, then the entire /dev/mapper/rl-root dies.

1 Like

Yes, this looks risky to me. A filesystem spanning two physical disks?

What is best solution?

Solution for what? Getting the space in use or backups?


A convenience of big filesystem volume is that any subset of data can grow to use (all) space.

A benefit of multiple small filesystem volumes is that no subset of data can grow to use space of other subsets. The downside is that some volumes may be unnecessarily big and unused space in them is “wasted”. One should thus predict wisely, if one wants multiple volumes as resizing volumes can become tricky (e.g. one cannot shrink XFS).


A system has basically three things:

  • system files (installed from packages)
  • config (configuration systems can make logical copy of it that is trivial to redeploy and easy to backup)
  • user data (that is the most valuable piece and also least predictable)

The default install creates ‘rl-root’ and ‘rl-home’, for / and /home. The latter has only “user data”. The latter is also example of mounting an additional filesystem (into the directory hierarchy) where “extra” space is required.

Lets say that the largest “user data” will be a Postgresql database that may need almost 240 GB.
One could create a partition into the second HDD (either plain partition or PV for new VG that has LV). Then mount that to /var/lib/pgsql, before installing the Postgresql packages. Now all of the SQL database will be in the “sda”, while system remains in “sdb”.

If the “sda” breaks, you get a new HDD, recreate filesystem, mount it to /var/lib/pgsql and restore database contents from backup.

If the “sdb” breaks, you get a new HDD, reinstall Rocky, mount “sda” to /var/lib/pgsql and restore rest of config and userdata that were in sda from backups.

1 Like

In addition, looking at the original post, isn’t there supposed to be a ‘/home’ mount point too?

It is not mandatory.

1 Like