Arch Linux Mobile Appliance
ALMA - Arch Linux Mobile Appliance
Project Link: r-darwish / alma
What you need to know
I first read about ALMA on reddit. I have already created Live environments on USB sticks with Arch Linux, but this one can automate the whole process for you. One can define .toml files to configure presets to reproduce your build - and that is the most interesting part of ALMA.
To create a simple, bootable stick or SD Card you simply run:
To create a bootable device and add some packages you like, for example vim and nano, you can run the following:
packages.toml contains:
If you want to add AUR Packages too, extend packages.toml by a aur_packages section:
To add a user, ask for the password and add the user to the wheel group, add the script section to your .toml file:
script = """
set -eux
useradd -m ${USB_USER}
passwd ${USB_USER}
usermod -G wheel -a ${USB_USER}
sed -i 's/# %wheel/%wheel/' /etc/sudoers
"""
enviroment_variables = ["USB_USER"]
You can also change the language by using the script section:
script = """
set -eux
sed -i 's/#de_DE/de_DE/' /etc/locale.gen
sed -i 's/en_US/#en_US/' /etc/locale.gen
locale-gen
echo KEYMAP=de-latin1 > /etc/vconsole.conf
echo FONT=lat9w-16 >> /etc/vconsole.conf
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
localectl set-locale de_DE.UTF-8
localectl --no-convert set-keymap de-latin1-nodeadkeys
echo "LANG=de_DE.UTF-8" > /etc/locale.conf
"""
Finally, you can also copy files to your Live environment. Therefore create a folder with files you want to copy. For example the folder copy_file:
alma_usb\
|__packages.toml
|__german.toml
|__user.toml
|__copy.toml
|__copy_file\
|__file1
|__file2
|__file3
shared_directories = ["copy_file"]
enviroment_variables = ["USB_USER"]
script = """
set -eux
cp /shared_dirs/copy_file/file1 /home/${USB_USER}/file1
cp /shared_dirs/copy_file/file2 /home/${USB_USER}/file2
cp /shared_dirs/copy_file/file3 /home/${USB_USER}/file3
"""
Test before create a bootable device
Create a bootable device with many packages and setting can take a while and if you want to test your presets before, alma provides the option to create an image instead of a bootable device which can be started via qemu.
# this will create a 20 GB image called "almatest.img" and run your presets
sudo alma create --image 20GiB --overwrite almatest.img --presets ./user.toml ./packages.toml ./german.toml ./copy.toml
To start the image in qemu, run the following:
# disconnect all other images, if any
sudo losetup -d /dev/loop? 2> /dev/null
# attach image to loop device
sudo losetup -f ./almatest.img
# get the loop device name
sudo losetup -j ./almatest.img
/dev/loop0: [65026]:26749036 (almatest.img)
# run the image in qemu
sudo alma qemu /dev/loop0
# all in one
sudo losetup -d /dev/loop? 2> /dev/null ; sudo losetup -f ./almatest.img ; sudo alma qemu $(sudo losetup -j ./almatest.img | awk '{print $1}' | sed 's/://')
Creation of a bootable device
Finally we can create our bootable device. Let's assume the following:
- We will have some .toml files:
- packages.toml
- user.toml
- german.toml
- copy.toml
- All our .toml files are in the folder ~/alma_usb/
- We want to add a new user called bknow
Test with image and automatically start in qemu after image creation:
cd ~/alma_usb ; rm almatest.img -f ; sudo USB_USER=bknow alma create --image 20GiB almatest.img --presets ./user.toml ./packages.toml ./german.toml ./copy.toml ; sudo losetup -d /dev/loop? 2> /dev/null ; sudo losetup -f ./almatest.img ; sudo alma qemu $(sudo losetup -j ./almatest.img | awk '{print $1}' | sed 's/://')