Last active
December 14, 2022 09:15
-
-
Save verdana/6138611 to your computer and use it in GitHub Desktop.
Shell script to help with installing and configuring Arch linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Updated: Wednesday Dec 14, 2022 | |
# 必须以超级用户权限运行,似乎没啥必要... | |
[[ $EUID != 0 ]] && echo "Please run as root. Terminating..." && exit 1 | |
# 显示系统时间 | |
timedatectl status | |
echo "" | |
# 磁盘分区布局 UEFI with GPT | |
# | |
# /mnt/boot -> EFI -> At least 300 MiB | |
# [swap] -> swap -> More than 512 MiB | |
# /mnt -> root -> Remainder of the device | |
# 磁盘设备名 | |
# disk="/dev/sda" | |
disk="/dev/nvme0n1" | |
p1="${disk}p1" | |
p2="${disk}p2" | |
p3="${disk}p3" | |
# 如果分区已经挂载,先卸载 | |
umount -R /mnt > /dev/null 2>&1 | |
swapoff $p2 > /dev/null 2>&1 | |
# UEFI/GPT layout | |
sgdisk -og $disk | |
sgdisk -n 1:2048:+500M -c 1:"Boot Partition" -t 1:ef00 $disk # 500M | |
sgdisk -n 2:0:+2G -c 2:"[SWAP]" -t 2:8200 $disk # 2G | |
sgdisk -n 3:0:0 -c 3:"Linux /" -t 3:8300 $disk # ... | |
sgdisk -p $disk | |
# 格式化分区 | |
mkfs.fat -F 32 $p1 && echo "" | |
mkswap $p2 && echo "" | |
mkfs.ext4 -q $p3 && echo "" | |
# 挂载分区 | |
swapon $p2 | |
mount $p3 /mnt | |
mount --mkdir $p1 /mnt/boot | |
# 选择中科大镜像 | |
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig | |
echo 'Server = http://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist | |
# 安装基础系统 | |
pacstrap -K /mnt base linux linux-firmware | |
# 生成 fstab 文件 | |
genfstab -U /mnt >> /mnt/etc/fstab | |
# 配置脚本 | |
chmod +x /root/setup.sh | |
mv /root/setup.sh /mnt/root | |
# 运行配置脚本 | |
arch-chroot /mnt sh /root/setup.sh | |
# 卸载文件系统 | |
swapoff $p2 | |
umount -Rl /mnt | |
# 重启 | |
# reboot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 配置时区 | |
ln -sf /usr/share/zoneinfo/PRC /etc/localtime | |
# 同步硬件时钟的时间 | |
hwclock --systohc | |
# 生成系统语言 | |
sed -i -e "s/^#en_US/en_US/g;s/^#zh_CN/zh_CN/g" /etc/locale.gen | |
locale-gen | |
# 配置系统语言 | |
locale > /etc/locale.conf | |
# 配置主机名 | |
echo "spinoza" > /etc/hostname | |
# 设置 root 账户的密码 | |
echo "root:qing" | chpasswd | |
# 恢复传统的网络接口名称 | |
ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules | |
# 启动相关的网络服务 | |
systemctl enable systemd-networkd.service | |
systemctl enable systemd-resolved.service | |
systemctl start systemd-networkd.service | |
systemctl start systemd-resolved.service | |
# 配置有线网络 | |
cat > /etc/systemd/network/20-wired.network <<EOF | |
[Match] | |
Name=eth0 | |
[Network] | |
DHCP=yes | |
EOF | |
# 安装一些基础的软件包 | |
pacman -S --noconfirm efibootmgr grub \ | |
openssh rsync dhcpcd wpa_supplicant dnsutils net-tools \ | |
sudo htop fish git neovim | |
# 禁止检测操作系统 | |
sed -i '/GRUB_DISABLE_OS_PROBER=/s/^#//' /etc/default/grub | |
# 安装 GRUB for EFI | |
grub-install --target=x86_64-efi --efi-directory=/boot | |
grub-mkconfig -o /boot/grub/grub.cfg | |
# Block piix4 module | |
# echo 'blacklist i2c_piix4' > /etc/modprobe.d/blacklist.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment