How to make a custom ISO image with mkimage: Difference between revisions

From Alpine Linux
No edit summary
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
This document explains how to build a custom ISO image using the new mkimage scripts located in aports directory.
This document explains how to build a custom ISO image using the new mkimage scripts located in [[aports]] directory.


== Prerequisite ==
== Prerequisite ==


First make sure we have the needed tools
First make sure we have the needed tools
{{Cmd|apk add build-base apk-tools alpine-conf busybox fakeroot syslinux xorriso}}
{{Cmd|apk add alpine-sdk build-base apk-tools alpine-conf busybox fakeroot syslinux xorriso squashfs-tools}}
For efi you shoud add
For efi you should add
{{Cmd|mtools dosfstools grub-efi}}
{{Cmd|mtools dosfstools grub-efi}}


Create a user (e.g. build) and add it to abuild group:
Create a user (e.g. build) and add it to abuild group:
{{Cmd|useradd build -G abuild}}
{{Cmd|adduser build -G abuild}}


Then create signing keys (-i installs them in /etc/apk/keys which is required for later)
Then create signing keys (-i installs them in /etc/apk/keys which is required for later)
{{Cmd|abuild-keygen -i -a}}
{{Cmd|abuild-keygen -i -a}}


{{Tip| Make sure your public keys are placed in /etc/apk/keys/ (example: build-xxxxxxxx.rsa.pub):
{{Tip| Make sure your public keys are placed in /etc/apk/keys/ (example: build-xxxxxxxx.rsa.pub)}}
{{Cmd|ls /etc/apk/keys/}}
{{Cmd|ls /etc/apk/keys/}}


Line 23: Line 23:
Make sure the apk index is up to date (so apk finds the packages):
Make sure the apk index is up to date (so apk finds the packages):
{{Cmd|apk update}}
{{Cmd|apk update}}


== Configuration ==
== Configuration ==
Line 36: Line 35:


<pre>export PROFILENAME=nas</pre>
<pre>export PROFILENAME=nas</pre>
{{Cmd|cat << EOF > ~/aports/scripts/mkimg.$PROFILENAME.sh}}


<pre>
<pre>
cat << EOF > ~/aports/scripts/mkimg.$PROFILENAME.sh
profile_$PROFILENAME() {
profile_$PROFILENAME() {
profile_standard
        profile_standard
kernel_flavors=""
        kernel_cmdline="unionfs_size=512M console=tty0 console=ttyS0,115200"
kernel_cmdline="unionfs_size=512M console=tty0 console=ttyS0,115200"
        syslinux_serial="0 115200"
syslinux_serial="0 115200"
        kernel_addons="zfs spl"
kernel_addons="zfs spl"
        apks="\$apks iscsi-scst zfs-scripts zfs zfs-utils-py
apks="$apks iscsi-scst zfs-scripts zfs zfs-utils-py
                cciss_vol_status lvm2 mdadm mkinitfs mtools nfs-utils
cciss_vol_status lvm2 mdadm mkinitfs mtools nfs-utils
                parted rsync sfdisk syslinux unrar util-linux xfsprogs
parted rsync sfdisk syslinux unrar util-linux xfsprogs
                dosfstools ntfs-3g
dosfstools ntfs-3g
                "
"
        local _k _a
local _k _a
        for _k in \$kernel_flavors; do
for _k in $kernel_flavors; do
                apks="\$apks linux-\$_k"
apks="$apks linux-$_k"
                for _a in \$kernel_addons; do
for _a in $kernel_addons; do
                        apks="\$apks \$_a-\$_k"
apks="$apks $_a-$_k"
                done
done
        done
done
        apks="\$apks linux-firmware"
apks="$apks linux-firmware"
}
}
EOF
</pre>
</pre>


Line 66: Line 63:
{{Cmd|chmod +x mkimg.$PROFILENAME.sh}}
{{Cmd|chmod +x mkimg.$PROFILENAME.sh}}


== Create the ISO ==
{{Cmd|mkimage.sh [--tag RELEASE] [--outdir OUTDIR] [--workdir WORKDIR]
[--arch ARCH] [--profile PROFILE] [--hostkeys] [--simulate]
[--repository REPO] [--extra-repository REPO] [--yaml FILE]
mkimage.sh --help
options:
--arch Specify which architecture images to build
(default: x86_64)
--hostkeys Copy system apk signing keys to created images
--outdir Specify directory for the created images
--profile Specify which profiles to build
--repository Package repository to use for the image create
--extra-repository Add repository to search packages from
--simulate Don't execute commands
--tag Build images for tag RELEASE
--workdir Specify temporary working directory (cache)
--yaml


== Create the ISO ==
known profiles: ali rpi uboot base minirootfs standard vanilla extended virt xen}}


Create a iso directory in your home dir:
Create a iso directory in your home dir:
Line 87: Line 103:
Of course, several passages of this doc can be automated with a script, like the repository/arch/outdir settings.
Of course, several passages of this doc can be automated with a script, like the repository/arch/outdir settings.
This steps are left to you and to your imagination :)
This steps are left to you and to your imagination :)


== Testing your ISO image ==
== Testing your ISO image ==

Revision as of 11:37, 10 January 2019

This document explains how to build a custom ISO image using the new mkimage scripts located in aports directory.

Prerequisite

First make sure we have the needed tools

apk add alpine-sdk build-base apk-tools alpine-conf busybox fakeroot syslinux xorriso squashfs-tools

For efi you should add

mtools dosfstools grub-efi

Create a user (e.g. build) and add it to abuild group:

adduser build -G abuild

Then create signing keys (-i installs them in /etc/apk/keys which is required for later)

abuild-keygen -i -a

Tip: Make sure your public keys are placed in /etc/apk/keys/ (example: build-xxxxxxxx.rsa.pub)

ls /etc/apk/keys/

Clone (or update) the git repository.

git clone git://git.alpinelinux.org/aports


Make sure the apk index is up to date (so apk finds the packages):

apk update

Configuration

The mkimg scripts are shipped with pre-configured profiles.

The format is mkimg.$PROFILENAME.sh

So, in order to have a custom ISO, you should create your own mkimg.$PROFILENAME.sh script.

This is an example used to have ZFS module, overlayfs (which allows to have /lib/modules in r/w), a serial console output and some other useful apks to build a simple NAS:

export PROFILENAME=nas
cat << EOF > ~/aports/scripts/mkimg.$PROFILENAME.sh
profile_$PROFILENAME() {
        profile_standard
        kernel_cmdline="unionfs_size=512M console=tty0 console=ttyS0,115200"
        syslinux_serial="0 115200"
        kernel_addons="zfs spl"
        apks="\$apks iscsi-scst zfs-scripts zfs zfs-utils-py
                cciss_vol_status lvm2 mdadm mkinitfs mtools nfs-utils
                parted rsync sfdisk syslinux unrar util-linux xfsprogs
                dosfstools ntfs-3g
                "
        local _k _a
        for _k in \$kernel_flavors; do
                apks="\$apks linux-\$_k"
                for _a in \$kernel_addons; do
                        apks="\$apks \$_a-\$_k"
                done
        done
        apks="\$apks linux-firmware"
}
EOF

Set the script as executable:

chmod +x mkimg.$PROFILENAME.sh

Create the ISO

mkimage.sh [--tag RELEASE] [--outdir OUTDIR] [--workdir WORKDIR] [--arch ARCH] [--profile PROFILE] [--hostkeys] [--simulate] [--repository REPO] [--extra-repository REPO] [--yaml FILE] mkimage.sh --help options: --arch Specify which architecture images to build (default: x86_64) --hostkeys Copy system apk signing keys to created images --outdir Specify directory for the created images --profile Specify which profiles to build --repository Package repository to use for the image create --extra-repository Add repository to search packages from --simulate Don't execute commands --tag Build images for tag RELEASE --workdir Specify temporary working directory (cache) --yaml known profiles: ali rpi uboot base minirootfs standard vanilla extended virt xen

Create a iso directory in your home dir:

mkdir -p ~/iso

Then create the actual ISO. In this example we will use the edge version x86_64:

sh mkimage.sh --tag edge \ --outdir ~/iso \ --arch x86_64 \ --repository http://dl-cdn.alpinelinux.org/alpine/edge/main \ --profile $PROFILENAME


Notes:

Of course, several passages of this doc can be automated with a script, like the repository/arch/outdir settings. This steps are left to you and to your imagination :)

Testing your ISO image

Qemu is useful for a quick test of your created ISO image.