Skip to content

Instantly share code, notes, and snippets.

@yohhaan
Created April 12, 2021 03:45
Show Gist options
  • Save yohhaan/3127792dc1570e4c4636b2fb142f0462 to your computer and use it in GitHub Desktop.
Save yohhaan/3127792dc1570e4c4636b2fb142f0462 to your computer and use it in GitHub Desktop.
Configurations to format the Western Digital My Book Duo external drives for GNU/Linux with LUKS encryption

Configuration

  1. Install WD Drive Utilities (available only on Windows and Mac).

  2. Under RAID Management in WD Drive Utilities, choose Individual Drives (JBOD) and format the 2 drives.

  3. Then boot on a GNU/Linux machine and run the following commands:

    • Remove existing partitions and make sure that you are using GPT:

      sudo parted /dev/sda
      (parted) print
      (parted) rm 1 (and other partitions if several)                                                           
      (parted) mklabel gpt 
      (parted) quit
      
      sudo parted /dev/sdb
      (parted) print
      (parted) rm 1 (and other partitions if several)                                                           
      (parted) mklabel gpt                                                      
      (parted) quit
      
    • Create the LUKS partitions:

      sudo cryptsetup luksFormat --type luks2 /dev/sda 
      sudo cryptsetup luksFormat --type luks2 /dev/sdb
      
    • Open the encrypted devices and create a mapping:

      sudo cryptsetup luksOpen /dev/sda backup1
      sudo cryptsetup luksOpen /dev/sdb backup2
      
    • Consider writing zeros to each mapped device, this may take several hours to complete (see https://wiki.archlinux.org/index.php/Dm-crypt/Drive_preparation):

      dd bs=1M if=/dev/zero of=/dev/mapper/backup1 status=progress
      dd bs=1M if=/dev/zero of=/dev/mapper/backup2 status=progress
      
    • Use the mapped devices as physical volumes:

      sudo lvm pvcreate /dev/mapper/backup1
      sudo lvm pvcreate /dev/mapper/backup2
      
    • Create a volume group to contain the physical volumes:

      sudo lvm vgcreate external-backup /dev/mapper/backup1 
      sudo lvm vgextend external-backup /dev/mapper/backup2
      
    • Create the logical volume (here we create one that occupies all the space):

      sudo lvm lvcreate -n lv_external_backup -l +100%FREE external-backup
      
    • You can check that the previous operations succeeded with:

      sudo lvm pvdisplay
      sudo fdisk -l
      
    • Create a filesystem on the logical volume:

      sudo mkfs.ext4 -v /dev/mapper/external--backup-lv_external_backup
      
    • Mount the logical volume:

      sudo mkdir -p /mnt/external-backup
      sudo mount /dev/mapper/external--backup-lv_external_backup /mnt/external-backup 
      
    • Perform your backup operation or other read/write operations on the mounted volume

    • Unmount and secure data:

      sudo umount /mnt/external-backup
      sudo lvm vgchange -a n external-backup
      sudo cryptsetup luksClose backup1        
      sudo cryptsetup luksClose backup2
      

Mount and unmount after configuration

  • Open the encrypted devices and mount the logical volume:

    sudo cryptsetup luksOpen /dev/sda backup1
    sudo cryptsetup luksOpen /dev/sdb backup2
    sudo mkdir -p /mnt/external-backup
    sudo mount /dev/mapper/external--backup-lv_external_backup /mnt/external-backup
    
  • Perform your backup operation or other read/write operations on the mounted volume

  • Unmount and secure data:

    sudo umount /mnt/external-backup
    sudo lvm vgchange -a n external-backup
    sudo cryptsetup luksClose backup1        
    sudo cryptsetup luksClose backup2
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment