DEV Community

samsepi0l
samsepi0l

Posted on

Arch from Scratch

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:

$ mount -o remount,size=8G /run/archiso/cowspace
Enter fullscreen mode Exit fullscreen mode

Execute wifi-menu to connect to wifi

$ wifi-menu
Enter fullscreen mode Exit fullscreen mode

Now you need to choose a mirror for the live pacman

$ vim /etc/pacman.d/mirrorlist
Enter fullscreen mode Exit fullscreen mode

Next, update the live system's repository database

$ pacman -Sy
Enter fullscreen mode Exit fullscreen mode

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

$ pacman -S git fakeroot binutils
Enter fullscreen mode Exit fullscreen mode

Open the README file in your terminal
Enter fullscreen mode Exit fullscreen mode

$ cd archfs $ vim README.md




## 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
Enter fullscreen mode Exit fullscreen mode

$ 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


## 4. Install pacman database
Enter fullscreen mode Exit fullscreen mode

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


## 5. Install pseudo systemd

### Pseudo systemd
Enter fullscreen mode Exit fullscreen mode

$ 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 ~


### Libsystemd.so
Enter fullscreen mode Exit fullscreen mode

$ 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 ~


## 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
Enter fullscreen mode Exit fullscreen mode

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


### C library
Enter fullscreen mode Exit fullscreen mode

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


### Shell
Enter fullscreen mode Exit fullscreen mode

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


### POSIX capabilities
Enter fullscreen mode Exit fullscreen mode

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


### Perl language
Enter fullscreen mode Exit fullscreen mode

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


### Filesystem
Enter fullscreen mode Exit fullscreen mode

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


### Crypto
Enter fullscreen mode Exit fullscreen mode

$ 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


### Compression
Enter fullscreen mode Exit fullscreen mode

$ 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


## Archiving
Enter fullscreen mode Exit fullscreen mode

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


### Coreutils
Enter fullscreen mode Exit fullscreen mode

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


### Binutils
Enter fullscreen mode Exit fullscreen mode

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


### Glib2
Enter fullscreen mode Exit fullscreen mode

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


### Text processing
Enter fullscreen mode Exit fullscreen mode

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


### Passwords
Enter fullscreen mode Exit fullscreen mode

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


### Kerberos
Enter fullscreen mode Exit fullscreen mode

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


### User management
Enter fullscreen mode Exit fullscreen mode

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


### More utility commands
Enter fullscreen mode Exit fullscreen mode

$ 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


### Sqlite
Enter fullscreen mode Exit fullscreen mode

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


### PKCS modules
Enter fullscreen mode Exit fullscreen mode

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


### Certificates
Enter fullscreen mode Exit fullscreen mode

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


### Internationalization
Enter fullscreen mode Exit fullscreen mode

$ 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


### Domain Names
Enter fullscreen mode Exit fullscreen mode

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


### Web fetching
Enter fullscreen mode Exit fullscreen mode

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


### GNU TLS
Enter fullscreen mode Exit fullscreen mode

$ pacman -Sr /mnt gnutls


### Assuan Protocol
Enter fullscreen mode Exit fullscreen mode

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


### GNU PG
Enter fullscreen mode Exit fullscreen mode

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


### Pacman
Enter fullscreen mode Exit fullscreen mode

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


### Text Editor
Enter fullscreen mode Exit fullscreen mode

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


### Message passing
Enter fullscreen mode Exit fullscreen mode

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


### USB
Enter fullscreen mode Exit fullscreen mode

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


### PCI
Enter fullscreen mode Exit fullscreen mode

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


### Packet capturing
Enter fullscreen mode Exit fullscreen mode

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


### Routing
Enter fullscreen mode Exit fullscreen mode

$ 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


### Network tools
Enter fullscreen mode Exit fullscreen mode

$ pacman -Sr /mnt iputils $ pacman -Sr /mnt inetutils $ pacman -Sr /mnt net-tools $ pacman -Sr /mnt wpa_supplicant


### ssh
Enter fullscreen mode Exit fullscreen mode

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


### Internet
Enter fullscreen mode Exit fullscreen mode

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


### GNU Package Conf tools
Enter fullscreen mode Exit fullscreen mode

$ 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


### C/C++ Compiler
Enter fullscreen mode Exit fullscreen mode

$ pacman -Sr /mnt libmpc $ pacman -Sr /mnt gcc $ pacman -Sr /mnt libatomic_ops $ pacman -Sr /mnt gc


### Make utility
Enter fullscreen mode Exit fullscreen mode

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


### Python
Enter fullscreen mode Exit fullscreen mode

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


### Ruby
Enter fullscreen mode Exit fullscreen mode

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


### NetworkManager
Enter fullscreen mode Exit fullscreen mode

$ pacman -Sr /mnt networkmanager


### Firewall
Enter fullscreen mode Exit fullscreen mode

$ pacman -Sr /mnt ufw


### Git
Enter fullscreen mode Exit fullscreen mode

$ pacman -Sr /mnt git


### ALSA
Enter fullscreen mode Exit fullscreen mode

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


## 7. Chrooting to the installed system

### Chroot
Enter fullscreen mode Exit fullscreen mode

$ chroot /mnt /usr/bin/bash


### Connect to the internet in chroot'd env
Enter fullscreen mode Exit fullscreen mode

$ vim /etc/resolv.conf nameserver 8.8.8.8


### Generate locale
Enter fullscreen mode Exit fullscreen mode

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


### Time
Enter fullscreen mode Exit fullscreen mode

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


### Host name
Enter fullscreen mode Exit fullscreen mode

$ echo archfs > /etc/hostname


### Initialize pacman
Enter fullscreen mode Exit fullscreen mode

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

### Add system groups
Enter fullscreen mode Exit fullscreen mode

$ 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


### Add system users
Enter fullscreen mode Exit fullscreen mode

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


### Create login user
Enter fullscreen mode Exit fullscreen mode

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


### Add login user to system groups
Enter fullscreen mode Exit fullscreen mode

$ 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


### Switch to the new user
Enter fullscreen mode Exit fullscreen mode

$ su igor $ cd ~ $ sudo su $ exit


### Install package-query (for yaourt)
Enter fullscreen mode Exit fullscreen mode

$ 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*


### Install yaourt
Enter fullscreen mode Exit fullscreen mode

$ 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*


### Now use yaourt to install eudev
Enter fullscreen mode Exit fullscreen mode

$ yaourt eudev


### Generate fstab
Enter fullscreen mode Exit fullscreen mode

$ sudo su $ genfstab / > /etc/fstab $ cat /etc/fstab $ exit


### Procps-ng-nosystemd
Enter fullscreen mode Exit fullscreen mode

$ yaourt procps-ng-nosystemd


### Dbus-nosystemd:
Enter fullscreen mode Exit fullscreen mode

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


## cups-nosystemd:
Enter fullscreen mode Exit fullscreen mode

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


## Configure ssh:
Enter fullscreen mode Exit fullscreen mode

$ 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


## Configure http
Enter fullscreen mode Exit fullscreen mode

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




## 8. Install the kernel!

### Install mkinitcpio
Enter fullscreen mode Exit fullscreen mode

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


### Install linux
Enter fullscreen mode Exit fullscreen mode

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


### Install the init script (or create your own if you like)
Enter fullscreen mode Exit fullscreen mode

$ 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 ..


## 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.
Enter fullscreen mode Exit fullscreen mode

$ 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'


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

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


## 10. Virtualization
Enter fullscreen mode Exit fullscreen mode

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


## 11. Reboot
Enter fullscreen mode Exit fullscreen mode

$ exit $ exit $ reboot

Top comments (0)