Last Update: 1st January 2013.
Outcome: To create a custom, bootable version of the Arch Linux operating system that will allow you to carry your OS,
pre-installed with all your needed programs, on a USB stick.
Update: 1st December 2013:
Arch Linix has recently switched from SysVinit to systemd, resulting in some of the instructions on customising the system to become incompatible.
The ‘archiso’ package (from git) has also been modified so that only dual (64 & 32 bit) ISO are created.
The post has been updated to reflect the changes.
Update: 5th April 2012:
Recent changes with mkarchiso now means that creating a chroot is no longer necessary, thus simplifying the process.
I have updated the Arch Linux wiki reflecting these changes to leave the wiki as simple as possible to follow.
I’ve been tinkering around lately with archiso, which is a set of bash scripts that, to put it briefly, allow you to create a fully customised version of the OS, squash it into an ISO file, and then stick it on a USB stick or CD ready to be booted from pretty much any computer, meaning I can have my beloved OS with me at all times, which is great if I’m at a friend’s house; internet cafe; University; or wherever, and not feeling to pleased with their choice of OS or programs.
I’ve also pre-filled it with many maintenance, and data recovery tools saving me the need to carry around a bunch of CDs if I ever need to do some maintenance.
I will try to explain as simply as possible on how to achieve this so you can have your own release up and booted in no time.
Whilst there is pretty informative wiki page on the Arch Linux website, the recent shift from Aufs2 to dm-snapshot has brought about many changes to the previous version of ArchIso, so the wiki page
is was a work in progress, which confused me for some time.
Depending on your experience, the steps below may look daunting, but many of them will only have to be done once to get everything set up, once it is the process of redefining and customising the OS in the future becomes a doddle.
To begin with, we need to install the dependencies for the ‘archiso’ packge.
So open up a terminal and execute:
(root): pacman -S make squashfs-tools libisoburn dosfstools patch lynx devtools git
Next we need to obtain archoiso which is a set of scripts that carry out the beef of the work for us. I recommend getting them from git, there is a package in the repositories, however, at this time of writing, it will not work with the instructions below.
So, grab the most recent version from git and install it:
(user): git clone git://projects.archlinux.org/archiso.git && cd archiso
(root): make install
Now we need to create a directory to work in, essentially a place where the live system will live while we work on it.
Within this tutorial I will be using /home/kroweer/livecd (~/livecd).
Note, that this directory will quickly fill up in space depending on how many packages you install and what files you decide to copy over, so you will need a fair bit of space. I recommend at least 4GB.
At this point, it is best to open a root shell (sudo su), as everything we do within this ‘livecd’ directory must be root owned.
Copy over the newly installed archiso scripts (which now live in /usr/share/archiso/configs/releng/) into this newly created directory:
(root): cp -r /usr/share/archiso/configs/releng/* ~/livecd
Essentially, that is it.
If you were to execute the build command, after some time you will be presented with a bare minimum ISO file you can boot from. But where is the fun in that? You could’ve just downloaded the Arch Linux install medium and have the same thing.
Now to move on to customising the system.
Customising the Live System
Inside the ~/livecd/ directory there are a number of files, most of which can be ignored; however, what is of importance to us are the packages.x86_64, packages.i686, packages.both files; and the root-image directory.
When you finally build the system, it will create a dual architecture system (32bit & 64bit both inside one ISO), and so inside the respective packages.* file you can list, line by line, the packages you want each system to have installed.
I’ve not had much luck in creating a single architecture system, so I recommend you list all the files you want inside the packages.both file, and leave the other two alone.
You will notice there are a few packages listed in there by default, it’s probably best you keep them in there (unless you know you don’t need them) and add your own to the end.
More than likely you will want to be able to boot into X so you can have a pretty GUI and all, so you will need to list the relevant Xorg packages (xorg-server, xorg-xinit, xorg-server-utils); a desktop environment, or window manager (such as i3, gnome, or openbox), you may also want to include all the xf86-video drivers so you can boot the USB on any computer regardless of what video chipset is in use.
Don’t forgot about sound (alsa-utils, if that’s you preference), networking (wicd), fonts, a file manager, a terminal emulator, and sudo.
To give you some ideas, you can get a full list of what you currently have installed on your host machine, by executing the following and picking out what you need.
(root): pacman -Qqe
I wouldn’t recommend copying everything from there into your packages file, as this may result in a huge ISO file that may not fit onto your USB, just select sparingly the main programs you want.
Make sure you do not make a spelling mistake with any of the package names and make that they all exist in the official repositories: failure to do so will make the build process fail without any indication of the error.
-Files & Configs
To customize your system further you place any files/configurations you want your image to contain inside the root-image directory: ~/livecd/root-image.
This directory is the root ‘/’ filesystem of the live system, and it will act as an overlay; anything within here will copied over to the live system during boot up.
Again, I will state that all the files within the whole ~livecd/ directory must be root owned, don’t chown them to a different user (we’ll sort out permissions soon).
If you look in this directory you will see there are already a few files as a starting point.
There’s an etc where you can place system files, and a root folder (which is the root users home folder, do not delete this, it contains an important file).
You can simply copy over files from your host system to here; for e.g., I want my iptables scripts, so I create the directory ‘iptables’ within ~/livecd/root-image/etc/ and copy the file from my host to this directory, ie:
(root): mkdir ~/livecd/root-image/etc/iptables
(root): cp /etc/iptables/iptables.rules ~/livecd/root-image/etc/iptables/
To add a user to the system, first create “home” within “etc”, and within “home” create a directory with the same name as the new user.
E.g. I want to add the user “kroweer”, so I execute (as root remember):
(root): mkdir -p ~/livecd/root-image/etc/home/kroweer
Populate the user’s home directory using the same process as above.
For example, I want to have my GTK configuration files copied over, so I execute:
(root): cp /home/kroweer/.gtkrc-2.0 ~/livecd/root-image/etc/home/kroweer/
Now to move on to actually adding the user account.
Inside root’s home folder (~/livecd/root-image/root), there is a script called customize_root_image.sh.
Whilst your system is being built, this script will be executed. We can use it to add users to the system, auto login to a user on boot and start X, start services, and sort out proper permissions on the files.
Here is my customize_root_image.sh, I’d recommend using this one instead of the one provided.
I’ve added the necessary commands to add the actual user account, password protect the accounts, set the correct permissions on home files, and starting services.
I’ve also disabled the automatic login to the root account on a TTY.
Take a look at it, and modify it to your needs.
Building the ISO
That should be it. Now you move on to actually building the ISO file and copying it to a USB.
Within the ~/livecd directory there is a bash script which will take care of everything for you.
Simply make it executable (chmod +x build.sh), and run it:
(root): ./build.sh -v
The build process can be slow depending on how many packages you’ve installed (it takes 40 minutes on my ageing 1.6GHz dual core +3GB RAM laptop).
This will output an ISO file in the ~/livecd/out directory which you can then simply dd onto your USB.
(root): dd if=~/livecd/out/N.iso of=/dev/sdX
Where N is the name of the ISO, and sdX is your USB.
Be careful with this command if you care for the precious data you hold on your hard disk! sdX must refer to your USB stick.
Also, do not specify a partition number on your USB, for example use sdb not sdb1
If you get any errors during the build process, or want to update it, first delete the “work” folder (~/livecd/work), and re-run the build command.
I hope this helps someone out there, if you notice any mistakes or room for improvement I would appreciate the feedback.
Spare change? 🙂