Blog

  • Using LVM2 for a resilient scalable drive array

    63 terabytes of storage built from 8 USB drives in RAID 1 configuration.

    A bit of background:

    • I started a (multi-domain) web service ten years ago. I wanted some extra storage as backups.
    • Fairly quickly I was running out of space, as well as backups of backups — so I had to add storage to my USB drive. Now I wanted to serve the pages of an NVME (originally M2.SATA) drive, and have the backups on a slower (cheaper medium). I started to grow the number of USB drives.
    • The number of USB drives became unwieldy because if the server (Linux) reboots, the drives come in an undetermined order. Sorting out the drives between sdb, sdc…sdi is not fun.

    To start with… this is a completely safe, benign operation — it just makes LVM2 available to your machine:

    sudo apt install lvm2

    Enter LVM2, which I had used in the past.

    sudo pvs 
    PV         VG   Fmt  Attr PSize  PFree    
     /dev/sdb   big2 lvm2 a--  <4.55t   <1.55t
     /dev/sdc   big  lvm2 a--  <7.28t <284.04g
     /dev/sdd   big  lvm2 a--  <7.28t   75.07g
     /dev/sde   big  lvm2 a--  <7.28t       0  
     /dev/sdf   big2 lvm2 a--  <3.64t   <3.64t
     /dev/sdg   big  lvm2 a--  <7.28t <284.04g
     /dev/sdh   big  lvm2 a--  12.73t   10.73t
     /dev/sdi   big2 lvm2 a--  14.55t  818.96g

    I took all the USB drives, ran PVcreate (Physical Volume create) on each drive, adding them to a Volume Groug (VG). I realized that the drives could be categorized as Slow and Fast, depending on their seek times (and whether they “fell asleep” between access). So I added the PVs into big and big2 groups [using VGcreate](not the best naming, should have used Fast and Slow).

    sudo vgs 
    VG   #PV #LV #SN Attr   VSize   VFree  
     big    5  28   0 wz--n-  41.84t 11.36t
     big2   3   9   0 wz--n- <22.74t <5.99t
    

    Finally I started creating Logical Volumes (LVcreate) for each purpose always creating LVcreate on VG1 and VG2 same size, and creating an rsync between the LVs (backup of a backup — effectively bring the whole array into a RAID1 configuration). Now, I could have used LVM2s native tools to do this as well, but I wanted more control (and I had been burned by LVM1 in the pre-historic 10year+ past).

    Nowadays, I have 38 Logical volumes (spread across 9 PVs), that I occasionally expand or shink depending on size needed, usually about a terabyte at a time.

    My LVS map is too long (and private to show).

    Here’s the killer!
    When the California heatwave occured, I lost the machine (srv3) completely. and I built a new server (srv4), I just took all the USB hubs from srv3, plugged into srv4, and ran PVSCAN. LVM2 rebuilt the whole raid array, with configurations (PVS, and VGs). All I needed to do was copy the /etc/fstab from a backup of srv3… and we’re back in business!

    The USBs, the drive IDs, the HUBs don’t matter, everything fell back in place correctly.

    The only thing I wish is that I hoped I hade done better job in taking mysqldumps of the databases instead of doing rsyncs, thus not needing to rebuild the sites. But the sites that were HTML came back immediately.

    Emails on user accounts were a bit trickier, Folder by folder reconstruction became a possibility, though some tricks were involved (sendmail, dovecot — I will probably write another article). I will likely add more details to this if interested.

  • I Like the NUCs (fanless tiny servers, except when the heatwave happens)

    I have a tower built on NUCs built to serve email/web/VPN/wifi/etc

    Only after the California Heatwave did I realize that you can just stash the whole system in a closet without some FANs for cooling — The Manufacturer suggested Amazon Infinity Fans, which have now worked beautifully.

    smartctl -ax /dev/nvme0

    Model Number:                       KINGSTON SNV3S4000G
    Serial Number:                      50026B72837023EB
    Firmware Version:                   P3DR0A27
    PCI Vendor/Subsystem ID:            0x2646
    IEEE OUI Identifier:                0x0026b7
    Total NVM Capacity:                 4,000,787,030,016 [4.00 TB]
    Unallocated NVM Capacity:           0
    Controller ID:                      0
    NVMe Version:                       1.4
    Number of Namespaces:               1
    Namespace 1 Size/Capacity:          4,000,787,030,016 [4.00 TB]
    Namespace 1 Formatted LBA Size:     512
    Namespace 1 IEEE EUI-64:            0026b7 2837023eb5
    Local Time is:                      Fri Jul 31 13:59:04 2026 PDT
    Firmware Updates (0x12):            1 Slot, no Reset required
    Optional Admin Commands (0x0016):   Format Frmw_DL Self_Test
    Optional NVM Commands (0x0056):     Wr_Unc DS_Mngmt Sav/Sel_Feat Timestmp
    Log Page Attributes (0x02):         Cmd_Eff_Lg
    Maximum Data Transfer Size:         64 Pages
    Warning  Comp. Temp. Threshold:     75 Celsius
    Critical Comp. Temp. Threshold:     80 Celsius
    
    SMART/Health Information (NVMe Log 0x02)
    Critical Warning:                   0x00
    Temperature:                        40 Celsius
    Available Spare:                    100%
    Available Spare Threshold:          10%
    Percentage Used:                    0%
    Data Units Read:                    1,170,245 [599 GB]
    Data Units Written:                 13,736,068 [7.03 TB]
    Host Read Commands:                 14,606,017
    Host Write Commands:                181,472,111
    Controller Busy Time:               454
    Power Cycles:                       48
    Power On Hours:                     4,544
    Unsafe Shutdowns:                   27
    Media and Data Integrity Errors:    0
    Error Information Log Entries:      0
    Warning  Comp. Temperature Time:    0
    Critical Comp. Temperature Time:    0
    Temperature Sensor 1:               58 Celsius
    Temperature Sensor 2:               59 Celsius
    Temperature Sensor 3:               40 Celsius