Skip to content

Instantly share code, notes, and snippets.

@mybigman
Forked from pvmart/arch-raid1.sh
Created December 6, 2022 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mybigman/eed00024c0304a3371488a122f00c4d6 to your computer and use it in GitHub Desktop.
Save mybigman/eed00024c0304a3371488a122f00c4d6 to your computer and use it in GitHub Desktop.
Install arch linux on btrfs raid1
#!/bin/bash
set -e
set -o pipefail
dd if=/dev/zero of=/dev/sda bs=1024 count=10
dd if=/dev/zero of=/dev/sdb bs=1024 count=10
RAM=$(free -m | awk '/Mem:/{print $2}')
cat > disk.sf <<EOF
label: gpt
, 512M, 21686148-6449-6E6F-744E-656564454649
; ${RAM}M, S
;
EOF
sfdisk /dev/sda < disk.sf
sfdisk /dev/sdb < disk.sf
# pacman -Sy btrfs-progs git
mkfs.btrfs -f -d raid1 -m raid1 /dev/sda3 /dev/sdb3
mount /dev/sda3 /mnt
cd /mnt
btrfs subvolume snapshot . __active
btrfs subvolume set-default $(btrfs subvolume list /mnt | awk '{print $2}') .
mkdir __snapshot
cd __active
btrfs subvolume create root
btrfs subvolume create home
btrfs subvolume create var
mkdir /target
mount -o subvol=__active/root /dev/sda3 /target
mkdir /target/home /target/var
mount -o subvol=__active/home /dev/sda3 /target/home
mount -o subvol=__active/var /dev/sda3 /target/var
pacstrap /target base base-devel btrfs-progs kexec-tools grub git vim openssh \
wget
mkdir /target/var/lib/btrfs
mount -o rw,relatime,space_cache,subvolid=0 /dev/sda3 /target/var/lib/btrfs
genfstab -U -p /target >> /target/etc/fstab
cat > /target/run_01.sh <<EOF
#!/bin/bash
set -e
set -o pipefail
git clone https://github.com/xtfxme/mkinitcpio-btrfs
cd mkinitcpio-btrfs
echo Y | makepkg -i
EOF
cat > /target/install.sh <<EOF
#!/bin/bash
set -e
set -o pipefail
sed -i 's/^# %wheel/%wheel/' /etc/sudoers
useradd -m -G wheel doc
echo doc:123123 | chpasswd
su - doc -c /run_01.sh
sed -i 's/fsck)/fsck btrfs)/' /etc/mkinitcpio.conf
mkinitcpio -p linux
grub-install /dev/sda
grub-install /dev/sdb
grub-mkconfig > /boot/grub/grub.cfg
systemctl enable dhcpcd
systemctl enable sshd
EOF
chmod +x /target/run_??.sh
chmod +x /target/install.sh
arch-chroot /target /install.sh
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment