Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- export SCRIPT_DIR="$(dirname "$(realpath "$0")")"
- set -euo pipefail
- [ "$(id -u)" -eq 0 ] || { echo "This script must be run as root." >&2; exit 1; }
- apk add parted btrfs-progs dhcpcd e2fsprogs
- export DISK=""
- export SEPARATE_HOME="no"
- export SECURE_BOOT="no"
- usage() {
- cat <<EOF
- Usage: $0 -d <disk> [-H] [-s]
- -d <disk> Target disk device (e.g. /dev/sda or /dev/nvme0n1)
- -H Create separate /home partition
- EOF
- exit 1
- }
- while getopts "d:Hs" opt; do
- case "$opt" in
- d) DISK="$OPTARG" ;; H) SEPARATE_HOME="yes" ;; *) usage ;;
- esac
- done
- [ -n "$DISK" ] || usage
- export UEFI="no"
- if [ -d /sys/firmware/efi ]; then
- UEFI="yes"
- fi
- echo "Installing on $DISK (UEFI: $UEFI, Separate /home: $SEPARATE_HOME, SecureBoot: $SECURE_BOOT)"
- if echo "$DISK" | grep -qE "^/dev/nvme"; then
- PART1=p1; PART2=p2; PART3=p3;
- else
- PART1=1; PART2=2; PART3=3;
- fi
- export BOOT_PART=${DISK}${PART1}
- export ROOT_PART=${DISK}${PART2}
- export HOME_PART=${DISK}${PART3}
- echo "Partitioning $DISK..."
- parted -s "$DISK" mklabel gpt
- if [ "$UEFI" = "yes" ]; then
- parted -s "$DISK" mkpart primary fat32 1MiB 513MiB
- parted -s "$DISK" name 1 EFI
- parted -s "$DISK" set 1 esp on
- parted -s "$DISK" mkpart primary btrfs 513MiB 100%
- parted -s "$DISK" name 2 ROOT
- if [ "$SEPARATE_HOME" = "yes" ]; then
- parted -s "$DISK" mkpart primary btrfs 90% 100%
- parted -s "$DISK" name 3 HOME
- fi
- mkfs.vfat -F 32 "$BOOT_PART"
- export BOOT_TYPE="vfat"
- else
- parted -s "$DISK" mkpart primary 1MiB 513MiB
- parted -s "$DISK" name 1 BIOS
- parted -s "$DISK" set 1 bios_grub on
- parted -s "$DISK" mkpart primary btrfs 513MiB 100%
- parted -s "$DISK" name 2 ROOT
- if [ "$SEPARATE_HOME" = "yes" ]; then
- parted -s "$DISK" mkpart primary btrfs 80% 100%
- parted -s "$DISK" name 3 HOME
- fi
- mkfs.ext4 -q -L PANORA_BOOT "$BOOT_PART"
- export BOOT_TYPE="ext4"
- fi
- mkfs.btrfs -f -L ROOT "$ROOT_PART"
- if [ "$SEPARATE_HOME" = "yes" ]; then
- mkfs.btrfs -f -L HOME "$HOME_PART"
- fi
- TARGET=/mnt/panora
- mkdir -p $TARGET
- mount -t btrfs -o compress=zstd:3,autodefrag $ROOT_PART $TARGET
- btrfs subvolume create $TARGET/@
- btrfs subvolume create $TARGET/@home
- btrfs subvolume create $TARGET/@opt
- btrfs subvolume create $TARGET/@root
- btrfs subvolume create $TARGET/@tmp
- btrfs subvolume create $TARGET/@var
- btrfs subvolume create $TARGET/@var-lib-flatpak
- btrfs subvolume create $TARGET/@var-cache
- btrfs subvolume create $TARGET/@var-log
- btrfs subvolume create $TARGET/@var-opt
- btrfs subvolume create $TARGET/@var-tmp
- btrfs subvolume create $TARGET/@usr-local
- umount $TARGET
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@ $ROOT_PART $TARGET
- mkdir -p $TARGET/home
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@home $ROOT_PART $TARGET/home
- mkdir -p $TARGET/opt
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@opt $ROOT_PART $TARGET/opt
- mkdir -p $TARGET/root
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@root $ROOT_PART $TARGET/root
- mkdir -p $TARGET/tmp
- mount -t btrfs -o compress=zstd:3,autodefrag,noexec,nosuid,subvol=@tmp $ROOT_PART $TARGET/tmp
- mkdir -p $TARGET/var
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var $ROOT_PART $TARGET/var
- mkdir -p $TARGET/var/lib/flatpak
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var-lib-flatpak $ROOT_PART $TARGET/var/lib/flatpak
- mkdir -p $TARGET/var/cache
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var-cache $ROOT_PART $TARGET/var/cache
- mkdir -p $TARGET/var/log
- mount -t btrfs -o compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-log $ROOT_PART $TARGET/var/log
- btrfs property set $TARGET/var/log compression none
- # chattr +C $TARGET/var/log
- mkdir -p $TARGET/var/opt
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var-opt $ROOT_PART $TARGET/var/opt
- mkdir -p $TARGET/var/tmp
- mount -t btrfs -o compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-tmp $ROOT_PART $TARGET/var/tmp
- btrfs property set $TARGET/var/tmp compression none
- # chattr +C $TARGET/var/tmp
- mkdir -p $TARGET/usr/local
- mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@usr-local $ROOT_PART $TARGET/usr/local
- mkdir -p $TARGET/boot
- mount -t "$BOOT_TYPE" "$BOOT_PART" $TARGET/boot
- if [ "$UEFI" = "yes" ]; then
- dhcpcd || true
- sleep 10
- mkdir $TARGET/boot/efi
- # mount $BOOT_PART $TARGET/boot/efi
- fi
- dhcpcd || true
- sleep 10
- ip route
- echo "-> Testing network connectivity"
- ping -c 3 1.1.1.1 || { echo "ERROR: Network connection failed"; exit 1; }
- setup-apkrepos -1 -c
- apk update
- apk add alpine-make-rootfs
- alpine-make-rootfs -p alpine-base -p dhcpcd -r /etc/apk/repositories $TARGET
- cp /etc/resolv.conf $TARGET/etc/
- mkdir -p $TARGET/sys
- mount --rbind /sys $TARGET/sys && mount --make-rslave $TARGET/sys
- mkdir -p $TARGET/dev
- mount --rbind /dev $TARGET/dev && mount --make-rslave $TARGET/dev
- mkdir -p $TARGET/proc
- mount --rbind /proc $TARGET/proc && mount --make-rslave $TARGET/proc
- export ROOT_UUID=$(blkid $ROOT_PART | grep -o 'UUID="[^"]*"' | cut -d'"' -f2)
- export BOOT_UUID=$(blkid $BOOT_PART | grep -o 'UUID="[^"]*"' | cut -d'"' -f2)
- echo "$ROOT_UUID / btrfs compress=zstd:3,autodefrag,subvol=@ 0 1 " > $TARGET/etc/fstab
- echo "$ROOT_UUID /home btrfs compress=zstd:3,autodefrag,subvol=@home 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /opt btrfs compress=zstd:3,autodefrag,subvol=@opt 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /root btrfs compress=zstd:3,autodefrag,subvol=@root 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /tmp btrfs compress=zstd:3,autodefrag,noexec,nosuid,subvol=@tmp 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /var btrfs compress=zstd:3,autodefrag,subvol=@var 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /var/lib/flatpak btrfs compress=zstd:3,autodefrag,subvol=@var-lib-flatpak 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /var/cache btrfs compress=zstd:3,autodefrag,subvol=@var-cache 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /var/log btrfs compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-log 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /var/opt btrfs compress=zstd:3,autodefrag,subvol=@var-opt 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /var/tmp btrfs compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-tmp 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /usr/local btrfs compress=zstd:3,autodefrag,subvol=@usr-local 0 0 " >> $TARGET/etc/fstab
- echo "$ROOT_UUID /boot ext4 defaults 0 0 " >> $TARGET/etc/fstab
- if [ "$UEFI" = "yes" ]; then
- echo "UUID=$BOOT_UUID /boot/efi vfat defaults 0 0 " >> $TARGET/etc/fstab
- fi
- echo "#tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGET/etc/fstab
- cp $SCRIPT_DIR/test-chroot.sh $TARGET/
- chroot $TARGET /bin/ash -c /test-chroot.sh
- ### TEST CHROOT HERE ###
- #!/bin/ash
- set -euo pipefail
- setup-apkrepos -f -c
- apk update
- echo panora > /etc/hostname
- apk add dhcpcd
- rc-update add dhcpcd default
- apk add btrfs-progs kmod linux-lts
- echo btrfs >> /etc/modules
- echo amdgpu >> /etc/modules
- echo fbcon >> /etc/modules
- echo tun >> /etc/modules
- echo "tun" >> /etc/modules-load.d/tun.conf
- echo "root:100000:65536" >> /etc/subuid
- echo "root:100000:65536" >> /etc/subgid
- KERNEL_VER=$(basename /lib/modules/*)
- modprobe -S $KERNEL_VER btrfs
- echo "UUID=\$ROOT_UUID / btrfs defaults,subvol=@ 0 0" > /etc/fstab
- [ "$SEPARATE_HOME" = "yes" ] && HOME_UUID=$(blkid $HOME_PART | grep -o 'UUID="[^"]*"' | cut -d'"' -f2) && echo "UUID=$HOME_UUID /home btrfs defaults 0 2" >> /etc/fstab || echo "UUID=$ROOT_UUID /home btrfs defaults,subvol=@home 0 0" >> /etc/fstab
- echo "UUID=\$EFI_UUID /boot vfat defaults 0 2" >> /etc/fstab
- echo "tmpfs /tmp tmpfs defaults,noatime 0 0" >> /etc/fstab
- apk add mkinitfs
- echo 'features="ata base cdrom keymap kms mmc nvme raid scsi usb virtio btrfs"
- ' > /etc/mkinitfs/mkinitfs.conf
- rc-update add btrfs-scan boot
- apk add grub-efi efibootmgr grub grub-bios
- if [ "$UEFI" = "yes" ]; then
- grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Panora
- else
- grub-install --target=i386-pc --recheck "$DISK"
- fi
- echo "GRUB_TIMEOUT=5
- GRUB_DISTRIBUTOR="Panora"
- grub-mkconfig -o /boot/grub/grub.cfg" >> /etc/default/grub
- mkinitfs -c /etc/mkinitfs/mkinitfs -b / $KERNEL_VER
- apk update
- apk upgrade
- echo "Installation complete. Reboot now."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement