Advertisement
echoslider

finish_ubuntu_deployment_standard

Oct 14th, 2021 (edited)
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e # Exit on error
  4.  
  5. DEVICE=/dev/vda
  6. release="focal"
  7.  
  8.  
  9. apt-get update
  10.  
  11. apt-get install -y \
  12.   debootstrap \
  13.   gdisk \
  14.   gparted \
  15.   dosfstools
  16.  
  17. sgdisk --zap-all ${DEVICE}
  18. sgdisk --clear ${DEVICE}
  19.  
  20. sgdisk     -n1:0:+2G      -t1:ef00 ${DEVICE}
  21. sgdisk     -n2:0:0        -t2:8300 ${DEVICE}
  22.  
  23. mkfs.ext4 -F ${DEVICE}2
  24.  
  25. mount ${DEVICE}2 /mnt
  26.  
  27. debootstrap focal /mnt
  28.  
  29. mount -o bind /dev /mnt/dev
  30. mount -o bind /dev/pts /mnt/dev/pts
  31. mount -t sysfs /sys /mnt/sys
  32. mount -t proc /proc /mnt/proc
  33.  
  34.  
  35. mkdosfs -F 32 -s 1 -n EFI /dev/vda1
  36. mkdir -p /mnt/boot/efi
  37.  
  38.  
  39. cat > /mnt/etc/apt/sources.list << EOFSOURCES
  40. deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
  41. deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
  42. deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
  43. deb http://security.ubuntu.com/ubuntu focal-security main restricted universe multiverse
  44. EOFSOURCES
  45.  
  46. echo "ubuntu_ai-`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 9 | head -n 1`" > /mnt/etc/hostname
  47. echo "nameserver 8.8.8.8" > /mnt/etc/resolv.conf
  48.  
  49.  
  50.  
  51. echo "/dev/disk/by-uuid/$(ls -lha /dev/disk/by-uuid/|grep vda1|awk '{print $9}')" /boot/efi vfat defaults 0 0 >> /mnt/etc/fstab
  52.  
  53. mkdir /mnt/boot/efi/grub /mnt/boot/grub
  54. echo /boot/efi/grub /boot/grub none defaults,bind 0 0 >> /mnt/etc/fstab
  55.  
  56.  
  57.  
  58. echo "/dev/disk/by-uuid/$(ls -lha /dev/disk/by-uuid/|grep vda2|awk '{print $9}')" / ext4    errors=remount-ro 0       1 >> /mnt/etc/fstab
  59.  
  60. modprobe efivarfs
  61.  
  62.  
  63. cat << EOFSUBINSTALL | chroot /mnt
  64. set -e
  65. export HOME=/root
  66. export DEBIAN_FRONTEND=noninteractive
  67.  
  68. apt-get update
  69. apt-get install --yes language-pack-de console-setup tzdata dosfstools efibootmgr
  70.  
  71. mount /boot/efi
  72.  
  73. mkdir /boot/efi/grub
  74. mount /boot/grub
  75.  
  76. apt install --yes grub-pc linux-image-generic
  77.  
  78. apt install --yes \
  79.     grub-efi-amd64 grub-efi-amd64-signed linux-image-generic \
  80.     shim-signed efibootmgr
  81.    
  82. apt remove --purge os-prober
  83.  
  84. fallocate -l 1G /swapfile
  85. dd if=/dev/zero of=/swapfile bs=1024 count=1048576
  86. chmod 600 /swapfile
  87. mkswap /swapfile
  88. swapon /swapfile
  89.  
  90. echo /swapfile swap swap defaults 0 0 >> /etc/fstab
  91.  
  92. grub-probe /boot
  93.  
  94. cat > /mnt/etc/apt/sources.list << EOFGRUB
  95. GRUB_DEFAULT=0
  96. GRUB_TIMEOUT=5
  97. GRUB_RECORDFAIL_TIMEOUT=5
  98. GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Ubuntu`
  99. GRUB_CMDLINE_LINUX_DEFAULT=""
  100. GRUB_CMDLINE_LINUX=""
  101. GRUB_TERMINAL=console
  102. EOFGRUB
  103.  
  104. update-grub
  105.  
  106. grub-install --recheck $DEVICE
  107.  
  108. grub-install --target=x86_64-efi --efi-directory=/boot/efi \
  109.     --bootloader-id=ubuntu --recheck --no-floppy
  110.  
  111. update-initramfs -v -u -t all
  112.  
  113. echo 'root:p@ssw0rd'|chpasswd
  114.  
  115. apt-get autoremove
  116. apt clean
  117. exit
  118. EOFSUBINSTALL
  119.  
  120. echo "Fertig"
  121. read -p "Press enter to continue"
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement