Debian Installation with LVM RAID 1 and Hot Spare

Jan 28, 2022 Linux, Storage

Debian 11 installation
Debian is a powerful, multipurpose, and super stable Linux distro, however, in my humble opinion, its installation wizard was never a strong point of this Linux distribution, making it pretty difficult to install for beginners. While the standard setup with just a single disk is still relatively digestible for most users, the more sophisticated setup involving RAID with LVM might be pretty hard and arduous. The purpose of this tutorial is to help you go through the whole installation procedure smoothly and painlessly.

In this tutorial, I present Debian 11 (Bullseye) installation based on MD-RAID, configured in Mirroring mode, with an additional Hot Spare drive and LVM partitioning on top of it.


Table of Contents

  1. Hardware Setup
  2. Booting from CD/DVD
  3. Language and Regional Settings
  4. Network Configuration
  5. User Configuration
  6. Physical Disks Partitioning for RAID Personas
  7. Partition Settings for md0 RAID Persona (boot partition)
  8. Partition Settings for md1 RAID Persona (LVM)
  9. Creating Partitions based on the Logical Volumes
  10. Installing the Base System and Software Packages
  11. Configuring the GRUB Boot Loader
  12. Verify the disks setup

1. Hardware Setup

  • distro: Debian 11 (Bullseye) amd64
  • 1st disk: /dev/vda (KVM-based Virtio block device)
  • 2nd disk: /dev/vdb (KVM-based Virtio block device)
  • 3rd disk: /dev/vdc (KVM-based Virtio block device)
  • RAID mode: RAID1 (Mirroring) + Hot Spare
  • RAID personas: md0 (vda1,vdb1,vdc1[spare]), md1 (vda2,vdb2,vdc2[spare])

2. Booting from CD/DVD

Boot your server from CD/DVD and choose Graphical install from the Debian installer menu:

Debian 11 Bullseye installer menu

3. Language and Regional Settings

3.1 Select your preferred language

Debian installation select language

3.2 Select your location

Debian 11 Bullseye regional settings

3.3 Configure locales

Debian 11 Bullseye installation configure locales

3.4 Configure the keyboard layout

Debian 11 Bullseye configure keyboard layout

4. Network Configuration

In this tutorial, I use a fixed IP address, and have no DHCP server configured in my network, hence the network autoconfiguration failed:

Debian 11 Bullseye network autoconfiguration fails

4.1 Configure the network manually (skip this point, if you use DHCP)

Select Configure network manually from the menu:

debian 11 configure network manually

Type your IP address in standard or CIDR format:

debian 11 configure IP address

Set your Gateway IP address:

debian 11 configure network gateway

Enter DNS servers’ IP addresses (for example Google DNS servers), separated by blank spaces:

Debian 11 configure Google DNS servers

Set your hostname:

Debian 11 set your hostname

Type your domain name:

Debian 11 configure domain name

5. User Configuration

5.1 Set password for root

Debian 11 enter root password

5.2 Create a regular account

First, type the full name for the new user:

Debian 11 add new user

Next, create a username for a regular account:

Debian 11 bullseye create username

Finally, set a password for a regular user:

Debian 11 Bullseye set user password

6. Physical Disks Partitioning for RAID Personas

At this point, we will partition all available physical disks into the same way, to create two MD RAID personas:

  • /dev/md0 persona for boot partition
  • /dev/md1 persona for LVM physical volume (including root and swap logical volumes)

The purpose of creating a separate md0 persona is to host the boot partition. This partition cannot reside on md1 persona, which is intended for LVM, because the GRUB loader can not read from LVM Logical Volume.

6.1 Select partitioning method

In order to install Debian 11 with software RAID, we need to select the Manual partitioning method:

Debian 11 manual disk partitioning

6.2 Select physical disk for partitioning

Below is the list of all physical disks detected by the Debian 11 installer. Select the first (highlighted) physical volume vda from the list and double click on the selected disk:

Debian 11 physical volumes

6.3 Create a partition table

Create a new partition table on the first disk:

Debian 11 create new partition table

6.4 Create a partition (for md0 RAID persona)

Now double click on the highlighted FREE SPACE line to create a new partition:

Debian 11 created partition table

Now select Create a new partition option from the list:

Debian 11 create a new partition

6.5 Set a partition size (for md0 RAID persona)

Choose a new partition size (for example 1GB):

Debian 11 Boot Partition size

6.6 Choose a partition type (for md0 RAID persona)

Select Primary partition type from the list:

Debian 11 set partition type

6.7 Choose a partition location (for md0 RAID persona)

Select the Beginning option from the list, since we want to fill the physical disk up with the partitions from its beginning:

Debian 11 partition location

6.8 Configure a partition (for md0 RAID persona)

Set partition parameters as follows:

  • Use as: physical volume for RAID
  • Bootable flag: on

