Difference between revisions of "Archiso"

From ArchWiki
Jump to navigation Jump to search
Line 42: Line 42:
* Now we are inside the chroot, install a few packages.
* Now we are inside the chroot, install a few packages.
  [chroot] # pacman -Sy devtools libisoburn squashfs-tools
  [chroot] # pacman -S devtools libisoburn squashfs-tools
* Copy over the archiso scripts that were installed earlier to a location that we can work from, /tmp will do.
* Copy over the archiso scripts that were installed earlier to a location that we can work from, /tmp will do.

Revision as of 17:40, 5 February 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Archiso is a small set of bash scripts that is capable of building fully functional Arch Linux based live CD/DVD and USB images. It is a very generic tool, so it could potentially be used to generate anything from rescue systems, to install disks, to special interest live CD/DVD/USB systems, and who knows what else. Simply put, if it involves Arch on a shiny coaster, it can do it. The heart and soul of Archiso is mkarchiso. All of its options are documented in its usage output, so its direct usage wont be covered here. Instead, this wiki article will act as a guide for rolling your own live mediums in no time!

Due to recent changes, Archiso will now automatically create ISO images that are also USB images! Separate CD/USB targets are therefore no longer necessary.

Note: There are two methods to creating the live media, depending on your intentions.

If you wish to create a fully customised live version of Arch Linux, pre-installed with all your favourite programs and configurations, see section 1.

If you just want to create the most basic live media, with no pre-installed packages and minimalistic configurations, then skip to section 2.

Building a custom Arch Linux live media. (configs/releng)

  • Some packages are needed before we can proceed, so if not already installed, go ahead and get devtools. git will also be needed if you choose to install the archiso scripts from the git repository (recommended), and not from AUR.
[host] # pacman -S devtools git --needed
  • Create a chroot to work in, and install the base packages to this chroot.
[host] # mkarchroot /home/youruser/archlive base
  • Go ahead and get the archiso scripts, which carry out the beef of the work for us, and install them into the chroot.
[host] # git clone git://projects.archlinux.org/archiso.git
[host] # make -C archiso/archiso DESTDIR=/home/youruser/archlive install

You can also install archiso from AUR, here, but I recommend the git method above.

  • Enter the newly created chroot:
[host] # mkarchroot -r bash /home/youruser/archlive
  • Create a device node. Note: You must do this every time you enter the chroot.
[chroot] # mknod /dev/loop0 b 7 0
  • Setup a mirror with a command below, or uncomment your preferred one within /etc/pacman.d/mirrorlist
Note: Change MIRROR to your preference
[chroot] # echo 'Server = MIRROR/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist
  • Now we are inside the chroot, install a few packages.
[chroot] # pacman -S devtools libisoburn squashfs-tools
  • Copy over the archiso scripts that were installed earlier to a location that we can work from, /tmp will do.

All the modifications we do to our live image will take place inside this /tmp directory within your chroot.

[chroot] # cp -r /usr/share/archiso/configs/releng/ /tmp
  • CD into this directory:
[chroot] cd /tmp/releng

and now skip ahead to Archiso#Configure_our_live_medium.

Building the most basic Arch Linux live media. (configs/baseline)

Follow all of the instructions above; however, instead of copying usr/share/archiso/configs/releng to your working directory, use usr/share/archiso/configs/baseline:

[chroot] # cp -r /usr/share/archiso/configs/baseline /tmp
  • You can now proceed with building the image, which will output an iso file to /tmp/out (or to wherever you are working from), which can the be burnt to a CD, or dd'd to a USB.
[chroot] # ./build.sh -v
  • Exit from chroot.
[chroot] # exit

General workflow (manual way)

  • Setup a base filesystem
mkarchiso -p "base" create
  • Install syslinux
mkarchiso -p "syslinux" create
  • Install other packages (optional)
mkarchiso -p "pkg1 pkg2 pkg3 ... pkgN" create
  • At this point, customize anything what you want in root-image, then exit when done.
mkarchroot -n -r bash work/root-image
  • Setup initramfs image.
    • Copy needed hooks to root-image
cp /lib/initcpio/hooks/archiso work/root-image/lib/initcpio/hooks
cp /lib/initcpio/install/archiso work/root-image/lib/initcpio/install
    • Create a config for mkinitcpio work/root-image/etc/mkinitcpio-archiso.conf
HOOKS="base udev archiso pata scsi sata usb fw filesystems usbinput"
    • Create a folder named as your PC's architecture:
mkdir work/root-image/boot/i686
    • and generate the initramfs image
mkarchroot -n -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/i686/archiso.img" work/root-image
  • Move kernel/initramfs to boot/
mkdir -p work/iso/arch/boot/i686
mv work/root-image/boot/vmlinuz-linux work/iso/arch/boot/i686/vmlinuz
mv work/root-image/boot/i686/archiso.img work/iso/arch/boot/i686/archiso.img
  • Setup syslinux
    • Create a directory for it.
 mkdir -p work/iso/arch/boot/syslinux
    • Create a work/iso/arch/boot/syslinux/syslinux.cfg file.
DEFAULT menu.c32

LABEL arch
LINUX /arch/boot/i686/vmlinuz
INITRD /arch/boot/i686/archiso.img
APPEND archisolabel=MY_ARCH

    • Copy menu.c32 needed by previous config.
cp work/root-image/usr/lib/syslinux/menu.c32 work/iso/arch/boot/syslinux/
  • Setup isolinux (optional, only needed for booteable iso)
mkdir work/iso/isolinux
cp work/root-image/usr/lib/syslinux/isolinux.bin work/iso/isolinux/
cp work/root-image/usr/lib/syslinux/isohdpfx.bin work/iso/isolinux/
    • Create a work/iso/isolinux/isolinux.cfg
DEFAULT loadconfig

LABEL loadconfig
  CONFIG /arch/boot/syslinux/syslinux.cfg
  APPEND /arch/boot/syslinux/
  • Create an work/iso/arch/aitab file.
# <img>         <mnt>                 <arch>   <sfs_comp>  <fs_type>  <fs_size>
root-image      /                     i686     xz          ext4       50%
  • Build all filesystem images specified in aitab (.fs .fs.sfs .sfs)
mkarchiso prepare
  • Generate an ISO 9660 with "El Torito" boot image (optional)
mkarchiso -L "MY_ARCH" iso "my-arch.iso"

Make a booteable "pendrive" that have more things than "Arch Linux"

Install the master boot sector code.

dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/dev/pen

Setup a filesystem label (for ext2/3/4)

e2label /dev/pen1 MY_ARCH

Setup a filesystem label (for vfat)

dosfslabel /dev/pen1 MY_ARCH

Mount and copy "work/iso/arch" directory

mount /dev/pen1 /mnt/pen1
cp -r work/iso/arch /mnt/pen1

Install extlinux then unmount (partition must be marked as booteable)

extlinux -i /mnt/pen1/arch/boot/syslinux
umount /mnt/pen1

Configure our live medium

Inside the chroot and within directory you are working from (/tmp if you have been following this guide), you will see a number of files and directory called root-image; use should only be concerned with a few of these files, and most definitely concerned with the root-image directory; this directory acts as an overlay and it is where you make all the customisations.

Installing packages

You'll also want to create a list of packages you want installed on your live CD system. A file full of package names, one-per-line, is the format for this. This is great for special interest live CDs, just specify packages you want and bake the image. Edit the packages.i686, or packages.x86_64 file depending on whether you are create a 32bit, or 64bit image, respectively.

Tip: You can also create a custom local repository for the purpose of preparing custom packages or packages from AUR/ABS. Just add your local repository at the first position (for top priority) of your build machine's pacman.conf and you are good to go!

Adding a user

There are two methods to creating a user: either by issuing the relevant useradd command or by copying over (and modify) /etc/shadow, /etc/passwd, and /etc/group. The latter method shall be discussed here.

Copy your /etc/shadow, /etc/passwd, and /etc/group from your host system to /etc/ within your chroot e.g.

