您的位置:首页 > 运维架构 > Linux

Archlinux安装简介

2012-07-16 17:11 387 查看
今天从http://releng.archlinux.org/isos/2012.07.16_04-00-01下载了最新的archlinux安装盘,发现现在仅仅提供netinstall形式的安装盘。启动后安装,发现熟悉的/arch/setup已经不再存在。询问万能的Google同学后,得知这是新的安装方法(为啥要换呢?难道老的方式不好维护了?),现记录下来。

 

Step 1

准备好磁盘用户安装,创建磁盘分许与文件系统。如果需要使用LVM/RAID类似的功能,同样创建之。

[code] cfdisk /dev/sda


mkfs.ext4 -L ROOT /dev/sda1


mkswap -L SWAP /dev/sda2

[/code]

Step 2

根据文件系统,挂载root分区到/mnt,当然同样包含其他需要使用的相应分区。例如,mount /dev/sda1 /mnt/boot

[code] mount /dev/sda1 /mnt


swapon /dev/sda2

[/code]

Step 3

连接因特网用于过去软件包,dhcpcd之。

修改mirrorlist到mirrors.163.com,这是我获取仓库最快的地址。

[code]# Add "Server = http://mirrors.163.com/archlinux/$repo/os/$arch"[/code] 
vi /etc/pacman.d/mirrorlist

[/code]

Step 4

下载软件包并安装,这是最重要的一个环节。使用pacstrap /mnt base{,-devel} [more packages...],其根基是pacman。pacstrap是一个bash脚本,咱们看看就知道它都干了什么。

[code]#!/bin/bash


 


#


# Assumptions:


#  1) User has partitioned, formatted, and mounted partitions on /mnt


#  2) Network is functional


#  3) Arguments passed to the script are valid pacman targets


#  4) A valid mirror appears in /etc/pacman.d/mirrorlist


#


 


shopt -s extglob


 


out() { printf "$1 $2\n" "${@:3}";}


error() { out "==> ERROR:" "$@";} >&2


msg() { out "==>" "$@";}


msg2() { out "  ->" "$@";}


die() { error "$@";exit 1;}


 


in_array() {


local i


for i in "${@:2}"; do


[[ $1 = "$i" ]] && return


done


}


 


api_fs_mount() {


if ! mountpoint -q "$1"; then


mount -B "$1" "$1" && ROOT_IS_BIND=1


fi &&


mount -t proc proc "$1/proc" -o nosuid,noexec,nodev &&


mount -t sysfs sys "$1/sys" -o nosuid,noexec,nodev &&


mount -t devtmpfs udev "$1/dev" -o mode=0755,nosuid &&


mount -t devpts devpts "$1/dev/pts" -o mode=0620,gid=5,nosuid,noexec &&


mount -t tmpfs shm "$1/dev/shm" -o mode=1777,nosuid,nodev &&


mount -t tmpfs run "$1/run" -o nosuid,nodev,mode=0755 &&


mount -t tmpfs tmp "$1/tmp" -o mode=1777,strictatime,nodev,nosuid,size=50M


}


 


api_fs_umount() {


umount \


"$1/tmp" \


"$1/run" \


"$1/dev/shm" \


"$1/dev/pts" \


"$1/dev" \


"$1/sys" \


"$1/proc"


 


(( ROOT_IS_BIND )) && umount "$1"


}


 


valid_number_of_base() {


local base=$1 len=${#2} i=


 


for (( i = 0; i < len; i++ )); do


(( (${2:i:1} & ~(base - 1)) == 0 )) || return


done


}


 


mangle() {


local i= chr= out=


 


unset {a..f} {A..F}


 


for (( i = 0; i < ${#1}; i++ )); do


chr=${1:i:1}


case $chr in


[[:space:]\\])


printf -v chr '%03o' "'$chr"


out+=\\


;;&


       # fallthrough


*)


out+=$chr


;;


esac


done


 


printf '%s' "$out"


}


 


unmangle() {


local i= chr= out= len=$(( ${#1} - 4 ))


 


unset {a..f} {A..F}


 


for (( i = 0; i < len; i++ )); do


chr=${1:i:1}


case $chr in


\\)


if valid_number_of_base 8 "${1:i+1:3}" ||


valid_number_of_base 16 "${1:i+1:3}"; then


printf -v chr '%b' "${1:i:4}"


(( i += 3 ))


fi


;;&


       # fallthrough


*)


out+=$chr


esac


done


 


printf '%s' "$out${1:i}"


}


 


fstype_is_pseudofs() {


 # list taken from util-linux source: libmount/src/utils.c


local pseudofs_types=('anon_inodefs'


'autofs'


'bdev'


'binfmt_misc'


'cgroup'


'configfs'


'cpuset'


'debugfs'


'devfs'


'devpts'


'devtmpfs'


'dlmfs'


'fuse.gvfs-fuse-daemon'


'fusectl'


'hugetlbfs'


'mqueue'


'nfsd'


'none'


'pipefs'


'proc'


'pstore'


'ramfs'


'rootfs'


'rpc_pipefs'


'securityfs'


'sockfs'


'spufs'


'sysfs'


'tmpfs')


in_array "$1" "${pseudofs_types[@]}"


}


 


 


 


newroot=/mnt


hostcache=0


 


usage() {


cat <<EOF


usage: ${0##*/} [options] root [packages...]


 


Options:


-c             Use the package cache on the host, rather than the target


-d             Allow installation to a non-mountpoint directory


 


pacstrap installs packages to the specified new root directory. If no packages


are given, pacstrap defaults to the "base" group.


 


EOF


}


 


if [[ -z $1 || $1 = @(-h|--help) ]]; then


usage


exit $(( $# ? 0 : 1 ))


fi


 


(( EUID == 0 )) || die 'This script must be run with root privileges'


 


while getopts ':cd' flag; do


case $flag in


d)


directory=1


;;


c)


hostcache=1


;;


:)


die '%s: option requires an argument -- '\''%s'\' "${0##*/}" "$OPTARG"


;;


?)


die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"


;;


esac


done


shift $(( OPTIND - 1 ))


 


(( $# )) || die "No root directory specified"


newroot=$1; shift


pacman_args=("${@:-base}")


 


if (( ! hostcache )); then


pacman_args+=(--cachedir="$newroot/var/cache/pacman/pkg")


fi


 


[[ -d $newroot ]] || die "%s is not a directory" "$newroot"


if ! mountpoint -q "$newroot" && (( ! directory )); then


die '%s is not a mountpoint!' "$newroot"


fi


 


# create obligatory directories


msg 'Creating install root at %s' "$newroot"


mkdir -p "$newroot/var/lib/pacman" "$newroot"/{dev,proc,sys,run,tmp,etc}


 


# always call umount on quit after this point


trap 'api_fs_umount "$newroot" 2>/dev/null' EXIT


 


# mount APIfilesystems


 api_fs_mount "$newroot" || die "failed to setup APIfilesystems in new root"


 


msg 'Installing packages to %s' "$newroot"


if ! pacman -r "$newroot" -Sy --noconfirm "${pacman_args[@]}"; then


die 'Failed to install packages to new root'


fi


 


# if there's a keyring on the host, copy it into the new root, unless it exists already


if [[ -d /etc/pacman.d/gnupg && ! -d $newroot/etc/pacman.d/gnupg ]]; then


cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"


fi


 


# install the host's mirrorlist onto the new root


cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"


 


# vim: et ts=2 sw=2 ft=sh:

[/code]

我的操作命令是

[code] pacstrap /mnt base syslinux vim

[/code]

Step 5

如果你忘记安装了必要的包,现在可以通过如下指令补救:

[code] pacman -r /mnt -Sy package

[/code]

在漫长的等待之后,基本上接下来的工作就是系统配置了。首先,我们切换root目录

[code]arch-chroot /mnt

[/code]

Setp 6

配置bootloader,我这里使用syslinux

[code] syslinux-install_update -iam


vim /boot/syslinux/syslinux.cfg

[/code]

Step 7

配置系统


[code]exit#exit arch-chroot


genfstab -p /mnt >> /mnt/etc/fstab


arch-chroot /mnt


cd /etc


echo "hostname" > hostname


echo "en_US.UTF-8" > locale.conf


vi locale.gen


locale-gen


ln -s /usr/share/zoneinfo/Zone/Subzone localtime


exit


cp /etc/mkinitcpio.conf /mnt/etc/


arch-chroot /mnt


mkinitcpio -p linux


exit


umount /mnt


reboot

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: