Difference between revisions of "Archiso"

From ArchWiki
Jump to: navigation, search
(Re-organised and cleaned up.)
(Removed section Make a booteable "pendrive" that has more things than "Arch Linux", as I don't think it is relavent. Reinstate if you feel otherwise.)
Line 3: Line 3:
 
{{i18n|Archiso}}
 
{{i18n|Archiso}}
  
'''Archiso''' is a small set of bash scripts that is capable of building fully functional '''Arch Linux based live CD and USB images'''. It is a very generic tool, so it could potentially be used to generate anything from rescue systems, 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.
+
'''Archiso''' is a small set of bash scripts that is capable of building fully functional Arch Linux based live CD and USB images. It is a very generic tool, so it could potentially be used to generate anything from rescue systems, 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!
+
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!
  
  
== Archiso installation ==
+
== Setup ==
  
 
Before we begin, we need to grab the archiso scripts which carry out the beef of the work for us. You can get archiso from Git (recommended) or from [https://aur.archlinux.org/packages.php?ID=25996 aur]. We also need a few packages which archiso relies on; the following commands take care of this for us:
 
Before we begin, we need to grab the archiso scripts which carry out the beef of the work for us. You can get archiso from Git (recommended) or from [https://aur.archlinux.org/packages.php?ID=25996 aur]. We also need a few packages which archiso relies on; the following commands take care of this for us:
Line 15: Line 15:
 
  # make -C archiso/archiso install
 
  # make -C archiso/archiso install
  
Create a directory to work within, this is where all the modifications to the live image will take place: /home/xxx/archlive should do fine.
+
Create a directory to work within, this is where all the modifications to the live image will take place: ~/archlive should do fine.
  $ mkdir /home/xxx/archlive (replacing 'xxx' with your username')
+
  $ mkdir ~/archlive
  
 
The archiso scripts that were installed to the host system earlier now need to be copied over into the newly created directory you will be working within.
 
The archiso scripts that were installed to the host system earlier now need to be copied over into the newly created directory you will be working within.
Line 30: Line 30:
 
If you are using the 'baseline' profile to create a bare bones, installation image, then you won't be needing to do any customisations and can proceed onto [[Archiso#Build_the_ISO]]
 
If you are using the 'baseline' profile to create a bare bones, installation image, then you won't be needing to do any customisations and can proceed onto [[Archiso#Build_the_ISO]]
  
== General workflow (manual way) ==
+
== Setup (manual way) ==
  
 +
If you have already completed the setup the 'automatic' way, using the steps above, then you do not need to read this section.
 
* Setup a base filesystem
 
* Setup a base filesystem
 
  # mkarchiso init
 
  # mkarchiso init
Line 112: Line 113:
 
* Generate an ISO 9660 with "El Torito" boot image (optional)
 
* Generate an ISO 9660 with "El Torito" boot image (optional)
 
  # mkarchiso -L "MY_ARCH" iso "my-arch.iso"
 
  # 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 ==
 
== Configure our live medium ==

Revision as of 18:20, 5 April 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 and USB images. It is a very generic tool, so it could potentially be used to generate anything from rescue systems, 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!


Setup

Before we begin, we need to grab the archiso scripts which carry out the beef of the work for us. You can get archiso from Git (recommended) or from aur. We also need a few packages which archiso relies on; the following commands take care of this for us:

# pacman -S make git libisoburn squashfs-tools --needed
# git clone git://projects.archlinux.org/archiso.git
# make -C archiso/archiso install

Create a directory to work within, this is where all the modifications to the live image will take place: ~/archlive should do fine.

$ mkdir ~/archlive

The archiso scripts that were installed to the host system earlier now need to be copied over into the newly created directory you will be working within. Archiso comes with two "profiles": releng, and baseline. If you wish to create a fully customised live version of Arch Linux, pre-installed with all your favourite programs and configurations, use "releng". If you just want to create the most basic live media, with no pre-installed packages and minimalistic configurations, the use "baseline".

So, depending on your needs, execute the following, replacing 'PROFILE' with either releng or baseline, and 'xxx' with your username (if relevant).

# cp -r /usr/share/archiso/configs/PROFILE/ /home/xxx/archlive

If you are using the 'releng' profile to make a fully customised image, then you can proceed onto Archiso#Configure_our_live_medium.

If you are using the 'baseline' profile to create a bare bones, installation image, then you won't be needing to do any customisations and can proceed onto Archiso#Build_the_ISO

Setup (manual way)

If you have already completed the setup the 'automatic' way, using the steps above, then you do not need to read this section.

  • Setup a base filesystem
# mkarchiso init
  • Install other packages (optional)
# mkarchiso -p "pkg1 pkg2 pkg3 ... pkgN" install
  • At this point, customize anything what you want in root-image, then exit when done.
# mkarchiso-r "bash" run
  • 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"
COMPRESSION="xz"
    • Create a folder named as your PC's architecture:
# mkdir work/root-image/boot/i686
    • and generate the initramfs image
# mkarchiso -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/i686/archiso.img" run
  • 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
PROMPT 0
MENU TITLE Arch Linux
TIMEOUT 300

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

ONTIMEOUT 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"

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 will 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
fi
# Copy files over to home
su -c "cp -r /etc/skel/.[a-zA-Z0-9]* /home/youruser/" youruser

mkinitcpio.conf

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 should not 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 is worth mentioning that hardware auto-detection and things of that nature do not belong here. Only what is 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.

aitab

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 should not need to touch it. It consists of some fields which define the behaviour of images.

# <img>         <mnt>                 <arch>   <sfs_comp>  <fs_type>  <fs_size>
<img>
Image name without extension (.fs .fs.sfs .sfs).
<mnt>
Mount point.
<arch>
Architecture { i686 | x86_64 | any }.
<sfs_comp>
SquashFS compression type { gzip | lzo | xz }. A special value of "none" denotes no usage of SquashFS.
<fs_type>
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.
<fs_size>
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 should not need to touch it.

DEFAULT menu.c32
PROMPT 0
MENU TITLE Arch Linux
TIMEOUT 300

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

ONTIMEOUT arch

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/

Build the ISO

Now you are ready to turn your files into the .iso which you can then burn to CD or USB:

# cd /tmp/releng
# ./build.sh build single core

The script will now download and install the packages you specified to work/*/root-image, create the kernel and init images, apply your customizations and finally build the iso into out/.

Using the build script you can also choose whether you want a dual architecture ISO or a netinstall image. You can also use it to clean up after old builds.

See also