<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jeffre</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jeffre"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Jeffre"/>
	<updated>2026-04-30T19:41:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=How_to_make_a_custom_ISO_image_with_mkimage&amp;diff=26829</id>
		<title>How to make a custom ISO image with mkimage</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=How_to_make_a_custom_ISO_image_with_mkimage&amp;diff=26829"/>
		<updated>2024-06-11T03:48:38Z</updated>

		<summary type="html">&lt;p&gt;Jeffre: fix path as referenced earlier&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document explains how to build a custom ISO image using the new mkimage scripts located in [[aports]] directory.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
First make sure we have the needed tools&lt;br /&gt;
{{Cmd|apk add alpine-sdk alpine-conf syslinux xorriso squashfs-tools grub grub-efi doas}}&lt;br /&gt;
For efi you should add the following: &lt;br /&gt;
{{Cmd|apk add mtools dosfstools grub-efi}}&lt;br /&gt;
&lt;br /&gt;
Create a user (e.g. build) and add them to the abuild group:&lt;br /&gt;
{{Cmd|adduser build -G abuild}}&lt;br /&gt;
&lt;br /&gt;
Give the user root-like permissions:&lt;br /&gt;
{{Cmd|vi /etc/doas.d/doas.conf}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
permit :abuild&lt;br /&gt;
permit persist :abuild&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change to the build user: &lt;br /&gt;
{{Cmd|su - build}}&lt;br /&gt;
&lt;br /&gt;
Then create signing keys (-i installs them in /etc/apk/keys which is required for later)&lt;br /&gt;
{{Cmd|abuild-keygen -i -a}}&lt;br /&gt;
&lt;br /&gt;
{{Tip| Make sure your public keys are placed in /etc/apk/keys/ (example: build-xxxxxxxx.rsa.pub)}}&lt;br /&gt;
{{Cmd|ls /etc/apk/keys/}}&lt;br /&gt;
&lt;br /&gt;
Clone (or update) the [https://gitlab.alpinelinux.org/alpine/aports git repository].&lt;br /&gt;
{{Cmd|git clone --depth&amp;amp;#61;1 https://gitlab.alpinelinux.org/alpine/aports.git}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the apk index is up to date (so apk can find the packages):&lt;br /&gt;
{{Cmd|doas apk update}}&lt;br /&gt;
&lt;br /&gt;
Make sure your /tmp is large enough.  If you have the default 1GB /tmp, then create a local one with:&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir -pv ~/tmp&lt;br /&gt;
export TMPDIR=~/tmp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The mkimg scripts are shipped with pre-configured profiles.&lt;br /&gt;
&lt;br /&gt;
The format is &#039;&#039;&#039;mkimg.$PROFILENAME.sh&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In order to have a custom ISO, you should create your own &#039;&#039;&#039;mkimg.$PROFILENAME.sh&#039;&#039;&#039; script.&lt;br /&gt;
&lt;br /&gt;
This is an example used to make a ZFS module, overlayfs (which enables r/w mode for /lib/modules), a serial console output and some other useful apks to build a simple NAS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;export PROFILENAME=nas&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; ~/aports/scripts/mkimg.$PROFILENAME.sh&lt;br /&gt;
profile_$PROFILENAME() {&lt;br /&gt;
        profile_standard&lt;br /&gt;
        kernel_cmdline=&amp;quot;unionfs_size=512M console=tty0 console=ttyS0,115200&amp;quot;&lt;br /&gt;
        syslinux_serial=&amp;quot;0 115200&amp;quot;&lt;br /&gt;
        kernel_addons=&amp;quot;zfs&amp;quot;&lt;br /&gt;
        apks=&amp;quot;\$apks iscsi-scst zfs-scripts zfs zfs-utils-py&lt;br /&gt;
                cciss_vol_status lvm2 mdadm mkinitfs mtools nfs-utils&lt;br /&gt;
                parted rsync sfdisk syslinux util-linux xfsprogs&lt;br /&gt;
                dosfstools ntfs-3g&lt;br /&gt;
                &amp;quot;&lt;br /&gt;
        local _k _a&lt;br /&gt;
        for _k in \$kernel_flavors; do&lt;br /&gt;
                apks=&amp;quot;\$apks linux-\$_k&amp;quot;&lt;br /&gt;
                for _a in \$kernel_addons; do&lt;br /&gt;
                        apks=&amp;quot;\$apks \$_a-\$_k&amp;quot;&lt;br /&gt;
                done&lt;br /&gt;
        done&lt;br /&gt;
        apks=&amp;quot;\$apks linux-firmware&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the script as executable:&lt;br /&gt;
{{Cmd|chmod +x ~/aports/scripts/mkimg.$PROFILENAME.sh}}&lt;br /&gt;
&lt;br /&gt;
== Making packages available on boot ==&lt;br /&gt;
&lt;br /&gt;
A package may be made available in the live system by defining the generation of an apkovl which contains a corresponding /etc/apk/world file, and adding that overlay definition to the mkimg-profile, e.g. with `apkovl=&amp;quot;genapkovl-mkimgoverlay.sh&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
Note that to *use* your added apks, you have to install them, with {{ic|apk add}}.&lt;br /&gt;
&lt;br /&gt;
The definition may be done as in the [https://github.com/alpinelinux/aports/blob/master/scripts/genapkovl-dhcp.sh genapkovl-dhcp.sh] example.&lt;br /&gt;
Copy the relevant parts (including the rc_add lines) into a `genapkovl-mkimgoverlay.sh` file and add the package(s) that should be installed in the live system on separate lines in the file contents for /etc/apk/world.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cp ~/aports/scripts/genapkovl-dhcp.sh ~/aports/scripts/genapkovl-mkimgoverlay.sh}}&lt;br /&gt;
&lt;br /&gt;
Edit the file to add:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
mkdir -p &amp;quot;$tmp&amp;quot;/etc/apk&lt;br /&gt;
makefile root:root 0644 &amp;quot;$tmp&amp;quot;/etc/apk/world &amp;lt;&amp;lt;EOF&lt;br /&gt;
alpine-base&lt;br /&gt;
&amp;lt;apk1-service&amp;gt;&lt;br /&gt;
&amp;lt;apk2-service&amp;gt;&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
rc_add &amp;lt;apk1-service&amp;gt; boot&lt;br /&gt;
rc_add &amp;lt;apk2-service&amp;gt; boot&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in the relevant locations.&lt;br /&gt;
&lt;br /&gt;
Then edit the profile build script above and add:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apkovl=&amp;quot;aports/scripts/genapkovl-mkimgoverlay.sh&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
immediately after the last apks= line.&lt;br /&gt;
&lt;br /&gt;
== Create the ISO ==&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mkimage.sh	[--tag RELEASE] [--outdir OUTDIR] [--workdir WORKDIR]&lt;br /&gt;
		[--arch ARCH] [--profile PROFILE] [--hostkeys] [--simulate]&lt;br /&gt;
		[--repository REPO] [--extra-repository REPO] [--yaml FILE]&lt;br /&gt;
mkimage.sh	--help&lt;br /&gt;
&lt;br /&gt;
options:&lt;br /&gt;
--arch			Specify which architecture images to build&lt;br /&gt;
			(default: x86_64)&lt;br /&gt;
--hostkeys		Copy system apk signing keys to created images&lt;br /&gt;
--outdir		Specify directory for the created images&lt;br /&gt;
--profile		Specify which profiles to build&lt;br /&gt;
--repository		Package repository to use for the image create&lt;br /&gt;
--extra-repository	Add repository to search packages from&lt;br /&gt;
--simulate		Don&#039;t execute commands&lt;br /&gt;
--tag			Build images for tag RELEASE&lt;br /&gt;
--workdir		Specify temporary working directory (cache)&lt;br /&gt;
--yaml&lt;br /&gt;
&lt;br /&gt;
known profiles: ali rpi uboot base minirootfs standard vanilla extended virt xen}}&lt;br /&gt;
&lt;br /&gt;
{{Tip| You can use the --repository option multiple times, which is very useful when mixing local and official repositories. The --extra-repository option is  there only for backward-compatibility.}}&lt;br /&gt;
&lt;br /&gt;
Create an iso directory in your home dir:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mkdir -p ~/iso}}&lt;br /&gt;
&lt;br /&gt;
Then create the actual ISO.&lt;br /&gt;
In this example we will use the edge version x86_64:&lt;br /&gt;
{{Cmd|sh aports/scripts/mkimage.sh --tag edge \&lt;br /&gt;
	--outdir ~/iso \&lt;br /&gt;
	--arch x86_64 \&lt;br /&gt;
	--repository &amp;lt;nowiki&amp;gt;https://dl-cdn.alpinelinux.org/alpine/edge/main&amp;lt;/nowiki&amp;gt; \&lt;br /&gt;
	--profile $PROFILENAME&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you want to make a customized installer, you need to create &amp;lt;code&amp;gt;.default_boot_services&amp;lt;/code&amp;gt; which will cause &amp;lt;code&amp;gt;mkinitfs&amp;lt;/code&amp;gt; to create the defaults for the live image.&lt;br /&gt;
&lt;br /&gt;
* Several parts of this doc can be automated with a script, like the repository/arch/outdir settings.&lt;br /&gt;
Those steps are left to you and your imagination :)&lt;br /&gt;
&lt;br /&gt;
== Testing your ISO image ==&lt;br /&gt;
&lt;br /&gt;
[[QEMU#Live_mode|QEMU]] is useful for a quick test of your newly created ISO image.&lt;br /&gt;
This ISO build process has been tested to work and generate an ISO with auto-installed APKs as of Nov 20, 2023 with Alpine edge. &lt;br /&gt;
&lt;br /&gt;
[[Category:Package Manager]]&lt;br /&gt;
[[Category:ISO]]&lt;/div&gt;</summary>
		<author><name>Jeffre</name></author>
	</entry>
</feed>