Portable Arch Linux On USB The Build

Published on October 8, 2022 at 8:39 pm by LEW


I talked about building Linux persistent Operating system (OS) on a USB key and why you might want to do it in the last post. In this post I will build an Arch Linux persistent OS on a USB Key.

I performed a similar process with base Debian OS to persistent USB, which was easier to do with their installer. But it took about three to four times as long to complete as compared to doing a base Arch Install.

Neither method was without issue. But then this is not something most peop0le are ever likely to do, so the available documentation was a bit scarce, and some of it was a bit dated.

The documentation about installing to removable media on the Arch wiki is was up to date, if a bit hard to follow at times.

A Few Caveats

First and foremost, which should go without saying, if you are not careful doing this, you can damage an installed OS. So if possible do it on a spare computer.

Note you do not need an operating system or even a storage drive on this computer.

You will need at least two 2 GB USB key, which should not be a problem. Most keys will will have much much more storage.

Note that USB keys are much slower than actual storage drives, so expect this to take some time.

Something I read in several articles on this subject, if you want to share data with the host computer, Windows will only recognize the first partition. You do not have to make a data partition the first partition. My instance of Windows Ten saw all partitions. Some of them it did not know what to do with, but it still saw them all.

Also if Windows does not know what to do with a partition, it will want to format it. Do not let Windows format it!

Basic setup

This will require one USB key with the Arch Installation instance on it. There are plenty of articles about flashing this to USB using Etcher, Rufus, or dd. So I will not cover it here.

The other USB key will hold your persistent OS, and everything on it will be erased in the process of installing.

We are going to boot from the the USB key with the Arch installer instance. Use whatever method works for your computer to make this happen. You will either need to set up the boot order in the BIOS, or call up the boot menu at startup. Either way check your documentation.

Before going to far, you will want to read this series of posts on a standard Arch install. I will be using it as a basis, and listing where I deviated from it.

Formatting the USB Key

I will be setting up strictly for UEFI boot. The Arch Wiki has some information on syslinux if you want to setup a combination legacy/UEFI boot. For this post I will focus on UEFI boot only.

I used fdisk -l to determine the USB device, then create partitions. I used the following partitions on the USB key.

Since this is a removable media device, I do not create a swap partition. This would be needless read/writes to a device with a limited number. There are a few other things we will do to do to help with this also.

Also, if you are creating an NTFS partition like I did, its type is Microsoft Basic Data. You will drive yourself crazy looking for an NTFS partition type.

Note, there was no way to create an NTFS partition using the Debian installer.

Once the partition data has been written, I format each partition with the following commands.

Note your drive location will be different than mine. I use “xx” as a generic placement.

mkfs -t ntfs -f /dev/sdxx

Make sure to use the -f option (fast), otherwise the NTFS partition will be zeroed, then error checked before formatting. This can take quite some time to complete.

mkfs.vfat -F 32 /dev/sdxx

This is your EFI System partition.

mkfs.ext4 -O "^has_journal" /dev/sdxx

This command creates an EXT4 partition with journaling disabled, to reduce reads and writes. The only time this will be an issue is on a power fail, system crash or premature removal. In these case data can and will be lost. If you are not worried about read/writes, then remove the“-O “^has_journal””

Mounting and Bootstrapping

Use the following commands to mount the partitions to the Arch Install

mount/dev/sdxx /mnt
mkdir /mnt/srv
mount /dev/sdxx /mnt/srv

I am mounting the NTFS partition to the /mnt/srv folder. When this drive is plugged in, but not booted up, I can copy files to this partition. Then when I boot into the USB OS, the files will be available.

To load the system we use the Arch pacstrap program to install the following packages.

pacstrap /mnt base linux vi networkmanager ntfs-3g sudo grub efibootmgr

After this, I create the fstab file.

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

Then chroot into my new install.

arch-chroot /mnt

Non Standard Configuration and Reboot

From the chroot environment I will go through and do the standard Arch configurations for a new install with these exceptions.

For general compatibility with a variety of computers, we need to make a change to the /etc/mkinitcpio.conf file. Open it in a text editor (like vi) and change the following line.

HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)

Move keyboard and block ahead of autodetect.

Make a modification to the command to install grub, for removable media.

grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable --recheck

For everything else follow standard Arch installation configuration. As shown in theses posts. Don’t forget to enable NetworkManager.

Now all that is left to do is reboot, and you should have Arch running off a USB key.

Note we have not done anything with wireless. Something I want to address in a later post.


In this post we created a OS on a bootable USB key .

The next step is to add custom modifications and possibly a Graphical User Interface.

Add New Comment

Your email address will not be published. Required fields are marked *