Advertisement
RobertKalmar

ZFS Booot

Aug 28th, 2019
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.87 KB | None | 0 0
  1. #!/bin/bash
  2. # PULCZ SERVER
  3. #
  4. export LANG=C
  5.  
  6.  
  7. sgdisk --clear -Z \
  8. -n9:-8M:0 -t9:bf07 -c9:sda9-Reserved \
  9. -n1::+1M -t 1:ef02 -c 1:"BIOS Boot Partition"  \
  10. -n2::+512M -t1:EF00 -c2:'EFI-SDA2' \
  11. -n3::+200G -t2:bf01 -c3:'sda3-zfs root filesystem' \
  12. -n4:0:0 -t2:bf01 -c4:'sda4-zfs data' \
  13.  /dev/sda
  14.  
  15. sgdisk -t 1:ef02 /dev/sda
  16.  
  17.  
  18. sgdisk --clear -Z \
  19. -n9:-8M:0 -t9:bf07 -c9:sdb9-Reserved \
  20. -n1::+1M --typecode=1:ef02 --change-name=1:'sdb1 - BIOS boot partition' \
  21. -n2::+512M -t1:EF00 -c2:'EFI-SDB2' \
  22. -n3::+200G -t2:bf01 -c3:'sdb2-zfs root filesystem' \
  23. -n4:0:0 -t2:bf01 -c4:'sdb3-zfs data' \
  24.  /dev/sdb
  25.  
  26.  sgdisk -t 1:ef02 /dev/sdb
  27.  
  28. sgdisk --clear -Z \
  29. -n9:-8M:0 -t9:bf07 -c9:sdc9-Reserved \
  30. -n1::+1M --typecode=1:ef02 --change-name=1:'sdc1 - BIOS boot partition' \
  31. -n2::+512M -t1:EF00 -c2:'EFI-SDC2' \
  32. -n3::+200G -t2:bf01 -c3:'sdc3-zfs root filesystem' \
  33. -n4:0:0 -t2:bf01 -c4:'sdc4-zfs data' \
  34.  /dev/sdc
  35.  
  36. sgdisk -t 1:ef02 /dev/sdc
  37.  
  38. sgdisk --clear -Z \
  39. -n9:-8M:0 -t9:bf07 -c9:sdd9-Reserved \
  40. -n1::+1M --typecode=1:ef02 --change-name=1:'sdd1 - BIOS boot partition' \
  41. -n2::+512M -t1:EF00 -c2:'EFI-SDD2' \
  42. -n3::+200G -t2:bf01 -c3:'sdd3-zfs root filesystem' \
  43. -n4:0:0 -t2:bf01 -c4:'sdd4-zfs data' \
  44.  /dev/sdd
  45.  
  46. sgdisk -t 1:ef02 /dev/sdd
  47.  
  48.  
  49. cat /proc/partitions
  50. ls -lh /dev/disk/by-partlabel
  51.  
  52. apt update
  53. apt -y install zfsutils-linux
  54. mkdir -p /target
  55.  
  56. zpool create -f -O recordsize=64K -o ashift=12 -O atime=off -O canmount=off -O compression=lz4 -O normalization=formD -O mountpoint=/ -R /target systempool mirror /dev/sda3 /dev/sdb3
  57.  
  58. zpool create systempool spare /dev/sdc3 /dev/sdd3
  59.  
  60. zpool create -f matrixdatas -o ashift=12 -O atime=off -O canmount=off -O compression=lz4 -O normalization=formD \
  61. -O mountpoint=/srv/matrixdatas mirror /dev/sda4 /dev/sdb4
  62.  
  63. zpool create matrixdatas spare /dev/sdc4 /dev/sdd4
  64.  
  65. zpool status
  66. zfs create -o canmount=off -o mountpoint=none systempool/ROOT
  67. zfs create -o canmount=noauto -o mountpoint=/ -o exec=on -o setuid=on -o devices=on systempool/ROOT/ubuntu
  68. zfs mount systempool/ROOT/ubuntu
  69. zpool set bootfs=systempool/ROOT/ubuntu systempool
  70.  
  71. zfs set exec=off systempool
  72. zfs set setuid=off systempool
  73. zfs set devices=off systempool
  74. zfs create -o canmount=off systempool/var
  75. ## zfs create -o canmount=off mountpoint=systempool/var
  76. #cannot create 'mountpoint=systempool/var': invalid character '=' in name
  77. zfs create -o canmount=off systempool/var/lib
  78. zfs create systempool/var/lib/apt
  79. zfs create -o exec=on systempool/var/lib/dpkg
  80. zfs create systempool/var/log
  81. zfs create -o com.sun:auto-snapshot=false systempool/var/tmp
  82. zfs create -o com.sun:auto-snapshot=false systempool/var/cache
  83. zfs create -o com.sun:auto-snapshot=false systempool/var/cache/apt
  84. zfs create systempool/var/spool
  85. zfs create systempool/var/mail
  86. zfs create -o com.sun:auto-snapshot=false -o exec=on systempool/tmp
  87. zfs create -o exec=on systempool/root
  88. zfs create -o mountpoint=/home systempool/home
  89. zfs create -o mountpoint=/srv systempool/srv
  90. df -h
  91. zfs list
  92.  
  93. chmod 1777 /target/tmp
  94. chmod 1777 /target/var/tmp
  95.  
  96. apt -y install debootstrap
  97.  
  98. debootstrap --include=zfsutils-linux bionic /target
  99.  
  100. echo matrixcbs > /target/etc/hostname
  101. echo "127.0.1.1 server.matrixcbs.lan matrixcbs" >> /target/etc/hosts
  102.  
  103. cat <<EOF > /target/etc/netplan/00-lan-config.yaml
  104. # This file is generated from information provided by
  105. # the datasource.  Changes to it will not persist across an instance.
  106. # To disable cloud-init's network configuration capabilities, write a file
  107. # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
  108. # network: {config: disabled}
  109. network:
  110.     ethernets:
  111.         enp2s0:
  112.             dhcp4: true
  113.     version: 2
  114. EOF
  115.  
  116.  
  117. cat <<EOF > /target/configure.sh
  118. #!/bin/bash
  119. apt update
  120.  
  121. apt -y full-upgrade
  122.  
  123. apt -y install language-pack-hu
  124.  
  125. dpkg-reconfigure locales
  126. dpkg-reconfigure debconf
  127. dpkg-reconfigure tzdata
  128.  
  129. export LANG=C
  130.  
  131. apt install --yes hfsprogs
  132. apt install -y --no-install-recommends linux-image-generic --force-yes
  133. apt install -y gdisk dosfstools zfs-initramfs
  134. apt -y install grub-efi grub-pc mkdosfs
  135. apt install --yes grub-efi-amd64-signed shim-signed
  136.  
  137. grub-install /dev/sda
  138. grub-install /dev/sdb
  139. grub-install /dev/sdc
  140. grub-install /dev/sdd
  141.  
  142.  
  143. grub-install --root-directory=/mnt/main /dev/sda
  144. grub-install --root-directory=/mnt/main /dev/sdb
  145. grub-install --root-directory=/mnt/main /dev/sdc
  146. grub-install --root-directory=/mnt/main /dev/sdd
  147.  
  148.  
  149. update-grub2
  150.  
  151. mkdosfs -F 32 -n EFI-SDA2 /dev/sda2
  152. mkdosfs -F 32 -n EFI-SDB2 /dev/sdb2
  153. mkdosfs -F 32 -n EFI-SDC2 /dev/sdc2
  154. mkdosfs -F 32 -n EFI-SDD2 /dev/sdd2
  155.  
  156. mkdir /boot/efi
  157.  
  158. # olds echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-partlabel/sda2-EFI) /boot/efi vfat defaults 0 1 >> /etc/fstab
  159.  
  160. echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-partlabel/sda2-EFI) /boot/efi vfat nofail,x-systemd.device-timeout=1 0 1 >> /etc/fstab
  161.  
  162. mount /boot/efi
  163.  
  164. grub-probe /
  165.  
  166. update-initramfs -u -k all
  167. update-grub
  168. grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy
  169. echo '\EFI\ubuntu\grubx64.efi' > /boot/efi/startup.nsh
  170.  
  171. ls /boot/grub/*/zfs.mod
  172.  
  173. apt -y ssh nano lshw rsync mc lswh ethtool di
  174.  
  175.  
  176. /bin/bash
  177. EOF
  178.  
  179. cat <<EOF >> /etc/apt/sources.list
  180. deb http://archive.ubuntu.com/ubuntu bionic main
  181. deb http://archive.ubuntu.com/ubuntu bionic-updates main
  182. deb http://security.ubuntu.com/ubuntu bionic-security main
  183. deb http://archive.ubuntu.com/ubuntu/ bionic universe
  184. deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
  185. deb http://security.ubuntu.com/ubuntu bionic-security universe
  186. EOF
  187.  
  188.  
  189. chmod +x /target/configure.sh
  190.  
  191. mount --rbind /dev /target/dev
  192. mount --rbind /proc /target/proc
  193. mount --rbind /sys /target/sys
  194. chroot /target /bin/bash
  195.  
  196. ./configure.sh
  197.  
  198. umount -Rfl /target/dev
  199. umount -Rfl /target/sys
  200. umount -Rfl /target/proc
  201. umount /target/boot/efi
  202. zpool export systempool
  203.  
  204. echo DONE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement