Advertisement
Guest User

Arch-install chroot

a guest
Oct 21st, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 15.40 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Replace username with the name for your new user
  4. export USER=xxx
  5. # Replace hostname with the name for your host
  6. export HOST=xxx
  7. # Replace Europe/London with your Region/City
  8. export TZ="Europe/Berlin"
  9. # - set root password
  10. passwd
  11. # - set locale
  12. echo "generating locale"
  13. echo "de_DE.UTF-8 UTF-8" >> locale.gen
  14. echo "de_DE ISO-8859-1"  >> locale.gen
  15. echo "de_DE@euro ISO-8859-15" >> locale.gen
  16. locale-gen
  17. echo "setting locale and keymap"
  18. echo "LANG=\"de_DE.UTF-8\"" > /etc/locale.conf
  19. echo "KEYMAP=de-latin1" > /etc/vconsole.conf
  20. echo "FONT=lat9w-16" >> /etc/vconsole.conf
  21. export LANG="de_DE.UTF-8"
  22.  
  23. # - set timezone
  24. echo "setting timezone"
  25. ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
  26. hwclock --systohc --utc # or hwclock --systohc --utc
  27. # - set hostname
  28. echo "setting hostname"
  29. echo $HOST > /etc/hostname
  30. # - add user
  31. echo "adding new user"
  32. useradd -mg users -G wheel,input,lp,storage,video,sys,network,power,libvirt,kvm,vboxusers -s /bin/zsh $USER
  33. passwd $USER
  34. echo "$USER ALL=(ALL) ALL" >> /etc/sudoers
  35. echo "Defaults timestamp_timeout=0" >> /etc/sudoers
  36. # - set hosts
  37. echo "creating hosts-file"
  38. cat << EOF >> /etc/hosts
  39. echo "# <ip-address>    <hostname.domain.org>   <hostname>"
  40. echo "127.0.0.1 localhost"
  41. echo "::1       localhost"
  42. echo "127.0.1.1 $HOST.localdomain   $HOST"
  43. EOF
  44. # - Set Network Manager iwd backend
  45. #echo "[device]" > /etc/NetworkManager/conf.d/nm.conf
  46. #echo "wifi.backend=iwd" >> /etc/NetworkManager/conf.d/nm.conf
  47.  
  48. # - Preventing snapshot slowdowns
  49. echo 'PRUNENAMES = ".snapshots"' >> /etc/updatedb.conf
  50.  
  51. # 6 - fix the mkinitcpio.conf to contain what we actually need.
  52. # sed -i 's/BINARIES=()/BINARIES=("\/usr\/bin\/btrfs")/' /etc/mkinitcpio.conf
  53. # If using amdgpu and would like earlykms
  54. echo "modifying mkinitcpio.conf"
  55. sed -i 's/MODULES=()/MODULES=(amdgpu)/' /etc/mkinitcpio.conf
  56. sed -i 's/#COMPRESSION="zstd"/COMPRESSION="zstd"/' mkinitcpio.conf
  57. #sed -i 's/#COMPRESSION_OPTIONS=()/COMPRESSION_OPTIONS=(-9)/' mkinitcpio.conf
  58. # if you have more than 1 btrfs drive
  59. sed -i 's/^HOOKS/HOOKS=(base systemd sd-vconsole autodetect modconf block keyboard sd-encrypt filesystems )/' mkinitcpio.conf
  60. # else
  61. # sed -i 's/^HOOKS/HOOKS=(base systemd autodetect modconf block sd-encrypt resume filesystems keyboard fsck)/' mkinitcpio.conf
  62.  
  63. echo "running mkinitcpio"
  64. mkinitcpio -p linux
  65.  
  66. # 10 Bootloader
  67. #su $USER
  68. #cd ~
  69. #git clone https://aur.archlinux.org/yay.git && cd yay
  70. #makepkg -si
  71. #cd .. && sudo rm -dR yay
  72. #yay -S shim-signed pamac-aur
  73.  
  74. # If you use a bare git to store dotfiles install them now
  75. # git clone --bare https://github.com/user/repo.git $HOME/.repo
  76. #exit
  77.  
  78. echo "installing refind"
  79. refind-install
  80. #refind-install --shim /usr/share/shim-signed/shimx64.efi --localkeys
  81. #sbsign --key /etc/refind.d/keys/refind_local.key --cert /etc/refind.d/keys/refind_local.crt --output /boot/vmlinuz-linux /boot/vmlinuz-linux
  82.  
  83. echo "creating some pacman hooks"
  84. mkdir -p /etc/pacman.d/hooks
  85.  
  86. # cat << EOF > /etc/pacman.d/hooks/999-sign_kernel_for_secureboot.hook
  87. # """
  88. # [Trigger]
  89. # Operation = Install
  90. # Operation = Upgrade
  91. # Type = Package
  92. # Target = linux
  93. # Target = linux-lts
  94. # Target = linux-hardened
  95. # Target = linux-zen
  96. # [Action]
  97. # Description = Signing kernel with Machine Owner Key for Secure Boot
  98. # When = PostTransaction
  99. # Exec = /usr/bin/find /boot/ -maxdepth 1 -name 'vmlinuz-*' -exec /usr/bin/sh -c '/usr/bin/sbsign --key /etc/refind.d/keys/refind_local.key --cert /etc/refind.d/keys/refind_local.crt --output {} {}'
  100. # Depends = sbsigntools
  101. # Depends = findutils
  102. # Depends = grep
  103. # EOF
  104.  
  105. cat << EOF > /etc/pacman.d/hooks/refind.hook
  106. [Trigger]
  107. Operation=Upgrade
  108. Type=Package
  109. Target=refind
  110. [Action]
  111. Description = Updating rEFInd on ESP
  112. When=PostTransaction
  113. Exec=/usr/bin/refind-install
  114. EOF
  115.  
  116. cat << EOF > /etc/pacman.d/hooks/zsh.hook
  117. [Trigger]
  118. Operation = Install
  119. Operation = Upgrade
  120. Operation = Remove
  121. Type = Path
  122. Target = usr/bin/*
  123. [Action]
  124. Depends = zsh
  125. When = PostTransaction
  126. Exec = /usr/bin/install -Dm644 /dev/null /var/cache/zsh/pacman
  127. EOF
  128.  
  129. cat << EOF > /etc/pacman.d/hooks/mirrorupgrade.hook
  130. [Trigger]
  131. Operation = Upgrade
  132. Type = Package
  133. Target = pacman-mirrorlist
  134.  
  135. [Action]
  136. Description = Updating pacman-mirrorlist with reflector and removing pacnew...
  137. When = PostTransaction
  138. Depends = reflector
  139. Exec = /bin/sh -c 'systemctl start reflector.service; if [ -f /etc/pacman.d/mirrorlist.pacnew ]; then rm /etc/pacman.d/mirrorlist.pacnew; fi'
  140. EOF
  141.  
  142. echo "setting schedulers for nvme, ssd and hdd"
  143. mkdir -p /etc/udev/rules.d
  144. cat << EOF > /etc/udev/rules.d/60-ioschedulers.rules
  145. # set scheduler for NVMe
  146. ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="none"
  147. # set scheduler for SSD and eMMC
  148. ACTION=="add|change", KERNEL=="sd[a-z]|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"
  149. # set scheduler for rotating disks
  150. ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"
  151. EOF
  152.  
  153. echo "creating reflector.conf"
  154. mkdir -p /etc/xdg/reflector
  155. cat << EOF > /etc/xdg/reflector/reflector.conf
  156. # Set the output path where the mirrorlist will be saved (--save).
  157. --save /etc/pacman.d/mirrorlist
  158. # Select the transfer protocol (--protocol).
  159. --protocol https
  160. # Use only the  most recently synchronized mirrors (--latest).
  161. --latest 100
  162. # Sort the mirrors by MirrorStatus score
  163. --sort score
  164. EOF
  165.  
  166.  
  167. # autologin with SDDM
  168. echo "creating sddm autologin .conf"
  169. mkdir -p /etc/sddm.conf.d
  170. cat << EOF > /etc/sddm.conf.d/kde_settings.conf
  171. [Autologin]
  172. Relogin=false
  173. Session=plasma
  174. User=$USER
  175.  
  176. [General]
  177. HaltCommand=/usr/bin/systemctl poweroff
  178. Numlock=on
  179. RebootCommand=/usr/bin/systemctl reboot
  180.  
  181. [Theme]
  182. Current=breeze
  183. CursorTheme=breeze_cursors
  184. Font=Noto Sans,10,-1,5,50,0,0,0,0,0
  185.  
  186. [Users]
  187. MaximumUid=60000
  188. MinimumUid=1000
  189. EOF
  190.  
  191. # this will help declutter the home directory from zsh-dotfiles
  192. mkdir -p /etc/zsh
  193. cat << EOF > /etc/zsh/zshenv
  194. export ZDOTDIR=$HOME/.config/zsh
  195. export HISTFILE="$XDG_DATA_HOME"/zsh/history
  196. EOF
  197.  
  198. echo "creating sysctl tweaks"
  199. mkdir -p /etc/sysctl.d
  200. cat << EOF >/etc/sysctl.d/99-sysctl-performance-tweaks.conf
  201. # The swappiness sysctl parameter represents the kernel's preference (or avoidance) of swap space. Swappiness can have a value between 0 and 100, the default value is 60.
  202. # A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. Using a low value on sufficient memory is known to improve responsiveness on many systems.
  203. vm.swappiness=10
  204.  
  205. # The value controls the tendency of the kernel to reclaim the memory which is used for caching of directory and inode objects (VFS cache).
  206. # Lowering it from the default value of 100 makes the kernel less inclined to reclaim VFS cache (do not set it to 0, this may produce out-of-memory conditions)
  207. vm.vfs_cache_pressure=50
  208.  
  209. # This action will speed up your boot and shutdown, because one less module is loaded. Additionally disabling watchdog timers increases performance and lowers power consumption
  210. # Disable NMI watchdog
  211. #kernel.nmi_watchdog = 0
  212.  
  213. # Contains, as a percentage of total available memory that contains free pages and reclaimable
  214. # pages, the number of pages at which a process which is generating disk writes will itself start
  215. # writing out dirty data (Default is 20).
  216. vm.dirty_ratio = 5
  217.  
  218. # Contains, as a percentage of total available memory that contains free pages and reclaimable
  219. # pages, the number of pages at which the background kernel flusher threads will start writing out
  220. # dirty data (Default is 10).
  221. vm.dirty_background_ratio = 5
  222.  
  223. # This tunable is used to define when dirty data is old enough to be eligible for writeout by the
  224. # kernel flusher threads.  It is expressed in 100'ths of a second.  Data which has been dirty
  225. # in-memory for longer than this interval will be written out next time a flusher thread wakes up
  226. # (Default is 3000).
  227. #vm.dirty_expire_centisecs = 3000
  228.  
  229. # The kernel flusher threads will periodically wake up and write old data out to disk.  This
  230. # tunable expresses the interval between those wakeups, in 100'ths of a second (Default is 500).
  231. vm.dirty_writeback_centisecs = 1500
  232.  
  233. # Enable the sysctl setting kernel.unprivileged_userns_clone to allow normal users to run unprivileged containers.
  234. kernel.unprivileged_userns_clone=1
  235.  
  236. # To hide any kernel messages from the console
  237. kernel.printk = 3 3 3 3
  238.  
  239. # Restricting access to kernel logs
  240. kernel.dmesg_restrict = 1
  241.  
  242. # Restricting access to kernel pointers in the proc filesystem
  243. kernel.kptr_restrict = 2
  244.  
  245. # Disable Kexec, which allows replacing the current running kernel.
  246. kernel.kexec_load_disabled = 1
  247.  
  248. # Increasing the size of the receive queue.
  249. # The received frames will be stored in this queue after taking them from the ring buffer on the network card.
  250. # Increasing this value for high speed cards may help prevent losing packets:
  251. net.core.netdev_max_backlog = 16384
  252.  
  253. # Increase the maximum connections
  254. #The upper limit on how many connections the kernel will accept (default 128):
  255. net.core.somaxconn = 8192
  256.  
  257. # Increase the memory dedicated to the network interfaces
  258. # The default the Linux network stack is not configured for high speed large file transfer across WAN links (i.e. handle more network packets) and setting the correct values may save memory resources:
  259. net.core.rmem_default = 1048576
  260. net.core.rmem_max = 16777216
  261. net.core.wmem_default = 1048576
  262. net.core.wmem_max = 16777216
  263. net.core.optmem_max = 65536
  264. net.ipv4.tcp_rmem = 4096 1048576 2097152
  265. net.ipv4.tcp_wmem = 4096 65536 16777216
  266. net.ipv4.udp_rmem_min = 8192
  267. net.ipv4.udp_wmem_min = 8192
  268.  
  269. # Enable TCP Fast Open
  270. # TCP Fast Open is an extension to the transmission control protocol (TCP) that helps reduce network latency
  271. # by enabling data to be exchanged during the sender’s initial TCP SYN [3].
  272. # Using the value 3 instead of the default 1 allows TCP Fast Open for both incoming and outgoing connections:
  273. net.ipv4.tcp_fastopen = 3
  274.  
  275. # Enable BBR
  276. # The BBR congestion control algorithm can help achieve higher bandwidths and lower latencies for internet traffic
  277. net.core.default_qdisc = cake
  278. net.ipv4.tcp_congestion_control = bbr
  279.  
  280. # TCP SYN cookie protection
  281. # Helps protect against SYN flood attacks. Only kicks in when net.ipv4.tcp_max_syn_backlog is reached:
  282. net.ipv4.tcp_syncookies = 1
  283.  
  284. # Protect against tcp time-wait assassination hazards, drop RST packets for sockets in the time-wait state. Not widely supported outside of Linux, but conforms to RFC:
  285. net.ipv4.tcp_rfc1337 = 1
  286.  
  287. # By enabling reverse path filtering, the kernel will do source validation of the packets received from all the interfaces on the machine. This can protect from attackers that are using IP spoofing methods to do harm.
  288. net.ipv4.conf.default.rp_filter = 1
  289. net.ipv4.conf.all.rp_filter = 1
  290.  
  291. # Disable ICMP redirects
  292. net.ipv4.conf.all.accept_redirects = 0
  293. net.ipv4.conf.default.accept_redirects = 0
  294. net.ipv4.conf.all.secure_redirects = 0
  295. net.ipv4.conf.default.secure_redirects = 0
  296. net.ipv6.conf.all.accept_redirects = 0
  297. net.ipv6.conf.default.accept_redirects = 0
  298. net.ipv4.conf.all.send_redirects = 0
  299. net.ipv4.conf.default.send_redirects = 0
  300.  
  301. # To use the new FQ-PIE Queue Discipline (>= Linux 5.6) in systems with systemd (>= 217), will need to replace the default fq_codel.
  302. net.core.default_qdisc = fq_pie
  303. EOF
  304.  
  305. # Optimize Makepkg
  306. echo "optimizing makepkg.conf"
  307. sed -i 's/^CFLAGS/CFLAGS="-march=native -mtune=native -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -fno-plt"/' /etc/makepkg.conf
  308. sed -i 's/^CXXFLAGS/CXXFLAGS="${CFLAGS}"/' /etc/makepkg.conf
  309. sed -i 's/^#RUSTFLAGS/RUSTFLAGS="-C opt-level=2 -C target-cpu=native"/' etc/makepkg.conf
  310. sed -i 's/^#BUILDDIR/BUILDDIR=\/tmp\/makepkg makepkg/' etc/makepkg.conf
  311. sed -i 's/^#MAKEFLAGS/MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN) --quiet"/' etc/makepkg.conf
  312. sed -i 's/^COMPRESSGZ/COMPRESSGZ=(pigz -c -f -n)/' etc/makepkg.conf
  313. sed -i 's/^COMPRESSBZ2/COMPRESSBZ2=(pbzip2 -c -f)/' etc/makepkg.conf
  314. sed -i 's/^COMPRESSXZ/COMPRESSXZ=(xz -T "$(getconf _NPROCESSORS_ONLN)" -c -z --best -)/' etc/makepkg.conf
  315. sed -i 's/^COMPRESSZST/COMPRESSZST=(zstd -c -z -q --ultra -T0 -22 -)/' etc/makepkg.conf
  316. sed -i 's/^COMPRESSLZ/COMPRESSLZ=(lzip -c -f)/' etc/makepkg.conf
  317. sed -i 's/^COMPRESSLRZ/COMPRESSLRZ=(lrzip -9 -q)/' etc/makepkg.conf
  318. sed -i 's/^COMPRESSLZO/COMPRESSLZO=(lzop -q --best)/' etc/makepkg.conf
  319. sed -i 's/^COMPRESSZ/COMPRESSZ=(compress -c -f)/' etc/makepkg.conf
  320. sed -i 's/^COMPRESSLZ4/COMPRESSLZ4=(lz4 -q --best)/' etc/makepkg.conf
  321.  
  322. # Misc options
  323. sed -i 's/#UseSyslog/UseSyslog/' etc/pacman.conf
  324. sed -i 's/#Color/Color\\\nILoveCandy/' etc/pacman.conf
  325. sed -i 's/#TotalDownload/TotalDownload/' etc/pacman.conf
  326. sed -i 's/#CheckSpace/CheckSpace/' etc/pacman.conf
  327.  
  328. mkdir -p /boot/EFI/refind/themes
  329. git clone https://github.com/dheishman/refind-dreary.git /boot/EFI/refind/themes/refind-dreary
  330. mv  /boot/EFI/refind/themes/refind-dreary/highres /boot/EFI/refind/themes/refind-dreary-tmp
  331. rm -dR /boot/EFI/refind/themes/refind-dreary
  332. mv /boot/EFI/refind/themes/refind-dreary-tmp /boot/EFI/refind/themes/refind-dreary
  333.  
  334. # Replace 2560 1440 with your monitors resolution
  335. sed -i 's/#resolution 3/resolution 2560 1440/' /boot/EFI/refind/refind.conf
  336. sed -i 's/#use_graphics_for osx,linux/use_graphics_for linux/' /boot/EFI/refind/refind.conf
  337. sed -i 's/#scanfor internal,external,optical,manual/scanfor manual,external/' /boot/EFI/refind/refind.conf
  338.  
  339. # add the UUID to the options (example below)
  340. echo "creating refind stanza"
  341. cat << EOF >> /boot/EFI/refind/refind.conf
  342. menuentry "Arch Linux" {
  343.     icon     icon /EFI/refind/themes/refind-dreary/icons/os_arch.png
  344.     volume   "Arch Linux"
  345.     loader   /vmlinuz-linux
  346.     initrd   /initramfs-linux.img
  347.     options  "rd.luks.name=UUID=cryptroot rd.luks.options=allow-discards,no-read-workqueue,no-write-workqueue root=/dev/mapper/cryptroot rootflags=subvol=@ rw quiet zswap.enabled=1 zswap.compressor=zstd zswap.max_pool_percent=20 zswap.zpool=z3fold amdgpu.ppfeaturemask=0xffffffff nmi_watchdog=0 initrd=/amd-ucode.img"
  348.     submenuentry "Boot using fallback initramfs" {
  349.         initrd /boot/initramfs-linux-fallback.img
  350.     }
  351. }
  352. include themes/refind-dreary/theme.conf
  353. EOF
  354.  
  355. # Laptop Battery Life Improvements
  356. #echo "vm.dirty_writeback_centisecs = 6000" > /etc/sysctl.d/dirty.conf
  357. #echo "load-module module-suspend-on-idle" >> /etc/pulse/default.pa
  358. #if [ $(( $(lspci -k | grep snd_ac97_codec | wc -l) + 1 )) -gt 1 ]; then echo "options snd_ac97_codec power_save=1" > /etc/modprobe.d/audio_powersave.conf; fi
  359. #if [ $(( $(lspci -k | grep snd_hda_intel | wc -l) + 1 )) -gt 1 ]; then echo "options snd_hda_intel power_save=1" > /etc/modprobe.d/audio_powersave.conf; fi
  360. #if [ $(lsmod | grep '^iwl.vm' | awk '{print $1}') == "iwlmvm" ]; then echo "options iwlwifi power_save=1" > /etc/modprobe.d/iwlwifi.conf; echo "options iwlmvm power_scheme=3" >> /etc/modprobe.d/iwlwifi.conf; fi
  361. #if [ $(lsmod | grep '^iwl.vm' | awk '{print $1}') == "iwldvm" ]; then echo "options iwldvm force_cam=0" >> /etc/modprobe.d/iwlwifi.conf; fi
  362. #echo 'ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="med_power_with_dipm"' > /etc/udev/rules.d/hd_power_save.rules
  363.  
  364. # 11 - reboot into your new install
  365. echo "Finished - now we can reboot with:
  366.    exit
  367.    umount -R /mnt
  368.    swapoff -a
  369.    reboot"
  370. read -p "Do you want to reboot now? " -n 1 -r
  371. echo    # (optional) move to a new line
  372. if [[ ! $REPLY =~ ^[Yy]$ ]]
  373. then
  374.     exit 1
  375. else
  376.     exit
  377.     umount -R /mnt
  378.     swapoff -a
  379.     reboot
  380. fi
  381.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement