This page explains how to install Artix on a USB flash drive. The end result is a persistent installation identical to that on a normal hard drive along with several optimizations aimed at running Linux on removable flash media. It is compatible with both BIOS and UEFI booting modes.

Install packages

# pacman artools-base gptfdisk

Install Base System

Plug in the drive and determine the device name.

# dmesg | tail

 # usb-storage 2-2:1.0: USB Mass Storage device detected
 # scsi host2: usb-storage 2-2:1.0
 # sd 2:0:0:0: [sdb] 965246976 512-byte logical blocks: (494 GB/460 GiB)
 # sd 2:0:0:0: [sdb] Write Protect is off
 # sd 2:0:0:0: [sdb] Mode Sense: 43 00 00 00
 # sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
 # sdb:
 # sd 2:0:0:0: [sdb] Attached SCSI removable disk

Use your device's name. For the remainder of this guide, the device name will be referred to as /dev/sdX.

 # export TARGET=/dev/sdX

Wipe (optional)

This may not be necessary with the -v switch added to sgdisk below.

Use dd to write the USB with all zeros, permanently erasing all data:

# dd if=/dev/zero of=$TARGET status=progress && sync

Expect this to take a relatively long time (hour++) depending on the size.

Partition

Create a 10M BIOS partition, an EFI partition, and a Linux partition with the remaining space (`sgdisk` is in the gptfdisk package):

 # sgdisk -o -n -v -I 1:0:+10M -t 1:EF02 -n 2:0:+1024M -t 2:EF00 -n 3:0:0 -t 3:8304 $TARGET
 # sgdisk -c 1:"BIOS" -c 2:"ESP"

Format

Do not format the `/dev/sdX1` block. This is the BIOS/MBR partition. Format the EFI system partition with a FAT32 filesystem:

 # mkfs.fat -F32 ${TARGET}2

Format the Linux partition with an ext4 filesystem:

 # mkfs.ext4 ${TARGET}3

Mount

Mount the ext4 formatted partition as the root filesystem:

 # export MNT=/mnt/usb
 # mkdir -p ${MNT}/boot
 # mount ${TARGET}2 ${MNT}/boot
 # mount ${TARGET}3 $MNT

Base System

By default, dinit will installed (alphabetical), adjust if desired as seen in: https://wiki.artixlinux.org/Main/Installation#Install_base_system Note: basestrap is in artools-base

 # basestrap $MNT base inetutils base-devel vim htop mc less grub efibootmgr linux linux-firmware

Side note: I could not create directory '/mnt/usb/var': Read-only file system

 # umount /dev/sdX1
 # fsck -y /dev/sdX1 
 # mount /dev/sdX1 $MNT 

Second try

 # basestrap $MNT base inetutils base-devel vim htop mc less grub efibootmgr linux linux-firmware

Add to the above as you like. Configure in chroot as noted below.

Generate a new /etc/fstab using UUIDs as source identifiers:

 # fstabgen -U $MNT > ${MNT}/etc/fstab

Configure

Unless otherwise noted, all configuration is done within a chroot. Chroot into the new system:

 # artix-chroot $MNT
 # export PS1="(chroot) $PS1"

Locale

Use tab-completion to discover the appropriate entries for _region_ and _city_:

 # ln -sf /usr/share/zoneinfo/region/city /etc/localtime

substitute en_US.UTF-8 for your desired locale

 # sed -i '/en_US.UTF-8/s/^#*//' /etc/locale.gen
 # locale-gen
 # echo 'LANG=en_US.UTF-8' > /etc/locale.conf

Hostname

"ghost" is an example

 # export HOSTNAME="ghost"
 # cat  << EOF > /etc/hosts
 # 127.0.0.1        localhost
 # ::1              localhost
 # 127.0.1.1        ${HOSTNAME}.localdomain ${HOSTNAME}
 # EOF
 # echo ${HOSTNAME} > /etc/hostname

Root password

passwd

Bootloader

Example GRUB install for both BIOS and UEFI booting modes

 # grub-install --target=i386-pc --recheck $TARGET
 # grub-install --target=x86_64-efi --efi-directory /boot --recheck --removable
  1. Generate a GRUB configuration
 # grub-mkconfig -o /boot/grub/grub.cfg

Network

 # pacman -S networkmanager-dinit
 # ln -s /etc/dinit.d/NetworkManager /etc/dinit.d/boot.d/

Add 'user'

  1. export USER=user
 # useradd -m -G wheel -s /bin/bash $USER
 # passwd $USER

Configure sudo

 # sed -i '/%wheel ALL=(ALL:ALL) ALL/s/^# //' /etc/sudoers
 # visudo -c # check if it parses

noatime (optional)

 # sed -i -s 's/relatime/noatime/' /etc/fstab

Sources