虚拟机安装ArchLinux的过程,使用ssh方便复制粘贴。

启动sshd

# 启动sshd服务
systemctl start sshd.service
# 设置ssh登录的root密码
passwd
# 查看ip
ip add

安装过程

root@archiso ~ # ls
install.txt
root@archiso ~ # ls /sys/firmware/efi/efivars
root@archiso ~ # timedatectl set-ntp true
root@archiso ~ # fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop0: 529.67 MiB, 555380736 bytes, 1084728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


root@archiso ~ # fdisk /dev/sda

Welcome to fdisk (util-linux 2.35.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xb921b361.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): g
Created a new GPT disklabel (GUID: B4CE73D7-CB8E-E84F-B3BD-5721A8CECAE0).

Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-41943006, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default 41943006): +256M

Created a new partition 1 of type 'Linux filesystem' and of size 256 MiB.

Command (m for help): n
Partition number (2-128, default 2):
First sector (526336-41943006, default 526336):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (526336-41943006, default 41943006):

Created a new partition 2 of type 'Linux filesystem' and of size 19.8 GiB.

Command (m for help): m

Help:

  GPT
   M   enter protective/hybrid MBR

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): t
Partition number (1,2, default 2): 1
Partition type (type L to list all types): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.
Command (m for help): t
Partition number (1,2, default 2):
Partition type (type L to list all types): 24
Changed type of partition 'Linux filesystem' to 'Linux root (x86-64)'.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@archiso ~ # mkfs.ext4 /dev/sda2
mke2fs 1.45.6 (20-Mar-202:0)
Creating filesystem with 5177083 4k blocks and 1294336 inodes
Filesystem UUID: 0a6eccbf-2065-4d0e-aa66-d8851133f007
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

root@archiso ~ # mkfs.fat /dev/sda1
mkfs.fat 4.1 (2017-01-24)
root@archiso ~ # mount /dev/sda1 /mnt/boot
mount: /mnt/boot: mount point does not exist.
32 root@archiso ~ # mount /dev/sda2 /mnt
root@archiso ~ # mkdir /mnt/boot
root@archiso ~ # mount /dev/sda1 /mnt/boot
root@archiso ~ # vim /etc/pacman.d/mirrorlist
Server = http://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch

root@archiso ~ # pacstrap /mnt base linux linux-firmware dhcpcd vim
root@archiso ~ # genfstab -U /mnt >> /mnt/etc/fstab
root@archiso ~ # cat /mnt/etc/fstab
# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sda2
UUID=0a6eccbf-2065-4d0e-aa66-d8851133f007       /               ext4           rw,relatime      0 1

# /dev/sda1
UUID=0AD1-7225          /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro       0 2

root@archiso ~ # arch-chroot /mnt
[root@archiso /]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@archiso /]# hwclock --systohc
[root@archiso /]# vim /etc/locale.gen
    en_US.UTF-8 UTF-8
    zh_CN.UTF-8 UTF-8
    zh_TW.UTF-8 UTF-8
    
[root@archiso /]# locale-gen
Generating locales...
  en_US.UTF-8... done
  zh_CN.UTF-8... done
  zh_TW.UTF-8... done
Generation complete.
[root@archiso /]# echo LANG=en_US.UTF-8 > /etc/locale.conf
[root@archiso /]# echo modao > /etc/hostname
[root@archiso /]# vim /etc/hosts
# /etc/hosts
127.0.0.1	localhost
::1		localhost
127.0.1.1	modao.localdomain	modao

[root@archiso /]# passwd

[root@archiso /]# pacman -S grub
[root@archiso /]# pacman -S efibootmgr
[root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=ARCHLINUX
Installing for x86_64-efi platform.
Installation finished. No error reported.
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
done
[root@archiso /]# exit
exit
arch-chroot /mnt  8.17s user 2.01s system 1% cpu 11:43.60 total
root@archiso ~ # umount -R /mnt
root@archiso ~ # reboot

命令汇总

ls /sys/firmware/efi/efivars
timedatectl set-ntp true
fdisk -l
fdisk /dev/sda
mkfs.ext4 /dev/sda2
mkfs.fat /dev/sda1
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
echo -e "Server = http://mirrors.ustc.edu.cn/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
pacstrap /mnt base linux linux-firmware dhcpcd vim
genfstab -U /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab
arch-chroot /mnt
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc
echo -e "en_US.UTF-8 UTF-8\nzh_CN.UTF-8 UTF-8\nzh_TW.UTF-8 UTF-8" >  /etc/locale.gen
locale-gen
echo LANG=en_US.UTF-8 > /etc/locale.conf
echo modao > /etc/hostname
echo -e "127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.1.1\tmodao.localdomain\tmodao" > /etc/hosts
passwd
pacman -S grub
pacman -S efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=ARCHLINUX
grub-mkconfig -o /boot/grub/grub.cfg
exit
umount -R /mnt
reboot

配置软件源

中科大-Arch Linux 源使用帮助

中科大-Arch Linux CN 源使用帮助

更新软件数据库

pacman -Syy

安装 archlinuxcn-keyring 包以导入 GPG key

pacman -S archlinuxcn-keyring

更新系统

pacman -Syu

配置桌面

安装xorg

pacman -S xorg
pacman -S xorg-xinit
cp /etc/X11/xinit/xinitrc ~/.xinitrc
pacman -S awesome
pacman -S xterm

配置awesome-wm主题

下载主题时:git clone --recursive 用于循环克隆git子项目

Awesome WM 4.x Ban theme

  • 启动不成功,将配置文件(rc.lua和theme.lua)里的“/home”改成了“/”
  • 修改默认终端为xterm(全小写)
  • 修改主题配置文件里的字体大小
  • 修改rc.lua的快捷键绑定

配置zsh

pacman -S zsh
chsh -s /bin/zsh
pacman -S oh-my-zsh-git
cp /usr/share/oh-my-zsh/zshrc ~/.zshrc
## 修改主题后,重新加载
source ~/.zshrc
## 安装字体
pacman -S ttf-monaco
pacman -S wqy-microhei
! .Xresources
! Xterm settings
! XTerm*vt100*reverseVideo: true

XTerm*vt100.background: black
XTerm*vt100.foreground: white

! copy & paste 
XTerm*VT100.translations: #override <Btn1Up>: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) 

! English font 
xterm*faceName: Monaco:antialias=True:pixelsize=15
! Chinese font 
xterm*faceNameDoublesize:WenQuanYi Micro Hei:antialias=True:pixelsize=15

!input method 
XTerm*inputMethod:fcitx 

! scrollbar 
XTerm*scrollBar: true 
XTerm*rightScrollBar: true 
XTerm*SaveLines: 4096

! Xterm*faceSize: 20
Xterm*VT100*geometry: 100x30

调整屏幕分辨率(可选)

会话中生效

xrandr 作出的改变只在本次会话中有效

分辨率后面带有一个***号和一个+**号

从已有分辨率中选择

xrandr --output HDMI-1 --mode 1920x1080
xrandr --output HDMI-1 --mode 1920x1080 --rate 60
  • --ouput:可用的显示输出设备
  • --mode:已有的分辨率
  • --rate:刷新速率

添加未被检测到的有效分辨率

# 首先,运行gtf或者cvt,查询某分辨率的有效扫描频率。 
cvt 1280 1024
1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz 
Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync 

# 然后通过--newmode参数新建一种xrandr模式,输入上面所得到的查询结果,其中Modeline关键词自然需要被省略。
xrandr --newmode "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync

# 新建模式后,我们需要把这模式添加到当前的输出设备(假定为VGA1)上。由于一些参数已经事先设置,只需输入模式名称即可,即1280x1024_60.00。
xrandr --addmode VGA1 1280x1024_60.00

# 最后,再把VGA1的分辨率指定为刚刚添加的新模式。
xrandr --output VGA1 --mode 1280x1024_60.00   

永久生效

使xrandr定制永久生效的方案有:(详见Arch wiki)

  • xorg.conf(推荐)
  • .xprofile
  • kdm/gdm

xorg.conf设置分辨率:

可以通过 /etc/X11/xorg.conf 配置 Xorg,用下面命令可以生成 xorg.conf 模板:

Xorg :0 -configure

执行后会在 /root/ 生成 xorg.conf.new 文件,然后你可以将它复制到 /etc/X11/xorg.conf

如果已经运行了 X 服务器,请使用不同的 display,例如 Xorg :2 -configure

利用gtf计算参数:

gtf 1920 1080 60

得到结果:

# 1920x1080 @ 60.00 Hz (GTF) hsync: 67.08 kHz; pclk: 172.80 MHz
Modeline "1920x1080_60.00"  172.80  1920 2040 2248 2576  1080 1081 1084 1118  -HSync +Vsync

修改xorg.conf文件:

  • 在Section "Monitor"中,加入:

    Modeline "1920x1080_60.00"  172.80  1920 2040 2248 2576  1080 1081 1084 1118  -HSync +Vsync
    
  • 在Section "Screen"中的 SubSection "Display"中,加入一行:

    Modes   "1920x1080_60.00"
    
  • 最终xorg.conf文件看上去是这样的(无关的Section可以删掉)

    ......(省略)
    
    Section "Monitor"
    	Identifier   "Monitor0"
    	Modeline "1920x1080_60.00"  172.80  1920 2040 2248 2576  1080 1081 1084 1118      -HSync +Vsync
    	Modeline "1888x1020_60.00"  160.17  1888 2008 2208 2528  1020 1021 1024 1056      -HSync +Vsync
        Modeline "1600x860_60.00"  112.78  1600 1688 1856 2112  860 861 864 890  -HSync +Vsync
    	VendorName   "Monitor Vendor"
    	ModelName    "Monitor Model"
    EndSection
    
    ......(省略)
    
    Section "Screen"
        Identifier "Screen0"
        Device     "Card0"
        Monitor    "Monitor0"
        SubSection "Display"
            Viewport   0 0
            Modes   "1920x1080_60.00"
            Depth     24
        EndSubSection
        SubSection "Display"
    		Viewport   0 0
            Modes   "1888x1020_60.00"
            Depth     24
        EndSubSection
        SubSection "Display"
    		Viewport   0 0
            Modes   "1600x860_60.00"
            Depth     24
        EndSubSection
    EndSection
    
    ......(省略)
    

参考资料

通过feh设置壁纸

pacman -S feh
feh --bg-fill master.jpg

通过picom设置窗口透明

pacman -S picom
cp /etc/xdg/picom.conf ~/.config/
vim ~/.config/picom.conf
picom&
# 修改配置,添加规则
# picom.conf

# 非活跃窗口透明度(非当前窗口)
inactive-opacity = 0.5;
# 框体透明度,窗口的标题栏等
frame-opacity = 0.6;
# 默认
inactive-opacity-override = false;
# 活跃窗口透明度(当前窗口)
active-opacity = 0.7

opacity-rule = [
	"100:class_g = 'Xterm'",
    "100:class_g = 'feh'"
];

禁止beep声音(可选)

/etc/modprobe.d中加入no-beep.conf 文件,内容为:

blacklist pcspkr

禁掉该模块就不会发出 beep 的声音了。

网络工具net-tools

pacman -S net-tools

校园网Linux客户端依赖ifconfig(没装显示无效网卡),尽管在arch中已经有ip addr代替

多线程下载工具 axel

more

代理

proxychains privxy

系统监控工具 conky(可选)

more

终端文件管理器ranger

搜索文件名数据库mlocate

archlinux不自带locate,提供mlocate

//安装并初始化数据库,需要root
pacman -S mlocate
updatedb

vscode

arch可以有多个版本的vscode供选择:

pacman -S code

arch打包的oss版的vscode默认不使用官方市场

可以手动修改product.json让oss版使用官方市场,修改这个字段:

"extensionsGallery": {
      "serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
      "cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
      "itemUrl": "https://marketplace.visualstudio.com/items"
}

可参考stackoverflow

安装fcitx5,配置中文输入法

//安装输入法框架和配置工具
pacman -S fcitx5 fcitx5-configtool
//配置启动fcitx5必要的环境变量,并重新登陆
//~/.pam_environment
GTK_IM_MODULE DEFAULT=fcitx
QT_IM_MODULE  DEFAULT=fcitx
XMODIFIERS    DEFAULT=\@im=fcitx
SDL_IM_MODULE DEFAULT=fcitx
//安装中文输入法引擎
pacman -S fcitx5-rime
//安装词库:四叶草拼音输入方案
//https://github.com/fkxxyz/rime-cloverpinyin
//切换普通用户
yay -S rime-cloverpinyin
//fcitx5-rime的用户资料文件夹:~/.local/share/fcitx5/rime
//在用户资料夹下创建 default.custom.yaml ,内容为
patch:
  "menu/page_size": 8
  schema_list:
    - schema: clover
//其中 8 表示打字的时候输入面板的每一页的候选词数目,可以设置成 1~9 任意数字。
//写好该文件之后,点击右下角托盘图标右键菜单,点“重新部署”

//配置startx启动时自动启动fcitx5
vim ~/.config/awesome/rc.lua

添加一条autorun为fcitx5即可

arch打包的oss版的vscode默认不使用官方市场

可以手动修改product.json让oss版使用官方市场,修改这个字段:

"extensionsGallery": {
      "serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
      "cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
      "itemUrl": "https://marketplace.visualstudio.com/items"
}

可供参考

杂碎记录

挂载相关

Linux和手机传输文件: mtpfs手动挂载 jmtpfs df -iT查看能否识别

分区相关

从性能角度考虑,/var/home 比较科学 把配置文件放在 /var 分区,速度更快 /home 单独分区,读写配置文件会比较慢 /var 如果没单独分区,那就在根分区,也不必如此操作

所以一般情况建议 /var /home 都还是留在根分区。 如果根分区在固态硬盘,则 /var 分到机械硬盘,/home 挪进 /var 分区。 我是根分区和 /boot 分区在固态,平时是只读挂载,提高安全性。/var 在机械硬盘,/home 挪入 /var。 第一,离根分区较远,磁头摆动大。 第二,单独的分区,不能和根分区集中进行布局优化。 第三,单独的主分区,必然会放一些七七八八的数据,磁盘碎片化严重。

软连接部分文件,配置文件和home都该放到根分区 较大的文件可以移走 然后软连接回来

依赖相关

先安装该包还是先安装其依赖? 直接apt install ./deb,可以自动装依赖

dpkg -i xxx.deb aptitude install dpkg 安装时缺少依赖就是返回非 0 值的 apt 只在 dpkg 失败时才补充

dpkg最差,pkg其次(arch属于pkg),rpm最舒服 dpkg主要问题是推荐和依赖分不清

Archlinux编译内核

https://wiki.archlinux.org/index.php/Kernel_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)/Traditional_compilation_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

archlinux可以使用 zcat命令获取当前运行内核的config文件。其它发行版的config文件可能直接放在/boot目录中。

$ zcat /proc/config.gz > .config