epicartificials blog

Setup Arch linux with i3

14.07.2020

About once a year I try to clean up my computer and experiment with new setups on my computer. This time I have decided that I want to switch from the Manjaro i3 community edition. I was a little worried that when everyone keeps saying that installing Arch linux is difficult, but for the most part it wasn't much difficult. The process is quite straight forward when you follow the Arch Wiki. The only problem I had was with installing the bootloader.

First thing to plan was the layout of partition and space that I want them occupy on my system. In my computer Dell Inspiron 15 Gaming 7655 I have two SSD drives, 512 GB SSD + 1 TB SSD.

The first rule I learned was to keep Windows and Linux operating systems on separate drives. Therefore I have decided to install Windows 10 on the 512 GB drive and Linux on the 1 TB drive.

Partitions

The partition structure of the system looks like this

On 512GB SSD there will be 250GB (C:), 150GB (D:), 100GB (Recovery)
⁣ ⁣ ⁣ ┌───────┬───────┬───────┐
⁣ ⁣  │ 250GB │ 150GB │ 100GB │
⁣ ⁣ ⁣ └───────┴───────┴───────┘

On 1TB   SSD there will be 500MB (/boot), 100GB (/), 60GB (/home), 10GB (swap), 830GB (unallocated)
⁣⁣ ⁣ ⁣ ┌───────┬───────┬──────┬──────┬────────┐
⁣ ⁣ ⁣ │ 500MB │ 100GB │ 60GB │ 3GB⁣ ⁣ | 830GB │
⁣ ⁣ ⁣ ⁣└───────┴───────┴──────┴──────┴────────┘

The recovery partition is a system partition that contains factory settings for my Windows, I could move it to an external CD, but I don't need to necessarily move it.

Arch installation

I have tried to follow multiple video tutorials, but I always got stuck on the bootloader installation. The tutorial that helped me in the end was this one

I will try to summarise the steps here:

  1. Make sure you have Windows installed first
  2. Download the arch iso from https://www.archlinux.org/download/
  3. Download rufus or other bootable USB creation tool
  4. Write the iso file on USB drive
  5. Reboot the computer and select the USB as a boot option by pressing F9

Once in Arch live OS:

  1. check you have an internet connection by typing ping archlinux.org
  2. set correct time by timedatectl set-ntp true
  3. use a command lsblk to show installed partitions and disks
  4. use a command fdisk /dev/sdX to mamange partitions on a disk sdX
  5. To create a new partiton do
    Command [m for help]: n
    Partition type:
     p primary
     e extended
    Select (default p): 
    Partition number (X-Y, default Z):
    Fist sector (X-Y, default X):
    Last sector, +sectors or +size{K,M,G} (X-Y, default Y): +500M
  6. Check the status with Command [m for help]: p
  7. To save the changes do Command [m for help]: w
  8. repeat this process until you create your (preferable 4) partitions
  9. you now have to format the disks with mkfs.ext4 /dev/sdaX
  10. for swap partition you need to do mkswap /dev/sdaX && swapon /dev/sdaX
  11. now mount the partition you want to be / partition with mount /dev/sdaX /mnt
  12. mount a home partition where the user will reside with mkdir /mnt/home && mount /dev/sdaX /mnt/home
  13. now create to bootloader mkdir /mnt/efi && mount /dev/sdaX /mnt/efi
  14. install linux pacstrap /mnt base linux linux-firmware
  15. generate fstab file so you can boot properly with genfstab -U /mnt >> /mnt/etc/fstab
  16. now login to the arch linux with arch-chroot /mnt
  17. set the correct timezone ln -sf /usr/share/zoneinfo/Eurote/Bratislava /etc/localtime
  18. switch to use a hardware clocks hwclock --systohc
  19. install a text editor sudo pacman -S nano or sudo pacman -S vim
  20. edit the file nano /etc/locale.gen and find the line #en_US.UTF-8 UTF8 and uncomment it
  21. update locale by doing locale-gen
  22. create a file nano /etc/locale.conf and write LANG=en_US.UTF-8 then save
  23. create a file nano /etc/hosts and write
    127.0.0.1   localhost
    ::1         localhost
    127.0.1.1   YOURNAME.localdomain    YOURNAME
  24. install a network manager sudo pacman -S networkmanager or sudo pacman -S netctl
  25. enable the network manager by sudo systemctl enable NetworkManager
  26. add your user useradd -G wheel,audio,video -m YOURNAME
  27. set your password with passwd YOURNAME
  28. set the root password with passwd
  29. install the bootloader sudo pacman -S grub efibootmgr
  30. install osprober sudo pacman -S os-prober
  31. install grub
    [root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/efi/ --bootloader-id=GRUB
    Installing for x86_64-efi platform.
    Installation finished. No errors reported.
  32. generate a config file grub-mkconfig -o /boot/grub/grub.cfg
  33. now reboot and check everything working

Post Arch installation

Now with Arch linux setup we have just a terminal interface. In order to have a usable deskktop we need to install Xorg. Then we can install a display manager if we want to such as lightdm or lxdm. After that we need to install a window manager such as i3, Xmonad, dwm, AwesomeWM or any other.

After we have a usable desktop enviroment we can install the tools that we are going to use:

We now have a ready dualboot with Arch and Windows 10 ready. Although if we want to access the Windows 10 for something trivial, we need to reboot the computer, start Windows 10, do the thing, reboot the computer, go back to Arch. The next problem is that we want to share the data between these operating systems.

Share partitions between Windows and Linux

Windows 10 uses either FAT or NTFS format of partitions. Linux uses mostly ext4 format. Linux can read the NTFS partition, but Windows can't read the ext4 partition. Therefore we can mount the windows drive on linux.

# install ntfs-3g so you can set the mount permissions
sudo pacman -S ntfs-3g

# get the partition UUID
sudo blkid -S UUID

# automount the partition on boot
cp /etc/fstab /etc/fstabl.backup
nano /etc/fstab

# place this line there
UUID=YOUR-PARTITION-UUID    /d  ntfs-3g     rw,defaults,uid=1000,fmask=0022,dmask=0000,utf8     0   0

Now when you reboot it should mount your Windows disk D: to /d/

Boot to Windows 10 from Arch linux

As mentioned above, sometimes I don't want to reboot to Windows just for any small stuff. The solution I found was VirtualBox. Virtualbox allowes us to create virtual machines but, you may ask, we want to access our physical Windows, not a virtual one. Luckily Virtualbox has an option for that. It's called accessing a raw disk partition. Be careful and read the manual in the link before properly as the WARNING says Raw hard disk access is for expert users only. Incorrect use or use of an outdated configuration can lead to total loss of data on the physical disk. Most importantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption.

The steps are quite simple. First you do the command to create a .vmdk file VBoxManage internalcommands createrawvmdk -filename /root/win.vmdk -rawdisk /dev/sda. This will mount the whole disk (which for me contains only Windows). You can also specify only certain partitions with -partitions 1,3 etc. Make sure to include a bootloader partition as well when specifying the partitions.

After creating the vmdk file you can start Virtualbox which needs to be run as root. Add a new machine, select Windows 10, create it from an existing image, add the vmdk file there. Set how much memory you want to assing and press done. Set the number of cores to at least 4, enable EFI and launch. You should boot into your real Windows 10 and everything should work fine. The progress and data are shared between your real Windows and the virtual one.

#linux #arch #i3