跳至主要内容

ArchLinux in Laptop - Dual OS Boot

手头有一台老笔记本,是2013年买的 Dell XPS14z。去年为她更换过 SSD ,将老的光驱拆了下来挂上了原本的 HDD。这样一共有`700+ GB` 的磁盘空间。去年更新了硬件之后也重灌了 Windows 10系统,时常更新,到目前位置体验都还不错。今天忽然心血来潮,想要做双系统——除了 Win10之外再弄一个 Linux。 14-16年之间在公司的机器上用 Virtualbox安装了 ArchLinux 作为开发环境,Desktop Manager 用的是 XFCE,体验挺不错,因此这次依旧想要使用这套配置。 于是先在 Windows 的 `compmgmt.msc` 里将磁盘卷压缩了一下,SSD 分出了80GB;HDD 上分出了23GB 。然后做了一个 ArchLinux 20190401 ISO 的优盘。Windows 电源选项里取消了关机的快速选项,然后重启,按 F12 到 boot options里面选择优盘进入。 以前在 VirtualBox 里只是一个 partition 挂载为 root(`/`)。这次稍微特殊化了一下,将分区做的多了几个: * `/usr` 推荐大小为12GB - 20GB * `/var` 推荐大小为10GB 左右 * `/home` 自行估计大小 * `/boot` 建议至少 100MB,如果考虑多内核的话,可以到300MB 左右。 用 `fdisk` 分了这几个 partitions,SSD 由于之前已经是4个 primary 所以不能直接 (n)ew,必须先 (d)elete 再创建一个 (e)xtensive 作为容器,在其中可以创建多个 logical partitions。 * `/dev/sda5` (extensive & container, total size 80GB) * `/dev/sda6` (for boot partition, 320MB) * `/dev/sda7` (for root partition, 50GB) * `/dev/sda8` (for usr partition, 18GB) * `/dev/sda9` (for var partition, 12GB) * `/dev/sdb3` (extensive & container, total size 23GB) * `/dev/sdb5` (for home partition, 23GB) 然后 `mkfs.ext4` 执行格式化(除了 boot 分区用的是 `mkfs.ext2` )。挂载的时候使用以下映射: ``` # mkdir /mnt && mount /dev/sda7 /mnt # mkdir /mnt/boot && mount /dev/sda6 /mnt/boot # mkdir /mnt/usr && mount /dev/sda8 /mnt/usr # mkdir /mnt/var && mount /dev/sda9 /mnt/var # mkdir /mnt/home && mount /dev/sdb5 /mnt/home ``` 之后参考以前写的一篇博文,以及网上的一篇攻略来安装: 1. [ArchLinux in VirtualBox](https://jlazy.blogspot.com/2015/05/archlinux-in-virtualbox.html) 2. [一步步教你如何安装 Arch Linux](https://linux.cn/article-9170-1.html) 都安装好(包括做好 grub 的配置)退出 `arch-chroot` 之后执行 `umount -R /mnt` 卸载掉所有的分区,然后 `reboot`。 ## 问题一:Grub可用但系统挂载失败 选择 Grub 的 ArchLinux 菜单项进入,美滋滋的等 login prompt,结果看到以下提示: ``` ERROR: Root device mounted successfully, but /sbin/init does not exist. Bailing out, you are on your own now. Good luck. sh: can't access tty: job control turned off [rootfs /]# _ ``` 做了一番研究后发现 `/sbin/init` 实际指向的是 `/usr/bin/systemd/systemd`,但是 `/usr` 没有正确挂载因此这个 link 是失效的。这正是因为自己手贱做了单独的 partition 给 `/usr`…… 参考 StackOverflow 上的相关问题[Root device mounted successfully, but /sbin/init does not exist](https://unix.stackexchange.com/questions/139802/error-root-device-mounted-successfully-but-sbin-init-does-not-exist#answer-139827),回到 `/etc/fstab` 文件里将 `/dev/sda8` 的 passno (也就是最后一个数字)改为0,表示跳过检查;然后在 `/etc/mkinitcpio.conf` 文件中按照注释添加了3个 hook,包括 `usr`, `fsck` 和 `shutdown`。 然后执行了 `mkinitcpio -p linux` 生成 RAMDISK 镜像,重做了 grub 的配置文件。重启后总算解决了这个问题。 ## 问题二:Grub 没有 Windows 10的菜单项 参考 Grub 的文档,以及网上的这篇攻略 [为 Grub 启动菜单添加 Windows 选项](https://yyjlinux.iteye.com/blog/1611244),编辑了 `/boot/grub/grub.cfg` 里和 `os_prober` 有关的部分: ``` menuentry 'Windows 10' { insmod part_msdos insmod ntfs set root='(hd0,msdos1)' chainloader +1 } ``` 因为我的笔记本不支持 UEFI,所以用的仍旧是 legacy 方式,不需要判断 `"efi"` 相关。`chainloading` 可以很方便地调用另一个操作系统的 boot-loader (例如之前安装的 Win10 就已经有自己的 boot-loader),因此自己不需要管理加载内核等工作。

评论