Setting up an Ubuntu 22.04 Server with RAID1 and LVM

Although setting up a simple single-drive Ubuntu server is a good start for building your self-hosted cloud, adding a second drive as a RAID array to the system from the start will give you far improved reliability and a greater sense of security for your data. Even if you have a drive fail, you have a redundant mirrored drive to keep your data safe and operational until you can replace the failed drive.

Additionally, LVM affords you the ability to somewhat future-proof your storage by essentially creating a virtual disk that you can migrate between physical disks and expand without needing to worry about the underlying storage configuration being a limiting factor.

Here's how to set up a RAID1 mirrored system with LVM from the start.

  • Plug in your network
  • Boot Ubuntu 22.04 Live from USB
  • Select your English, and hit enter
  • Leave layout and variant as English (US) and hit enter
  • Leave the type of install as Ubuntu Server and hit enter
  • Leave Network connections as-is (assuming you use DHCP on your network) and hit enter
  • Leave Configure server Proxy address blank and hit enter
  • Leave Configure Ubuntu archive mirror as-is and hit enter
  • Under Guided storage configuration, select Custom storage layout and hit the space bar
  • Select Done and hit enter
  • Storage configuration
    • Clear all partitions from your drives (if existing partitions/RAID exist)
    • You should now have 2 identically-sized drives with all free space under AVAILABLE DEVICES
    • For each of your drives under AVAILABLE DEVICES...
      • Tab to select the local disk and hit enter
      • Tab to select Use As Boot Device (or Add As Another Boot Device) and hit enter
      • Tab- to select free space under that drive and hit enter
      • Tab- to select  Add GPT Partition and hit enter
        • Tab, then hit enter
        • Tab to select Leave unformatted, then hit enter
        • Tab to select Create then hit enter
    • Select Create software RAID (md) and hit enter
      • Leave Name as md0 and tab
      • Leave RAID Level as 1 (mirrored) and tab
      • Tab to the first of you drives' partitions labeled as partition 2 and hit Space to choose it
      • Tab to the second of you drives' partitions labeled as partition 2 and hit Space to choose it
      • Tab to Create and hit enter
    • Under md0 select free space and hit enter
    • Select  Add GPT Partition and hit enter
      • Set the Size to 2G and hit tab
      • Tab again, leaving Format set to ext4
      • On Mount, hit enter, then select /boot, then hit enter
      • Tab to select Create then hit enter
    • Under md0 select free space again and hit enter
    • Select  Add GPT Partition and hit enter
      • Leave the Size blank and hit tab
      • Hit enter on Format, select Leave unformatted, and hit enter
      • Tab to select Create then hit enter
    • Select Create volume group (LVM) and hit enter
      • Leave Name set to vg0 and hit tab
      • Under md0 select partition 2 and hit space to choose it
      • Tab to Create and hit enter
    • Under vg0 (new) select free space and hit enter
    • Select Create Logical Volume and hit enter
      • Leave the Name set to lv-0
      • Select Create and hit enter
    • Select Done and hit enter
    • On the Confirm destructive action screen, select Continue and hit enter
    • Congrats! You made it past the most complicated part of the installation!
  • Profile setup...
    • Beside the Your name field,  type in your full name and hit tab
    • For Your server's name, you can use whatever name you want. Might I suggest selfserve01 if you don't have a name in mind. Hit tab when done.
    • For Pick a username,  enter the username you wish to create for yourself, and hit tab.
    • Enter a password of your choosing, hit tab and confirm it, then hit tab
    • With Done selected, hit enter
    • Leave Skip for now checked on the Ubuntu Pro advert
    • Tab to Continue and hit enter
    • Press Space to choose Install OpenSSH server
    • Tab to Done and hit enter
    • Leave the Featured Server Snaps as-is
    • Tab to Done and hit enter
    • Wait for the installation to complete
    • You should see one of two messages when you are ready to reboot:
      • Cancel update and reboot, which you can select if you just want to move on and do updates later
      • Reboot Now, which you can wait for if you want to start up with a fully updated system from the start.

Ideally at this point we should get the mdraid service set up to email us about drive failures. For now, we'll have to wait until we get some basic mail server capabilities installed.