[host] $ cp /etc/{shadow,passwd,group} /home/youruser/archlive/tmp/root-image/etc/
Warning: The passwd file will contain your encrypted password. I recommend before you copy the passwd file over to the chroot, you change the password of your host user to that which you want your live user to have, copy the passwd file over, and then change back your password.

Populating the users /home directory

To have the live users home directory populated with files, simply create a skel directory within root-image/etc/, and copy any files you would like there, and add the relevant commands to an rc.local file so:

  • Create the skel directory:
[chroot] cd root-image/etc/ && mkdir skel
  • Copy your files over from your host machine to the chroot,

e.g for .bashrc.

[host] # cp ~/.bashrc /home/youruser/archlive/tmp/root-image/etc/skel/
Note: You must be root to do this, do not change the ownership of any of the files you copy over, everything within the root-image directory must be root owned, ownership will be sorted out shortly.
  • Inside the root-image/etc/ directory, create the rc.local file, and make sure you make it executable:
[chroot] # cd root-image/etc/
[chroot] # touch rc.local && chmod +x rc.local
  • Now add the following:
# Create user directory for live session
if [ ! -d /home/youruser ]; then
    mkdir /home/youruser && chown youruser /home/youruser
# Copy files over to home
su -c "cp -r /etc/skel/.[a-zA-Z0-9]* /home/youruser/" youruser


An initcpio is necessary for creating a system that is able to "wake-up" from a CD/DVD/USB, the default file should work fine, so you shouldn't need to touch it.

Therefore, you should create a mkinitcpio.conf that holds a list of our hooks:

$ vim mkinitcpio.conf

A typical set of hooks for archiso looks something like this:

HOOKS="base udev memdisk archiso archiso_pxe_nbd archiso_loop_mnt pata scsi sata usb fw pcmcia filesystems usbinput"

This list will get you a system that can be booted off a CD/DVD or a USB device. It's worth mentioning that hardware auto-detection and things of that nature do not belong here. Only what's necessary to get the system on its feet, and out of the initcpio really belong here, fancier stuff can be done on the booted system anyway.


The aitab file holds information about the filesystems images that must be created by mkarchiso and mounted at initramfs stage from the archiso hook. The default file should work fine, so you shouldn't need to touch it. It consists of some fields which define the behaviour of images.

# <img>         <mnt>                 <arch>   <sfs_comp>  <fs_type>  <fs_size>
Image name without extension (.fs .fs.sfs .sfs).
Mount point.
Architecture { i686 | x86_64 | any }.
SquashFS compression type { gzip | lzo | xz }. A special value of "none" denotes no usage of SquashFS.
Set the filesystem type of the image { ext4 | ext3 | ext2 | xfs }. A special value of "none" denotes no usage of a filesystem. In that case all files are pushed directly to SquashFS filesystem.
An absolute value of file system image size in MiB (example: 100, 1000, 4096, etc) A relative value of file system free space [in percent] {1%..99%} (example 50%, 10%, 7%). This is an estimation, and calculated in a simple way. Space used + 10% (estimated for metadata overhead) + desired %
Note: Some combinations are invalid. Example both sfs_comp and fs_type are set to none

Boot Loader

The default file should work fine, so you shouldn't need to touch it.

DEFAULT menu.c32

LABEL arch
LINUX /%INSTALL_DIR%/boot/%ARCH%/vmlinuz
INITRD /%INSTALL_DIR%/boot/%ARCH%/archiso.img
APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL%


Due to the modular nature of isolinux, you are able to use lots of addons since all *.c32 files are copied and available to you. Take a look at the official syslinux site and the archiso git repo. Using said addons, it is possible to make visually attractive and complex menus. See here.

Finishing the root-image

Some tips that will not be covered in this article because there are other articles on this wiki that already do, but please feel free to add them here.

  • Configure an inittab to start into X at boot time
  • Configure the hosts file
  • Configure rc.conf (no fancy modules required here)
  • Configure sudoers
  • Configure rc.local
  • Put additional artworks onto the medium
  • Put arbitrary binary stuff into opt/

See also