Arch Linux (LVM) dual-boot with Windows tutorial

I’ve been trying various Linux distributions on my laptop(HP Envy j0014tx) since I got it. So far I have tried Ubuntu, Fedora and Fedora spin (KDE). Ubuntu got boring once I started using it for a while and fedora got buggy after the 24 update. After some disastrous hardships me and my friend went through at the last hackathon we had attended, I decided to move from the KDE environment altogether. I found KDE really complicated and overloaded with customisable features, which is what most linux users look forward to, but not really what I wanted(sweat smile). I really like the cleanliness GNOME environment and I like the concept of installing a distro without a desktop environment as it gives user the freedom to install the one they want. I have decided not to install Fedora and Ubuntu anymore. The next option was Debian, which is considered to be the most stable Linux distro around and ideally you would want a stable OS for your laptop but, I thought I’ll learn a bit about Linux from this install (well.. why not, its study leave) and chose to install Arch Linux. I had installed a version of Arch Linux previously on my desktop computer but I knew the story would be different installing on my laptop with as the desktop was pretty old and used Legacy boot mode. Since I liked to get my hands dirty, I decided to proceed with it anyway.

When installing Arch, you do have the option to download a fully automated GUI mode install (like Arch Anywhere or Architect ) but if you are like me and loves learning stuff to the core, you can install the image from Arch Linux website which doesn’t come with an installer. I had initially decided to write this article (my first article on the web) as I was doing the installation process but didn’t have any other device to work on (desktop needs repair). Now I am glad I didn’t do that ’cause it took me 2 installs and 2 days to get Arch working. For reference, I decided to follow the Arch wiki page to install the distro and ended up looking for all other sources as well, but most of the commands I use here would be a direct clone of the wiki page. I have decided to skip the making a bootable USB part (trust me, you wouldn’t wanna be installing Arch if you don’t know how to make a USB bootable). So here’s how I finally installed the distro:


Before installation:

You need to have some unallocated space for installing Arch Linux, I am dual-booting with Windows 8.1 here and had previously freed up enough space for installing Arch. Also, I would advice you to have a wired connection while installing the distro atleast ’cause a wired connection will be detected automatically without any configuration. A wireless connection could be set up but I decided to set it up after installation.

Installation:

Test the connection by pinging a website:

 ping www.google.com

Update the system clock:

timedatectl set-ntp true

Partitioning:

This may vary with the boot mode you are in. On older PCs it may be MBR boot mode. My computer is using UEFI boot mode, you can do

fdisk -l

to list all partitions in your hard-drive and check the boot mode. There are various partitioning tools one can use for partitioning Arch, I used gdisk as it is directly compatible with UEFI bootmode. In UEFI bootmode, you will not be needing a /boot partition as the bootloader should be installed in the EFI partition. I will be using LVM parition to manage all the different partitions that Arch will be needing (You may follow normal partitioning instead of LVM as well ).

LVM is mainly used to concatenate space from different devices. Here’s the link on how to do it: https://wiki.archlinux.org/index.php/LVM.

Assuming that you have sufficient space to install Arch, type:

gdisk /dev/sda

/dev/sda can be replaced with the device you are installing to. Press ? to get options. Then:

  1. Create a partition (or delete on of your partition to get space for installing and then create).
  2. Assign appropirate number (here I’m using 4).
  3. Press return on First sector (unless you would like to do something clever), and when it asks for End sector press return to use entire free space or type + followed by size followed by G or M depending on the size
  4. Change the partition type to LVM by referring to the list of Hexcodes available.
  5. Write the changes to disk.

Now we need to create Physical Volume on the LVM partition. Then add Volume Group on it to add various other Logical volumes for creating partitions for Arch (replace /dev/sda4 with the appropriate LVM partition in your drive for the following commands).

pvcreate /dev/sda4
vgcreate archvol /dev/sda4

NOTE: archvol can be replaced with any name. The partitions will be available under this name at /dev/mapper/archlin-lvname.

Now lets create logical volumes for root,swap and home. I am installing root and home in different partitions if you want, you may install it in single partition, in that case you need only two logical partitions.

lvcreate -L 200G -n root archvol
lvcreate -L 5G -n swap archvol
lvcreate -l 100%FREE -n home archvol

I have used up the entire free space left in the physical volume for home (note ‘l’ instead of ‘L’) . You may use lvremove to remove logical volumes.

Now we format home and root partition as ext4.

mkfs.ext4 /dev/sda4/archlin/root
mkfs.ext4 /dev/sda4/archlin/home

For swap partition:

mkswap /dev/sda4/archlin/swap
swapon /dev/sda4/archlin/swap

Mount root partition to /mnt directory:

mount /dev/sda4/archlin/root /mnt

Make a separate directory for home and mount home partition to it:

mkdir -p /mnt/home
mount /dev/sda4/archlin/home /mnt/home

Mount the EFI partition to /mnt/boot/efi (use gdisk -l or fdisk -l to determine your EFI partition and mount that parition for me, it was on /dev/sda1):

mkdir -p /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi

This will make sure that bootloader gets installed to EFI partition.

Install system packages:

pacstrap /mnt base base-devel

Sit and relax as this command will download packages from internet and install it. Wait till it gets completed.

Generate fstab:

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

This command generates fstab file which contains information about your partitions and mounting etc.

Change to root:

arch-chroot /mnt

Now we will begin making changes to our Arch Linux on our hard-drive.

Set time-zone:

ln -s /usr/share/zoneinfo/Region/City /etc/localtime
hwclock --systohc

Set language:

Uncomment en_US.UTF-8 UTF-8 in /etc/locale.gen. You can use nano or vi editor. Then create file /etc/locale.conf and type the following:

LANG=en_US.UTF-8

Create file /etc/vconsole.conf and insert the following to it to set keyboard layout:

KEYMAP=de-latin1

Set Hostname:

This will set your computer’s name on a network. Create file /etc/hostname and insert:

yourhostnamehere

Initramfs:

Since we are using LVM we need to regenereate initramfs to detect the LVM partition. Add lvm2 to the uncommented string HOOKS towards the end of /etc/mkinitcpio.conf file (The following line maybe different in your PC):

HOOKS="base udev autodetect modconf block lvm2 filesystems keyboard fsck"

Add it before filesystems. Make sure you are inserting it in the already uncommented line (without ‘#’). Now, regenerate initramfs image using:

mkinitcpio -p linux

Creating root password:

passwd

Then type in your password.

Installing bootloader:

Install grub and efibootmgr packages using pacman.

pacman -S grub efibootmgr

Configuring Boot-loader:

There are many boot-loaders available, you can choose anyone and install, I’m using grub here (Mount EFI partiton also).

mount /dev/sda1 /mnt/boot/efi
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=archlinux

Here I’m not installing boot-loader into EFI partition instead to its parent directory. Some say writing it to EFI partition is a good practice ’cause even if your Linux partition gets corrupted you will still be able to load the other OS from grub menu. Most computers have a way to launch OSes from BIOS menu even if grub fails. So it doesn’t matter.

You may change the bootloader-id option to something else. This will be the title of the boot-loader when it is listed in BIOS. Then generate the configuration file:

grub-mkconfig -o /boot/grub/grub.cfg

Adding the Windows boot option to grub:

Open the file /boot/grub/grub.cfg and add the following to provide a windows boot option. You could install os-prober package via pacman and then generate grub configuration file to detect windows partition but it didn’t work for me so had to add it manually (thanking the website tech.memoryimprintstudio.com for that).

menuentry "Windows" {
insmod part_gpt
insmod fat
insmod search_fs_uuid
insmod chain
search --fs-uuid --set=root $hints_string $fs_uuid
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}

Replace $hints_string by the output of

grub-probe --target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi 

Replace $fs_uuid by the output of:

grub-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi

Installation process is now complete. You may exit from root and unmount the drive and reboot to boot into Arch Linux.

exit
umount -R /mnt
reboot

You will be greeted with Arch Linux login type username as root and the password you had created earlier to login.

Installing a Desktop-Environment

You may install a Desktop environment to suit your style here’s a link to Desktop Environments available. I’ve installed GNOME and will include that too. Install GNOME packages:

pacman -S gnome gnome-extra

Then install a display manager I used GDM(GNOME Display Manager):

pacman -S gdm

Enable GDM from boot and start GDM:

systemctl enable gdm
systemctl start gdm.service

GNOME lockscreen shows up and you can login as root and later add a user. Also configure wireless networks by enabling NetworkManager using systemctl.

And that’s all folks!