Skip to content

Instantly share code, notes, and snippets.

@kcollasarundell
Last active May 28, 2021 10:24
Show Gist options
  • Save kcollasarundell/4592091 to your computer and use it in GitHub Desktop.
Save kcollasarundell/4592091 to your computer and use it in GitHub Desktop.
Part all the disks.
#!/bin/bash
#this echoes EVERYTHING
set -x verbose
echo "THIS SCRIPT IS DANGEROUS do not be stupid"
apt-get install lvm2 mdadm
# $disks should be replaced with the last char on each disk you want to apply this to
#disks="a b c d e f"
disks="a b c d e f g h i" #EDIT THIS LINE
#totalnumberofdisks == total number of disks
numdisks="8" #EDIT THIS LINE
for i in $disks ;
do
# create the partition table
parted -s -a optimal /dev/sd$i mklabel gpt ;
# create the gpt boot volume
parted -s -a optimal /dev/sd$i mkpart non-fs 0 2;
# create the boot volume
parted -s -a optimal /dev/sd$i mkpart ext3 2 512 ;
# set the rest of it ready for the storage array
parted -s -a optimal /dev/sd$i mkpart ext3 512 100%;
# mark the partitions correctly
parted -s /dev/sd$i set 1 bios_grub on;
parted -s /dev/sd$i set 2 raid on;
parted -s /dev/sd$i set 3 raid on;
done
#create your /boot volume
for i in $disk; do alldisks2="$alldisks2 /dev/sd${i}2"; alldisks3="$alldisks3 /dev/sd${i}3"
mdadm --create /dev/md0 --level=mirror --raid-devices=$numdisks $alldisks2
#create your storage array
mdadm --create /dev/md1 --level=6 --raid-devices=$numdisks $alldisks3
pvcreate /dev/md1
vgcreate storage /dev/md1
#root volume mount it as / format it as whatever (recommned ext4)
lvcreate storage -L 50G -n root
#format the root vol
mkfs.ext4 /dev/storage/root
#Make me a swap volume
lvcreate storage -L 8G -n swap
#make it a swap
mkswap /dev/storage/swap
#creates your home partition this is where verything goes in the install mount it as
#/home format it as whatever (recommned ext4)
lvcreate storage -l 100%FREE -n home
#format the home dir
mkfs.ext4 /dev/storage/home
echo 'wait a while before restarting'
@kcollasarundell
Copy link
Author

Once you add the disks into this script it will do the following.

create a 2 MB in size volume at the start of the disk for the efi boot stuff

create a 512MB vol that you should use as /boot (this should be a raid 1 of all disks in your array)
create a rest of disk vol for the main storage array this should be turned into lvm once raided
root should be in here somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment