Skip to content

Instantly share code, notes, and snippets.

@gtello
Created August 24, 2023 15:53
Show Gist options
  • Save gtello/c4af5ec517e8b106aecc5f2f04272832 to your computer and use it in GitHub Desktop.
Save gtello/c4af5ec517e8b106aecc5f2f04272832 to your computer and use it in GitHub Desktop.
Guide to Installing Arch Linux on a USB Drive with Persistence

Guide to Installing Arch Linux on a USB Drive with Persistence

On an Arch machine, run: sudo pacman -S arch-install-scripts to have the commands to install the OS into the USB

Run the following as root

Make sure USB is NOT mounted and format it

wipefs -a /dev/sdX where X is the assigned letter your USB is mounted on

fdisk /dev/sdX

Disable journaling:

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

Mount and install arch as usual:

mount /dev/sdfX /mnt

pacstrap /mnt base base-devel grub

genfstab -U /mnt >> /mnt/etc/fstab then change relatime to noatime

arch-chroot /mnt

passwd to change root password

To make persistent:

e2label /dev/sdX1 arch-usb

Add your user with privileges, add hostname and change the hosts file:

useradd -m -g users -G wheel -s /bin/bash user123

echo arch-usb > /etc/hostname

# /etc/hosts
# Static table lookup for hostnames.
# <ip-address>  <hostame.domain.org>   <hostname>
127.0.0.1       arch-usb.localdomain    arch-usb

Locale:

To display the currently set locale and its related environmental settings, type: locale The locale to be used, chosen among the previously generated ones, is set in locale.conf files. Each of these files must contain a new-line separated list of environment variable assignments, having the same format as output by locale.

To list available locales which have been previously generated, run: localedef --list-archive

Or alternatively, using localectl: localectl list-locales

To set the system locale, write the LANG variable to /etc/locale.conf, where en_US.UTF-8 belongs to the first column of an uncommented entry in /etc/locale.gen:

LANG=en_US.UTF-8

Alternatively, run: localectl set-locale LANG=en_US.UTF-8

General drivers and programs:

pacman -S xf86-video-vesa xf86-video-ati xf86-video-intel xf86-video-nouveau networkmanager network-manager-applet dosfstools ntfs-3g ttf-inconsolata alsa-utils xorg-server xorg-xinit xterm xorg-server-devel strace git firefox

systemctl enable NetworkManager to enable networking

pacman -S lxde a desktop environment

echo exec startlxde > /home/user123/.xinitrc in order to be able to use startx

And to make the DE boot on startup for Bash, add the following to the bottom of ~/.bash_profile, if the file doesn't exist, copy a skeleton version from /etc/skel/.bash_profile or for Zsh, add it to ~/.zprofile

if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
  exec startx
fi

Install an AUR helper

git clone https://aur.archlinux.org/trizen.git
cd trizen
makepkg -si

Minimizing disk access

You may want to configure journald to store its journals in RAM, e.g. by creating a custom configuration file:

nano /etc/systemd/journald.conf.d/usbstick.conf

[Journal]
Storage=volatile
RuntimeMaxUse=30M

To disable fsync and related system calls in web browsers and other applications that do not write essential data, use the eatmydata command from libeatmydata AUR to avoid such system calls:

eatmydata firefox

Final Steps

Before creating the initial RAM disk with mkinitcpio -p linux, in /etc/mkinitcpio.conf move the block hook to the hooks array right after udev. This is necessary for appropriate module loading in early userspace

mkinitcpio -p linux

grub-install --removable --target=i386-pc /dev/sdX

nano /etc/default/grub on the GRUB_CMDLINE_LINUX_DEFAULT variable, add elevator=noop to have better I/O performance since we're using the system on a USB

Also you may want to disable Kernel mode setting for various reasons, such as getting a blank screen or a "no signal" error from the display, when using some Intel video cards, etc. To disable KMS, add nomodeset as a kernel parameter on GRUB_CMDLINE_LINUX_DEFAULT

nano /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet nomodeset"

Generate the grub config file with those changes with:

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

Now do exit then umount -R /mnt and eject your USB then boot it from a computer

That's it!

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