Creating a Custom Arch Linux LiveCD/LiveUSB

Posted in computers on May 11th, 2011 by karrth

Since I’m a huge fan of Arch Linux, it was my distro of choice for creating a LiveCD (for me, a USB key). It’s pretty easy with Arch, using a wonderful tool called archiso. ISOs built with this tool will also have the ability to be either burned to a CD, OR put onto a USB key. Below, you can find a copy of the ISO I built and a tarball of the files needed to build it so you can use it as a template for your own build. Have fun!

Creating your live image

I followed the Arch Wiki page for archiso to build all of this. Be sure to read the wiki page for all of the details for each file – I’m only going to provide templates for your own build and my own finished files. For a basic setup, none of the template files need to be modified.

  1. Create a working directory – mine is called “archlive”
  2. Create a file called “Makefile”. Here’s a template. If you don’t modify anything, this file will build your ISO with the name “myarch[date].iso”
  3. Create a file called “mkinitcpio.conf”. Here’s a template.
  4. Create a file called “packages.list”. Here’s a template. This is where you specify which packages will be included in your live image. The template has a basic set that will get you started, but you can expand on this as much as you want.
  5. Create a file called “isomounts”. Here’s a template.
  6. Setup syslinux (your boot manager) by creating the folderboot-files/syslinux/ and then creating the file boot-files/syslinux/syslinux.cfg. Here’s a template for syslinux.cfg.
  7. Create a folder called “overlay”. This will contain any files that you want to be copied into the root directory of your live image. When the ISO is created, any permissions/attributes will be copied as well, so make sure they are all owned by root, and any executables are set as such (chmod +x [file]).
  8. Inside of the overlay folder, create an “etc” folder, and inside of that create your “fstab” file. Here’s a template.
  9. Inside of the “overlay/etc” folder, create a file called “rc.conf”. If you don’t know what it does, check out the template.
  10. Inside of the “overlay/etc” folder, create a file called “inittab”. If you don’t know what it does, here’s the Arch Wiki inittab page. Here’s a template.
  11. Inside of the “overlay/etc” folder, create a file called “hosts”. Here’s a template.
  12. Finally, once you have all of your files setup in your working directory, it’s time to compile the ISO. From your working directory (the one with your Makefile in it), type make all. If you encounter an error, or have to stop half-way through, type make clean before doing a make all again.
  13. After a while (10-20 minutes even if you have a slow machine), your image will be generated inside of your folder. You can either burn this to a CD, or put it on a USB stick with this command:
    dd if=my-image.iso of=/dev/some-usb-drive bs=8M

And you’re done! There are maany changes you can make to this setup, which really is the point of making a custom LiveCD… So mess around with it, see what you can change!

My personal changes

  • I added a second, regular user through the file overlay/etc/rc.d/setup, which also does some other boot time configs, such as checking permissions and copying the user’s files from the overlay/skel
  • I added some personal scripts, aurget, and the Archiso PXE server program into overlay/usr/bin/
  • I moved the Arch Linux install script from overlay/arch/ to overlay/usr/sbin.
  • I added some config files, such as ones for vim, iptables, pacman, and aurget into overlay/etc/

Again, there is a lot you can do with this - so don't be afraid to just try something. Once you get it working, it's a good idea to make a copy of your working directory before making other changes if you are unsure what you are doing. Otherwise, you might end up having to start all over if you forget excatly what change broke your build. And just because the ISO is created without a hitch, doesn't mean that it will boot without a problem as well. If you're unsure with your changes, it's a good idea to compile the ISO and test your builds regularly.

Be sure to check out Archiso's example! Going through a working set of files is the best way to learn in my opinion. Also be aware that your Live image will be read only - while you can make changes to the system while booted, it will be reset when you reboot. I've included a link to a page on how to create a second writeable partition on your USB key if you want to have some storage on the same device.

Downloads

Sources

Tags: , ,