Forked from Fusl/gist:13b54ae1ca3bc144536bc59329fe84be
Created
April 6, 2025 16:16
-
-
Save silviu-social1st-ro/188d7b17f36a15616618f71b7240bad5 to your computer and use it in GitHub Desktop.
Set up Alpine Linux RAID1 over 4 disks with 16GB rootfs size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set up basic alpine environment (networking, kbd layout, apk repo) | |
setup-alpine -q | |
# add some required packages | |
apk add e2fsprogs mdadm parted sgdisk gptfdisk | |
# create partition layout on the first disk | |
gdisk /dev/sda | |
> o | |
> y | |
> n | |
> | |
> | |
> +128M | |
> fd00 | |
> n | |
> | |
> | |
> +16G | |
> fd00 | |
> w | |
> y | |
# copy the partition layout to all other disks | |
sgdisk /dev/sda -R /dev/sdb | |
sgdisk /dev/sda -R /dev/sdc | |
sgdisk /dev/sda -R /dev/sgd | |
# randomize the UUIDs on all the disks | |
sgdisk -G /dev/sdb | |
sgdisk -G /dev/sdc | |
sgdisk -G /dev/sdd | |
# set the bootable flag on the first partition of all disks | |
# Note: I'm not sure if this is being copied by the sgdisk -R command above, | |
# so to be 100% sure, we set it manually on all disks | |
sgdisk /dev/sda --attributes=1:set:2 | |
sgdisk /dev/sdb --attributes=1:set:2 | |
sgdisk /dev/sdc --attributes=1:set:2 | |
sgdisk /dev/sdd --attributes=1:set:2 | |
# create our /boot raid1 | |
# Note: --metadata 1.0 is VERY important here, syslinux does not support anything newer! | |
mdadm --create /dev/md0 --metadata 1.0 -l 1 -n 4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 | |
# create our / raid1 | |
mdadm --create /dev/md1 -l 1 -n 4 /dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2 | |
# create ext4 partitions | |
mkfs.ext4 -m 0 /dev/md0 | |
mkfs.ext4 /dev/md1 | |
# mount the partitions | |
mount -t ext4 /dev/md1 /mnt | |
mkdir /mnt/boot /mnt/etc | |
mount -t ext4 /dev/md0 /mnt/boot | |
# write the mdadm config so we don't end up with md127/md126 instead of md0/md1 | |
mdadm --detail --scan > /mnt/etc/mdadm.conf | |
# make sure we include the raid1 module in our initrd | |
echo raid1 >> /etc/modules | |
# do the actual alpine linux installation | |
setup-disk -m sys /mnt | |
# cleanly unmount everything | |
umount /mnt/boot /mnt | |
# write the GPT/MBR bootloader to the disk protective mbr | |
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda | |
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sdb | |
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sdc | |
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sdd | |
# make sure all disks are synced before rebooting/shutting down | |
sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment