Skip to content

Instantly share code, notes, and snippets.

@sjoqvist
Created February 24, 2014 13:00
Show Gist options
  • Save sjoqvist/9187974 to your computer and use it in GitHub Desktop.
Save sjoqvist/9187974 to your computer and use it in GitHub Desktop.
Guide to install Arch Linux on an HP Pavilion g6 laptop with encryption and suspend-to-disk using LVM on LUKS

Arch Linux on HP Pavilion g6 with encryption and suspend-to-disk using LVM on LUKS

Hardware (relevant to this guide)

  • Exact model: HP Pavilion g6-1229so (I believe this is detailed enough to explain for example that the keyboard layout is Swedish)
  • Firmware Interface: BIOS (i.e. UEFI not available)
  • Graphics controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
  • Wi-Fi controller: Ralink corp. RT5390 Wireless 802.11n 1T/1R PCIe
  • RAM: 4GB

License

Copyright (c) 2014, Anders Sjöqvist

Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

Acknowledgments

Remarks

  1. I used nano while installing, and there's some reference to it in the guide. Feel free to use whatever editor you're comfortable with.
  2. Feel free to pick other names for things than lvm, system, lvswap, lvroot, arch-host and anders (especially the last one, which happens to be my given name).
  3. For several reasons, I never cleared my drive before installing. Typically, you want to do this partly to get rid of old unencrypted data, and partly to keep information about how much of your space you've used up secret. In order to achieve the latter, you'll want to fill the encrypted drive with data from /dev/zero.
  4. I'm assuming that there's a working Internet connection using an Ethernet cable during the entire installation process.

Installation

Place the Arch Linux image on a flash drive or CD, and use it when rebooting the laptop. Prepare the disk with GPT:

sgdisk -Z /dev/sda

A small partition is needed for GRUB to work with GPT:

sgdisk -n 1:0:+2M /dev/sda
sgdisk -t 1:ef02 /dev/sda

I chose 256MB for my boot partition. Some people suggest 200MB.

sgdisk -n 2:0:+256M /dev/sda
sgdisk -t 2:8300 /dev/sda

The rest of the disk will be used for LVM:

sgdisk -n 3:0:0 /dev/sda
sgdisk -t 3:8e00 /dev/sda

Make sure that the kernel handles encryption:

modprobe dm-crypt

I chose the default encryption, but used a stronger hash function for my password, and used /dev/random instead of /dev/urandom to avoid the theoretical possibility of a weak key. This could happen if /dev/urandom runs out of entropy.

cryptsetup --hash sha512 --iter-time 5000 --use-random \
--verify-passphrase luksFormat /dev/sda3
cryptsetup luksOpen /dev/sda3 lvm

Setting up a logical volume, volume group and two partitions. I picked a slightly larger swap partition than the size of my RAM (4GB).

pvcreate /dev/mapper/lvm
vgcreate system /dev/mapper/lvm
lvcreate system --size 5G -n lvswap
lvcreate system --extents 100%FREE -n lvroot

Create the file systems. In my case, I chose ext2 for the boot partitions, although there are several others that would have worked as well.

mkfs.ext2 /dev/sda2
mkswap /dev/mapper/system-lvswap
mkfs.ext4 /dev/mapper/system-lvroot

Mount everything:

mount /dev/system/lvroot /mnt
swapon /dev/mapper/system-lvswap
mkdir /mnt/boot
mount /dev/sda2 /mnt/boot

Edit the file /etc/pacman.d/mirrorlist to use proper mirrors for downloading the system. This file will be copied onto your newly installed system. I installed my system while being in China, and moving Chinese mirrors above the others made my downloads significantly faster.

Install the basic system. I decided to install the basic development tools as well at this point.

pacstrap -i /mnt base base-devel

Generate /etc/fstab and verify that it looks correct:

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

Change root and install the boot loader package (GRUB in our case):

arch-chroot /mnt /bin/bash
pacman -S grub

When configuring GRUB, we need to decide whether we want to use partition UUID or change the default settings. I chose to use UUID. You need to copy these identifiers into a config file. Do this in any way that you like. In my case, I left the 'chroot' environment since UUID couldn't be read from the disks as easily from within. Here's a (complicated) way that should work:

exit
rootvol=/dev/disk/by-uuid/$(lsblk -dno UUID /dev/sda3)
swapvol=/dev/disk/by-uuid/$(lsblk -dno UUID /dev/system/lvswap)

Check that the paths exist:

ls -l $rootvol $swapvol

To edit the GRUB configuration with a single command (otherwise do it manually according to the example below):

sed -i \
"s,^\(GRUB_CMDLINE_LINUX_DEFAULT=\".*\)\"$,\1 cryptdevice=${rootvol}:system resume=$swapvol\"," \
/mnt/etc/default/grub

Now open /mnt/etc/default/grub to check that the result looks reasonable. It should be something like GRUB_CMDLINE_LINUX_DEFAULT="quiet cryptdevice=/dev/disk/by-uuid/01234567-89ab-cdef-0123-456789abcdef:system resume=/dev/disk/by-uuid/fedcba98-7654-3210-fedc-ba9876543210".

The complete the detour, return to the chroot environment:

arch-chroot /mnt /bin/bash

Then install GRUB and its config file. Don't worry about the i386-pc, it still applies to 64-bit Arch Linux.

grub-install --target=i386-pc --recheck /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

Open /etc/mkinitcpio.conf. While not necessary, I chose to require my graphics driver early: MODULES="i915" Then edit the hooks. You'll need encrypt and lvm2 because of the encryption, and resume because of suspend-to-disk. These should all go before the filesystems hook. It should look something like this: HOOKS="... encrypt lvm2 resume ... filesystems ..."

Build the initramfs image:

mkinitcpio -p linux

Edit /etc/locale.gen and uncomment what you want, for example en_US.UTF-8 UTF-8. Then run

locale-gen
echo 'LANG="en_US.UTF-8"' > /etc/locale.conf

Set up the timezone. Again, I happened to be in China and in my case this meant

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Unless you have reasons to keep the hardware clock at local time:

hwclock --systohc --utc

Make sure that the Ethernet connection works after reboot:

systemctl enable dhcpcd.service

Come up with a hostname:

echo arch-host > /etc/hostname

At this point, I chose to set up ntpd to let the system keep track of the time. If you want to do the same, run

pacman -S ntp

Then edit /etc/ntp.conf so that it refers to local servers. Afterwards:

systemctl enable ntpd
systemctl start ntpd

Check that ntpd is able to update by running ntpq -np. You can request an update manually using ntpd -q.

At this point, I was eager to boot into my new system and log in as root (without password) to see that everything was working:

exit
shutdown -r now

From now on, the settings get more specific, and even more focused on the particular hardware on my laptop. Be selective if you have different hardware.

These should be safe options for the graphics driver:

echo "options i915 i915_enable_rc6=7 i915_enable_fbc=1 lvds_downclock=1" > /etc/modprobe.d/i915.conf

Installing X Windows:

pacman -S xorg-server xorg-server-utils xorg-xinit
pacman -S mesa

Graphics driver for X Windows:

pacman -S xf86-video-intel

I noticed problems with tearing. In order to get rid of that, create the file /etc/X11/xorg.conf.d/20-intel.conf and type the following:

Section "Device"
  Identifier "Intel Graphics"
  Driver "intel"
  Option "TearFree" "true"
EndSection

In order to get the touchpad working:

pacman -S xf86-input-synaptics

The Wi-Fi card is already supported by the kernel, but this is needed to connect to networks:

sudo pacman -S iw wpa_supplicant

Time to set up a user account. I wanted zsh as my shell:

pacman -S zsh
useradd -m -g users -G wheel -s /usr/bin/zsh anders
passwd anders
export EDITOR=nano
visudo

Uncomment the line %wheel ALL=(ALL) ALL. Then change the root password:

passwd

I wanted Awesome WM:

sudo pacman -S awesome

Leave the root account:

exit

Log in to your new account, and then create ~/.xinitrc with the following content:

[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources
exec awesome

X Windows can now be started with startx.

You'll want to continue configuring the system. For example, what you've done so far should allow suspend-to-disk, but you'll have to figure out how to issue the actual command. A useful package might be pm-utils.

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment