Archlinux Installation Guide

准备工作

镜像下载 && 启动盘制作

镜像文件可以直接从官方网站上下载。
下载完成后,Windows用户可以用Ultraiso制作启动盘,Linux用户可以用dd制作启动盘,具体如下:

# dd if=*.iso of=/dev/sd*

其中if表示输入文件,of表示输出文件,/dev/sd*表示U盘。具体参数要根据实际情况确定。

开始安装 && 分区操作

使用U盘启动系统,进入命令行界面后,用以下命令查看硬盘状态:

# parted -l

从硬盘列表中找到希望安装到的硬盘,假设为/dev/sda,那么可以用以下命令进行分区操作:

# parted /dev/sda

一般来说,Linux只需要分出/主分区和swap分区,当然也可以根据个人需要分出/home/boot等分区。对于内存在2GiB以下的电脑,建议将swap分区的大小设为实际内存大小的2倍,其他电脑只需设为实际内存大小。关于parted的使用,这里不再赘述。
分区后需进行格式化。假设将/dev/sda1设为/主分区,/dev/sda2设为/home分区,/dev/sda3设为swap分区,执行以下命令来格式化:

# mkfs.ext4 /dev/sda1
# mkfs.ext4 /dev/sda2
# mkswap /dev/sda3
# swapon /dev/sda3

将分区挂载到Linux根目录下:

# mount /dev/sda1 /mnt
# mkdir /mnt/home
# mount /dev/sda2 /mnt/home

如果BIOS是UEFI的,还需要用parted创建EFI分区(假设为/dev/sda4),并进行以下操作:

# mkfs.vfat -F32 /dev/sda4
# mkdir -p /mnt/boot/efi
# mount /dev/sda4 /mnt/boot/efi

准备工作完成。

安装系统

安装过程中需要网络,可以使用以下命令连接WiFi:

# wifi-menu

有线网的连接方法将在后面提及。
使用以下命令编辑/etc/pacman.conf(vim使用方法不再赘述):

# vim /etc/pacman.conf

在文件最后添加一段:

[archlinuxcn]
SigLevel = Optional TrustAll
Server   = https://mirrors.ustc.edu.cn/archlinuxcn/$arch

接着,需要将/etc/pacman.d/mirrorlist中非China的源删去(因为外国源访问速度较慢)。
使用以下命令更新源:

# pacman -Syy

安装基本系统:

# pacstrap /mnt base base-devel

此过程持续时间较长,需要耐心等待。
生成fstab:

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

切换主目录:

# arch-chroot /mnt /bin/bash

这时命令提示符会发生变化。首先安装vim:

pacman -S vim

接下来设置语言环境,创建/etc/locale.conf,添加一行LANG=en_US.UTF-8,修改/etc/locale.gen,把en_US.UTF-8 UTF-8zh_CN.GBK GBKzh_CN.UTF-8 UTF-8zh_CN GB2312前面的注释去掉。使用以下命令更新语言环境:

# locale-gen

设置时间:

# rm /etc/localtime
# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# hwclock --systohc --utc

设置主机名以及root密码:

# vim /etc/hostname
# passwd

安装net工具:

# pacman -S net-tools dnsutils inetutils iproute2 dialog

安装GRUB:

For BIOS:

# pacman -S grub os-prober
# grub-install --recheck /dev/sda
# grub-mkconfig -o /boot/grub/grub.cfg

For UEFI:

# pacman -S dosfstools grub efibootmgr
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --recheck
# grub-mkconfig -o /boot/grub/grub.cfg

卸载分区:

# exit
# umount /mnt/home
# umount /mnt
# reboot

安装系统完成。重启后,输入root和密码即可进入系统。

基本配置

配置有线网络:
使用ifconfig查看网卡信息,假设有线网卡名为eth0。创建/etc/systemd/network/eth0.network,添加以下内容:

[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1

创建/etc/systemd/resolved.conf,添加以下内容:

[Resolve]
DNS=114.114.114.114

执行以下命令:

# rm -f /etc/resolv.conf
# ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
# systemctl disable netctl.service
# systemctl enable systemd-networkd.service
# systemctl enable systemd-resolved.service
# reboot

即可正常使用有线网。
添加用户:

# useradd -m -k /etc/skel -G users,wheel YourName
# passwd YourName

安装Xorg以及字体:

# pacman -S xorg xorg-server xorg-xinit xorg-twm xtrem ttf-dejavu wqy-zenhei wqy-microhei

安装触摸板驱动:

# pacman -S xf86-input-libinput xorg-xinput
# libinput list-devices

安装显卡驱动:

For Intel:

# pacman -S xf86-video-intel

For Nvidia:

# pacman -S xf86-video-nouveau

For ATi:

# pacman -S xf86-video-ati

安装压缩软件:

# pacman -S p7zip zip unzip rar unrar

安装NTFS支持:

# pacman -S ntfs-3g

同步网络时间:

# pacman -S ntp
# systemctl enable ntpd

安装桌面环境:

For Gnome:

# pacman -S gnome gnome-extra gdm
# systemctl enable gdm

For KDE:

# pacman -S plasma sddm
# systemctl enable sddm

For Deepin:

# pacman -S deepin deepin-extra lightdm

For i3wm:

# pacman -S i3-gaps i3status i3blocks i3lock

配置startx:
编辑/etc/X11/xinit/xinitrc,注释掉以下内容:

twm &
xclock -geometry 50x50-1+1 &
xterm -geometry 80x50+494+51 &
xterm -geometry 80x20+494-0 &
exec xterm -geometry 80x66+0+0 -name login

添加以下内容:

For Gnome:

exec gnome-session

For KDE:

exec startkde

For i3wm:

exec i3

保存后就可以用startx进入桌面了。

后续优化

yaourt

/etc/pacman.conf最后添加一段:

[archlinuxcn]
SigLevel = Optional TrustAll
Server   = https://mirrors.ustc.edu.cn/archlinuxcn/$arch

更新源,然后执行:

# pacman -S yaourt

fcitx

使用以下命令安装fcitx:

# pacman -S fcitx fcitx-im fcitx-libpinyin

创建~/.xprofile,添加一段:

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"

然后使用fcitx设置进行配置即可。

chromium

使用以下命令安装chromium以及flash插件:

# pacman -S chromium pepper-flash

总结

Archlinux的核心理念就是KISS原则(Keep It Simple, Stupid)。这个原则就是让系统保持简单。而这里的简单却不是所谓的开箱即用(out-of-the-box),而是让默认的软件与配置“能少就少”。Arch还拥有非常强大的包管理器pacman以及社区用户软件仓库AUR,软件几乎应有尽有。Arch的wiki也是所有发行版中做的最好最全面的。它还支持滚动升级,一次安装可以永久使用。当然,更重要的是用户可以从中学到很多:用户几乎是从零开始安装整个系统,包括硬盘分区、设置语言及时区、安装软件包等等。只有亲手操作一遍后,才会了解Linux发行版的安装方式。另外,因为所有软件都是用户自己安装的,如果某个软件出了问题,可以自己尝试调试,或者卸载重装,这并不会影响操作系统本身。

My .conkyrc

use_spacer right
use_xft yes
font Microsoft YaHei:size=8
xftfont Microsoft YaHei:size=8
override_utf8_locale yes
update_interval 1.0
own_window yes
own_window_type desktop
own_window_transparent yes
#own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
own_window_argb_visual yes
own_window_argb_value 120
double_buffer yes
minimum_size 206 5
maximum_width 400
draw_shades yes
draw_outline no
draw_borders no
draw_graph_borders no
default_color ffffff
default_shade_color 000000
default_outline_color 000000
alignment top_right
gap_x 5
gap_y 35
cpu_avg_samples 2
uppercase no # set to yes if you want all text to be in uppercase

TEXT
${font Microsoft YaHei:style=Bold:pixelsize=22}${alignc}${time %H:%M:%S}
${font Microsoft YaHei:pixelsize=16}${alignc}${time %b%d日星期%a}${alignc}
${color #ffa200}${hr 2}
${font Microsoft YaHei:pixelsize=12}
${color #00ffcf}主机名:${color #00ffcf} $alignr$nodename
${color #00ffcf}内核: ${color #00ffcf}$alignr$kernel
${color #00ffcf}已运行时间: ${color #00ffcf}$alignr$uptime
${color #ffd700}${stippled_hr 1}
${font Microsoft YaHei:pixelsize=12}
${color #00ff1e}CPU 0: ${cpu cpu0}% $alignr$acpitemp°C(T)
${color #dcff82}${cpubar 8 cpu0}
${color #00ff1e}CPU 1: ${cpu cpu1}% 
${color #dcff82}${cpubar 8 cpu1}
${color #00ff1e}CPU占用:$alignr CPU%
${color #ddaa00} ${top name 1}$alignr${top cpu 1}
${color lightgrey} ${top name 2}$alignr${top cpu 2}
${color lightgrey} ${top name 3}$alignr${top cpu 3}
${color #ffd700}${stippled_hr 1}$color
${font Microsoft YaHei:pixelsize=12}
${color #00ff1e}SAM: $mem $alignr${color #db7093}$memperc%
${color #78af78}${membar 8}
${color #00ff1e}SWAP: $swap $alignr ${color #db7093}$swapperc%
${color #78af78}${swapbar 8}
${color #00ff1e}内存占用: $alignr MEM% 
${color #ddaa00} ${top_mem name 1}$alignr ${top_mem mem 1}
${color lightgrey} ${top_mem name 2}$alignr ${top_mem mem 2}
${color lightgrey} ${top_mem name 3}$alignr ${top_mem mem 3}
${color #ffd700}${stippled_hr 1}$color
${font Microsoft YaHei:pixelsize=12}
${color #00ff1e}硬盘读取速度:${alignr}${diskio_read}
${color #00ff1e}硬盘写入速度:${alignr}${diskio_write}
${color #ffd700}${stippled_hr 1}$color
${font Microsoft YaHei:pixelsize=12}
${color #00ff1e}网络 $alignr ${color #00ff1e}IP地址: ${color DDAA00}${addr enp3s0}
${voffset 1}${color #98c2c7} 上传: ${color #db7093}${upspeed enp3s0}/s ${alignr}${color #98c2c7}总共: ${color #db7093}${totalup enp3s0}
${voffset 1}${color #98c2c7} 下载: ${color #ddaa00}${downspeed enp3s0}/s ${alignr}${color #98c2c7}总共: ${color #ddaa00}${totaldown enp3s0}
${font Microsoft YaHei:pixelsize=12}
${color #ffa200}${hr 2}

My .vimrc

" Basis
"set cul
set nowrap
set mouse=a
"set paste
set history=1000
set bg=dark
syntax on
set ai
set cin
set sw=2
set sts=2
set ts=2
set nu
set si
set sm
set nobk
"set guioptions-=T
"set guioptions-=m
set ignorecase smartcase
set vb t_vb=
set ruler
set magic
set nohls
set incsearch
set et
set sta
"set spell
"set ww=b,s,h,l,<,>,~,[,]
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set ambiwidth=double
set cino=:0g0t0(sus
set selection=inclusive
set keymodel=startsel,stopsel
"set wildmenu
"set cmdheight=1
"set laststatus=2
"set statusline=\ %<%F[%1<em>%M%</em>%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %l/%L:%c%)
"set foldenable
"set foldmethod=syntax
"set foldcolumn=0
"setlocal foldlevel=1
"set foldclose=all
"nnoremap <space> @=((foldclosed(line('.')) < -3) ? 'zc' : 'zo')<cr>
colorscheme delek</cr></space>

" Plugins
set nocp
filetype off

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'sCRooloose/nerdtree'
Plugin 'Valloric/YouCompleteMe'
Plugin 'vim-syntastic/syntastic'
Plugin 'easymotion/vim-easymotion'
Plugin 'fholgado/minibufexpl.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-sCRipts/taglist.vim'
Plugin 'majutsushi/tagbar'
Plugin 'Yggdroot/indentLine'
Plugin 'Yggdroot/vim-mark'
Plugin 'kien/ctrlp.vim'
Plugin 'sCRooloose/nerdcommenter'
Plugin 'sjl/gundo.vim'
Plugin 'godlygeek/tabular'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
"Plugin 'tpope/vim-fugitive'
" plugin from http://vim-sCRipts.org/vim/sCRipts.html
"Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim sCRipt is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstaCRuz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
"Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append <code>!</code> to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append <code>!</code> to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append <code>!</code> to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

let mapleader=","

let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
nnoremap <leader>gt :YcmCompleter GoToDefinitionElseDeclaration<cr></cr></leader>

let g:EasyMotion_smartcase = 1
nnoremap <leader><leader>h <plug>(easymotion-linebackward)
nnoremap <leader><leader>j <plug>(easymotion-j)
nnoremap <leader><leader>k <plug>(easymotion-k)
nnoremap <leader><leader>l <plug>(easymotion-lineforward)
nnoremap <leader><leader>. <plug>(easymotion-repeat)</plug></leader></leader></plug></leader></leader></plug></leader></leader></plug></leader></leader></plug></leader></leader>

let g:syntastic_enable_signs = 1
let g:syntastic_error_symbol = '!'
let g:syntastic_warning_symbol = '?'
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_enable_highlighting = 1

nnoremap <leader>a= :Tabularize /=<cr>
vnoremap <leader>a= :Tabularize /=<cr>
nnoremap <leader>a: :Tabularize /:\zs<cr>
vnoremap <leader>a: :Tabularize /:\zs<cr></cr></leader></cr></leader></cr></leader></cr></leader>

nnoremap <f2> :NERDTreeToggle<cr>
nnoremap <f3> :TlistToggle<cr>
nnoremap <f4> :TagbarToggle<cr>
nnoremap <f5> :GundoToggle<cr>
nnoremap <f7> :w<cr>:!clang++ -std=c++11 % -o %< && time ./%<<cr>
nnoremap <f9> :MBEbp<cr>
nnoremap <f10> :MBEbn<cr></cr></f10></cr></f9></cr></cr></f7></cr></f5></cr></f4></cr></f3></cr></f2>

inoremap ; ;<esc>a
inoremap ' <c-r>=QuoteDelim("'")<cr><esc>a
inoremap " <c-r>=QuoteDelim('"')<cr><esc>a
inoremap ( ()<esc>i
inoremap ) <c-r>=ClosePair(')')<cr><esc>a
inoremap [ []<esc>i
inoremap ] <c-r>=ClosePair(']')<cr><esc>a
inoremap { {<cr>}<esc>O
"inoremap } <c-r>=CloseBracket()<cr></cr></c-r></esc></cr></esc></cr></c-r></esc></esc></cr></c-r></esc></esc></cr></c-r></esc></cr></c-r></esc>

function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<right>"
else
return a:char
endif
endf</right>

function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<cr>}"
else
return "\<esc>j0f}a"
endif
endf</esc></cr>

function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\"
return a:char
elseif line[col - 1] == a:char
return "\<right>"
else
return a:char.a:char."\<esc>i"
endif
endf