Setting up ArchLinux on a Lenovo Yoga

So, I recently broke my computer by spilling tea unto it, so I needed a new computer, and found the Lenovo Yoga 710, which is pretty lightweight and yet strong. As the resources on installing Linux (ArchLinux specifically) on this machine are barely existing, I thought I had to make this post, explaining various critical thing about the installation.

Bear in mind that all this is made from notes and what I recall from when I installed it (yesterday), so there might be minor inaccuracies.

Goals

The goal is to get started with a system, which is fully encrypted, supports wifi, sounds and is usable in general.

There might be things, which I will not cover. In that case, the ArchLinux wiki is your friend.

Creating the Arch USB flash media

Grab the torrent from their website and load it onto an USB flash. Refer to this for details.

Booting to the flash media

You will likely initially have Windows installed on the machine. Due to fastboot, you must do some special steps to close it. In particular, you need to hold down shift while clicking "shutdown".

Before we boot to our flash, you must enable legacy booting. This is done by entering the UEFI menu, by holding down F2 while you start the computer. An interface should appear, navigate to the tab that says something like "Boot". Then enable all the options with "legacy booting" or "legacy USB" or similar.

Now, you can save the settings and restart the computer with the USB flash in it. While you start the computer, hold down F12, which will cause a menu of bootable devices to show up.

Hopefully, the flash drive should appear. Select this, and you should start up.

Getting internet connection

To get any further, you need to connect to the internet. You can either use Ethernet cable (assuming you have an adapter, as the machine in question has no ethernet port) or use Wifi, as I explain below.

Write wifi-menu and you should get a TUI-like interface allowing you to choose your network. This should etablish connection to the internet.

To test the internet connection, do ping google.com.

Setting up the partitions

Now, we want to set up the disk, which we will install ArchLinux on. This disk must first be properly partitioned for the usage.

I will assume your disk is /dev/sda for now. If not, substitute this with the disk, you want to install Arch on (if you don't know which disk, try to run fdisk -l and see if that solves your question).

To create the partitions, we use the cgdisk utility:

cgdisk /dev/sda

This should give you a TUI. Delete all the existing partitions, and create the following:

  1. 128 MB¹ partition named "EFI" with type "EFI partition" (hex code ef00).
  2. 256 MB partition named "boot" with default type (just press enter when it asks for type).
  3. The rest (press enter to fill out the rest) forming a partition named "fs" with default type (again, just press enter).

The utility will probably ask for where to start and end. Just press enter and let it fill out the values.

Don't be freaked out if the highest row contains some small space, that you can't use. This space is usually reserved, and we won't touch it.

Now click "Write" to write the new partition table to the disk.

¹Note that the utility takes units, so you don't need to calculate the number of sectors yourself.

Setting up the file system

Now, we want to initialize the file system of the two first partitions (important: do not touch the last partition yet!):

mkfs.vfat -F32 /dev/sda1
mkfs.ext2 /dev/sda2

Don't change the FS types. These are for the bootloader and thus only support a limited collections of file systems.

Next, we want to set up our main partition (/dev/sda3), which is going to be encrypted at block-level:

cryptsetup -c aes-xts-plain64 -y --use-random luksFormat /dev/sda3

This will prompt you for a password, which you will have to remember. Use a strong password.

Next, we want to mount this partition:

cryptsetup luksOpen /dev/sda3 luks

Now that we have this going, we are going to set up some logical/virtual volumes within this physical partition:

pvcreate /dev/mapper/luks
vgcreate vg0 /dev/mapper/luks
# This is the swap partition, change the size (8G) if necessary.
lvcreate --size 8G vg0 --name swap
# This is the rest of the disk, which will be used to store the root of the filesystem.
lvcreate -l +100%FREE vg0 --name root

We will now set up the swap logical volume:

mkswap /dev/mapper/vg0-swap

Now we can create the filesystem. I choose btrfs because it's the best the Linux kernel has IMO:

mkfs.btrfs /dev/mapper/vg0-root

Bootstrapping the system

Now, first we want to mount it to /mnt, which we can do like this:

mount /dev/mapper/vg0-root /mnt
mkdir /mnt/boot
mount /dev/sda2 /mnt/boot
mkdir /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi

Next, we will install ArchLinux on the disk!

pacstrap /mnt base base-devel efibootmgr grub-efi-x86_64

The disk should have Arch now, but it can't boot yet. First, let's chroot into it:

arch-chroot /mnt

Basic setup

Set the locale:

echo LANGUAGE=en_US >> /etc/locale.conf
echo LANG=en_US.UTF-8 >> /etc/locale.conf
echo LC_ALL=C >> /etc/locale.conf

Set the hw clock:

rm /etc/localtime
ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime
hwclock --systohc --utc

Set the root password:

passwd

Creating your user

Next, you probably want to create a user:

useradd -m -g users -G wheel YOUR_USERNAME_HERE

The -G wheel ensures that you can do sudo.

Next, set the password for this user:

passwd YOUR_USERNAME_HERE

Configuring the kernel

Open up /etc/mkinitcpio.conf in your editor of choice.

Encryption

Add encrypt and lvm2 to the HOOKS line, but BEFORE filesystems, so it looks something like this:

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

Enable nouveau and btrfs

nouveau is the open-source NVIDIA driver, which I found to work better than the proprietary. btrfs is needed because of our file system.

Add nouveau and btrfs to MODULES so the line reads:

MODULES="btrfs nouveau"

Generate the initial ramdisk image

Simply run:

mkinitcpio -p linux

Setting up a bootloader

We'll choose GRUB as our bootloader.

First, install it:

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id="Red Hat Enterprise Linux" --recheck --debug

Note that the "Red Hat Enterprise Linux" is necessary on the hardware, we use, due to some weird whitelist of bootloader IDs.

Configuring GRUB

This step is important. Without this, you won't be able to boot.

Since there are issues with ACPI IRQs on our computer, we will disable those. Add acpi=noirq to /etc/default/grub in GRUB_CMDLINE_LINUX_DEFAULT, so that the line looks something like

GRUB_CMDLINE_LINUX_DEFAULT="acpi=noirq quiet splash"

Next, we want to tell the initial Linux kernel that our disk is encrypted. We can do so by adding cryptdevice=/dev/sda3:luks:allow-discards in the GRUB_CMDLINE_LINUX variable, so it looks something like this:

GRUB_CMDLINE_LINUX="cryptdevice=/dev/sda3:luks:allow-discards"

Finally, we can generate the config:

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

Reboot

You need to be careful not to destroy anything here, as the initial unmounting can contain all sorts of weird operations setting up stuff etc., so do:

exit
cd
umount -R /mnt
swapoff -a
reboot

You should now boot up to an ArchLinux system.

Internet

Again, unless you have Ethernet, use wifi-menu initially.

Disableing the beep sound

First, disable to module

rmmod pcspkr

Then blacklist the module, so you won't have to repeat on reboot:

echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf

Getting audio

I tried a bunch of things, but found that installing pulseaudio and co. worked the best:

pacman -S pulseaudio pulseaudio-jack pulseaudio-alsa

Audio should now work.

Power management and CPU frequency scaling

TLP is a deamon that manages battery and power for you. It's pretty simple and works very well:

pacman -S tlp

To avoid having the machine getting too hot, we install thermald, which will control the fans based on the CPU usage:

pacman -S thermald
systemctl start thermald

Setting up Xorg

Next, we want to set up Xorg, which can be done by simply:

pacman -S xorg-server xorg-apps xorg-xinit

Next, install the window manager or desktop environment of your choice. I personally like i3, but pick what you want.

I recommend installing a display manager, like slim:

pacman -S slim

.xinitrc

In order to get QT to use GTK's style, add this to your .xinitrc:

export QT_STYLE_OVERRIDE=GTK+

(before xrdb -merge)

Touchpad

Just install xf86-input-synaptics:

pacman -S xf86-input-synaptics

It can be a little bothersome, because the touchpad is super sensitive and will sometimes click when writing. Therefore, go to /etc/X11/xorg.conf.d/70-synaptics.conf and set:

Option "FingerLow" "50"
Option "FingerHigh" "70"

If you dislike this driver, try xorg-libinput instead.

Basic desktop necessities

We need a tray icon for battery, network, and volume. We also want to be able to control the volume through the respective keys. For this, install these utilities:

pacman -S volumeicon networkmanager network-manager-applet cbatticon

Make these run when you start your desktop environment or window manager.

Fixing the font size

For unknown reasons, the fonts seem to be screwed up, but adjusting the DPI doesn't work. If you find a good solution, please leave a comment, but until then, I found a working, but ugly solution (visually it looks just like).

First, go to .Xresources and set:

Xft.dpi: 96

Then adjust the cursor size to something like this:

Xcursor.size: 20

Next, open ~/.gtkrc-2.0 and ~/.config/gtk-3.0/settings.ini, and set the font like this:

gtk-font-name="DejaVu Sans 13"

(if you haven't already, install ttf-dejavu)

Although most GTK applications should work fine now, Firefox is still kinda messy with super small UI. I found that going to about:config and setting layout.css.devPixelsPerPx to 1.5 fixed this.

If you use Thunderbird, repeat the instructions for Firefox. You can find about:config under Preferences -> Advanced -> Config Editor.

If you think the font in websites looks small in Firefox, go to Preferences -> Content and adjust the size to what you like.

Firewall

For security, you might want to install a firewall. I recommend ufw, which is simple and nice. Simply do:

pacman -S ufw
ufw enable

And it should work. Refer to the UFW docs to information on adding rules etc. if necessary.

Cleaning up

You can uninstall efibootmgr and wifi-menu if you want to.

Finally

Reboot!

reboot

and hopefully you computer won't explode.

Troubleshooting

I ran into one problem, which took me a while to fix. When I booted, it kept saying something like a start job started by dev-disk-by.... I ended up fixing it by booting to the USB stick and doing:

# Mount the disk
cryptsetup luksOpen /dev/sda3 luks
mount /dev/mapper/vg0-root /mnt
mkdir /mnt/boot
mount /dev/sda2 /mnt/boot
mkdir /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi
# Install necessary utilities
pacman -S efibootmgr
# Reconstruct initrd
pacman -S linux
mkinitcpio -p linux
# Reinstall GRUB
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id="Red Hat Enterprise Linux" --recheck --debug
grub-mkconfig -o /boot/grub/grub.cfg
# Remake the swap
mkswap /dev/mapper/vg0-swap
# Cleanup
pacman -Rncs efibootmgr

If you get problems with booting, run the above lines in bash and try to reboot.

Things I haven't figured out

  • Touchscreen. No idea on how to get it working, but I haven't tried much either, since I don't really use it.

Credits

The authors of the ArchLinux wiki deserves a huge "thank you". That wiki is an absolutely amazing resource, for not only ArchLinux but Linux in general.


Follow me on Twitter or Github.