You are currently viewing Installing Arch Linux on a USB Key for UEFI systems

Installing Arch Linux on a USB Key for UEFI systems

Task:

Install Arch on a UEFI bootable USB drive or SD card so that it can be used on machines that have we don’t have the luxury of changing the local disk partition structure (corporate IT policy, low space, etc.)

Hardware:

So I have this 32GB USB 3.0 Key that I’m going to use, it seems to perform well enough to be usable without being frustrating.  Sure is ugly though!  I’ve ordered a nice fast SD card that will take over when it arrives.  If your UEFI firmware can read the SD card it will boot from it using the same methods.

 

I’m going to use a virtual machine for the install, you could do it on the real hardware or use Virtualbox or similar.  You don’t need it, but it does mean you don’t have to present the core OS drive to the VM so you can’t accidentally delete your Windows install.  Also you can use the host PC fully while you go through the installation process.  Finally it saves you messing about with WiFi, you can do that later which is handy, especially if you need to install a package or files before you can get WiFi working, so for me its a big benefit!

I’m using VMware Workstation 10.x.  The VM is setup is simple, some memory, some CPU’s, a local disk that we won’t use, our Arch Linux .iso is attached to the virtual CD/DVD drive, we use NAT so that our VM has network access and that about it.

After booting the .iso I’ll insert the USB Key and pass it through to the VM then, check dmesg to see what it is called.  So for this install its going to be /dev/sdb that we are working with.  If i run ‘fdisk -l’ the only disks I see are the 512MB virtual disk and the 32GB USB key, so my Windows SSD is nice and safe.  This VM can’t delete what it doesn’t know about.

Install – Disk Partitions:

First we will change the keyboard, then partition the disk as a GPT disk with a UEFI boot partition (FAT 32)

  • # loadkeys /usr/share/kbd/keymaps/i386/qwerty/uk.map.gz
  • # gdisk /dev/sdb

In gdisk I issued command o, which creates a new GPT partition table, the I created the following partitions.

  • sdb1 512M EF00 for /boot
  • sdb2 1024M 8200 for swap
  • sdb3 (all remaining space) 8300 for /

Then we create some partitions, the boot partition absolutely must be fat32 as that is what the UEFI firmware will expect to see.

  • For /boot
    • mkfs.fat -F32 /dev/sdb1
  • For swap
    • mkswap /dev/sdb2
    • (optional: if you want to use during the install) swapon /dev/sdb2
  • for /
    • mkfs.ext4 /dev/sdb3

Install – Mount and Select a Mirror: 

After mounting the partitions and selecting a mirror start the file downloads.

# pacstrap -i /mnt base base-devel

On my laptop this amounted to 222.3 Mb of download which is good as I’m using my smartphone as a WiFi hot spot for this install.  One package did fail on me for too slow data transfer so I added another mirror, that didn’t work either, so I replaced the mirrorlist file with mirrorlist.old, then after i got the file I put it back to just heanet which is my local mirror.

Make an fstab with UUID’s as we don’t know if this key is always going to be sda or sdb at least we should be able to find our paritions by UUID regardless of the system.

  • #genfstab -U -p /mnt >> /mnt/etc/fstab
  • # arch-chroot /mnt
  • # nano /etc/locale.gen
  • # locale-gen
  • # echo LANG=en_US.UTF-8 > /etc/locale.conf
  • # export LANG
  • # ln -s /usr/share/zoneinfo/Europe/Dublin > /etc/localtime
  • # echo sanlinux > /etc/hostname
  • # passwd
  • # useradd -m -G wheel,power -s /bin/bash karl
  • # passwd karl

Now we are ready to setup the boot loader, as I’m running in a VM that does not emulate UEFI it tells me “Not booted with EFI, skipping EFI variable setup” but that appears to affect nothing.

  • # bootctl install
  • # blkid -s PARTUUID -o value /dev/sdb3 >> /boot/loader/entries/arch.conf

Then use nano to edit the file so that it looks like this

  • title Arch Linux
  • linux /vmlinuz-linux
  • initrd /intel-ucode.img
  • initrd /initramfs-linux.img
  • options root=PARTUUID=the-id-that-was-in-the-file rw

Install some additional requirements, intel-ucode is for CPU microcode updates, networkmanager is my preferred way of networking, firewalld is a handy front end for iptables and bash completion is very helpful everywhere but especially with firewall-cmd.  mesa for opengl,

  • # pacman -S intel-ucode
  • # pacman -S networkmanager
  • # pacman -S firewalld
  • # pacman -S bash-completion mesa

So now the moment of truth, I rebooted windows, hit F12 a bunch of times to get a boot menu, picked the USB key and 10 seconds later I had this

Great, so I’ve one remaining issue, my WiFi card needs firmware, so I downloaded it to an SD mounted it and copied it to the right folder, job done.   Expect more arch Linux posts in the future.  Now because its Arch I need to go off and install my favorite window manager and apps.  I can’t wait for that SD card to show up so that I’ll have 64 GB to play with at reasonable speeds and no ugly USB Key!

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.