Arch from Scratch
Published: 2023-05-02 12:42:59

# Arch from Scratch

Install Arch Linux from scratch - a very clean setup with pacman used as a package manager, and without systemd.

## 1\. Download Arch Linux Live Disk

You need a live boot to continue.

Boot up the system and expand the live image:

```plaintext
$ mount -o remount,size=8G /run/archiso/cowspace
```

Execute wifi-menu to connect to wifi

```plaintext
$ wifi-menu
```

Now you need to choose a mirror for the live pacman

```plaintext
$ vim /etc/pacman.d/mirrorlist
```

Next, update the live system's repository database

```plaintext
$ pacman -Sy
```

Now you need to install packages that we will need later on for the live system:

```plaintext
$ pacman -S git fakeroot binutils
```

```plaintext

Open the README file in your terminal
```

$ cd archfs $ vim README.md

```plaintext



## 2. Create System Partition

Use the live boot to create an ext4fs partition for the new
system:

- BIOS System Partition
- UEFI System Partition
- Linux swap partition
- Linux system
- ...
- Linux /home partion



## 3. Mount the target system
```

$ mount /dev/sda4 /mnt

$ mkdir /mnt/boot $ mkdir /mnt/tmp $ mkdir /mnt/run $ mkdir /mnt/dev $ mkdir /mnt/sys $ mkdir /mnt/proc $ mkdir /mnt/home

$ mount /dev/sda2 /mnt/boot $ mount /dev/sda8 /mnt/home $ swapon /dev/sda3

$ mount --bind /tmp /mnt/tmp $ mount --bind /run /mnt/run $ mount --bind /dev /mnt/dev $ mount --bind /sys /mnt/sys $ mount --bind /proc /mnt/proc $ mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars

```plaintext

## 4. Install pacman database
```

$ mkdir -p /mnt/var/lib/pacman $ pacman -Sy -r /mnt

```plaintext

## 5. Install pseudo systemd

### Pseudo systemd
```

$ cd /tmp $ mkdir systemd $ chmod a+rw systemd $ cd systemd $ vim PKGBUILD pkgname=('systemd' 'systemd-libs' 'libsystemd' 'systemd-resolvconf' 'systemd-sysvcompat') pkgver=500.0 pkgrel=1 arch=('any') package\_systemd() { echo; } package\_systemd-libs() { echo; } package\_libsystemd() { echo; } package\_systemd-resolvconf() { echo; } package\_systemd-sysvcompat() { echo; } $ su -s /bin/bash nobody makepkg $ pacman -Ur /mnt \*.xz $ cp \*.xz /mnt/var/lib/pacman/ $ cd ~

```plaintext

### Libsystemd.so
```

$ mkdir -p /mnt/usr/lib $ cd /mnt/usr/lib $ cp /usr/lib/libsystemd.so.0.*.0 . $ ln -sv libsystemd.so.0.*.0 libsystemd.so.0 $ ln -sv libsystemd.so.0 libsystemd.so $ cd ~

```plaintext

## 6. Install the base system

while you are installing these packages (below), you can pause at
any time and chroot to /mnt to see the fruits of your labor.

### Filesystem tree
```

$ pacman -Sr /mnt iana-etc $ pacman -Sr /mnt tzdata $ pacman -Sr /mnt filesystem

```plaintext

### C library
```

$ pacman -Sr /mnt linux-api-headers $ pacman -Sr /mnt glibc $ pacman -Sr /mnt gcc-libs

```plaintext

### Shell
```

$ pacman -Sr /mnt ncurses $ pacman -Sr /mnt readline $ pacman -Sr /mnt bash

```plaintext

### POSIX capabilities
```

$ pacman -Sr /mnt attr $ pacman -Sr /mnt acl $ pacman -Sr /mnt libcap $ pacman -Sr /mnt libcap-ng

```plaintext

### Perl language
```

$ pacman -Sr /mnt db $ pacman -Sr /mnt gdbm $ pacman -Sr /mnt perl

```plaintext

### Filesystem
```

$ pacman -Sr /mnt libutil-linux $ pacman -Sr /mnt e2fsprogs $ pacman -Sr /mnt dosfstools

```plaintext

### Crypto
```

$ pacman -Sr /mnt gmp $ pacman -Sr /mnt openssl $ pacman -Sr /mnt openssl-1.0 $ pacman -Sr /mnt libsasl $ pacman -Sr /mnt libgpg-error $ pacman -Sr /mnt libgcrypt $ pacman -Sr /mnt nettle

```plaintext

### Compression
```

$ pacman -Sr /mnt zlib $ pacman -Sr /mnt bzip2 $ pacman -Sr /mnt lz4 $ pacman -Sr /mnt xz $ pacman -Sr /mnt pcre $ pacman -Sr /mnt pcre2 $ pacman -Sr /mnt less $ pacman -Sr /mnt gzip $ pacman -Sr /mnt zip

```plaintext

## Archiving
```

$ pacman -Sr /mnt expat $ pacman -Sr /mnt tar $ pacman -Sr /mnt zstd $ pacman -Sr /mnt libarchive $ pacman -Sr /mnt cpio

```plaintext

### Coreutils
```

$ pacman -Sr /mnt coreutils $ pacman -Sr /mnt findutils

```plaintext

### Binutils
```

$ pacman -Sr /mnt libelf $ pacman -Sr /mnt binutils

```plaintext

### Glib2
```

$ pacman -Sr /mnt libffi $ pacman -Sr /mnt glib2

```plaintext

### Text processing
```

$ pacman -Sr /mnt mpfr $ pacman -Sr /mnt gawk $ pacman -Sr /mnt grep $ pacman -Sr /mnt sed

```plaintext

### Passwords
```

$ pacman -Sr /mnt keyutils $ pacman -Sr /mnt cracklib

```plaintext

### Kerberos
```

$ pacman -Sr /mnt libldap $ pacman -Sr /mnt krb5 $ pacman -Sr /mnt libtirpc $ pacman -Sr /mnt libnsl

```plaintext

### User management
```

$ pacman -Sr /mnt pambase $ pacman -Sr /mnt pam $ pacman -Sr /mnt shadow

```plaintext

### More utility commands
```

$ pacman -Sr /mnt util-linux $ pacman -Sr /mnt diffutils $ pacman -Sr /mnt patch $ pacman -Sr /mnt procps $ pacman -Sr /mnt psmisc $ pacman -Sr /mnt sudo

```plaintext

### Sqlite
```

$ pacman -Sr /mnt sqlite $ pacman -Sr /mnt yajl

```plaintext

### PKCS modules
```

$ pacman -Sr /mnt libtasn1 $ pacman -Sr /mnt p11-kit

```plaintext

### Certificates
```

$ pacman -Sr /mnt ca-certificates-utils $ pacman -Sr /mnt ca-certificates-mozilla $ pacman -Sr /mnt ca-certificates

```plaintext

### Internationalization
```

$ pacman -Sr /mnt perl-xml-parser $ pacman -Sr /mnt libunistring $ pacman -Sr /mnt intltool $ pacman -Sr /mnt icu $ pacman -Sr /mnt libxml2 $ pacman -Sr /mnt libcroco $ pacman -Sr /mnt gettext

```plaintext

### Domain Names
```

$ pacman -Sr /mnt libidn $ pacman -Sr /mnt libidn2 $ pacman -Sr /mnt libpsl

```plaintext

### Web fetching
```

$ pacman -Sr /mnt libssh2 $ pacman -Sr /mnt libnghttp2 $ pacman -Sr /mnt curl

```plaintext

### GNU TLS
```

$ pacman -Sr /mnt gnutls

```plaintext

### Assuan Protocol
```

$ pacman -Sr /mnt libassuan $ pacman -Sr /mnt libsecret $ pacman -Sr /mnt pinentry

```plaintext

### GNU PG
```

$ pacman -Sr /mnt libksba $ pacman -Sr /mnt npth $ pacman -Sr /mnt gnupg $ pacman -Sr /mnt gpgme

```plaintext

### Pacman
```

$ pacman -Sr /mnt fakeroot $ pacman -Sr /mnt archlinux-keyring $ pacman -Sr /mnt pacman-mirrorlist $ pacman -Sr /mnt pacman $ pacman -Sr /mnt arch-install-scripts

```plaintext

### Text Editor
```

$ pacman -Sr /mnt file $ pacman -Sr /mnt nano $ pacman -Sr /mnt gpm $ pacman -Sr /mnt vim-runtime $ pacman -Sr /mnt vim

