You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
8.1 KiB
Markdown

4 years ago
# Arch Linux installation to serve as a docker host
4 years ago
###### guide-by-example
4 years ago
![logo](https://i.imgur.com/SkENpGn.png)
1 year ago
# Notice
**Since 2022 I am using the [archinstall script](https://github.com/archlinux/archinstall)
that comes with arch iso**<br>
**After the install [I use my ansible playbooks](https://github.com/DoTheEvo/ansible-arch) to setup the arch the way I like it**
4 years ago
# Purpose
Linux that will run docker.
4 years ago
This is not a hand holding explaining guide how to install arch.<br>
4 years ago
It's more of a checklist on what to do if you already done it
4 years ago
and know what you are doing.<br>
4 years ago
* [Official site](https://www.archlinux.org/)
* [Arch wiki install guide](https://wiki.archlinux.org/index.php/installation_guide)
* [Arch wiki docker entry](https://wiki.archlinux.org/index.php/docker)
# Files and directory structure
```
/home/
└── bastard/
└── docker/
├── container-setup #1
├── container-setup #2
├── ...
```
# Make installation usb
4 years ago
[wiki](https://wiki.archlinux.org/index.php/USB_flash_installation_media)
4 years ago
`sudo dd bs=4M if=archlinux-2020.05.01-x86_64.iso of=/dev/sdX status=progress oflag=direct`
4 years ago
The above command will fuck your machine up if you dunno what you are doing.
4 years ago
# Boot from the usb
4 years ago
This is BIOS/MBR setup as I am running on an old thinkpad with a busted screen,
4 years ago
plus I like the simplicity of it.<br>
4 years ago
So if theres boot menu option choose non-uefi.
# Installation
4 years ago
* create a single partition and mark it bootable<br>
4 years ago
`cfdisk -z /dev/sda`
4 years ago
* build ext4 filesystem on it<br>
4 years ago
`mkfs.ext4 /dev/sda1`
4 years ago
* mount the new partition<br>
4 years ago
`mount /dev/sda1 /mnt`
4 years ago
* install the base system <br>
3 years ago
`pacstrap /mnt base linux linux-firmware base-devel grub micro`
4 years ago
* generate fstab<br>
4 years ago
`genfstab -U /mnt > /mnt/etc/fstab`
4 years ago
* chroot in to the new system<br>
4 years ago
`arch-chroot /mnt`
4 years ago
* install grub<br>
`grub-install /dev/sda`<br>
4 years ago
`grub-mkconfig -o /boot/grub/grub.cfg`
4 years ago
* set password for root<br>
4 years ago
`passwd`
4 years ago
* remove the bootable media and restart the machine<br>
`exit`<br>
4 years ago
`reboot`
# Basic configuration after the first boot
4 years ago
* login as `root`<br>
* set hostname<br>
4 years ago
`echo docker-host > /etc/hostname`
4 years ago
* add new user and set their password<br>
`useradd -m -G wheel bastard`<br>
4 years ago
`passwd bastard`
4 years ago
* edit sudoers to allow users of the group wheel to sudo<br>
3 years ago
`EDITOR=micro visudo`<br>
4 years ago
*%wheel ALL=(ALL) ALL*
4 years ago
* check the network interface name<br>
4 years ago
`ip link`
3 years ago
* setup networking using systemd-networkd and systemd-resolved<br>
create `20-wired.network` file either in static or dhcp configuration
3 years ago
`micro /etc/systemd/network/20-wired.network`
4 years ago
```
[Match]
Name=enp0s25
[Network]
Address=10.0.19.2/24
Gateway=10.0.19.1
3 years ago
#DNS=8.8.8.8
4 years ago
```
```
3 years ago
[Match]
Name=enp0s25
[Network]
DHCP=yes
4 years ago
```
3 years ago
for DNS resolution and hostname exposure using mDNS and LLMNR<br>
`systemd-resolved` will be used in stub mode</br>
by replacing `/etc/resolv.conf` with a link to `stub-resolv.conf`
4 years ago
3 years ago
`ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf`
enable the services
* `systemctl enable --now systemd-resolved`
* `systemctl enable --now systemd-networkd`
4 years ago
4 years ago
* uncomment desired locales in locale.gen<br>
3 years ago
`micro /etc/locale.gen`<br>
4 years ago
* generate new locales and set one system wide<br>
`locale-gen`<br>
4 years ago
`localectl set-locale LANG=en_US.UTF-8`
4 years ago
* select timezone and set it permanent<br>
`tzselect`<br>
4 years ago
`timedatectl set-timezone 'Europe/Bratislava'`
4 years ago
* set hardware clock and sync using ntp<br>
`hwclock --systohc --utc`<br>
4 years ago
`timedatectl set-ntp true`
4 years ago
* setup a swap file<br>
4 years ago
`dd if=/dev/zero of=/swapfile bs=1M count=8192 status=progress`<br>
4 years ago
`chmod 600 /swapfile`<br>
`mkswap /swapfile`<br>
3 years ago
`micro /etc/fstab`<br>
4 years ago
*/swapfile none swap defaults 0 0*
4 years ago
* reboot<br>
4 years ago
`reboot`
4 years ago
# SSH, Docker, ZSH, AUR
4 years ago
4 years ago
From now on its login as non-root user.
4 years ago
### Setup SSH access
4 years ago
[wiki](https://wiki.archlinux.org/index.php/OpenSSH)
4 years ago
* install openssh package<br>
4 years ago
`sudo pacman -S openssh`
4 years ago
* edit sshd_config<br>
3 years ago
`sudo micro /etc/ssh/sshd_config`<br>
4 years ago
*PasswordAuthentication yes*
4 years ago
* enable sshd service<br>
4 years ago
`sudo systemctl enable --now sshd`
4 years ago
4 years ago
### Setup docker
[Wiki](https://wiki.archlinux.org/index.php/docker)
4 years ago
* have `docker` and `docker-compose` packages installed<br>
4 years ago
`sudo pacman -S docker docker-compose`
4 years ago
* enable docker service<br>
4 years ago
`sudo systemctl enable --now docker`
4 years ago
* add non-root user to the docker group<br>
4 years ago
`sudo gpasswd -a bastard docker`
4 years ago
### ZSH shell
4 years ago
[wiki](https://wiki.archlinux.org/index.php/zsh)
4 years ago
I like [Zim](https://github.com/zimfw/zimfw),
it's the fastest zsh framework and set up nicely out of the box
4 years ago
4 years ago
* install zsh and curl packages<br>
4 years ago
`sudo pacman -S zsh git curl`
4 years ago
* install zim<br>
4 years ago
`curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh`
4 years ago
* change the default shell to zsh <br>
4 years ago
`chsh -s /bin/zsh`
2 years ago
* I prefer [steeef](https://github.com/zimfw/steeef) theme
`echo 'zmodule steeef' >> ~/.zimrc && zimfw install`
4 years ago
4 years ago
##### Adding stuff to .zshrc
3 years ago
`micro .zshrc`
4 years ago
3 years ago
* `export EDITOR=micro`<br>
`export VISUAL=micro`
4 years ago
4 years ago
* for ctrl+f prepending sudo
```bash
add_sudo (){
BUFFER="sudo $BUFFER"
zle -w end-of-line
}
zle -N add_sudo
bindkey "^f" add_sudo
```
4 years ago
4 years ago
##### ZSH docker autocomplete
4 years ago
4 years ago
[Here](https://docs.docker.com/compose/completion/#zsh).
For zim it's "Without oh-my-zsh shell" section.
4 years ago
4 years ago
### Access to AUR
4 years ago
4 years ago
Using [Yay](https://github.com/Jguer/yay).
4 years ago
4 years ago
* install git package<br>
4 years ago
`sudo pacman -S git`
4 years ago
* install yay<br>
`git clone https://aur.archlinux.org/yay-bin.git`<br>
`cd yay-bin && makepkg -si`<br>
`cd .. && rm -rf yay-bin`<br>
4 years ago
4 years ago
`ctop-bin` and `inxi` are good AUR packages.
4 years ago
# Extra stuff
4 years ago
4 years ago
[wiki - general general recommendations](https://wiki.archlinux.org/index.php/general_recommendations)<br>
[wiki - improving performance](https://wiki.archlinux.org/index.php/Improving_performance)<br>
### CPU [microcode](https://wiki.archlinux.org/index.php/Microcode)
* `sudo pacman -S intel-ucode`
* `sudo grub-mkconfig -o /boot/grub/grub.cfg`
4 years ago
4 years ago
### Some packages
Tools
3 years ago
* `sudo pacman -S fuse curl wget micro nnn bind-tools borg python-llfuse`
4 years ago
Monitoring and testing
4 years ago
* `sudo pacman -S htop lm_sensors iotop nload powertop iproute2`
4 years ago
### Performance and maintenance
4 years ago
* install cron and enable the service<br>
`sudo pacman -S cronie`<br>
4 years ago
`sudo systemctl enable --now cronie`
4 years ago
* if ssd, enable periodic trim<br>
`sudo pacman -S util-linux`<br>
4 years ago
`sudo systemctl enable --now fstrim.timer`
4 years ago
* set noatime in fstab to prevent unnecessary tracking of read times<br>
3 years ago
`sudo micro /etc/fstab`<br>
4 years ago
*UUID=cdd..addb / ext4 rw,noatime 0 1*
4 years ago
* enable use of all cpu cores for makepkg jobs and disable compression<br>
3 years ago
`sudo micro /etc/makepkg.conf`<br>
4 years ago
*MAKEFLAGS="-j$(nproc)"*<br>
4 years ago
*PKGEXT='.pkg.tar'*
4 years ago
* clean up old packages weekly, keep last 3<br>
`sudo pacman -S pacman-contrib`<br>
4 years ago
`sudo systemctl enable --now paccache.timer`
2 years ago
4 years ago
* use reflector to get the fastest mirrors based on country `-c <country code>`<br>
`sudo pacman -S reflector`<br>
2 years ago
`sudo reflector -c SK,CZ,UA -p http --score 20 --sort rate --save /etc/pacman.d/mirrorlist`
automatic mirror update with reflector
`/etc/xdg/reflector/reflector.conf`
```
--save /etc/pacman.d/mirrorlist
--protocol http
--country SK,CZ,UA
--score 20
--sort rate
```
enable it, it will run weekly
2 years ago
`sudo systemctl enable --now reflector.timer`
4 years ago
### Comfort
4 years ago
* enable colors in pacman.conf<br>
3 years ago
`sudo micro /etc/pacman.conf`<br>
4 years ago
*Color*
4 years ago
### Notebook
4 years ago
Lid closed should not make the machine go to sleep.
* Set lid handle switch to ignore in systemd logind.conf<br>
3 years ago
`sudo micro /etc/systemd/logind.conf`<br>
4 years ago
*HandleLidSwitch=ignore*
4 years ago
**But this alone leaves the screen running nonstop.**
4 years ago
4 years ago
Tried to find solution, and while `sudo vbetool dpms off` works,
turning it back on does not `sudo vbetool dpms on` and it timesout without
any message or error.
4 years ago
Might be specific for the hardware, currently its latitude E5570