This post was from the Ubuntu 12.04 era, or around 2013. So it may be out of date. It’s here for reference.
This note explains how to install Ubuntu Linux Server on a computer with two hard disks, with RAID 1, so it boots from the array. The entire installation, including partitioning and RAID administration, is done through the installer, and doesn’t really require any access to the commands.
Use Case
The use case is that we’ll have a small server with two disks, which use RAID 1 (mirroring) for fault tolerance. We would like the system to boot if one of the disks fails. The assumption is, in the event of a failure, the hard disk will be replaced, then the entire computer may be replaced as well with a new system with two fresh drives. The reasoning is that rebuilding a broken RAID 1 isn’t necessarily safe, given that it’s likely that the disk is failing due to age and use.
Theory
Booting into a raid volume is possible because the GRUB2 bootloader knows how to start RAID 1 before the OS is loaded. This is possible because GRUB2 is a large bootloader – but that also requires that we reserve more space at the start of the disk, to allow GRUB to start.
For this reason, we’ll create partitions at the END of the disk, rather than the start. We’ll leave plenty of room at the start, before the partitions, to allow for a big GRUB bootloader.
Practicalities
Before you start installing the server, I suggest loading up a computer to run a Squid proxy. (Use Squid, because Lusca seems flaky on Ubuntul 12.04 at this time.) Configure it to cache requests on port 80. The reason to use a caching proxy is speed: odds are, you’re going to do more than one installation, just to get it right. Why suffer long waits on the 2nd and subsequent installations?
You might want to practice on a VirtualBox VM. In the simulated environment, you can use small disks, which will format and otherwise react faster than a real server’s larger disks. I used 8GB, but think a 3GB would be enough. Create two virtual disks of fixed size.
When you start the install, press Esc, F6, and then space bar to select the “Advanced Mode”. You’ll need that to enable the partitioning options.
Go through most of the install as usual.
If you’re using a proxy, it’s probably at http://ip-address-of-your-box:3128/
When you get to the partitioning options, select Manually Configure.
If you see existing partitions or RAID, carefully delete each partition until you have totally blank disks. There’s no need to write the partition – just get the partitions cleared out.
Let’s then create this layout:
– at least 8MB of empty space (for GRUB2)
– at least enough swap to equal our physical RAM
– a huge partition that will be RAID 1
Work out the partition sizes on paper, before you perform the partition.
Then, you basically add the partitions in this order:
– the huge RAID 1 partition. Primary, at the end of the disk, and set the type to “raid”.
– the swap space. Primary, at end of disk, set type to swap.
– double check to see that there’s free space at the beginning, for GRUB2.
Do the same thing for the second disk.
Then, from the first partitioning screen, select to configure RAID.
Pick a name for the RAID device, like md0. Choose raid level 1, 2 disks, no spares. Then, select the two RAID partitions you defined. The installer will ask if you want to boot from a degraded array. Answer YES.
On the partitioning screen, you should see the new raid device /dev/md0. Add a partition to that, and set it to mount at the root /.
Alternatively, for better flexibility, ou can create an LVM group out of the new /dev/md0, and then create logical volumes within the LVM volume group. Define one as the root file system. (Article to be written.)
Write the partition table.
Then write the boot sector to the disks. When you select this, it’ll ask you if you want to do it – say yes, and it’ll write the boot sector to BOTH the disks. It probably does this because you chose to boot from the degraded array.
(Note: I think this last paragraph may be wrong. You may need to specify the boot devices by selection the option that allows you to enter them manually. Enter “/dev/sda /dev/sdb” as the parameters so the boot sectors are written to both disks.)
Continue with the server installation as usual.
Swapping In New Disks
The disk weren’t failing, but the system load was rising too much for comfort, so I bought two SSDs and installed them.
Find a tutorial that will explain this in detail. (Read thrice, take notes, and execute once.)
The basic sequence:
- Break the set. Reboot if necessary.
- Replace one disk with a new disk. Add it to the set.
- Wait for the system to replicate the first disk to the new disk. (Took around 50 minutes to clone a 500GB HDD to a 2TB SSD.)
- (I think I rebooted after it was replicated.) Break the set again. Replace the old disk with a new disk. Then add the new disk to the set, and wait for the replication. The mirror rebuilding should be faster this time.
- Reboot to test.
Enlarging the volumes
I don’t recall what I did to enlarge the mirror set. I don’t recall if resizing it up to 2TB was automatic, or if it required explicitly growing the set. (It probably required resizing. See 1.)
To resize the logical volume, you use lvresize and then resize2fs.
The first command, lvresize, grows the logical volume, so it looks like a bigger sidsk or volume.
# lvresize -L +100G /dev/mapper/ubuntu--vg-root The second command, resize2fs, resizes the file system within the logical volume. If you don’t specify the size to grow to, it’ll assume you want to use the entire volume.
# resize2fs /dev/mapper/ubuntu--vg-root