Debian 11 configure partition

Next, select Done setting up the partition to finish creating a partition for /dev/md0 RAID persona.

At this point our partition layout on /dev/vda disk looks like the below:

Debian 11 partition layout

6.9 Create a partition (for md1 RAID persona)

Now it’s time to create a second partition for /dev/md1 RAID persona, which will host a Physical Volume for our LVM Volume Group. Select FREE SPACE line and double click on it:

Debian 11 create partition for RAID persona

Now select Create a new partition option from the list:

Debian Bullseye create new partition

6.10 Set a partition size (for md1 RAID persona)

In this example, I am using the maximum available space on the disk, since I am not planning any more RAID personas in the future:

Debian Bullseye set partition size

6.11 Choose a partition type (for md1 RAID persona)

Select Primary partition type from the list:

Debian Bullseye set partition type

6.12 Configure a partition (for md1 RAID persona)

Set partition parameters as follows:

  • Use as: physical volume for RAID
  • Bootable flag: off

Debian Bullseye configure partition

Finally, select Done setting up the partition to finish creating a partition for /dev/md1 RAID persona.

At this stage of installation our partition layout on /dev/vda disk looks like the below:

Debian Bullseye partition layout

6.13 Create RAID partition layout on the remaining disks

Repeat steps 6.2 – 6.12 for the remaining disks, that is /dev/vdb and /dev/vdc (Hot Spare).

Finally, our partition layout on all disks should look like on the below picture:

Debian Bullseye configure software raid

Now, select the Configure software RAID option and click on the Continue button.

Next, check the Yes radio button to write the changes to the storage devices and configure RAID, and click on the Continue button.

Debian Bullseye write changes to the disks

6.14 Create md0 RAID persona for boot partition

Now we are creating /dev/md0 persona from the specific partitions on each disk.

Select the Create MD device option:

Debian Bullseye create md RAID persona

As stated at the very beginning of this tutorial, we are creating a RAID1 (Mirroring) setup:

Debian Bullseye RAID1 device  type

Our RAID1 setup is going to be built on exactly 2 (two) devices:

Debian Bullseye choose active devices

We are going to use exactly 1 (one) Hot Spare device:

Debian Bullseye RAID1 hot spare device

Create the md0 persona based on /dev/vda1 and /dev/vdb1 previously prepared partitions:

Debian 11 Bullseye  RAID1  choose active devices

Choose /dev/vdc1 as a spare device for our md0 RAID persona:

Debian Bullseye choose Hot Spare device

We have successfully created the md0 RAID persona for boot partition, where we are going to mount /boot directory.

6.15 Create md1 RAID persona for LVM

Now it’s time to set up /dev/md1 persona from the specific, previously prepared partitions on the disks, to create a Physical Volume for Logical Volume Manager (LVM).

Select the Create MD device option once again:

Debian 11 Bullseye create md-raid

Here, again, we are creating a RAID1 setup, this time for md1 persona:

Debian Bullseye creat raid1  setup

Type in 2 (two) active devices for RAID1 array:

Debian 11 Bullseye active devices for raid1

Type in 1 (one) spare device for RAID1 array:

Debian 11 Bullseye md-raid spare device

Pick /dev/vda2 and /dev/vdb2 partitions as active devices for md1 persona:

Debian 11 Bullseye RAID1 active devices

Choose /dev/vdc2 as a spare device for md1 persona:

Debian 11 Bullseye RAID1 hot spare

Now select the Finish option and click on the Continue button:

Debian 11 Bullseye finish RAID persona creation

We have finished creating the md1 RAID persona for LVM Physical Volume, where the root filesystem and the swap partition will reside.

At this stage of installation, our disk setup is presented in the below picture. Newly created RAID personas: md0 and md1 are marked by the red rectangle:

Debian 11 Bullseye RAID personas

7. Partition Settings for md0 RAID Persona (boot partition)

Since the /boot partition cannot reside on md1 persona, intended for LVM, we will place it on md0 instead, as a standard partition.

Select the RAID1 Device #0, which stands for md0 persona, and click on the Continue button:

Debian 11 Select md0 raid persona

7.1 Create a standard partition for boot

Configure partition settings:

  • Use as: select preferred filesystem type
  • Mount point: /boot
  • Mount options: defaults
  • Label: set the label for your reference

When done, select the Done setting up the partition option and click on the Continue button.

Debian 11 create boot partition

We have successfully created a standard partition on md0 persona, which will be mounted in /boot mount point.

8. Partition Settings for md1 RAID Persona (LVM)

Our LVM Volume Group will contain root and swap Logical Volumes and will be placed on md1 persona, that means md1 will become a Physical Volume for the Volume Group.

Select the RAID1 Device #1, which stands for md1 persona, and click on the Continue button:

Debian 11 create physical volume for LVM

8.1 Create a Physical Volume for LVM

Now create the aforementioned LVM Physical Volume on top of the md1 persona.

Use the volume as physical volume for LVM, select Done setting up the partition option and click on the Continue button.

Debian 11 create physical volume for lvm

8.2 Create a Volume Group for LVM

Once, we have a Physical Volume created, we can proceed with the Volume Group creation.

Select Configure the Logical Volume Manager option form the menu:

Debian Bullseye create LVM volume group

Check the Yes radio button to write the changes to the disks and configure LVM

Debian 11 write changes to the disks

Now select the Create volume group option and click on the Continue button:

Debian 11 Bullseye create VG

Type in the preferred Volume Group name:

Debian 11 Bullseye volume group name

Now is the time to pick the Physical Volume we created in point 8.1.

Choose the /dev/md1 based Physical Volume and click on the Continue button:

Debian 11 Bullseye select PV for VG

We have successfully created an LVM Volume Group, named debian, and in the next steps, we will create the Logical Volumes on top of that Group.

8.3 Create a Logical Volume for the root filesystem

Select the Create logical volume option and click on the Continue button:

Debian 11 Bullseye create logical volume for root partition

Choose a Volume Group, we have recently created, named debian:

Debian 11 Bullseye choose a volume group

Type in a name for the new Logical Volume, let’s name it root, since it’s going to host our root filesystem:

Debian 11 Bullseye root logical volume

Enter the size of the root Logical Volume:

Debian 11 Bullseye root fs size

8.4 Create a Logical Volume for the swap partition

Select the Create logical volume option once again and click on the Continue button:

Debian 11 Bullseye create lv for swap

Select a previously created debian Volume Group:

Debian 11 Bullseye choose a volume group for swap lv

Enter a name for the Logical Volume:

Debian 11 Bullseye swap lv name

Enter the size for the swap Logical Volume:

Debian 11 Bullseye  swap lv size

8.5 Verify the LVM Configuration

Once we have created the Volume Group and Logical Volumes, let’s check the current configuration before we write changes to the disk.

Select Display configuration details option and click on the Continue button:

Debian 11 Bullseye display LVM configuration

Our final LVM config looks like the below:

Debian 11 Bullseye final lvm configuration

Now select the Finish option from the menu and click on the Continue button.

Debian 11 Bullseye finish LVM configuration

9. Creating Partitions based on the Logical Volumes

We will now format our Logical Volumes accordingly for the root and the swap partition.

9.1 Create the root filesystem partition

Select the root Logical Volume and click on the Continue button:

Debian 11 Bullseye partition setup

Configure partition settings:

  • Use as: select preferred filesystem type
  • Mount point: / (root directory)
  • Mount options: defaults
  • Label: set the label for your reference

Debian 11 Bullseye format root partition

When done, select Done setting up the partition option, and click on the Continue button.

9.2 Create the swap partition

Select the swap Logical Volume and click on the Continue button:

Debian 11 Bullseye create swap partition

Use the partition as a swap area:

Debian 11 Bullseye create swap area

Finally, select Done setting up the partition option, and click on the Continue button.

9.3 Review the disk layout and write changes to the disk

This is our complete and final disk layout:

Debian 11 Bullseye review disk layout

Scroll down the screen, select the Finish partitioning and write changes to disk option, and click on the Continue button:

Debian 11 Bullseye write changes to disk

Check the Yes radio button and click on the Continue button to write changes to the disks.

Debian 11 Bullseye write changes to disks

10. Installing the Base System and Software Packages

Once the partitioning is finished and the changes have been written to the disks, the base system installation will begin right away:

Debian 11 Bullseye install base system

10.1 Configure the Package Manager

If you don’t have any additional installation media to scan, choose No when prompted:

Debian 11 Bullseye scan extra media

Use the network mirror for the supplementary package installation:

Debian 11 Bullseye use the network mirror

Select Country to look for the most suitable archive mirror:

Debian 11 Bullseye select network mirror country

Select a Debian archive mirror from the list:

Debian 11 Bullseye select archive mirror

Enter a proxy server for external connectivity, if you use one in your network:

Debian 11 Bullseye use proxy server

Decide, if you are going to participate in the package usage survey:

Debian 11 Bullseye package survey

10.2 Select the software

Select the software collections you would like to install along with the system and click on the Continue button:

Debian 11 Bullseye choose software

11. Configuring the GRUB Boot Loader

Now is the final, and a bit tricky part of the installation – choosing a location for the GRUB Boot Loader.

11.1 Install the GRUB Boot Loader

When prompted for the location, check the Yes radio button to install the GRUB Boot Loader to your primary drive:

Debian 11 Bullseye install GRUB to primary drive

On the next screen, select Enter device manually option:

Debian 11 Bullseye select device manually

Now enter the /dev/vda as the device for boot loader installation:

