[Linux] Arch 安裝 script

OS:Arch Linux
官方文件

功能:安裝 Arch Linux
  1. #!/bin/bash
  2. # Program:
  3. # This program is for installing arch
  4. # History:
  5. # 2016/11/1 zWind First release
  6.  
  7. # use sh -n fileName to only check grammar
  8. # use sh -x fileName to debug
  9. # disk divide partition must be done and mount
  10.  
  11. function genSetting()
  12. {
  13. cat <<EOF > /mnt/setting.sh
  14. pacman -S vim --noconfirm
  15. # set timezone
  16. ln -s /usr/share/zoneinfo/Asia/Taipei /etc/localtime
  17. hwclock --systohc
  18. hwclock
  19.  
  20. # set Locale
  21. vim /etc/locale.gen
  22. locale-gen
  23. echo LANG=en_US.UTF-8 > /etc/locale.conf
  24. cat /etc/locale.conf
  25.  
  26. # set hostName
  27. echo ${hostName} > /etc/hostname
  28. cat /etc/hostname
  29. echo "127.0.1.1 ${hostName}.localdomain ${hostName}" >> /etc/hosts
  30. vim /etc/hosts
  31.  
  32. # Initramfs
  33. mkinitcpio -p linux
  34.  
  35. # set grub
  36. pacman -S grub --noconfirm
  37. grub-install --recheck ${disk}
  38. grub-mkconfig -o /boot/grub/grub.cfg
  39. # change root password
  40. passwd
  41.  
  42. # add user
  43. read -p "Please input your userName: " -t 30 userName
  44. userName=${userName:-${hostName}}
  45. useradd -m -g users ${userName}
  46. passwd ${userName}
  47. # exit
  48. exit
  49. EOF
  50. }
  51.  
  52. disk="/dev/sda"
  53. bootDisk="${disk}1"
  54. swapDisk="${disk}2"
  55.  
  56. echo "create sda1 for root and sda2 for swap"
  57. fdisk ${disk}
  58. test ! -e ${bootDisk} && echo "'${bootDisk}' DO NOT exist" && exit 0
  59. test ! -e ${swapDisk} && echo "'${swapDisk}' DO NOT exist" && exit 0
  60.  
  61. mkfs.ext4 ${bootDisk}
  62. mount ${bootDisk} /mnt
  63. mkswap ${swapDisk}
  64. swapon ${swapDisk}
  65.  
  66. read -p "Please input your hostName name: " -t 30 hostName
  67. hostName=${hostName:-archTest}
  68. export hostName
  69.  
  70. # install base
  71. pacstrap /mnt base base-devel
  72.  
  73. # gen fstab
  74. genfstab -p -U /mnt >> /mnt/etc/fstab
  75. vim /mnt/etc/fstab
  76.  
  77. genSetting
  78.  
  79. # change root and run script
  80. arch-chroot /mnt /bin/bash ./setting.sh
  81.  
  82. umount -R /mnt
  83. reboot

留言