本文根据Github Arch Linux安装脚本写的,有需要的可以根据原作者代码进行更改,但是作者好久都没有更新了,注意必要的修改
提取出主要的两个文件,根据我自己的情况修改了一些,粗略的解释一下,新手可以多翻翻
arch-linux-installer.sh
#!/bin/bash #字体颜色 color(){ case $1 in red) echo -e "\033[31m$2\033[0m" ;; green) echo -e "\033[32m$2\033[0m" ;; esac } #分区分配 partition(){ if (echo $1 | grep '/' > /dev/null 2>&1);then other=$1 else other=/$1 fi fdisk -l color green "Input the partition (/dev/sdaX" read OTHER color green "Format it ? y)yes ENTER)no" read tmp if [ "$other" == "/boot" ];then boot=$OTHER fi if [ "$tmp" == y ];then umount $OTHER > /dev/null 2>&1 color green "Input the filesystem's num to format it" select type in 'ext2' "ext3" "ext4" "btrfs" "xfs" "jfs" "fat" "swap";do case $type in "ext2") mkfs.ext2 $OTHER break ;; "ext3") mkfs.ext3 $OTHER break ;; "ext4") mkfs.ext4 $OTHER break ;; "btrfs") mkfs.btrfs $OTHER -f break ;; "xfs") mkfs.xfs $OTHER -f break ;; "jfs") mkfs.jfs $OTHER break ;; "fat") mkfs.fat -F32 $OTHER break ;; "swap") swapoff $OTHER > /dev/null 2>&1 mkswap $OTHER -f break ;; *) color red "Error ! Please input the num again" ;; esac done fi if [ "$other" == "/swap" ];then swapon $OTHER else umount $OTHER > /dev/null 2>&1 mkdir /mnt$other mount $OTHER /mnt$other fi } #分区准备 #建议手动分区,在后边删除调用这个程序的命令 prepare(){ fdisk -l color green "Do you want to adjust the partition ? y)yes ENTER)no" read tmp if [ "$tmp" == y ];then color green "Input the disk (/dev/sdX" read TMP cfdisk $TMP fi color green "Input the ROOT(/) mount point:" read ROOT color green "Format it ? y)yes ENTER)no" read tmp if [ "$tmp" == y ];then umount $ROOT > /dev/null 2>&1 color green "Input the filesystem's num to format it" select type in "ext4" "btrfs" "xfs" "jfs";do umount $ROOT > /dev/null 2>&1 if [ "$type" == "btrfs" ];then mkfs.$type $ROOT -f elif [ "$type" == "xfs" ];then mkfs.$type $ROOT -f else mkfs.$type $ROOT fi break done fi mount $ROOT /mnt color green "Do you have another mount point ? if so please input it, such as : /boot /home and swap or just ENTER to skip" read other while [ "$other" != '' ];do partition $other color green "Still have another mount point ? input it or just ENTER" read other done } install(){ #修改源 echo "Server = https://mirrors.ustc.edu.cn/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist #配置基本系统 #注意选择的包,最小的只需要base,linux,linux-firmware即可,原作者更新于2019年九月以前,那时候linux包还在base包组里 pacstrap /mnt base base-devel linux-lts linux-firmware genfstab -U -p /mnt > /mnt/etc/fstab } config(){ #复制配置脚本到新系统里,并且chroot进去 cp config.sh /mnt/root/config.sh chmod +x /mnt/root/config.sh arch-chroot /mnt /root/config.sh $ROOT $boot } if [ "$1" != '' ];then case $1 in "--prepare") prepare ;; "--install") install ;; "--chroot") config ;; "--help") color red "--prepare : prepare disk and partition\n--install : install the base system\n--chroot : chroot into the system to install other software" ;; *) color red "Error !\n--prepare : prepare disk and partition\n--install : install the base system\n--chroot : chroot into the system to install other software" ;; esac else
#程序调用处 prepare install config fi
config.sh
#!/bin/bash root=$1 boot=$2 set -e #字体颜色 color(){ case $1 in red) echo -e "\033[31m$2\033[0m" ;; yellow) echo -e "\033[33m$2\033[0m" ;; esac } config_base(){
#设置电脑名称 color yellow "Input your hostname" read TMP echo $TMP > /etc/hostname #设置root密码
color yellow "Change your root passwd" passwd } config_locale(){ #选择时区,tzselect有同样的作用
color yellow "Please choose your locale time" select TIME in `ls /usr/share/zoneinfo`;do if [ -d "/usr/share/zoneinfo/$TIME" ];then select time in `ls /usr/share/zoneinfo/$TIME`;do ln -sf /usr/share/zoneinfo/$TIME/$time /etc/localtime break done else ln -sf /usr/share/zoneinfo/$TIME /etc/localtime break fi break done
#同步硬件时间 hwclock --systohc --utc #设置语言,建议Lang选择en,locale.gen修改成
#en_US.UTF-8 UTF-8
#zh_CN.UTF-8 UTF-8
color yellow "Choose your language" select LNAG in "en_US.UTF-8" "zh_CN.UTF-8";do echo "$LNAG UTF-8" > /etc/locale.gen locale-gen echo LANG=$LANG > /etc/locale.conf break done } #无特殊需求首选grub,也可以选用其他引导工具,但是其他引导工具需要根据Wiki修改,此处不适用,如果双系统需要添加os-prober包,修改成pacman -S --noconfirm grub efibootmgr os-prober -y即可 install_grub(){ if (mount | grep efivarfs > /dev/null 2>&1);then pacman -S --noconfirm grub efibootmgr -y rm -f /sys/firmware/efi/efivars/dump-* grub-install --target=`uname -m`-efi --efi-directory=/boot --bootloader-id=Arch #配置grub,可以根据需求修改grub.cfg文件
grub-mkconfig -o /boot/grub/grub.cfg else pacman -S --noconfirm grub fdisk -l color yellow "Input the disk you want to install grub (/dev/sdX" read TMP grub-install --target=i386-pc $TMP grub-mkconfig -o /boot/grub/grub.cfg fi } install_bootctl(){ if (mount | grep efivarfs > /dev/null 2>&1);then bootctl --path=/boot install cp /usr/share/systemd/bootctl/loader.conf /boot/loader/ echo "timeout 4" >> /boot/loader/loader.conf echo -e "title Arch Linux\nlinux ../vmlinuz-linux\ninitrd ../initramfs-linux.img" > /boot/loader/entries/arch.conf else color yellow "Looks like your PC doesn't suppot UEFI or not in UEFI mode ENTER to use grub. Input q to quit" read TMP if [ "$TMP" == "" ];then install_grub else exit fi fi } install_efistub(){ UUID=`blkid -s UUID -o value $root` efi=`echo $boot | grep -o "[0-9]*"` if (mount | grep efivarfs > /dev/null 2>&1);then pacman -S --noconfirm efibootmgr rm -f /sys/firmware/efi/efivars/dump-* efibootmgr --disk $boot --part $efi --create --label "Arch Linux" --loader /vmlinuz-linux --unicode "root=UUID=$UUID rw initrd=\initramfs-linux.img" else color yellow "Looks like your PC doesn't suppot UEFI or not in UEFI mode ENTER to use grub. Input q to quit" read TMP if [ "$TMP" == "" ];then install_grub else exit fi fi } #添加用户 add_user(){ color yellow "Input the user name you want to use (must be lower case)" read USER useradd -m -g wheel $USER color yellow "Set the passwd" passwd $USER pacman -S --noconfirm sudo
#使添加的用户组拥有sudo权限 sed -i 's/\# \%wheel ALL=(ALL) ALL/\%wheel ALL=(ALL) ALL/g' /etc/sudoers sed -i 's/\# \%wheel ALL=(ALL) NOPASSWD: ALL/\%wheel ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers } #安装显卡驱动,我的上一个电脑i5-7200U+MX150可以用此安装显卡驱动
#但是现在的电脑i7-9750H+1660ti不适用,不建议使用bumblebee管理显卡
#可以根据wiki,从Nvidia官网下载Linux显卡驱动安装,使用optimus-manager管理
#点此处查看Wiki关于optimus-manager的说明
install_graphic(){ color yellow "What is your video graphic card?" select GPU in "Intel" "Nvidia" "Intel and Nvidia" "AMD";do case $GPU in "Intel") pacman -S --noconfirm xf86-video-intel -y break ;; "Nvidia") color yellow "Version of nvidia-driver to install" select NVIDIA in "GeForce-8 and newer" "GeForce-6/7" "Older";do case $NVIDIA in "GeForce-8 and newer") pacman -S --noconfirm nvidia -y break ;; "GeForce-6/7") pacman -S --noconfirm nvidia-304xx -y break ;; "Older") pacman -S --noconfirm nvidia-340xx -y break ;; *) color red "Error ! Please input the correct num" ;; esac done break ;; "Intel and Nvidia") pacman -S --noconfirm bumblebee -y systemctl enable bumblebeed color yellow "Version of nvidia-driver to install" select NVIDIA in "GeForce-8 and newer" "GeForce-6/7" "Older";do case $NVIDIA in "GeForce-8 and newer") pacman -S --noconfirm nvidia -y break ;; "GeForce-6/7") pacman -S --noconfirm nvidia-304xx -y break ;; "Older") pacman -S --noconfirm nvidia-340xx -y break ;; *) color red "Error ! Please input the correct num" ;; esac done break ;; "AMD") pacman -S --noconfirm xf86-video-ati -y break ;; *) color red "Error ! Please input the correct num" ;; esac done } #蓝牙驱动 install_bluetooth(){ pacman -S --noconfirm bluez systemctl enable bluetooth color yellow "Install blueman? y)YES ENTER)NO" read TMP if [ "$TMP" == "y" ];then pacman -S --noconfirm blueman fi } #安装一些软件 install_app(){ color yellow "Install yay(aur helper) from archlinuxcn or use git ? (just for China users) y)YES ENTER)NO" read TMP if [ "$TMP" == "y" ];then sed -i '/archlinuxcn/d' /etc/pacman.conf sed -i '/archlinux-cn/d' /etc/pacman.conf
#添加archlinuxcn源 select MIRROR in "USTC" "TUNA" "163";do case $MIRROR in "USTC") echo -e "[archlinuxcn]\nServer = https://mirrors.ustc.edu.cn/archlinuxcn/\$arch" >> /etc/pacman.conf break ;; "TUNA") echo -e "[archlinuxcn]\nServer = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/\$arch" >> /etc/pacman.conf break ;; "163") echo -e "[archlinuxcn]\nServer = http://mirrors.163.com/archlinux-cn/\$arch" >> /etc/pacman.conf break ;; *) color red "Error ! Please input the correct num" ;; esac done pacman -Sy pacman -S --noconfirm archlinuxcn-keyring else pacman -S --noconfirm git su - $USER -c "cd ~ git clone https://aur.archlinux.org/package-query.git cd package-query && makepkg -si cd .. git clone https://aur.archlinux.org/yay.git cd yay && makepkg -si cd .. rm -rf package-query yay" fi
#安装一些软件,可手动修改,建议使用networkmanager而不是wicd等网络管理软件 pacman -S --noconfirm networkmanager xorg-server wqy-zenhei wget systemctl enable NetworkManager
#由于我是手动安装显卡驱动故注释 # if [ "$GPU" == "Intel and Nvidia" ];then # gpasswd -a $USER bumblebee # fi } #安装桌面环境,可根据wiki说明选择自己需要的包,这里给的不是最小化安装 install_desktop(){ color yellow "Choose the desktop you want to use" select DESKTOP in "KDE" "Gnome" "Lxde" "Lxqt" "Mate" "Xfce" "Deepin" "Budgie" "Cinnamon";do case $DESKTOP in "KDE") pacman -S plasma kdebase kdeutils kdegraphics sddm systemctl enable sddm break ;; "Gnome") pacman -S gnome gnome-terminal systemctl enable gdm break ;; "Lxde") pacman -S lxde lightdm lightdm-gtk-greeter systemctl enable lightdm break ;; "Lxqt") pacman -S lxqt lightdm lightdm-gtk-greeter systemctl enable lightdm break ;; "Mate") pacman -S mate mate-extra mate-terminal lightdm lightdm-gtk-greeter systemctl enable lightdm break ;; "Xfce") pacman -S xfce4 xfce4-terminal lightdm lightdm-gtk-greeter # xfce4-goodies systemctl enable lightdm break ;; "Deepin") pacman -S deepin deepin-extra deepin-terminal lightdm lightdm-gtk-greeter systemctl enable lightdm sed -i '108s/#greeter-session=example-gtk-gnome/greeter-session=lightdm-deepin-greeter/' /etc/lightdm/lightdm.conf break ;; "Budgie") pacman -S budgie-desktop gnome-terminal lightdm lightdm-gtk-greeter systemctl enable lightdm break ;; "Cinnamon") pacman -S cinnamon gnome-terminal lightdm lightdm-gtk-greeter systemctl enable lightdm break ;; *) color red "Error ! Please input the correct num" ;; esac done } clean(){ sed -i 's/\%wheel ALL=(ALL) NOPASSWD: ALL/\# \%wheel ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers } #主程序,根据需要修改,由于该脚本没有纠错功能,输入错误就会崩溃,运行到哪一步崩溃了把前面的删了再运行即可 main(){ config_base config_locale color yellow "Use Bootctl EFISUB or GRUB ? b)Bootctl e)EFISTUB ENTER)GRUB" read TMP if [ "$TMP" == "b" ];then install_bootctl elif [ "$TMP" == "e" ];then install_efistub else install_grub fi add_user # install_graphic color yellow "Do you have bluetooth ? y)YES ENTER)NO" read TMP if [ "$TMP" == "y" ];then install_bluetooth fi install_app install_desktop clean color yellow "Done , Thanks for using" } main