Debian 11 Bullseye device for boot loader

The installer will now run grub-install /dev/vda command on /dev/vda disk:

Debian 11 Bullseye grub-install command

The installer says the installation is complete:

Debian 11 Bullseye installation complete

…but it isn’t. In fact, the GRUB loader has been installed on /dev/vda device only, so we need to install it on the remaining devices, that is vdb and vdc.

So now, switch to the other console by pressing CTRL+ALT+F2, and activate a console by pressing ENTER.

Change the root directory to the installed system:

~ # chroot /target /bin/bash

Install GRUB on /dev/vdb:

root@debian:/# grub-install /dev/vdb

Debian 11 Bullseye grub-install on sdb

Finally, install GRUB on /dev/vdc (spare device):

root@debian:/# grub-install /dev/vdc

Debian 11 Bullseye grub-install  vdc

Now press CTRL+ALT+F5 to go back to the Debian installer console:

Debian 11 Bullseye installation complete

Click on the Continue button to reboot the system.

12. Verify the disks setup

After reboot login to your system:

Debian 11 Bullseye Gnome login screen

12.1 Check RAID synchronization

Your RAID (md1 persona) should be now resyncing or already resynced:

Debian 11 Bullseye RAID synchronization

12.2 Verify RAID Personas

RAID md0 persona details:

Debian 11 Bullseye RAID md0 persona

RAID md1 persona details:

Debian 11 Bullseye RAID md1 persona

12.3 Verify LVM Setup

Finally, verify LVM configuration:

Debian 11 Bullseye verify LVM


11 thoughts on “Debian Installation with LVM RAID 1 and Hot Spare”
  1. Can you show or explain how to do this with UEFI? This method only works with legacy If I’m not mistaken.

  2. On the image 89, you can just type:
    /dev/vda /dev/vdb /dev/vdc

    So you can skip the extra steps to install the bootloader on other disks.
    Works pretty well if you remove the first disk, it will boot using the second one and so forth.

    The only thing I didn’t figure it out is… if you replace the first disk with an empty one, then the boot fails and you need to repair it on rescue. Any tips on that?

    1. Thank you for a good hint navossoc, I will give it a try in some upcoming installations.

      Regarding your concern:
      “if you replace the first disk with an empty one, then the boot fails and you need to repair it on rescue” – If you replace the first disk and you recreate the partition table on that first disk (using sfdisk) and then you install the GRUB bootloader on that first disk in the same way, like on image 92 then it SHOULD NOT FAIL during next boot, the whole replacement procedure in software RAID I described in the below post:

      https://tuxfixer.com/how-to-replace-a-volume-in-mdadm-software-raid-array/

      Please let me know if the above link fixes your problem?

      1. Yes, that way works…

        What I mean is:
        If you remove the first disk, it will boot using the bootloader from the second disk (GOOD).
        If you replace the first disk with an empty one, it will fail at boot needing reinstall the grub on the first disk (BAD).

        Is there anyway to do like in the first case? fallback to another disk…
        I think the purpose of having a /boot in raid 1 is exactly that (to be used as a fallback).

        1. Ok, I get your point and IMHO this is a shortcoming of mdadm software RAID that the disks that are currently in the RAID array are still visible in BIOS as individual disks and Boot order is set for individual disks, not for the whole RAID array.

          In first case that you described the system will boot probably because in BIOS’s Boot Order you have a second disk placed right after the first one, and the first one is gone so BIOS will try to boot from the second one.

          If you replace the first disk with an empty one (without recreating partitions and GRUB) it will fail because BIOS will still try to Boot from first one, but there will be no OS installed on the first drive, because mdadm software RAID does not rebuild itself right after replacing the disk – in this case you will have to set Boot order in BIOS manually to second disk in order to boot from second disk.

          This problem would not happen if you had a hardware RAID controller, which would rebuild itself automatically after replacing the failed disk, and moreover boot order in BIOS wouldn’t be altered, because BIOS would still see the whole RAID array as one logical disk regardless of the amount of working disks in the array.

          So I am afraid you can’t do anything about it – it’s the disadvantage of software RAID versus the hardware RAID.

  3. Thanks for that fantastic tuto that is very clear and works like a charm 😉 after few hours killing my head to succeed to install Debian in such configuration, have worked straight at first try !

  4. Finally – a post that actually deals with setting up RAID1 from scratch and is, as far as is possible in the never ending tweaks that constitute Linux, up to date and correct. RAID using mdadm etc. etc. is still a complete mess in comparison to ZFS but unfortunately, wonderful as ZFS is on Solaris, it remains an even bigger unworkable mess on Linux. And we won’t start on BTRFS which should, really, be humanely euthanised

  5. on Image26, Debian installation doesn’t allow me set bootable flag “on” so on the last step where grub-install running I have error..

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.