Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Ubuntu on RAID 0 and UEFI/GPT system
# http://askubuntu.com/questions/505446/how-to-install-ubuntu-14-04-with-raid-1-using-desktop-installer
# http://askubuntu.com/questions/660023/how-to-install-ubuntu-14-04-64-bit-with-a-dual-boot-raid-1-partition-on-an-uefi%5D
sudo -s
apt-get -y install mdadm
apt-get -y install grub-efi-amd64
sgdisk -z /dev/sda
sgdisk -z /dev/sdb
sgdisk -n 1:0:+100M -t 1:ef00 -c 1:"EFI System" /dev/sda
sgdisk -n 2:0:+8G -t 2:fd00 -c 2:"Linux RAID" /dev/sda
sgdisk -n 3:0:0 -t 3:fd00 -c 3:"Linux RAID" /dev/sda
sgdisk /dev/sda -R /dev/sdb -G
mkfs.fat -F 32 /dev/sda1
mkdir /tmp/sda1
mount /dev/sda1 /tmp/sda1
mkdir /tmp/sda1/EFI
umount /dev/sda1
mdadm --create /dev/md0 --level=0 --raid-disks=2 /dev/sd[ab]2
mdadm --create /dev/md1 --level=0 --raid-disks=2 /dev/sd[ab]3
sgdisk -z /dev/md0
sgdisk -z /dev/md1
sgdisk -N 1 -t 1:8200 -c 1:"Linux swap" /dev/md0
sgdisk -N 1 -t 1:8300 -c 1:"Linux filesystem" /dev/md1
ubiquity -b
mount /dev/md1p1 /mnt
mount -o bind /dev /mnt/dev
mount -o bind /dev/pts /mnt/dev/pts
mount -o bind /sys /mnt/sys
mount -o bind /proc /mnt/proc
cat /etc/resolv.conf >> /mnt/etc/resolv.conf
chroot /mnt
nano /etc/grub.d/10_linux
# change quick_boot and quiet_boot to 0
apt-get install -y grub-efi-amd64
apt-get install -y mdadm
nano /etc/mdadm/mdadm.conf
# remove metadata and name
update-grub
mount /dev/sda1 /boot/efi
grub-install --boot-directory=/boot --bootloader-id=Ubuntu --target=x86_64-efi --efi-directory=/boot/efi --recheck
update-grub
umount /dev/sda1
dd if=/dev/sda1 of=/dev/sdb1
efibootmgr -c -g -d /dev/sdb -p 1 -L "Ubuntu #2" -l '\EFI\Ubuntu\grubx64.efi'
exit # from chroot
exit # from sudo -s
reboot
@luisgazola

This comment has been minimized.

Copy link

luisgazola commented Jan 25, 2016

Good afternoon , I wonder if this is for RAID0 or RAID1 , and if not to RAID1 how do I make a RAID1 with EFI on Ubuntu Server. thank you so much

@umpirsky

This comment has been minimized.

Copy link
Owner Author

umpirsky commented Jan 29, 2016

@luisgazola This is RAID 0. For RAID 1 please see link on line 2.

@Casey7747

This comment has been minimized.

Copy link

Casey7747 commented Feb 13, 2017

You Sir, are nothing short of Amazing!

Tested with Ubuntu 16.04.01 LTS Desktop UEFI
Works great by copying the commands into bash terminal. (Not as a bash script)
Creates two RAID0 partitions, one for the rootfs and another for swap.

Notes for noobs:
It is assumed that the two hard drives are located at /dev/sda and /dev/sdb
Adjust line 10 for swap size: SWAP will be twice the value presented. Here 8G, over two disks gives 16G SWAP.
When running the installer ubiquity -b and you get to the partitioning choose "Something Else"
-Set Partition ending in md0 to "SWAP"
-Set Partition ending in md1 to "/" and format
Once ubiquity has finished press "Continue Testing" and continue with the steps.

@ArrEssJay

This comment has been minimized.

Copy link

ArrEssJay commented Sep 7, 2017

This is great. Roughly followed for installing 16.04 server in RAID 1 configuration. The key to success appears to be the correct installation of GRUB into EFI. The installer gets it way way wrong.

@tombatron

This comment has been minimized.

Copy link

tombatron commented Nov 22, 2017

Worked like a champ!

I did have to change sda and sdb to nvme0n1 and nvme1n1. But other than that, the install went off without a hitch.

@mecworks

This comment has been minimized.

Copy link

mecworks commented Jun 13, 2018

BTW, you shouldn't swap onto a RAID partition. That adds a lot of overhead that slows down raid and you don't need the redundancy on swap. The best way to use two or more disks for swap as in this situation is to set both partitions to the type swap then in /etc/fstab, set them with the same priority. Linux will automatically stripe swap partitions set to the same priority, giving you a roughly 2x performance boost in your swap R/W access.

@fabienengels

This comment has been minimized.

Copy link

fabienengels commented Jun 28, 2019

BTW, you shouldn't swap onto a RAID partition. That adds a lot of overhead that slows down raid and you don't need the redundancy on swap. The best way to use two or more disks for swap as in this situation is to set both partitions to the type swap then in /etc/fstab, set them with the same priority. Linux will automatically stripe swap partitions set to the same priority, giving you a roughly 2x performance boost in your swap R/W access.

But if one of the disks crashes, the swap will be corrupted and may lead to a system crash.

@fabienengels

This comment has been minimized.

Copy link

fabienengels commented Jun 28, 2019

Why partitioning /dev/md* and not formatting them directly ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.