```plaintext

### Message passing
```

$ pacman -Sr /mnt audit $ pacman -Sr /mnt dbus

```plaintext

### USB
```

$ pacman -Sr /mnt hwids $ pacman -Sr /mnt libusb $ pacman -Sr /mnt usbutils

```plaintext

### PCI
```

$ pacman -Sr /mnt kbd $ pacman -Sr /mnt kmod $ pacman -Sr /mnt pciutils

```plaintext

### Packet capturing
```

$ pacman -Sr /mnt libnl $ pacman -Sr /mnt libpcap

```plaintext

### Routing
```

$ pacman -Sr /mnt libmnl $ pacman -Sr /mnt libnftnl $ pacman -Sr /mnt libnfnetlink $ pacman -Sr /mnt libnetfilter\_conntrack $ pacman -Sr /mnt iptables $ pacman -Sr /mnt iproute2

```plaintext

### Network tools
```

$ pacman -Sr /mnt iputils $ pacman -Sr /mnt inetutils $ pacman -Sr /mnt net-tools $ pacman -Sr /mnt wpa\_supplicant

```plaintext

### ssh
```

$ pacman -Sr /mnt dnssec-anchors $ pacman -Sr /mnt ldns $ pacman -Sr /mnt libedit $ pacman -Sr /mnt openssh

```plaintext

### Internet
```

$ pacman -Sr /mnt dhclient $ pacman -Sr /mnt wget $ pacman -Sr /mnt lynx $ pacman -Sr /mnt lighttpd

```plaintext

### GNU Package Conf tools
```

$ pacman -Sr /mnt m4 $ pacman -Sr /mnt autoconf $ pacman -Sr /mnt automake $ pacman -Sr /mnt pkg-config $ pacman -Sr /mnt libtool $ pacman -Sr /mnt which

```plaintext

### C/C++ Compiler
```

$ pacman -Sr /mnt libmpc $ pacman -Sr /mnt gcc $ pacman -Sr /mnt libatomic\_ops $ pacman -Sr /mnt gc

```plaintext

### Make utility
```

$ pacman -Sr /mnt texinfo $ pacman -Sr /mnt guile $ pacman -Sr /mnt make

```plaintext

### Python
```

$ pacman -Sr /mnt python2 $ pacman -Sr /mnt python3 $ pacman -Sr /mnt python2-pip $ pacman -Sr /mnt python-pip

```plaintext

### Ruby
```

$ pacman -Sr /mnt libyaml $ pacman -Sr /mnt ruby rubygems

```plaintext

### NetworkManager
```

$ pacman -Sr /mnt networkmanager

```plaintext

### Firewall
```

$ pacman -Sr /mnt ufw

```plaintext

### Git
```

$ pacman -Sr /mnt git

```plaintext

### ALSA
```

$ pacman -Sr /mnt moc alsaplayer alsa-tools alsa-utils alsa-firmware

```plaintext

## 7. Chrooting to the installed system

### Chroot
```

$ chroot /mnt /usr/bin/bash

```plaintext

### Connect to the internet in chroot'd env
```

$ vim /etc/resolv.conf nameserver 8.8.8.8

```plaintext

### Generate locale
```

$ vim /etc/locale.gen $ locale-gen

```plaintext

### Time
```

$ ln -sf /usr/share/zoneinfo/Canada/Eastern /etc/localtime

```plaintext

### Host name
```

$ echo archfs &gt; /etc/hostname

```plaintext

### Initialize pacman
```

$ vim /etc/pacman.d/mirrorlist $ pacman-key --init $ pacman-key --populate archlinux

```plaintext
### Add system groups
```

$ groupadd users $ groupadd tty $ groupadd uucp $ groupadd kmem $ groupadd input $ groupadd audio $ groupadd video $ groupadd storage $ groupadd disk $ groupadd optical $ groupadd network $ groupadd rfkill $ groupadd lp

```plaintext

### Add system users
```

$ useradd avahi $ useradd polkitd $ useradd colord $ useradd nobody $ useradd http

```plaintext

### Create login user
```

$ useradd -s /bin/bash -d /home/igor -m igor $ passwd root $ passwd igor $ chmod +w /etc/sudoers $ vim /etc/sudoers

```plaintext

### Add login user to system groups
```

$ usermod -a -G tty igor $ usermod -a -G input igor $ usermod -a -G audio igor $ usermod -a -G video igor $ usermod -a -G storage igor $ usermod -a -G disk igor $ usermod -a -G optical igor $ usermod -a -G network igor $ usermod -a -G lp igor

```plaintext

### Switch to the new user
```

$ su igor $ cd ~ $ sudo su $ exit

```plaintext

### Install package-query (for yaourt)
```

$ wget https://aur.archlinux.org/cgit/aur.git/snapshot/package-query.tar.gz $ tar -xzf package-query.tar.gz $ cd package-query $ makepkg $ sudo pacman -U package-query\*.xz $ cd .. $ rm -rf package-query\*

```plaintext

### Install yaourt
```

$ wget https://aur.archlinux.org/cgit/aur.git/snapshot/yaourt.tar.gz $ tar -xzf yaourt.tar.gz $ cd yaourt $ makepkg $ sudo pacman -U yaourt\*.xz $ cd .. $ rm -rf yaourt\*

```plaintext

### Now use yaourt to install eudev
```

$ yaourt eudev

```plaintext

### Generate fstab
```

$ sudo su $ genfstab / &gt; /etc/fstab $ cat /etc/fstab $ exit

```plaintext

### Procps-ng-nosystemd
```

$ yaourt procps-ng-nosystemd

```plaintext

### Dbus-nosystemd:
```

$ yaourt dbus-nosystemd # edit PKGBUILD to remove git commit $ sudo su $ dbus-uuidgen &gt; /etc/machine-id $ exit

```plaintext

## cups-nosystemd:
```

$ yaourt cups-nosystemd $ sudo su $ vim /etc/nsswitch.conf hosts: ... mdns\_minimal \[NOTFOUND=return\] resolve \[!UNAVAIL=return\] dns ... $ exit

```plaintext

## Configure ssh:
```

$ sudo su $ ssh-keygen -t rsa -f /etc/ssh/ssh\_host\_rsa\_key $ ssh-keygen -t ecdsa -f /etc/ssh/ssh\_host\_ecdsa\_key $ ssh-keygen -t ed25519 -f /etc/ssh/ssh\_host\_ed25519\_key $ chmod 0600 /etc/ssh/ssh\_host\_rsa\_key $ chmod 0600 /etc/ssh/ssh\_host\_ecdsa\_key $ chmod 0600 /etc/ssh/ssh\_host\_ed25519\_key $ exit

```plaintext

## Configure http
```

$ sudo su $ chown http /var/log/lighttpd $ chown http /srv/http $ exit

```plaintext



## 8. Install the kernel!

### Install mkinitcpio
```

$ sudo pacman -S mkinitcpio-busybox $ sudo pacman -S mkinitcpio

```plaintext

### Install linux
```

$ sudo pacman -S linux-firmware $ sudo pacman -S linux $ sudo pacman -S linux-headers

```plaintext

### Install the init script (or create your own if you like)
```

$ cd archfs $ sudo cp init /usr/bin $ sudo cp lastmins /usr/bin $ sudo cp reboot /usr/bin $ sudo cp respawn /usr/bin $ sudo cp shutdown /usr/bin $ sudo cp uptime2 /usr/bin $ cd ..

```plaintext

## 9. Install the bootloader

If your firmware supports UEFI standard, you can simply use "efibootmgr"
to add an entry to your NVRAM for the kernel (vmlinuz-linux), with 
`initrd=initramfs-linux.img root=/dev/sda4 rw` as command line.
```

$ sudo pacman -S efivar efibootmgr $ sudo efibootmgr -d /dev/sda -p 2 -c -L "Arch Linux" -l /vmlinuz-linux  
\-u 'root=/dev/sda4 rw initrd=\\initramfs-linux.img'

```plaintext

If you are using virtualbox, you need to use startup.nsh because
the nvram of virtualbox is non-persistent:
```

$ sudo su $ echo 'vmlinuz-linux root=/dev/sda4 rw initrd=\\initramfs-linux.img' &gt; /boot/startup.nsh $ exit

```plaintext

## 10. Virtualization
```

$ sudo pacman -S virtualbox $ sudo pacman -S qemu

```plaintext

## 11. Reboot
```

$ exit $ exit $ reboot