Advertisement
Guest User

Untitled

a guest
May 28th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. export SCRIPT_DIR="$(dirname "$(realpath "$0")")"
  4.  
  5. set -euo pipefail
  6. [ "$(id -u)" -eq 0 ] || { echo "This script must be run as root." >&2; exit 1; }
  7.  
  8. apk add parted btrfs-progs dhcpcd e2fsprogs
  9.  
  10. export DISK=""
  11. export SEPARATE_HOME="no"
  12. export SECURE_BOOT="no"
  13.  
  14. usage() {
  15. cat <<EOF
  16. Usage: $0 -d <disk> [-H] [-s]
  17. -d <disk> Target disk device (e.g. /dev/sda or /dev/nvme0n1)
  18. -H Create separate /home partition
  19. EOF
  20. exit 1
  21. }
  22.  
  23. while getopts "d:Hs" opt; do
  24. case "$opt" in
  25. d) DISK="$OPTARG" ;; H) SEPARATE_HOME="yes" ;; *) usage ;;
  26. esac
  27. done
  28. [ -n "$DISK" ] || usage
  29.  
  30. export UEFI="no"
  31. if [ -d /sys/firmware/efi ]; then
  32. UEFI="yes"
  33. fi
  34.  
  35. echo "Installing on $DISK (UEFI: $UEFI, Separate /home: $SEPARATE_HOME, SecureBoot: $SECURE_BOOT)"
  36.  
  37. if echo "$DISK" | grep -qE "^/dev/nvme"; then
  38. PART1=p1; PART2=p2; PART3=p3;
  39. else
  40. PART1=1; PART2=2; PART3=3;
  41. fi
  42. export BOOT_PART=${DISK}${PART1}
  43. export ROOT_PART=${DISK}${PART2}
  44. export HOME_PART=${DISK}${PART3}
  45.  
  46. echo "Partitioning $DISK..."
  47. parted -s "$DISK" mklabel gpt
  48. if [ "$UEFI" = "yes" ]; then
  49. parted -s "$DISK" mkpart primary fat32 1MiB 513MiB
  50. parted -s "$DISK" name 1 EFI
  51. parted -s "$DISK" set 1 esp on
  52. parted -s "$DISK" mkpart primary btrfs 513MiB 100%
  53. parted -s "$DISK" name 2 ROOT
  54. if [ "$SEPARATE_HOME" = "yes" ]; then
  55. parted -s "$DISK" mkpart primary btrfs 90% 100%
  56. parted -s "$DISK" name 3 HOME
  57. fi
  58. mkfs.vfat -F 32 "$BOOT_PART"
  59. export BOOT_TYPE="vfat"
  60. else
  61. parted -s "$DISK" mkpart primary 1MiB 513MiB
  62. parted -s "$DISK" name 1 BIOS
  63. parted -s "$DISK" set 1 bios_grub on
  64. parted -s "$DISK" mkpart primary btrfs 513MiB 100%
  65. parted -s "$DISK" name 2 ROOT
  66. if [ "$SEPARATE_HOME" = "yes" ]; then
  67. parted -s "$DISK" mkpart primary btrfs 80% 100%
  68. parted -s "$DISK" name 3 HOME
  69. fi
  70. mkfs.ext4 -q -L PANORA_BOOT "$BOOT_PART"
  71. export BOOT_TYPE="ext4"
  72. fi
  73.  
  74. mkfs.btrfs -f -L ROOT "$ROOT_PART"
  75. if [ "$SEPARATE_HOME" = "yes" ]; then
  76. mkfs.btrfs -f -L HOME "$HOME_PART"
  77. fi
  78.  
  79. TARGET=/mnt/panora
  80. mkdir -p $TARGET
  81. mount -t btrfs -o compress=zstd:3,autodefrag $ROOT_PART $TARGET
  82.  
  83. btrfs subvolume create $TARGET/@
  84. btrfs subvolume create $TARGET/@home
  85. btrfs subvolume create $TARGET/@opt
  86. btrfs subvolume create $TARGET/@root
  87. btrfs subvolume create $TARGET/@tmp
  88. btrfs subvolume create $TARGET/@var
  89. btrfs subvolume create $TARGET/@var-lib-flatpak
  90. btrfs subvolume create $TARGET/@var-cache
  91. btrfs subvolume create $TARGET/@var-log
  92. btrfs subvolume create $TARGET/@var-opt
  93. btrfs subvolume create $TARGET/@var-tmp
  94. btrfs subvolume create $TARGET/@usr-local
  95.  
  96. umount $TARGET
  97.  
  98. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@ $ROOT_PART $TARGET
  99.  
  100. mkdir -p $TARGET/home
  101. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@home $ROOT_PART $TARGET/home
  102.  
  103. mkdir -p $TARGET/opt
  104. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@opt $ROOT_PART $TARGET/opt
  105.  
  106. mkdir -p $TARGET/root
  107. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@root $ROOT_PART $TARGET/root
  108.  
  109. mkdir -p $TARGET/tmp
  110. mount -t btrfs -o compress=zstd:3,autodefrag,noexec,nosuid,subvol=@tmp $ROOT_PART $TARGET/tmp
  111.  
  112. mkdir -p $TARGET/var
  113. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var $ROOT_PART $TARGET/var
  114.  
  115. mkdir -p $TARGET/var/lib/flatpak
  116. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var-lib-flatpak $ROOT_PART $TARGET/var/lib/flatpak
  117.  
  118. mkdir -p $TARGET/var/cache
  119. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var-cache $ROOT_PART $TARGET/var/cache
  120.  
  121. mkdir -p $TARGET/var/log
  122. mount -t btrfs -o compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-log $ROOT_PART $TARGET/var/log
  123. btrfs property set $TARGET/var/log compression none
  124. # chattr +C $TARGET/var/log
  125.  
  126. mkdir -p $TARGET/var/opt
  127. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@var-opt $ROOT_PART $TARGET/var/opt
  128.  
  129. mkdir -p $TARGET/var/tmp
  130. mount -t btrfs -o compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-tmp $ROOT_PART $TARGET/var/tmp
  131. btrfs property set $TARGET/var/tmp compression none
  132. # chattr +C $TARGET/var/tmp
  133.  
  134. mkdir -p $TARGET/usr/local
  135. mount -t btrfs -o compress=zstd:3,autodefrag,subvol=@usr-local $ROOT_PART $TARGET/usr/local
  136.  
  137. mkdir -p $TARGET/boot
  138. mount -t "$BOOT_TYPE" "$BOOT_PART" $TARGET/boot
  139.  
  140. if [ "$UEFI" = "yes" ]; then
  141. dhcpcd || true
  142. sleep 10
  143. mkdir $TARGET/boot/efi
  144. # mount $BOOT_PART $TARGET/boot/efi
  145. fi
  146.  
  147. dhcpcd || true
  148. sleep 10
  149.  
  150. ip route
  151. echo "-> Testing network connectivity"
  152. ping -c 3 1.1.1.1 || { echo "ERROR: Network connection failed"; exit 1; }
  153.  
  154. setup-apkrepos -1 -c
  155. apk update
  156. apk add alpine-make-rootfs
  157. alpine-make-rootfs -p alpine-base -p dhcpcd -r /etc/apk/repositories $TARGET
  158. cp /etc/resolv.conf $TARGET/etc/
  159.  
  160. mkdir -p $TARGET/sys
  161. mount --rbind /sys $TARGET/sys && mount --make-rslave $TARGET/sys
  162. mkdir -p $TARGET/dev
  163. mount --rbind /dev $TARGET/dev && mount --make-rslave $TARGET/dev
  164. mkdir -p $TARGET/proc
  165. mount --rbind /proc $TARGET/proc && mount --make-rslave $TARGET/proc
  166.  
  167. export ROOT_UUID=$(blkid $ROOT_PART | grep -o 'UUID="[^"]*"' | cut -d'"' -f2)
  168. export BOOT_UUID=$(blkid $BOOT_PART | grep -o 'UUID="[^"]*"' | cut -d'"' -f2)
  169.  
  170. echo "$ROOT_UUID / btrfs compress=zstd:3,autodefrag,subvol=@ 0 1 " > $TARGET/etc/fstab
  171. echo "$ROOT_UUID /home btrfs compress=zstd:3,autodefrag,subvol=@home 0 0 " >> $TARGET/etc/fstab
  172. echo "$ROOT_UUID /opt btrfs compress=zstd:3,autodefrag,subvol=@opt 0 0 " >> $TARGET/etc/fstab
  173. echo "$ROOT_UUID /root btrfs compress=zstd:3,autodefrag,subvol=@root 0 0 " >> $TARGET/etc/fstab
  174. echo "$ROOT_UUID /tmp btrfs compress=zstd:3,autodefrag,noexec,nosuid,subvol=@tmp 0 0 " >> $TARGET/etc/fstab
  175. echo "$ROOT_UUID /var btrfs compress=zstd:3,autodefrag,subvol=@var 0 0 " >> $TARGET/etc/fstab
  176. echo "$ROOT_UUID /var/lib/flatpak btrfs compress=zstd:3,autodefrag,subvol=@var-lib-flatpak 0 0 " >> $TARGET/etc/fstab
  177. echo "$ROOT_UUID /var/cache btrfs compress=zstd:3,autodefrag,subvol=@var-cache 0 0 " >> $TARGET/etc/fstab
  178. echo "$ROOT_UUID /var/log btrfs compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-log 0 0 " >> $TARGET/etc/fstab
  179. echo "$ROOT_UUID /var/opt btrfs compress=zstd:3,autodefrag,subvol=@var-opt 0 0 " >> $TARGET/etc/fstab
  180. echo "$ROOT_UUID /var/tmp btrfs compress=no,autodefrag,nodev,noexec,nosuid,nodatacow,subvol=@var-tmp 0 0 " >> $TARGET/etc/fstab
  181. echo "$ROOT_UUID /usr/local btrfs compress=zstd:3,autodefrag,subvol=@usr-local 0 0 " >> $TARGET/etc/fstab
  182. echo "$ROOT_UUID /boot ext4 defaults 0 0 " >> $TARGET/etc/fstab
  183. if [ "$UEFI" = "yes" ]; then
  184. echo "UUID=$BOOT_UUID /boot/efi vfat defaults 0 0 " >> $TARGET/etc/fstab
  185. fi
  186. echo "#tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGET/etc/fstab
  187.  
  188. cp $SCRIPT_DIR/test-chroot.sh $TARGET/
  189. chroot $TARGET /bin/ash -c /test-chroot.sh
  190. ### TEST CHROOT HERE ###
  191. #!/bin/ash
  192.  
  193. set -euo pipefail
  194.  
  195. setup-apkrepos -f -c
  196. apk update
  197. echo panora > /etc/hostname
  198. apk add dhcpcd
  199. rc-update add dhcpcd default
  200. apk add btrfs-progs kmod linux-lts
  201. echo btrfs >> /etc/modules
  202. echo amdgpu >> /etc/modules
  203. echo fbcon >> /etc/modules
  204. echo tun >> /etc/modules
  205. echo "tun" >> /etc/modules-load.d/tun.conf
  206. echo "root:100000:65536" >> /etc/subuid
  207. echo "root:100000:65536" >> /etc/subgid
  208.  
  209. KERNEL_VER=$(basename /lib/modules/*)
  210. modprobe -S $KERNEL_VER btrfs
  211. echo "UUID=\$ROOT_UUID / btrfs defaults,subvol=@ 0 0" > /etc/fstab
  212. [ "$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
  213. echo "UUID=\$EFI_UUID /boot vfat defaults 0 2" >> /etc/fstab
  214. echo "tmpfs /tmp tmpfs defaults,noatime 0 0" >> /etc/fstab
  215. apk add mkinitfs
  216. echo 'features="ata base cdrom keymap kms mmc nvme raid scsi usb virtio btrfs"
  217. ' > /etc/mkinitfs/mkinitfs.conf
  218. rc-update add btrfs-scan boot
  219. apk add grub-efi efibootmgr grub grub-bios
  220.  
  221.  
  222. if [ "$UEFI" = "yes" ]; then
  223. grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Panora
  224. else
  225. grub-install --target=i386-pc --recheck "$DISK"
  226. fi
  227. echo "GRUB_TIMEOUT=5
  228. GRUB_DISTRIBUTOR="Panora"
  229. grub-mkconfig -o /boot/grub/grub.cfg" >> /etc/default/grub
  230. mkinitfs -c /etc/mkinitfs/mkinitfs -b / $KERNEL_VER
  231. apk update
  232. apk upgrade
  233.  
  234. echo "Installation complete. Reboot now."
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement