четверг, 5 января 2017 г.

Detailed Arch Linux installation for beginners.

1. Preparation
First of all we need to get the latest installation CD:

https://www.archlinux.org/download/ - here we can get it via torrent or download directly from one of Arch Linux mirrors.

After successfull download it is nesessary to burn it to DVD or prepare USB-stick.

for Linux users:

$ md5sum isoimage.iso
after calculating the result should be the same for source *.iso and for burned one!

burn DVD through terminal:
$ growisofs -dvd-compat -Z /dev/sr0=isoimage.iso | md5sum
dvd+rw-tools package contains this command
or use any other DVD-burning application: brasero, xfburn etc.

prepare a stick:
# dd if=isoimage.iso of=/dev/sdX status=progress | md5sum

for Windows users:

burn DVD through any DVD-burning application

prepare stick with "win32 disk imager"

for macOS users:

burn DVD through any DVD-burning application

prepare a stick:
insert USB-stick
open Terminal
$ sudo -s
# diskutil list (find your stick)
# umount /dev/diskX
# dd if=isoimage.iso of=/dev/diskX

2. Boot installation media

In my article I will use UEFI, so please keep in mind that on older hardware some steps won't work!
Also it is recommended to disable CSM in your UEFI-bios.

This is what you should see if the previous step was made correctly:
By default the first entry will boot.

When the boot process is completed a shell with blinking cursor should appear:

First of all it is nesessary to check if the network is up to be able to proceed with installation:
# ifconfig -a
On the picture we can see that we got ip address via dhcp (by default), if you have non-standard configuration of you network or wish to connect via Wi-Fi - please read the "Setup network" section of my article. Otherwise let's proceed to the preparation of our storage for the installation.

3. Prepare storage

Important! Always check carefully that the disk with which you are working is selected correctly, otherwise you can loose your data!

# ls /dev | grep sd
This command shows all the contents of /dev directory containing letters "sd"
In my case the result is:
sda
It means that I have 1 physical drive with no partitions. Partitioned drives are shown as sdX1, sdX2, ..

Let's choose and write partition table:
# gdisk /dev/sda
o (it will create clean GPT partition table)
w (it will write all changes to the media)

The next step is to create some partitions:
# cgdisk /dev/sda
[New] - Enter - 128M - ef00 - EFI (create special EFI partition for bootloader)
Select free space after - [New] - Enter - 10G - 8300 - System (root "/" partition)
Select free space after - [New] - Enter - 1G - 8200 - Swap (swap partition)
Select free space after - [New] - Enter - 4G - 8300 - Var ("/var" partition)
Select free space after - [New] - Enter - Enter - 8300 - Home ("/home" partition)
[Write]
[Quit]

Now let's choose and format our partitions:
# mkfs.fat -F32 -v /dev/sda1 -n EFI
# mkfs.ext4 -L System /dev/sda2
# mkswap -L Swap /dev/sda3
# mkfs.ext4 -L Var /dev/sda4
# mkfs.ext4 -L Home /dev/sda5
# swapon /dev/sda3

You can create as many partitions as you want, but you should understand what each partition will be used for! For better understanding please read http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/

4. Creating mountpoints
It is important to mount our root "/" filesystem and then to create some directories to be able to proceed with the installation:

# mount /dev/sda2 /mnt
# mkdir /mnt/{boot,var,home}
# mount /dev/sda1 /mnt/boot
# mount /dev/sda4 /mnt/var
# mount /dev/sda5 /mnt/home

Please check that the mounted filesystems and mountpoints are correct with the:
# lsblk

5. Basic system installation

In Arch Linux pacstrap command is used to download and install packages during basic installation:
# pacstrap /mnt base base-devel sudo syslinux traceroute openssh mc docbook-xsl pv srm efibootmgr p7zip dosfstools ntfs-3g acpid net-tools usbip btrfs-progs cpulimit dmidecode zip unzip unarj unace unrar ethtool hexedit cabextract hfsprogs atool atftp lm_sensors gpm hddtemp hdparm sdparm cifs-utils bridge-utils dnsutils cronie xmlto pkgfile rsync nbtscan ico2xpm gptfdisk gpart parted mtools smartmontools tree xdg-user-dirs dvd+rw-tools gif2png nrg2iso ccd2iso mdf2iso bin2iso squashfs-tools exfat-utils pm-utils hwinfo f2fs-tools fsarchiver lsof strace htop inotify-tools cdrkit cdparanoia dnsmasq icoutils

Not all of these pacakges are strictly needed but they can be very handy in the future.
TIP: if it is difficult for you to manually enter the whole list of packages - you can connect from any other PC to your installation via SSH-protocol using putty in Windows or terminal in Linux or macOS. For this enter:
# passwd
Enter your root password twice!
# systemctl restart sshd
# ifconfig (find what IP-address you have)
Connect remotely: root@<ip-address>
Enter "Yes" to accept RSA key
Enter root password
Now you can read this article and paste necessary commands in the ssh-terminal!

If all packages were downloaded and installed successfully we can proceed.

6. Basic setup

Now we need to inform our system about partitions and filesystems: to which mountpoint each partitin should be mounted to. So we need to enter:

# genfstab -U -p /mnt >> /mnt/etc/fstab

It will generate special file called "fstab" with the list of our partitions and mountpoints and the option "-U" will help to mount them using UUID 

# cat /mnt/etc/fstab (check if everything is OK)
# arch-chroot /mnt (enter the newly installed system via chroot)

Locales

# nano /etc/locale.gen (edit additional locales, in my case English, Russian)
en_US.UTF-8 UTF-8
ru_RU.UTF-8 UTF-8

Ctrl+X, Enter (This will save changed document)

# nano /etc/locale.conf
LANG=ru_RU.UTF-8

# nano /etc/vconsole.conf
KEYMAP=ru
FONT=cyr-sun16

# locale-gen

Time

# date
# hwclock --set --date "MM/DD/YYYY hh:mm:ss" (set date and time if it is nesessary)
# hwclock --systohc (sync system clock to hardware clock - optional)
# hwclock --hctosys (sync hardware clock to system clock - optional)

# nano /etc/adjtime
LOCAL (or UTC)

# ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime

Hostname

# nano /etc/hostname
ARCH-TEST

Repositories

# nano /etc/pacman.conf
[archlinuxfr]
SigLevel = Optional
Server = http://repo.archlinux.fr/$arch

This is the largest repository in Arch Linux where you can download extra packages not included in official repositories.

# pacman -Syu (update package database)
# pacman -Scc (clean local package database)

Bootloader (UEFI)

# mkdir -p /boot/EFI/syslinux
# cp -r /usr/lib/syslinux/efi64/* /boot/EFI/syslinux
# efibootmgr -c -d /dev/sda -p 1 -l /EFI/syslinux/syslinux.efi -L "UEFI: Arch Test"
(This command should be executed very carefully, check the disk and the partition number!)

# blkid /dev/sda2
(You should get all info about partition: Name, UUID, PARTUUID etc.) Write down, remember or copy via ssh the UUID or PARTUUID!

# nano /boot/syslinux/syslinux.cfg
Find string:
APPEND root=/dev/... rw 
and replace it with:
APPEND root=PARTUUID=<paste_here_your_PARTUUID> rw

The same should be repeated for "LABEL archfallback"
It will prevent your installation from boot errors if you forgot some usb-stick in the port and rebooted your PC. For extra options please read: https://wiki.archlinux.org/index.php/syslinux

Kernel modules
# nano /etc/mkinitcpio.conf
(This file contains modules and hooks for early boot stage, it is strictly nesessary to edit it if you need something to be configured before the root file system is mounted)

# mkinitcpio -p linux (if you made changes and want to apply them)

Services
Also we need to setup and enable some services:

# systemctl enable sshd.service (SSH Daemon)
# systemctl enable acpid.service (ACPI Subsystem)
# systemctl enable gpm.service (Enable mouse support in terminal)
# systemctl enable cronie.service (Schedule tasks)
# systemctl enable atftpd (Advanced TFTP daemon)

# chown nobody:users /srv/atftp (set correct rights to our TFTP directory)

Users
# passwd
(Change root password)
# useradd -m -g users -s /bin/bash -G audio,video,network,optical,storage,lp,scanner,uucp,wheel -c "User" user (create new user and add him to several system groups)
# passwd user (change user password)

Reboot

# exit
# umount /mnt/{boot,var,home}
# umount /mnt
# reboot

Final steps

If you did everything right a fresh Arch Linux system should successfully boot.
You should be able to see console and move mouse in it, also if your network is up - you will be able to connect to your PC remotely via SSH (as user NOT as root!) for further setup!

7. Network

Wired

# ifconfig -a
If you have wired ethernet connection you should find something like enp0s6 (in my case)
In Arch Linux netctl daemon controls network connections, so first of all we should choose what type of connection we want to setup:

# ls /etc/netctl/examples
Here are some example configuration files. In my case it will be ethernet-static.
# cp /etc/netctl/examples/ethernet-static /etc/netctl/

Now change these lines, according to your "ifconfig -a" output:
# nano /etc/netctl/ethernet-static
Interface=enp0s6
Address=('192.168.1.115/24')
Gateway='192.168.1.1'
DNS=('192.168.1.1')

# netctl enable ethernet-static
# netctl start ethernet-static
# ping google.com
If you did everything correctly you will see ping responses from google.com
The setup of other types of wired connections is indentical.

Wireless

# rfkill list all (display all locked/unlocked/turned off wireless, bluetooth devices)
# rfkill unblock all (unblock all locked/unlocked/turned off wireless, bluetooth devices)
# iw dev (some usefull information about your wireless device)
# iw dev wlp2s0 link (check if you're connected to the network)
# ip link set wlp2s0 up (set your wireless interface up)
# ip link show wlp2s0 (check if the wireless interface is up)
# iw dev wlp2s0 scan | less (display available SSIDs)
# iw dev wlp2s0 connect SSID (no encryption)
# iw dev wlp2s0 connect SSID key 0:WEP_KEY
# iw dev wlp2s0 connect SSID key d:2:WEP_KEY (ASCII WEP key)
# wpa_supplicant -B -i wlp2s0 -c <(wpa_passphrase SSID WPA_KEY)
# nano /etc/wpa_supplicant.conf (this is for hidden SSIDs)
network={

                ssid="HIDDEN_SSID"
                scan_ssid=1
                psk="PASSWORD"
                mode=0
                proto=WPA2
                key_mgmt=WPA-PSK
                pairwise=CCMP
                group=CCMP
                auth_alg=OPEN
                id_str="ARCH-TEST"
                priority=1
}
# wpa_supplicant -B -i wlp2s0 -c /etc/wpa_supplicant.conf
# dhcpcd wlp2s0
# ping google.com

Now you should be able to access Internet through your wireless network!

8. Graphical environment
Xorg server


Let's setup Xorg server to be able to use more user-friendly interface:
# pacman -S xorg
(Here you can either choose only some components or if you're not sure install all of them)
# cp /usr/share/X11/xorg.conf.d/* /etc/X11/xorg.conf.d/
# nano /etc/X11/xorg.conf.d/10-evdev.conf
(Here it is nessesary to add some options to have server keyboard layouts and to be able to change them)
Add these lines in the section with Identifier "evdev keyboard catchall":
                Option "XkbLayout" "us,ru"
Option "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll"
Save the document.

# cd /etc/fonts/conf.d
# ln -s ../conf.avail/XX-foo.conf (this is for proper font hinting)
# pacman -S xorg-xinit evtest ttf-liberation (some extra useful packages)
Now you have installed basic graphical environment.

MATE Desktop
# pacman -S mate mate-extra
(Here you can choose to install all or separate components)

# pacman -S gtk-engines gtk-engine-murrine xdg-user-dirs-gtk pulseaudio ossp alsa-plugins alsa-utils pulseaudio-alsa lightdm lightdm-gtk-greeter tigervnc ffmpegthumbnailer gtk-recordmydesktop pavucontrol gvfs-smb gvfs-mtp gvfs-gphoto2 gnome-disk-utility gparted transmission-gtk gnome-schedule chromium python2-blueman obexftp obextool cups
networkmanager modemmanager ppp usb_modeswitch network-manager-applet 
(This is some basic packages which can help you)
# netctl disable <you-ethernet-connection>
(to be able to configure networks through Network Manager)
# systemctl enable NetworkManager
# systemctl enable bluetooth
# systemctl enable org.cups.cupsd.service (Printing subsystem)
# systemctl enable cups-browsed.service
# systemctl enable lightdm (Enable display manager)
# reboot
If you did everything correctly you will see login screen:

Enter your password and you are on your own graphical MATE desktop!
Congratulations!

Now you can read official Arch Linux documentaion and try to install some more packages:
Open Applications -> System -> MATE Terminal and enter:
$ su
Enter your root password
# pacman -S libreoffice-fresh
# pacman -S yaourt (to be able to get packages from AUR repository)