Skip to content

Instantly share code, notes, and snippets.

@swatwithmk3
Forked from umpirsky/ubuntu-raid.sh
Last active November 14, 2022 02:27
Show Gist options
  • Save swatwithmk3/5497ee8bfa8e576eedbc9ca08e2cc598 to your computer and use it in GitHub Desktop.
Save swatwithmk3/5497ee8bfa8e576eedbc9ca08e2cc598 to your computer and use it in GitHub Desktop.
Install Ubuntu on RAID 0 and UEFI/GPT system
# Thanks to https://gist.github.com/umpirsky for the original code
sudo -s
apt-get -y install mdadm
apt-get -y install grub-efi-amd64
sgdisk -z -g /dev/sda
sgdisk -z -g /dev/sdb
sgdisk -z -g /dev/sdc
sgdisk -z -g /dev/sdd
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=4 /dev/sd[abcd]2
# I was getting errors regarding /dev/sd2 but the array was still mounted, if you get an error wait a few minutes and check mounted partitions in gparted
mdadm --create /dev/md1 --level=0 --raid-disks=4 /dev/sd[abcd]3
# Same error for /dev/sd3 inspite the array being created and mounted successfully
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 # You need to mount the primary partition where the OS was installed.
# Warning, in my case the primary partition was locked after OS install and it wouldn't let me mount it.
# I had to reboot into the live usb again then reassemble the array using mdadm --assemble
# Then I mounted the OS partition to /mnt which for me was md1p2
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 from the arrays
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
dd if=/dev/sda1 of=/dev/sdc1
dd if=/dev/sda1 of=/dev/sdd1
efibootmgr -c -g -d /dev/sdb -p 1 -L "Ubuntu #2" -l '\EFI\Ubuntu\grubx64.efi'
efibootmgr -c -g -d /dev/sdc -p 1 -L "Ubuntu #3" -l '\EFI\Ubuntu\grubx64.efi'
efibootmgr -c -g -d /dev/sdd -p 1 -L "Ubuntu #4" -l '\EFI\Ubuntu\grubx64.efi'
exit # from chroot
exit # from sudo -s
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment