313 lines
7.2 KiB
Markdown
313 lines
7.2 KiB
Markdown
---
|
|
title: "archlinux install by syui"
|
|
slug: "arch"
|
|
date: "2025-08-08"
|
|
tags: ["arch"]
|
|
draft: false
|
|
---
|
|
|
|
## 最小構成
|
|
|
|
まずはdiskの設定から。
|
|
|
|
```sh
|
|
# cfdisk /dev/sda
|
|
```
|
|
|
|
次にdiskのフォーマットなど。それをmountしてarchlinuxを入れます。bootloaderも設定しておきましょう。
|
|
|
|
```sh
|
|
$ mkfs.vfat /dev/sda1
|
|
$ mkfs.ext4 /dev/sda2
|
|
|
|
$ mount /dev/sda2 /mnt
|
|
$ mount --mkdir /dev/sda1 /mnt/boot
|
|
|
|
$ pacstrap /mnt base base-devel linux linux-firmware linux-headers
|
|
$ genfstab -U /mnt >> /mnt/etc/fstab
|
|
|
|
$ arch-chroot /mnt
|
|
$ pacman -S dhcpcd grub os-prober efibootmgr
|
|
$ grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
|
|
$ grub-mkconfig -o /boot/grub/grub.cfg
|
|
```
|
|
|
|
これで`exit;reboot`すると起動できます。
|
|
|
|
## よく使うもの
|
|
|
|
```sh
|
|
$ pacman -S openssh zsh vim git tmux cargo
|
|
```
|
|
|
|
## userの作成
|
|
|
|
```sh
|
|
$ passwd
|
|
$ useradd -m -G wheel ${USER}
|
|
$ passwd ${USER}
|
|
```
|
|
|
|
```sh
|
|
$ chsh -s /bin/zsh ${USER}
|
|
or
|
|
$ useradd -m -G wheel -s /bin/zsh ${USER}
|
|
```
|
|
|
|
```sh
|
|
$ HOSTNAME=archlinux
|
|
$ echo "$HOSTNAME" > /etc/hostname
|
|
```
|
|
|
|
## sudoの使い方
|
|
|
|
1. `/etc/sudoers`は編集を間違えると起動できなくなります。安全のため`visudo`が推奨されています。
|
|
2. `vim`では`:w!`で保存します。
|
|
|
|
```sh
|
|
$ sudo visudo
|
|
or
|
|
$ vim /etc/sudoers
|
|
```
|
|
|
|
```sh:/etc/sudoers
|
|
%wheel ALL=(ALL:ALL) ALL
|
|
%wheel ALL=(ALL:ALL) NOPASSWD: /usr/bin/pacman -Syu --noconfirm
|
|
```
|
|
|
|
よく`update`する人はpasswordなしで特定のコマンドをsudoを実行できるようにしておいたほうが良いでしょう。
|
|
|
|
```sh
|
|
$ sudo pacman -Syu --noconfirm
|
|
```
|
|
|
|
## networkの設定
|
|
|
|
次にnetworkです。ここでは`systemd-networkd`を使用します。`dhcpcd`を使ったほうが簡単ではあります。もし安定しないようなら`dhcpcd`を使用。
|
|
|
|
```sh
|
|
# systemctl enable dhcpcd
|
|
```
|
|
|
|
```sh
|
|
$ systemctl enable systemd-networkd
|
|
```
|
|
|
|
network deviceをeth0にします。
|
|
|
|
```sh
|
|
$ ip link
|
|
$ ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
|
|
```
|
|
|
|
```sh:/etc/systemd/network/eth.network
|
|
[Match]
|
|
Name=eth0
|
|
[Network]
|
|
Address=192.168.1.2/24
|
|
Gateway=192.168.1.1
|
|
DNS=192.168.1.1
|
|
```
|
|
|
|
```sh
|
|
$ systemctl enable systemd-resolved
|
|
```
|
|
|
|
## auto-login
|
|
|
|
次にauto-loginを設定していきます。ここでは`getty`を使用。`${USER}`のところを自分のusernameにしてください。
|
|
|
|
```sh
|
|
$ mkdir -p /etc/systemd/system/getty@tty1.service.d/
|
|
```
|
|
|
|
```sh:/etc/systemd/system/getty@tty1.service.d/override.conf
|
|
[Service]
|
|
ExecStart=
|
|
ExecStart=-/usr/bin/agetty --autologin ${USER} --noclear %I $TERM
|
|
```
|
|
|
|
```sh
|
|
$ systemctl daemon-reload
|
|
$ systemctl restart getty@tty1
|
|
```
|
|
|
|
## window-manager
|
|
|
|
`xorg`でdesktop(window-manager)を作ります。`i3`を使うことにしましょう。`xorg`は`wayland`に乗り換えたほうがいいかも。その場合は`sway`がおすすめ。
|
|
|
|
```sh
|
|
$ pacman -S xorg xorg-xinit i3 xterm
|
|
|
|
# 確認
|
|
$ startx
|
|
$ i3
|
|
```
|
|
|
|
```sh:~/.xinitrc
|
|
exec i3
|
|
```
|
|
|
|
```sh:~/.bash_profile
|
|
if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
|
|
exec startx
|
|
fi
|
|
```
|
|
|
|
## sshの使い方
|
|
|
|
```sh
|
|
$ systemctl enable sshd
|
|
$ cat /etc/ssh/sshd_config
|
|
Port 22119
|
|
PasswordAuthentication no
|
|
|
|
$ systemctl restart sshd
|
|
```
|
|
|
|
基本的にlanから使う場合はdefaultで問題ありませんが、wanから使う場合は変更します。とはいえ、lanでもport, passwordは変えておいたほうがいいでしょう。
|
|
|
|
次に接続側でkeyを作ってserverに登録します。
|
|
|
|
```sh
|
|
$ ssh-keygen -f ~/.ssh/archlinux
|
|
$ ssh-copy-id -i ~/.ssh/archlinux ${USER}@192.168.1.2 -p 22119
|
|
```
|
|
|
|
`ssh-copy-id`がない場合は以下のようにしましょう。
|
|
|
|
```sh
|
|
$ cat ~/.ssh/archlinux.pub | ssh -p 22119 ${USER}@192.168.1.2 'cat >> ~/.ssh/authorized_keys'
|
|
```
|
|
|
|
この設定で`ssh archlinux`コマンドで接続できます。
|
|
|
|
```sh:~/.ssh/config
|
|
Host archlinux
|
|
User syui
|
|
Hostname 192.168.1.2
|
|
Port 22119
|
|
IdentityFile ~/.ssh/archlinux
|
|
```
|
|
|
|
おそらく、これがarchlinuxを普通に使っていくうえでの最小構成かと思います。
|
|
|
|
serverだけならxorgなどは必要ありません。
|
|
|
|
## zshの使い方
|
|
|
|
```sh
|
|
$ sudo pacman -S git-zsh-completion powerline zsh-autocomplete zsh-autosuggestions zsh-completions zsh-history-substring-search zsh-syntax-highlighting
|
|
```
|
|
|
|
例えば、`ls -`と入力すると補完され、`C-n`, `C-p`で選択。
|
|
|
|
```sh:~/.zshrc
|
|
alias u="sudo pacman -Syu --noconfirm"
|
|
alias zs="vim ~/.zshrc"
|
|
alias zr="exec $SHELL && source ~/.zshrc"
|
|
|
|
source /usr/share/zsh/plugins/zsh-autocomplete/zsh-autocomplete.plugin.zsh
|
|
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
|
|
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
|
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
|
|
# source /usr/share/powerline/bindings/zsh/powerline.zsh
|
|
|
|
autoload -Uz compinit
|
|
compinit
|
|
fpath=(/usr/share/zsh/site-functions $fpath)
|
|
|
|
HISTSIZE=10000
|
|
SAVEHIST=10000
|
|
HISTFILE=~/.zsh_history
|
|
setopt SHARE_HISTORY
|
|
setopt HIST_IGNORE_DUPS
|
|
bindkey '^[[A' history-substring-search-up
|
|
bindkey '^[[B' history-substring-search-down
|
|
```
|
|
|
|
`powerline`は重いのでコメントしています。
|
|
|
|
## archlinuxの作り方
|
|
|
|
archlinuxはシンプルなscriptと言えるでしょう。なので色々と便利です。ここでは、`img.sh`, `install.sh`を作ります。
|
|
|
|
### img.sh
|
|
|
|
```sh:img.sh
|
|
#!/bin/bash
|
|
pacman -Syuu --noconfirm git base-devel archiso
|
|
git clone https://gitlab.archlinux.org/archlinux/archiso
|
|
./archiso/archiso/mkarchiso -v -o ./ ./archiso/configs/releng/
|
|
|
|
# mkdir -p root.x86_64/var/lib/machines/arch
|
|
# pacstrap -c root.x86_64/var/lib/machines/arch base
|
|
# arch-chroot root.x86_64 /bin/sh -c 'pacman-key --init'
|
|
# arch-chroot root.x86_64 /bin/sh -c 'pacman-key --populate archlinux'
|
|
# tar -zcvf archlinux.tar.gz root.x86_64/
|
|
```
|
|
|
|
例えば、`pacstrap`で自分の好きなツールを指定すれば、独自のimgを作成できます。これは`docker-img`にもできます。
|
|
|
|
```sh
|
|
$ docker import archlinux.tar.gz archlinux:syui
|
|
```
|
|
|
|
### install.sh
|
|
|
|
最小構成のinstall scriptです。どこかのurlに置いて、install時にcurlして実行するようにすれば便利です。
|
|
|
|
```sh
|
|
$ curl -sLO arch.example.com/install.sh
|
|
$ chmod +x install.sh
|
|
$ ./install.sh
|
|
```
|
|
|
|
```sh:install.sh
|
|
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# 変数定義
|
|
DISK="/dev/sda"
|
|
HOSTNAME="ai-arch"
|
|
USERNAME="ai"
|
|
|
|
# パーティション作成(自動)
|
|
parted $DISK mklabel gpt
|
|
parted $DISK mkpart ESP fat32 1MiB 1GiB
|
|
parted $DISK set 1 esp on
|
|
parted $DISK mkpart primary linux-swap 1GiB 5GiB
|
|
parted $DISK mkpart primary ext4 5GiB 100%
|
|
|
|
# ファイルシステム作成
|
|
mkfs.fat -F32 ${DISK}1
|
|
mkswap ${DISK}2
|
|
mkfs.ext4 ${DISK}3
|
|
|
|
# マウント
|
|
mount ${DISK}3 /mnt
|
|
mkdir -p /mnt/boot
|
|
mount ${DISK}1 /mnt/boot
|
|
swapon ${DISK}2
|
|
|
|
# インストール
|
|
pacstrap -K /mnt base linux linux-firmware base-devel vim networkmanager grub efibootmgr
|
|
|
|
# 設定
|
|
genfstab -U /mnt >> /mnt/etc/fstab
|
|
|
|
arch-chroot /mnt /bin/bash << EOF
|
|
ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
|
|
hwclock --systohc
|
|
echo "ja_JP.UTF-8 UTF-8" >> /etc/locale.gen
|
|
locale-gen
|
|
echo "LANG=ja_JP.UTF-8" > /etc/locale.conf
|
|
echo "$HOSTNAME" > /etc/hostname
|
|
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=ARCH
|
|
grub-mkconfig -o /boot/grub/grub.cfg
|
|
systemctl enable NetworkManager
|
|
useradd -m -G wheel $USERNAME
|
|
EOF
|
|
```
|
|
|