GLOSSARY

ACRONYM NAME DESCRIPTION
pv physical volume The physical disk or partition in array
vg volume group The name of the whole array
lv logical volume The name of a virtual disk within the array. More than one LV may be in a VG

CREATING A NEW LV

  1. Create PV(s)

    sudo pvcreate /dev/sdX
    
  2. Create VG - give it the disk names for the PVs at hand, one or more PVs can be added initially

    sudo vgcreate VG-NAME /dev/sdX /dev/sdY
    
  3. Add PV(s) to VG

    sudo vgextend /dev/sdZ
    
  4. Create LV-NAME

    # Non-mirrored LV - (100MB in example, and %100 afterwards) in VG-NAME
    sudo lvcreate -L 100M -n LV-NAME VG-NAME
    sudo lvcreate %100FREE -n LV-NAME VG-NAME
    
    # Create a single mirror lv.
    # -- You need .1% roughly for log file if keeping on same set.
    # -- Presuming 100G VG.
    # -- You can add "--nosync" to the command to skip initial sync.
    sudo lvcreate -L 49G -m1 -n LV-NAME VG-NAME
    
  5. Format lv as ext4 or xfs

    sudo mkfs.ext4 /dev/VG-NAME/LV-NAME && e2label /dev/VG-NAME/LV-NAME labelname
    sudo mkfs.xfs /dev/VG-NAME/LV-NAME
    

MIRROR EXISTING LV

  1. Reduce filesystem

    # Use 'df' to see where things are mounted
    sudo umount LV-MOUNTPOINT
    
    # Resize ext filesystem on LV
    sudo resize2fs /dev/VG-NAME/LV-NAME NEWSIZE
    
    # OPTIONAL :
    # Resize both LV and filesystem to 5G (POTENTIALLY UNSAFE)
    # -- Skip to step 4 afterwards
    sudo lvreduce --resizefs -L 5G /dev/VG-NAME/LV-NAME
    
  2. Reduce LV

    # Reduce LV by 5G (Sufficient for ~ 5TB @ .1% rule)
    sudo lvreduce -L -5G /dev/VG-NAME/LV-NAME
    
    # Reduce LV to 5G
    sudo lvreduce -L 5G /dev/VG-NAME/LV-NAME
    
  3. Resize filesystem (presuming ext4)

    sudo resize2fs /dev/VG-NAME/LV-NAME
    
  4. Create pv for new drive(s). One more drive may be necessary if you want to create a mirrorlog disk.

    sudo pvcreate /dev/sdX
    
  5. Add new pv(s) to vg

    sudo vgextend /dev/VG-NAME /dev/sdX
    
  6. Create mirror using new drive(s)

    sudo lvconvert -m1 /dev/VG-NAME/LV-NAME
    

MIGRATION FROM OLD DISKS IN VG TO NEW ONES

  1. Create PV for new disk

    sudo pvcreate /dev/sdz
    
  2. Extend the VG to include the new disk

    sudo vgextend VG-NAME /dev/sdz
    
  3. Migrate extents to new disk

    sudo pvmove /dev/sdb /dev/sdz
    
  4. Remove PV from LV

    sudo vgreduce VG-NAME /dev/sdb
    
  5. Remove PV from VG & VLIDATE

    sudo pvremove /dev/sdb
    sudo pvdisplay
    

MIGRATION OF LVM ARRAY TO NEW HOST

  1. Unmount the LVM VG(s) in question, and validate that it is indeed unmounted

    sudo umount /dev/VG-NAME/LV-NAME
    df -h
    
  2. Mark VG as inactive and verify inactive status

    sudo vgchange -an VG-NAME
    sudo lvdisplay
    
  3. Export VG and verify state

    sudo vgexport VG-NAME
    sudo vgs
    
  4. Power off hardware and transfer it to new host

  5. Import VG and verify import status

    sudo vgimport VG-NAME
    sudo vgs
    
  6. Mark VG as active and verify active status

    sudo vgchange -ay VG-NAME
    sudo vgs
    
  7. Mount VG and verify mount status

    sudo mkdir -p /mnt/VG-NAME
    mount /dev/VG-NAME/LV-NAME /mnt/VG-NAME/LV-NAME
    df -h
    

TROUBLESHOOTING

CANNOT CREATE PV

If you get the message:

    $ sudo pvcreate /dev/sdb /dev/sdc
      Device /dev/sdb not found (or ignored by filtering).
      Device /dev/sdc not found (or ignored by filtering).

The solution is to recreate the disklabel from gpt to msdos:

    $ sudo parted /dev/sdb
    GNU Parted 3.1
    Using /dev/sdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) mklabel msdos
    Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? y                                                                 
    (parted) select /dev/sdc                                                  
    Using /dev/sdc
    (parted) mklabel msdos
    Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? y                                                                 
    (parted) q                                                                
    Information: You may need to update /etc/fstab.

You likely will need a reboot, but then the disks should be able to be turned into a PV without issue:

    $ sudo pvcreate /dev/sdb
    WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/sdb.
      Physical volume "/dev/sdb" successfully created.
    $ sudo pvcreate /dev/sdg
    WARNING: dos signature detected on /dev/sdg at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/sdg.
      Physical volume "/dev/sdg" successfully created.

All fixed!