arch Linux(一)
制作啟動盤
將U盤插入待裝主機,設置U盤啟動,重啟進入系統安裝界面
設置root密碼
root@archiso~ # passwd
啟動允許遠程連接
root@archiso~ # systemctl start sshd
鏈接無線網絡
root@archiso~ # wifi-menu
查看待裝主機的IP地址
root@archiso~ # ip a
拿出MacBook我們使用遠程安裝
macOS:~ hhbsh$ ssh [email protected]
更新在線安裝源
在下列文件開頭
root@archiso ~ # vim /etc/pacman.d/mirrorlist
添加
Server = http://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch Server = http://mirrors.zju.edu.cn/archlinux/$repo/os/$arch
更新
root@archiso ~ # sudo pacman -Syy
分區,使用如下命令查看磁盤分區情況
root@archiso ~ # fdisk -l
找到待裝磁盤符。我這裏是
/dev/sda
Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors Disk model: Lenovo SSD SL700 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 6109DCF3-362D-468B-970C-81967DD0D852 Device Start End Sectors Size Type /dev/sda1 2048 6143 4096 2M BIOS boot /dev/sda2 6144 415743 409600 200M Linux filesystem /dev/sda3 415744 17192959 16777216 8G Linux filesystem /dev/sda4 17192960 250069646 232876687 111G Linux filesystem
抹除
/dev/sda
磁盤的所有數據root@archiso ~ # fdisk /dev/sda Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors Disk model: Lenovo SSD SL700 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 6109DCF3-362D-468B-970C-81967DD0D852 Device Start End Sectors Size Type /dev/sda1 2048 6143 4096 2M BIOS boot /dev/sda2 6144 415743 409600 200M Linux filesystem /dev/sda3 415744 17192959 16777216 8G Linux filesystem /dev/sda4 17192960 250069646 232876687 111G Linux filesystem Command (m for help): d Partition number (1-4, default 4): Partition 4 has been deleted. Command (m for help): d Partition number (1-3, default 3): Partition 3 has been deleted. Command (m for help): d Partition number (1,2, default 2): Partition 2 has been deleted. Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): d No partition is defined yet! Command (m for help): Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
使用下面命令刷新信息
root@archiso ~ # partprobe
重啟機器
root@archiso ~ # reboot
註:當然還是選擇U盤啟動。選第一個即可。
在待安裝主機重復 3~6 步驟
然後我們就到MacBook使用遠程安裝,執行步驟 7。出現下列問題
macOS:~ hhbsh$ ssh [email protected] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the ECDSA key sent by the remote host is SHA256:kGzwhZIhRjRwXG7UNenF1zhXruVLaOz6MyGCtnAu5Wg. Please contact your system administrator. Add correct host key in /Users/hhbsh/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /Users/hhbsh/.ssh/known_hosts:8 ECDSA host key for 192.168.3.8 has changed and you have requested strict checking. Host key verification failed.
原因是我們之前鏈接的ssh協商的
192.168.3.8
該 IP 地址的主機密鑰失效。我們在MacBook的/Users/hhbsh/.ssh/known_hosts
文件內刪除192.168.3.8
相關信息,:wq
保存退出,重新生成密鑰即可。macOS:~ hhbsh$ vim /Users/hhbsh/.ssh/known_hosts macOS:~ hhbsh$ ssh [email protected] The authenticity of host '192.168.3.8 (192.168.3.8)' can't be established. ECDSA key fingerprint is SHA256:IhRjRwXG7fsfgUNenF1zhXruVLaOz6MdfgdfGCtnAu5Wg. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.3.8' (ECDSA) to the list of known hosts. [email protected]'s password: Last login: Mon Feb 4 05:08:29 2019 root@archiso ~ #
我們再來查看
/dev/sda
分區信息。發現與 11 步的信息完全不同了,我們已經擦除了該磁盤數據。root@archiso ~ # fdisk -l Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors Disk model: Lenovo SSD SL700 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 6109DCF3-362D-468B-970C-81967DD0D852
創建分區
- 首先我們創建一個 2MB 大小的分區
sda1
,留著後邊我們設定它的標誌為bios_grub
; - 再創建一個 200MB 的分區
sda2
; - 再創建一個 8G 的分區
sda3
; - 余下的空間創建分區
sda4
。
root@archiso ~ # fdisk /dev/sda Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition number (1-128, default 1): First sector (34-250069646, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-250069646, default 250069646): +2M Created a new partition 1 of type 'Linux filesystem' and of size 2 MiB. Command (m for help): n Partition number (2-128, default 2): First sector (6144-250069646, default 6144): Last sector, +/-sectors or +/-size{K,M,G,T,P} (6144-250069646, default 250069646): +200M Created a new partition 2 of type 'Linux filesystem' and of size 200 MiB. Partition #2 contains a ext2 signature. Do you want to remove the signature? [Y]es/[N]o: y The signature will be removed by a write command. Command (m for help): n Partition number (3-128, default 3): First sector (415744-250069646, default 415744): Last sector, +/-sectors or +/-size{K,M,G,T,P} (415744-250069646, default 250069646): +8G Created a new partition 3 of type 'Linux filesystem' and of size 8 GiB. Partition #3 contains a swap signature. Do you want to remove the signature? [Y]es/[N]o: y The signature will be removed by a write command. Command (m for help): n Partition number (4-128, default 4): First sector (17192960-250069646, default 17192960): Last sector, +/-sectors or +/-size{K,M,G,T,P} (17192960-250069646, default 250069646): Created a new partition 4 of type 'Linux filesystem' and of size 111 GiB. Partition #4 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o: y The signature will be removed by a write command. Command (m for help): Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
- 首先我們創建一個 2MB 大小的分區
格式化分區
root@archiso ~ # partprobe /dev/sda 1 root@archiso ~ # mkfs.ext4 /dev/sda1 root@archiso ~ # mkfs.ext2 /dev/sda2 root@archiso ~ # mkswap /dev/sda3 root@archiso ~ # mkfs.ext4 /dev/sda4
掛載文件系統
分區 掛載點 sda4 / sda2 /boot sda3 swap root@archiso ~ # mount /dev/sda4 /mnt root@archiso ~ # mkdir /mnt/boot root@archiso ~ # mount /dev/sda2 /mnt/boot root@archiso ~ # swapon /dev/sda3 root@archiso ~ # swapon -a root@archiso ~ # swapon -s Filename Type Size Used Priority /dev/sda3 partition 8388604 0 -2 root@archiso ~ #
因為我們在步驟 14 有重啟過系統,需要再次執行步驟 8,配置源。
刷新源
root@archiso ~ # pacman -Syy
安裝基本的 package
root@archiso ~ # pacstrap /mnt base base-devel
註:此步稍費時,去喝杯咖啡~
chroot
環境下的配置:root@archiso ~ # arch-chroot /mnt [root@archiso /]# pacman -S vim
註:安裝 vim 編輯器,利於編輯(可選擇任意你喜歡的編輯器即可)。
時區、時間配置
[root@archiso /]# ln -sf /usr/share/zoneinfo/Asia/Beijing /etc/localtime [root@archiso /]# hwclock --systohc
主機名配置
[root@archiso /]# vim /etc/hostname
本地化設置
[root@archiso /]# vim /etc/locale.gen
把 locale.gen 文件內的
#en_US.UTF-8 UTF-8 #zh_CN.UTF-8 UTF-8
前邊的註釋符號
#
刪除,使該語句生效。en_US.UTF-8 UTF-8 zh_CN.UTF-8 UTF-8
執行下列語句使步驟 3 生效
[root@archiso /]# locale-gen
配置
fstab
。執行此步驟需要暫時退出arch-chroot
。[root@archiso /]# exit exit arch-chroot /mnt 7.39s user 0.86s system 0% cpu 18:25.04 total root@archiso ~ # genfstab -U /mnt > /mnt/etc/fstab root@archiso ~ # cat /mnt/etc/fstab # /dev/sda4 UUID=cc6af4fb-f72b-47a2-9a41-6e5253bf0167 / ext4 rw,relatime 0 1 # /dev/sda2 UUID=bce9b3fa-b6ad-45ad-918f-5b3a46b3a04d /boot ext2 rw,relatime,block_validity,barrier,user_xattr,acl 0 2 # /dev/sda3 UUID=c9b5a804-988b-4a7c-8519-a1e3fe63554c none swap defaults,pri=-2 0 0 root@archiso ~ #
配置
grub
。需要再次進入arch-chroot
root@archiso ~ # arch-chroot /mnt [root@archiso /]# pacman -S grub
網絡配置
我們可以安裝
networkmanager
包來管理我們的網絡:[root@archiso /]# pacman -S networkmanager
啟用
NetworkManager
:[root@archiso /]# sudo systemctl enable NetworkManager [root@archiso /]# sudo systemctl start NetworkManager
安裝
openssh
並設置為開機啟動[root@archiso /]# pacman -S openssh [root@archiso /]# sudo systemctl enable sshd Created symlink /etc/systemd/system/multi-user.target.wants/sshd.service → /usr/lib/systemd/system/sshd.service. [root@archiso /]# sudo systemctl start sshd Running in chroot, ignoring request: start
用戶及權限配置
設置 root 用戶密碼
[root@archiso /]# passwd New password: Retype new password: passwd: password updated successfully
配置 sudoers 文件
[root@archiso /]# vim /etc/sudoers
將
# %wheel ALL=(ALL) NOPASSWD: ALL
語句前邊的註釋符#
刪掉,:q!
強制保存退出。添加一個與 root 同一個組的用戶,並給該用戶創建密碼
[root@archiso /]# useradd -m -G wheel eric [root@archiso /]# id eric uid=1000(eric) gid=1000(eric) groups=1000(eric),998(wheel) [root@archiso /]# passwd eric New password: Retype new password: passwd: password updated successfully [root@archiso /]#
再次配置
grub
[root@archiso /]# grub-install /dev/sda Installing for i386-pc platform. grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible. grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.. grub-install: error: will not proceed with blocklists.
發現執行錯誤。參考此帖,這裏也是解釋了為什麽步驟 19-1 我們要分配 2M 的分區
/dev/sda1
。執行:
[root@archiso /]# pacman -S parted [root@archiso /]# parted /dev/sda set 1 bios_grub on Information: You may need to update /etc/fstab. [root@archiso /]# parted /dev/sda print Model: ATA Lenovo SSD SL700 (scsi) Disk /dev/sda: 128GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 3146kB 2097kB ext4 bios_grub 2 3146kB 213MB 210MB ext2 3 213MB 8803MB 8590MB linux-swap(v1) 4 8803MB 128GB 119GB ext4 [root@archiso /]#
再次執行下列語句
[root@archiso /]# grub-install /dev/sda Installing for i386-pc platform. Installation finished. No error reported. [root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-linux Found initrd image: /boot/initramfs-linux.img Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img done [root@archiso /]#
成功。
安裝
neofetch
[root@archiso /]# pacman -S neofetch
通過下邊這條命令我們發現 arch Linux 基本已經安裝好了:
[root@archiso /]# neofetch -` root@archiso .o+` ------------ `ooo/ OS: Arch Linux x86_64 `+oooo: Host: IdeaPad Y460 Rev 1.0 `+oooooo: Kernel: 4.20.6-arch1-1-ARCH -+oooooo+: Uptime: 2 hours, 9 mins `/:-:++oooo+: Packages: 186 (pacman) `/++++/+++++++: Shell: bash 5.0.0 `/++++++++++++++: Terminal: /dev/pts/0 `/+++ooooooooooooo/` CPU: Intel i3 M 380 (4) @ 2.533GHz ./ooosssso++osssssso+` GPU: Intel Core Processor .oossssso-````/ossssss+` GPU: NVIDIA GeForce GT 425M -osssssso. :ssssssso. Memory: 247MiB / 3743MiB :osssssss/ osssso+++. /ossssssss/ +ssssooo/- `/ossssso+/:- -:/+osssso+- `+sso+:-` `.-/+oso: `++:. `-/+/ .` `/ [root@archiso /]#
退出
arch-chroot
環境。配置NetworkManager
和openssh
開機自啟[root@archiso /]# exit exit arch-chroot /mnt 9.40s user 4.36s system 0% cpu 1:02:26.92 total root@archiso ~ # sudo systemctl start NetworkManager Failed to start NetworkManager.service: Unit NetworkManager.service not found. 5 root@archiso ~ # sudo systemctl start sshd :( root@archiso ~ #
關閉
/mnt
下的所有掛載點,重啟計算機root@archiso ~ # umount -R /mnt root@archiso ~ # reboot
註:
reboot
命令執行會關閉待裝主機,主機關機時(重啟前)拔下 U 盤。如果沒來得及拔掉,直接用物理關機鍵強制關機,拔下 U 盤,然後開機。
留作擴充
參考帖子
Archlinux安裝第一部分
解決Linux安裝過程中不能安裝Grub的問題
以官方Wiki的方式安裝ArchLinux
Arch Linux 怎麽安裝?
arch Linux(一)