因作者的電腦 HDMI 電視時,Windows 顯示卡驅動程式卻無法取得最佳更新。Arch Linux 顯示卡驅動程式讓作者驚艷,大嘆好美的畫質!於是安裝雙系統。
建議先參閱 Dual boot with Windows,底下以 UEFI 模式,先 Windows 後 Arch Linux 為例。
前置作業
Windows 在 UEFI 上的限制
Arch Linux 的安裝尚不支持 Secure Boot(安全開機),要停用
Windows 控制台的電源選項停用 快速啟動(Fast Startup)與休眠(hibernation)
硬碟磁區調整
安裝 Windows UEFI systems 後有四個分區,EFI 系統磁碟分區 (ESP) 內定約 100M,但 Arch Linux 的 EFI 至少須 300M,建議 550M以上,使用 MiniTool Partition 處理(EFI 之後的 MSR分區被隱藏保護)。下圖是作者增加 D槽,並挪出空間 80.54GB 安裝 Arch Linux。 如果你的 Windows 系統如下,第2分區就是 MSR(不可調整大小)
基礎安裝
以常見的 Windows UEFI systems 為例
參閱 Backup and Restore Boot Configuration Data (BCD) Store in Window 備份 Boot Configuration Data
bcdedit /export "<full path>\<file name>.bcd"
使用 DiskGenius 備份 EFI 分區,以便日後輕鬆還原 Windows 開機。
USB安裝碟開機(可參閱設置電腦用USB裝置開機)到 live environment
cfdisk /dev/sda 增加分區
修改 Arch Linux Base Install - 基礎安裝 的 install.txt,第 127行 至 130行 成為
#mkfs.fat -F32 /dev/sda1
mkfs.ext4 -F /dev/sda5
mount /dev/sda5 /mnt
mount --mkdir /dev/sda2 /mnt/boot
新的 install.txt 如下
#!/bin/bash
#-------------------------------------------------------------------------------
#Created by helmuthdu mailto: helmuthdu[at]gmail[dot]com
#-------------------------------------------------------------------------------
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License.
#-------------------------------------------------------------------------------
# Modified for ArchBang by Mr Green mrgreen(at)archbang(dot)org
# Modified by chuanjang(at)gmail(dot)com
#Usage:
#pacman -Sy wget
#wget https://diii.neocities.org/install.txt
#nano install.txt OR vim install.txt
#sh install.txt
# COLORS
Bold=$(tput bold)
Underline=$(tput sgr 0 1)
Reset=$(tput sgr0)
# Regular Colors
Red=$(tput setaf 1)
Green=$(tput setaf 2)
Yellow=$(tput setaf 3)
Blue=$(tput setaf 4)
Purple=$(tput setaf 5)
Cyan=$(tput setaf 6)
White=$(tput setaf 7)
# Bold
BRed=${Bold}$(tput setaf 1)
BGreen=${Bold}$(tput setaf 2)
BYellow=${Bold}$(tput setaf 3)
BBlue=${Bold}$(tput setaf 4)
BPurple=${Bold}$(tput setaf 5)
BCyan=${Bold}$(tput setaf 6)
BWhite=${Bold}$(tput setaf 7)
arch_chroot() { #{{{
arch-chroot /mnt /bin/bash -c "${1}"
}
#}}}
check_root() { #{{{
if [[ "$(id -u)" != "0" ]]; then
error_msg "ERROR! You must execute the script as the 'root' user."
fi
} #}}}
print_line() { #{{{
printf "%$(tput cols)s\n"|tr ' ' '-'
} #}}}
print_title() { #{{{
clear
print_line
echo -e "# ${Bold}$1${Reset}"
print_line
echo ""
} #}}}
read_input_text() { #{{{
read -p "$1 [y/N]: " OPTION
OPTION=`echo "$OPTION" | tr '[:upper:]' '[:lower:]'`
} #}}}
pause_function() { #{{{
print_line
read -e -sn 1 -p "Press enter to continue..."
} #}}}
print_warning() { #{{{
T_COLS=`tput cols`
echo -e "${BYellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
} #}}}
error_msg() { #{{{
local _msg="${1}"
echo -e "${_msg}"
exit 1
} #}}}
create_new_user(){ #{{{
print_title "CREATE USER HAVE $(tput setaf 2)SUDO $(tput sgr0)$(tput bold)PRIVILEGES"
while [[ -z "$username" ]]; do
read -p "username: " username
username=`echo $username | tr '[:upper:]' '[:lower:]'`
if [ -z "$username" ] ; then
print_warning "username empty, don't create user.\n"
fi
done
arch_chroot "useradd -m -g users -G wheel -s /bin/bash ${username}"
#arch_chroot "chfn ${username}"
arch_chroot "passwd ${username}"
while [[ $? -ne 0 ]]; do
arch_chroot "passwd ${username}"
done
#arch_chroot "visudo"
arch_chroot "chmod 777 /etc/sudoers"
arch_chroot "echo '%wheel ALL=(ALL:ALL) ALL' >> /etc/sudoers"
arch_chroot "chmod 440 /etc/sudoers"
} #}}}
# Verify the boot mode
if [[ -d "/sys/firmware/efi/" ]]; then
echo -e "${Cyan}UEFI${Reset} Mode detected\n"
UEFI=true
else
echo -e "${Cyan}BIOS Mode${Reset} detected\n"
UEFI=false
fi
pause_function
# Connect to the internet
ip link
# Verify connection
ping -c 1 archlinux.org
echo -e "\n${Cyan}Connection${Reset} verified"
read_input_text "Continue or not"
if [[ $OPTION != y ]]; then
echo -e "\n\nExit"
exit 0
fi
# Ensure the system clock is accurate:
#timedatectl
# Partition the disks. To identify these devices, use lsblk
#fdisk /dev/sda
if $UEFI ; then
echo -e "\n${Purple}UEFI${Reset}. Format and mount\n"
#mkfs.fat -F32 /dev/sda1
mkfs.ext4 -F /dev/sda5
mount /dev/sda5 /mnt
mount --mkdir /dev/sda2 /mnt/boot
else
echo -e "\n${Purple}BIOS${Reset}. Format and mount\n"
BOOT_MNT="/dev/sda"
mkfs.ext4 -F /dev/sda1
mount /dev/sda1 /mnt
fi
# Select the mirrors - https://archlinux.org/mirrors/status/
echo -e "\n\n"
PS3="Select ${Purple}mirror region${Reset}: "
items=("China" "Taiwan")
select item in "${items[@]}"
do
case $REPLY in
1) reflector --verbose --latest 10 --sort rate --country china --save /etc/pacman.d/mirrorlist
break
;;
2) reflector --verbose --latest 10 --sort rate --country taiwan --save /etc/pacman.d/mirrorlist
break
;;
#$((${#items[@]}+1))) echo -e "\n${Red}Cancel${Reset}"; break;;
*) echo -e "Invalid option ${Red}$REPLY${Reset}";;
esac
done
# Install essential packages and ...
pacstrap /mnt base linux linux-firmware sudo networkmanager wget nano vim dhcpcd
# Configure the system
genfstab -U /mnt >> /mnt/etc/fstab
echo -e "\n\nChange root into the new system and ..."
pause_function
#Set the time zone
#arch_chroot "ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime"
#arch_chroot "ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime"
#Assumes the hardware clock is set to localtime
#arch_chroot "hwclock --systohc --localtime"
#Set language U.S. English
arch_chroot "sed -i '/#en_US.UTF-8/{s/#//}' /etc/locale.gen"
arch_chroot "locale-gen"
arch_chroot "echo 'LANG=en_US.UTF-8' > /etc/locale.conf"
#Create the hostname file
arch_chroot "echo archlinux > /etc/hostname"
# Configure mkinitcpio
arch_chroot "mkinitcpio -p linux"
echo -e "\nSet the root password"
arch_chroot "passwd"
# Enable NetworkManager
arch_chroot "systemctl enable NetworkManager"
# Enable network connect
echo -e "\nEnable Ethernet plug in the cable\n"
arch_chroot "systemctl enable dhcpcd"
create_new_user
# Install Grub
read_input_text "Install GRUB boot loader:"
if [[ $OPTION != y ]]; then
#arch-chroot /mnt
echo -e "\n\n${Red}Must${Reset} install boot loader.\n"
exit 0
fi
# Microcode must be loaded by the boot loader, Intel processors or AMD processors
arch_chroot "pacman -S intel-ucode amd-ucode --noconfirm"
arch_chroot "pacman -S grub os-prober efibootmgr --noconfirm"
if $UEFI ; then
arch_chroot "grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB"
else
arch_chroot "grub-install --target=i386-pc ${BOOT_MNT}"
fi
arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg"
# Installation finished
read_input_text "Installation finished. Reboot system"
if [[ $OPTION != y ]]; then
arch-chroot /mnt
exit 0
fi
umount -R /mnt
reboot
exit 0
sh install.txt。完成後,重新開機。
安裝桌面
上一個步驟,GRUB 開機選單並未加入 Windows系統,安裝桌面後再處理是聰明選擇。
LXQt 桌面
Xfce 桌面
KDE 桌面
GRUB 開機選單加入 Windows系統
使用兩顆硬碟分別安裝 Windows 與 Arch Linux 時,底下操作也適用。
先建立 ~/tmp,掛載 ESP
mkdir ~/tmp
sudo mount /dev/sda2 ~/tmp
有兩種方法加入 Windows開機:
方法一:偵測其他作業系統
編輯 /etc/default/grub (sudo l3afpad /etc/default/grub
) 並取消下面這一行的注釋,或在文件最後增加
GRUB_DISABLE_OS_PROBER=false
再執行
sudo grub-mkconfig -o /boot/grub/grub.cfg
查看 /boot/grub/grub.cfg (sudo l3afpad /boot/grub/grub.cfg
),可得到下面這一行
menuentry 'Windows Boot Manager (on /dev/sda2)'
方法二:
參閱 UEFI/GPT 模式下安裝的 Windows 編輯
if [ "${grub_platform}" == "efi" ]; then
menuentry "Microsoft Windows Vista/7/8/8.1 UEFI/GPT" {
insmod part_gpt
insmod fat
insmod chain
search --no-floppy --fs-uuid --set=root $hints_string $fs_uuid
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
fi
其中 $hints_string 和 $fs_uuid 由下述兩個命令得到
sudo grub-probe --target=fs_uuid ~/tmp/EFI/Microsoft/Boot/bootmgfw.efi
1AF6-3340
sudo grub-probe --target=hints_string ~/tmp/EFI/Microsoft/Boot/bootmgfw.efi
--hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2
因此編輯成
if [ "${grub_platform}" == "efi" ]; then
menuentry "Microsoft Windows 10 UEFI/GPT" {
insmod part_gpt
insmod fat
insmod chain
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 1AF6-3340
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
fi
再將上面代碼貼至 /boot/grub/grub.cfg (sudo l3afpad /boot/grub/grub.cfg
)
如果於### BEGIN /etc/grub.d/10_linux ###
之前加入,則開機順序 Windows 優先
如果於submenu 'Advanced
之前加入,則開機順序 Arch Linux 優先
重新開機至 Windows
參閱 Backup and Restore Boot Configuration Data (BCD) Store in Window 備份 Boot Configuration Data,使用 DiskGenius 備份 EFI 分區,以便輕鬆還原 Windows 與 Arch Linux 雙系統開機。
可使用本篇 基礎安裝 備份的 Boot Configuration Data 及 EFI 分區,還原純 Windows 系統開機。
系統時間
參閱 Arch Linux基礎安裝重新開機與系統時間,設置 Arch Linux 系統時間與 Windows 系統時間
存取 Windows NTFS
雖然安裝桌面可使用檔案管理員(如 pcmanfm-qt)掛載 NTFS,但功能上似稍嫌不足,安裝 NTFS-3G 較優