参考 [Josh Braun 的博客](http://wideaperture.net/blog/?p=3851) 来在 VirtualBox 上安装 Arch Linux。
## 准备磁盘
使用 VirtualBox 来创建虚拟机的第一件事就是挂载一块虚拟磁盘和一张 Linux 发行版的 ISO 文件。为这块虚拟磁盘划分空间并格式化存储区很自然就成为了第一道坎。
先根据磁盘的总大小做规划,例如,我的虚拟磁盘一共是 16GB,被划分为这么几个分区:
+ Boot loader partition
BIOS启动的时候需要查找一些程序用于计算机自举。Boot loader partition 就是存放这类程序的地方。通常BIOS会在 MBR (Master Boot Record) 查找boot loader,MBR 是在驱动器开始处的一块小区域。
+ /boot partition
lilo 和 grub 都是 boot loader,后者比较大一些。BIOS 在找到这块区域之后,会读入一些代码,继而从磁盘分区(通常是 `/boot` 分区)内读入更多的代码。
+ root partition
这就是最基本的 `/` 分区,如果不特别创建 `/var`、`/usr` 或是 `/home` 等挂载点的话,大部分文件都是存放在这个分区内的。
## 分区
使用 `gdisk` 来创建新的 partition tables,
+ `?` - print the help information
+ `l` - list all types
+ `n` - create a new partition, required arguments include partition number, first sector, last sector and hex code for type
+ `w` - write the partition tables to disk
可以参考[这里](http://www.taylorbyte.com/docs/wiki/archlinux/arch-install-gpt-ssd)
/dev/sda 12G
sda1 16MB for boot loader
sda2 256MB for `/boot`
sda3 11GB+ for `/`
/dev/sdb 8G
sdb1 8GB for `/home`
这样 GPT partition 就创建好了,可以使用 `fdisk` 或是 `lsblk` 命令来查看
fdisk -l /dev/sda
然后使用 `mkfs` 命令来格式化分区
# /dev/sda1 is reserved for GRUB boot loader (16M)
mkfs.ext2 /dev/sda2
mkfs.ext4 /dev/sda3
mkfs.ext4 /dev/sda4
接着可以创建 `/mnt` 来挂载新的驱动器:
mount /dev/sda3 /mnt
mkdir /mnt/boot && mount /dev/sda2 /mnt/boot
mkdir /mnt/home && mount /dev/sdb1 /mnt/home
## 初始化系统
Arch Linux 将被安装在 root partition 上,由于当前该分区被挂在在 `/mnt` 路径下,所以要执行以下命令来安装 `base` 和 `base-devel` 包:
cd / && pacstrap /mnt base base-devel
安装好了之后将 `fstab` 保存到系统中,这样在重启之后系统才能顺利找到 root partition 并从中加载 Linux kernel 来启动。
genfstab -p /mnt >> /mnt/etc/fstab
接着可以进入准系统来进行配置,但问题是 boot loader 还没有安装,所以暂时无法重新启动进入新的系统。好在可以直接以 `arch-chroot` 命令来切换至新的系统而无需重启。
arch-chroot /mnt /bin/bash
# 配置机器名
echo ARCH2015 > /etc/hostname
# 配置系统的时区
ln -sf /usr/share/zoneinfo/Australia/Melbourne /etc/localtime
# 编辑系统的 locale
vi /etc/locale.gen
locale-gen
# 并指定默认的 locale
echo LANG=en_US.UTF-8 > /etc/locale.conf
在继续安装之前,需要确保修改 `/etc/pacman.d/mirrorlist` 文件指向本地区的服务器,这样才能达到较快的安装速度。
## 安装 boot loader
将 GRUB 安装到 GPT 分区上,可以参考 [Archlinux Wiki](https://wiki.archlinux.org/index.php/Beginners%27_guide#For_BIOS_motherboards)
pacman -S grub os-prober
# Install the boot loader to the driver where Arch was installed to
grub-install --target=i386-pc --recheck --debug /dev/sda
# Automatically generate grub.cfg
grub-mkconfig -o /boot/grub/grub.cfg
最后还可以执行以下命令来设置初始化的 ramdisk,这样在计算机第一次启动的时候就会将系统的内存作为disk。
mkinitcpio -p linux
## 收工重启
推出新系统,
exit
将挂载的分区都卸载下来,
umount /mnt/home
umount /mnt/boot
umount /mnt
并将 `/boot` 分区的 BIOS flag 设置为 `bootable` 这样新的系统在重启之后才会被识别为可以启动的。
sgdisk /dev/sda --attributes=1:set:2
这样就可以收工了:
reboot
## 初见
由于 `dhcpd` 并没有被设置为默认启动,在第一次进入新系统的时候可能无法联网。只需要执行以下命令来允许每次自启动 dhcpd 服务即可:
# run `ip addr`to get Ethernet Interface name, it is not 'eth0' any more
systemctl enable dhcpcd@enp0s3.service
评论