Advertisement
RobertKalmar

UBUNTU 18.04 ZFS Install.sh

Aug 10th, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.37 KB | None | 0 0
  1. #!/bin/bash
  2. sgdisk -Z -n9:-8M:0 -t9:bf07 -c9:sda9-Reserved -n1:1M:+512M -t1:EF00 -c1:sda1-EFI -n2:513M:+105G -t2:bf01 -c2:sda2-zfssytem /dev/sda
  3.  
  4. sgdisk -Z -n9:-8M:0 -t9:bf07 -c9:sdb9-Reserved -n1:1M:+512M -t1:EF00 -c1:sdb1-EFI -n2:513M:+105G -t2:bf01 -c2:sdb2-zfssytem -n3:0:0 -t2:bf01 -c3:sdb3-zfsdata /dev/sdb
  5.  
  6. sgdisk -Z -n9:-8M:0 -t9:bf07 -c9:sdc9-Reserved -n1:1M:+512M -t1:EF00 -c1:sdc1-EFI -n2:513M:+105G -t2:bf01 -c2:sdc2-zfssytem -n3:0:0 -t2:bf01 -c3:sdc3-zfsdata /dev/sdc
  7.  
  8. cat /proc/partitions
  9. ls -lh /dev/disk/by-partlabel
  10.  
  11. apt update
  12. apt -y install zfsutils-linux
  13. mkdir -p /target
  14.  
  15. zpool create -f -o ashift=12 -O atime=off -O canmount=off -O compression=lz4 -O normalization=formD -O mountpoint=/ -R /target systempool mirror /dev/sda2 /dev/sdb2 /dev/sdc2
  16.  
  17. zpool status
  18.  
  19. zfs create -o canmount=off -o mountpoint=none systempool/ROOT
  20.  
  21. zfs create -o canmount=noauto -o mountpoint=/ -o exec=on -o setuid=on -o devices=on systempool/ROOT/ubuntu
  22.  
  23. zfs mount systempool/ROOT/ubuntu
  24.  
  25. zpool set bootfs=systempool/ROOT/ubuntu systempool
  26. zfs set exec=off systempool
  27. zfs set setuid=off systempool
  28. zfs set devices=off systempool
  29.  
  30. zfs create -o canmount=off systempool/var
  31. zfs create -o canmount=off systempool/var/lib
  32. zfs create systempool/var/lib/apt
  33. zfs create -o exec=on systempool/var/lib/dpkg
  34. zfs create systempool/var/log
  35. zfs create -o com.sun:auto-snapshot=false systempool/var/tmp
  36. zfs create -o com.sun:auto-snapshot=false systempool/var/cache
  37. zfs create -o com.sun:auto-snapshot=false systempool/var/cache/apt
  38. zfs create systempool/var/spool
  39. zfs create systempool/var/mail
  40. zfs create -o com.sun:auto-snapshot=false -o exec=on systempool/tmp
  41. zfs create -o exec=on systempool/root
  42. zfs create -o mountpoint=/home systempool/home
  43. zfs create -o mountpoint=/srv systempool/srv
  44. df -h
  45. zfs list
  46.  
  47. chmod 1777 /target/tmp
  48. chmod 1777 /target/var/tmp
  49.  
  50. apt -y install debootstrap
  51.  
  52. debootstrap --include=zfsutils-linux bionic /target
  53.  
  54. echo asztalos01 > /target/etc/hostname
  55. echo "127.0.1.1 asztalos01.matrixhome.lan asztalos01" >> /target/etc/hosts
  56.  
  57. cat <<EOF > /target/etc/netplan/00-lan-config.yaml
  58. # This file is generated from information provided by
  59. # the datasource.  Changes to it will not persist across an instance.
  60. # To disable cloud-init's network configuration capabilities, write a file
  61. # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
  62. # network: {config: disabled}
  63. network:
  64.     ethernets:
  65.         enp2s0:
  66.             dhcp4: true
  67.     version: 2
  68. EOF
  69.  
  70.  
  71. cat <<EOF > /target/configure.sh
  72. #!/bin/bash
  73.  
  74. apt update
  75.  
  76. apt -y full-upgrade
  77.  
  78. apt -y install language-pack-hu
  79.  
  80. dpkg-reconfigure locales
  81. dpkg-reconfigure debconf
  82. dpkg-reconfigure tzdata
  83.  
  84. apt install --yes hfsprogs
  85. apt install -y --no-install-recommends linux-image-generic
  86. apt install -y gdisk dosfstools zfs-initramfs
  87. apt -y install grub-efi
  88. apt install --yes grub-efi-amd64-signed shim-signed
  89.  
  90. mkdosfs -F 32 -n EFI-SDA1 /dev/sda1
  91. mkdosfs -F 32 -n EFI-SDB1 /dev/sdb1
  92. mkdosfs -F 32 -n EFI-SDC1 /dev/sdc1
  93.  
  94. mkdir /boot/efi
  95.  
  96. # olds echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-partlabel/sda1-EFI) /boot/efi vfat defaults 0 1 >> /etc/fstab
  97.  
  98. echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-partlabel/sda1-EFI) /boot/efi vfat nofail,x-systemd.device-timeout=1 0 1 >> /etc/fstab
  99.  
  100. mount /boot/efi
  101.  
  102. grub-probe /
  103.  
  104. update-initramfs -u -k all
  105. update-grub
  106. grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy
  107. echo '\EFI\ubuntu\grubx64.efi' > /boot/efi/startup.nsh
  108.  
  109. ls /boot/grub/*/zfs.mod
  110.  
  111. apt -y ssh nano lshw rsync mc lswh ethtool di
  112.  
  113. passwd root
  114.  
  115. /bin/bash
  116. EOF
  117.  
  118.  
  119. cat <<EOF >> /etc/apt/sources.list
  120. #deb http://archive.ubuntu.com/ubuntu bionic main
  121.  deb http://archive.ubuntu.com/ubuntu bionic-updates main
  122.  deb http://security.ubuntu.com/ubuntu bionic-security main
  123.  deb http://archive.ubuntu.com/ubuntu/ bionic universe
  124.  deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
  125.  deb http://security.ubuntu.com/ubuntu bionic-security universe
  126. EOF    
  127.  
  128. chmod +x /target/configure.sh
  129.  
  130. mount --rbind /dev /target/dev
  131. mount --rbind /proc /target/proc
  132. mount --rbind /sys /target/sys
  133. chroot /target /bin/bash
  134. chroot /target /configure.sh
  135.  
  136.  
  137.  
  138. ./configure.sh
  139.  
  140. umount -Rfl /target/dev
  141. umount -Rfl /target/sys
  142. umount -Rfl /target/proc
  143. umount /target/boot/efi
  144. zpool export systempool
  145.  
  146. echo DONE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement