Archlinux安装简介
今天从http://releng.archlinux.org/isos/2012.07.16_04-00-01下载了最新的archlinux安装盘,发现现在仅仅提供netinstall形式的安装盘。启动后安装,发现熟悉的/arch/setup已经不再存在。询问万能的Google同学后,得知这是新的安装方法(为啥要换呢?难道老的方式不好维护了?),现记录下来。
Step 1
准备好磁盘用户安装,创建磁盘分许与文件系统。如果需要使用LVM/RAID类似的功能,同样创建之。
1: cfdisk /dev/sda
2: mkfs.ext4 -L ROOT /dev/sda1
3: mkswap -L SWAP /dev/sda2
Step 2
根据文件系统,挂载root分区到/mnt,当然同样包含其他需要使用的相应分区。例如,mount /dev/sda1 /mnt/boot
1: mount /dev/sda1 /mnt
2: swapon /dev/sda2
连接因特网用于过去软件包,dhcpcd之。
修改mirrorlist到mirrors.163.com,这是我获取仓库最快的地址。
1: # Add "Server = http://mirrors.163.com/archlinux/$repo/os/$arch"
2: vi /etc/pacman.d/mirrorlist
Step 4
下载软件包并安装,这是最重要的一个环节。使用pacstrap /mnt base{,-devel} [more packages...],其根基是pacman。pacstrap是一个bash脚本,咱们看看就知道它都干了什么。
1: #!/bin/bash
2:
3: #
4: # Assumptions:
5: # 1) User has partitioned, formatted, and mounted partitions on /mnt
6: # 2) Network is functional
7: # 3) Arguments passed to the script are valid pacman targets
8: # 4) A valid mirror appears in /etc/pacman.d/mirrorlist
9: #
10:
11: shopt -s extglob
12:
13: out() { printf "$1 $2\n" "${@:3}"; }
14: error() { out "==> ERROR:" "$@"; } >&2
15: msg() { out "==>" "$@"; }
16: msg2() { out " ->" "$@";}
17: die() { error "$@"; exit 1; }
18:
19: in_array() {
20: local i
21: for i in "${@:2}"; do
22: [[ $1 = "$i" ]] && return
23: done
24: }
25:
26: api_fs_mount() {
27: if ! mountpoint -q "$1"; then
28: mount -B "$1" "$1" && ROOT_IS_BIND=1
29: fi &&
30: mount -t proc proc "$1/proc" -o nosuid,noexec,nodev &&
31: mount -t sysfs sys "$1/sys" -o nosuid,noexec,nodev &&
32: mount -t devtmpfs udev "$1/dev" -o mode=0755,nosuid &&
33: mount -t devpts devpts "$1/dev/pts" -o mode=0620,gid=5,nosuid,noexec &&
34: mount -t tmpfs shm "$1/dev/shm" -o mode=1777,nosuid,nodev &&
35: mount -t tmpfs run "$1/run" -o nosuid,nodev,mode=0755 &&
36: mount -t tmpfs tmp "$1/tmp" -o mode=1777,strictatime,nodev,nosuid,size=50M
37: }
38:
39: api_fs_umount() {
40: umount \
41: "$1/tmp" \
42: "$1/run" \
43: "$1/dev/shm" \
44: "$1/dev/pts" \
45: "$1/dev" \
46: "$1/sys" \
47: "$1/proc"
48:
49: (( ROOT_IS_BIND )) && umount "$1"
50: }
51:
52: valid_number_of_base() {
53: local base=$1 len=${#2} i=
54:
55: for (( i = 0; i < len; i++ )); do
56: (( (${2:i:1} & ~(base - 1)) == 0 )) || return
57: done
58: }
59:
60: mangle() {
61: local i= chr= out=
62:
63: unset {a..f} {A..F}
64:
65: for (( i = 0; i < ${#1}; i++ )); do
66: chr=${1:i:1}
67: case $chr in
68: [[:space:]\\])
69: printf -v chr '%03o' "'$chr"
70: out+=\\
71: ;;&
72: # fallthrough
73: *)
74: out+=$chr
75: ;;
76: esac
77: done
78:
79: printf '%s' "$out"
80: }
81:
82: unmangle() {
83: local i= chr= out= len=$(( ${#1} - 4 ))
84:
85: unset {a..f} {A..F}
86:
87: for (( i = 0; i < len; i++ )); do
88: chr=${1:i:1}
89: case $chr in
90: \\)
91: if valid_number_of_base 8 "${1:i+1:3}" ||
92: valid_number_of_base 16 "${1:i+1:3}"; then
93: printf -v chr '%b' "${1:i:4}"
94: (( i += 3 ))
95: fi
96: ;;&
97: # fallthrough
98: *)
99: out+=$chr
100: esac
101: done
102:
103: printf '%s' "$out${1:i}"
104: }
105:
106: fstype_is_pseudofs() {
107: # list taken from util-linux source: libmount/src/utils.c
108: local pseudofs_types=('anon_inodefs'
109: 'autofs'
110: 'bdev'
111: 'binfmt_misc'
112: 'cgroup'
113: 'configfs'
114: 'cpuset'
115: 'debugfs'
116: 'devfs'
117: 'devpts'
118: 'devtmpfs'
119: 'dlmfs'
120: 'fuse.gvfs-fuse-daemon'
121: 'fusectl'
122: 'hugetlbfs'
123: 'mqueue'
124: 'nfsd'
125: 'none'
126: 'pipefs'
127: 'proc'
128: 'pstore'
129: 'ramfs'
130: 'rootfs'
131: 'rpc_pipefs'
132: 'securityfs'
133: 'sockfs'
134: 'spufs'
135: 'sysfs'
136: 'tmpfs')
137: in_array "$1" "${pseudofs_types[@]}"
138: }
139:
140:
141:
142: newroot=/mnt
143: hostcache=0
144:
145: usage() {
146: cat <<EOF
147: usage: ${0##*/} [options] root [packages...]
148:
149: Options:
150: -c Use the package cache on the host, rather than the target
151: -d Allow installation to a non-mountpoint directory
152:
153: pacstrap installs packages to the specified new root directory. If no packages
154: are given, pacstrap defaults to the "base" group.
155:
156: EOF
157: }
158:
159: if [[ -z $1 || $1 = @(-h|--help) ]]; then
160: usage
161: exit $(( $# ? 0 : 1 ))
162: fi
163:
164: (( EUID == 0 )) || die 'This script must be run with root privileges'
165:
166: while getopts ':cd' flag; do
167: case $flag in
168: d)
169: directory=1
170: ;;
171: c)
172: hostcache=1
173: ;;
174: :)
175: die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"
176: ;;
177: ?)
178: die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
179: ;;
180: esac
181: done
182: shift $(( OPTIND - 1 ))
183:
184: (( $# )) || die "No root directory specified"
185: newroot=$1; shift
186: pacman_args=("${@:-base}")
187:
188: if (( ! hostcache )); then
189: pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")
190: fi
191:
192: [[ -d $newroot ]] || die "%s is not a directory" "$newroot"
193: if ! mountpoint -q "$newroot" && (( ! directory )); then
194: die '%s is not a mountpoint!' "$newroot"
195: fi
196:
197: # create obligatory directories
198: msg 'Creating install root at %s' "$newroot"
199: mkdir -p "$newroot/var/lib/pacman" "$newroot"/{dev,proc,sys,run,tmp,etc}
200:
201: # always call umount on quit after this point
202: trap 'api_fs_umount "$newroot" 2>/dev/null' EXIT
203:
204: # mount API filesystems
205: api_fs_mount "$newroot" || die "failed to setup API filesystems in new root"
206:
207: msg 'Installing packages to %s' "$newroot"
208: if ! pacman -r "$newroot" -Sy --noconfirm "${pacman_args[@]}"; then
209: die 'Failed to install packages to new root'
210: fi
211:
212: # if there's a keyring on the host, copy it into the new root, unless it exists already
213: if [[ -d /etc/pacman.d/gnupg && ! -d $newroot/etc/pacman.d/gnupg ]]; then
214: cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
215: fi
216:
217: # install the host's mirrorlist onto the new root
218: cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
219:
220: # vim: et ts=2 sw=2 ft=sh:
我的操作命令是
1: pacstrap /mnt base syslinux vim
Step 5
如果你忘记安装了必要的包,现在可以通过如下指令补救:
1: pacman -r /mnt -Sy package
在漫长的等待之后,基本上接下来的工作就是系统配置了。首先,我们切换root目录
1: arch-chroot /mnt
Setp 6
配置bootloader,我这里使用syslinux
1: syslinux-install_update -iam
2: vim /boot/syslinux/syslinux.cfg
Step 7
配置系统
1: exit # exit arch-chroot
2: genfstab -p /mnt >> /mnt/etc/fstab
3: arch-chroot /mnt
4: cd /etc
5: echo "hostname" > hostname
6: echo "en_US.UTF-8" > locale.conf
7: vi locale.gen
8: locale-gen
9: ln -s /usr/share/zoneinfo/Zone/Subzone localtime
10: exit
11: cp /etc/mkinitcpio.conf /mnt/etc/
12: arch-chroot /mnt
13: mkinitcpio -p linux
14: exit
15: umount /mnt
16: reboot