Commit 9acabb63 authored by A. Wilcox's avatar A. Wilcox 🦊
Browse files

Initial commit to Git

parents
cdroot-*/
initrd-*
squashroot-*/
*.iso
=================================================
Contribution Guide for Adélie Linux Image Tools
=================================================
:Author:
* **A. Wilcox**, documentation writer
:Status:
Final
:Copyright:
© 2016 Adélie Linux. NCSA open source licence.
Introduction
============
This repository contains the Adélie Linux image tools, which are used by the
Release Engineering team to create the official Adélie Linux ISO images.
License
```````
The tools contained in this repository are licensed under the NCSA open source
license. The bzImage files are created from the ``sys-kernel/easy-kernel``
package (the ``/boot/vmlinuz`` file created for each architecture is copied
unchanged to ``bzImage-${ARCH}``), and as such are licensed under the kernel's
GPL2 license.
Changes
```````
Any changes to this repository must be reviewed before being pushed to the
master branch. There are no exceptions to this rule. For security-sensitive
updates, contact the Security Team at sec-bugs@adelielinux.org.
Patch Format
============
This section describes the format required for patches in this repository.
Unifed Diff Format
``````````````````
Patches must be submitted in unifed diff format (``diff -Nu``). There are no
exceptions to this rule.
Size
````
Patch files must be under 50 Kbyte, and under 500 lines.
Directory Level
```````````````
All patch files must be appliable using ``patch -p1``. This means that the
``diff`` command must be run one directory above the package's root.
Comments
````````
It is highly encouraged that you use the top matter of your patch file to
describe the changes being made. This grants other developers and the Adélie
Linux team the same level of understanding that you have over the patch set.
The format provided by ``svn`` or ``git`` is acceptable, and a direct upstream
commit number is even better.
Contributing Changes
====================
This section describes the usual flows of contribution to this repository.
GitLab Pull Requests
````````````````````
#. If you do not already have a GitLab account, you must create one.
#. Create a *fork* of the packages repository. For more information, consult
the GitLab online documentation.
#. Clone your forked repository to your computer.
#. Make your changes.
#. Test your changes to ensure they are correct.
#. Add (or remove) changed files using ``git add`` and ``git rm``.
#. Commit your changes to the tree using the command ``git commit`` and
``git push``.
#. Visit your forked repository in a Web browser.
#. Choose the *Create Pull Request* button.
#. Review your changes to ensure they are correct, and then submit the form.
Mailing List
````````````
#. Clone the packages repository to your computer.
#. Make your changes.
#. Test your changes to ensure they are correct.
#. Add (or remove) changed files using ``git add`` and ``git rm``.
#. Commit your changes to the tree using the command ``git commit``.
#. Use the command ``git format-patch HEAD^`` to create a patch file for your
commit.
.. note:: If you have made multiple commits to the tree, you will need to
add an additional ^ for each commit you have made. For example,
if you have made three commits, you will use the command
``git format-patch HEAD^^^``.
#. Email the resulting patch to the release engineering mailing list.
====================
Adélie Image Tools
====================
:Author:
A\. Wilcox
:Version:
1.0
:Status:
Production
:Copyright:
© 2016 Adélie Linux Team. NCSA open source licence.
Introduction
============
This repository contains the Adélie Linux image tools, which are used by the
Release Engineering team to create the official Adélie Linux ISO images.
License
```````
The tools contained in this repository are licensed under the NCSA open source
license. The bzImage files are created from the ``sys-kernel/easy-kernel``
package (the ``/boot/vmlinuz`` file created for each architecture is copied
unchanged to ``bzImage-${ARCH}``), and as such are licensed under the kernel's
GPL2 license.
Changes
```````
Any changes to this repository must be reviewed before being pushed to the
master branch. There are no exceptions to this rule. For security-sensitive
updates, contact the Security Team at sec-bugs@adelielinux.org.
Usage
=====
This section contains usage information for the software in this repository.
``build-cd``
````````````
This script is where the magic happens. ``build-cd`` will create the ISO for
the architecture specified (defaulting to the currently running system
architecture if not specified).
``build-cd`` requires the following utilities to be installed on your computer:
* apk-tools
* cpio
* squashfs-tools
* A variant of ``mkisofs`` - releng uses the cdrtools package, but you may be
able to use cdrkit.
``build-cd`` is run on the Z shell on official releng machines, but should be
functional in any POSIX compliant shell; it relies on no non-POSIX shell
constructs.
The ``cdinit-${ARCH}`` file must exist in the directory that you run
``build-cd``; it does not need to be in the same directory as the ``build-cd``
script itself.
``cdinit``
``````````
This functions as early init for the CD, probing for the SquashFS root and
mounting it appropriately. Pre-compiled binaries statically linked to the
current release's version of musl, util-linux, and eudev are provided for each
Tier I and Tier II architecture of the current release.
You may build your own ``cdinit``, for veriication purposes or for another
architecture, and place it in the same directory as you invoke ``build-cd``.
Reporting Issues
================
If you have issues installing with the official media, you should report your
issue to `the BTS`_.
If you have issues running ``build-cd`` or compiling ``cdinit``, you may file
an issue in the GitLab repository.
`the BTS`_: http://bts.adelielinux.org/
#!/bin/sh
def_arch=x86_64
def_kernel=4.6
declare -r PROGNAME=$(basename $0)
warn() {
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>>\n'
}
fatal() {
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>>\n'
}
ensure_commands() {
if ! type apk>/dev/null; then
fatal
printf 'You must have apk installed. On Gentoo, see sys-devel/apk-tools.\n'
exit -1
fi
if ! type cpio>/dev/null; then
fatal
printf 'You must have cpio installed. On Gentoo, see app-arch/cpio.\n'
exit -1
fi
if ! type mksquashfs>/dev/null; then
fatal
printf 'You must have mksquashfs installed. On Gentoo, see sys-fs/squashfs-tools.\n'
exit -1
fi
if ! type mkisofs>/dev/null; then
fatal
printf 'You must have mkisofs installed. Try cdrtools or cdrkit.\n'
exit -1
fi
}
usage() {
printf 'usage: %s [-a ARCH] [-k KERNEL] [--help]\n\n' $PROGNAME
printf 'Create an Adélie Linux CD image (.ISO) using the specified parameters.\n'
printf 'Default ARCH: %s\nDefault kernel version: %s\n' $def_arch $def_kernel
}
while [ -n "$1" ]; do
case $1 in
-a | --arch)
shift
declare -r MY_ARCH=$1
;;
-h | --help)
usage
exit
;;
-k | --kernel)
shift
declare -r MY_KERNEL=$1
;;
*)
usage >&2
exit -1
;;
esac
shift
done
declare -r ARCH=${MY_ARCH:-$def_arch}
declare -r KERNEL=${MY_KERNEL:-$def_kernel}
declare -r LDARCH=${LDARCH:-$ARCH}
ensure_commands
warn
printf 'This will erase all files at the directories %s/cdroot-%s\n' `pwd` $ARCH
printf '%s/initrd-%s and %s/squashroot-%s.\n\n' `pwd` $ARCH `pwd` $ARCH
printf 'When you are ready, press RETURN. To cancel, press Ctrl-C.\n'
read
printf '\033[01;32m * \033[37mAdélie Linux CD Creation Tool\033[00;39m\n\n'
rm -rf cdroot-$ARCH
rm -rf initrd-$ARCH
rm -rf squashroot-$ARCH
mkdir cdroot-$ARCH
mkdir initrd-$ARCH
mkdir squashroot-$ARCH
printf '\033[01;32m * \033[37mInstalling base system to squash root...\033[00;39m\n'
apk --arch $ARCH -X "https://distfiles.adelielinux.org/adelie/1.0-alpha/$EXTRA_MIRROR" -U --allow-untrusted --root squashroot-$ARCH --initdb add shadow libffi adelie-base bash openrc openrc-openrc hwids eudev udev-init-scripts-openrc parted lvm2-openrc easy-kernel-modules easy-kernel-firmware dhcpcd net-tools ca-certificates
mkdir -p squashroot-$ARCH/etc/apk/keys
mkdir -p squashroot-$ARCH/home/live
mkdir squashroot-$ARCH/target
mkdir -p squashroot-$ARCH/media/live
ln -s /bin/bash squashroot-$ARCH/bin/sh
echo 'hostname="adelie"' > squashroot-$ARCH/etc/conf.d/hostname
echo 'mtab_is_file=no' > squashroot-$ARCH/etc/conf.d/mtab
cp -RPp squashroot-$ARCH/usr/share/openrc/runlevels squashroot-$ARCH/etc/runlevels
cp 'packages@adelielinux.org.pub' squashroot-$ARCH/etc/apk/keys/
ln -s /etc/init.d/udev squashroot-$ARCH/etc/runlevels/sysinit/udev
ln -s /etc/init.d/udev-trigger squashroot-$ARCH/etc/runlevels/sysinit/udev-trigger
ln -s /etc/init.d/lvmetad squashroot-$ARCH/etc/runlevels/sysinit/lvmetad
cat >squashroot-$ARCH/etc/fstab <<- FSTAB
# Welcome to Adélie Linux.
# This fstab(5) is for the live media only. Do not edit or use for your installation.
tmpfs /tmp tmpfs defaults 0 1
tmpfs /var/log tmpfs size=8m 0 1
tmpfs /root tmpfs size=16m 0 1
tmpfs /home/live tmpfs size=16m 0 1
proc /proc proc defaults 0 1
FSTAB
cat >squashroot-$ARCH/etc/passwd <<- PASSWD
root:x:0:0:Charlie Root:/root:/bin/bash
man:x:13:15:man-db:/usr/share/man:/sbin/nologin
at:x:25:25:at:/var/spool/at/atjobs:/sbin/nologin
fcron:x:101:206:fcron:/dev/null:/sbin/nologin
postfix:x:207:207:postfix:/var/spool/postfix:/sbin/nologin
live:x:1000:1000:Live User:/home/live:/bin/bash
PASSWD
cat >squashroot-$ARCH/etc/group <<- GROUP
root:x:0:
tty:x:5:
wheel:x:10:live
mail:x:12:postfix
uucp:x:14:
cron:x:16:
at:x:25:
fcron:x:206:
postfix:x:207:
postdrop:x:208:
live:x:1000:
GROUP
cat >squashroot-$ARCH/etc/shadow <<- SHADOW
root::::::::
man::::::::
at::::::::
fcron::::::::
postfix::::::::
live::::::::
SHADOW
cat >squashroot-$ARCH/etc/shells <<- SHELLS
/bin/bash
/bin/zsh
SHELLS
cat >squashroot-$ARCH/etc/resolv.conf <<- RESOLVE
nameserver 8.8.8.8
RESOLVE
cat >squashroot-$ARCH/etc/apk/repositories <<-REPOS
https://distfiles.adelielinux.org/adelie/1.0-alpha/$EXTRA_MIRROR
REPOS
cat >squashroot-$ARCH/etc/issue <<-ISSUE
Welcome to Adélie Linux!
You may log in as 'root' to install, or 'live' to play around.
Have fun.
ISSUE
chmod 600 squashroot-$ARCH/etc/shadow
printf '\033[01;32m * \033[37mCreating compressed file system image...\033[00;39m\n'
mksquashfs squashroot-$ARCH cdroot-$ARCH/adelie.squashfs
printf '\033[01;32m * \033[37mCreating initrd structure...\033[00;39m\n'
# mount points
mkdir initrd-$ARCH/dev
mkdir initrd-$ARCH/media
mkdir initrd-$ARCH/newroot
mkdir initrd-$ARCH/proc
mkdir initrd-$ARCH/sys
# manual /dev nodes for initial udev startup
mknod -m 600 initrd-$ARCH/dev/console c 5 1
mknod -m 666 initrd-$ARCH/dev/null c 1 3
mknod -m 666 initrd-$ARCH/dev/ptmx c 5 2
mknod -m 666 initrd-$ARCH/dev/random c 1 8
mknod -m 666 initrd-$ARCH/dev/tty c 5 0
mknod -m 620 initrd-$ARCH/dev/tty1 c 4 1
mknod -m 666 initrd-$ARCH/dev/urandom c 1 9
mknod -m 666 initrd-$ARCH/dev/zero c 1 5
# base
mkdir initrd-$ARCH/lib
cp squashroot-$ARCH/usr/lib/libc.so initrd-$ARCH/lib/ld-musl-$LDARCH.so.1
cp squashroot-$ARCH/lib/libblkid.so.1 initrd-$ARCH/lib/
cp squashroot-$ARCH/lib/libuuid.so.1 initrd-$ARCH/lib/
# udev
mkdir -p initrd-$ARCH/etc/udev
mkdir initrd-$ARCH/run
mkdir initrd-$ARCH/sbin
cp squashroot-$ARCH/bin/udevadm initrd-$ARCH/sbin/
cp squashroot-$ARCH/sbin/udevd initrd-$ARCH/sbin/
cp squashroot-$ARCH/lib/libkmod.so.2 initrd-$ARCH/lib/
cp squashroot-$ARCH/lib/libudev.so.1 initrd-$ARCH/lib/
cp squashroot-$ARCH/etc/udev/hwdb.bin initrd-$ARCH/etc/udev/
# init
cp cdinit-$ARCH initrd-$ARCH/init
printf '\033[01;32m * \033[37mCompressing initrd...\033[00;39m\n'
pushd initrd-$ARCH
find . | cpio -H newc -o > ../cdroot-$ARCH/initrd
popd
gzip -9 cdroot-$ARCH/initrd
mv cdroot-$ARCH/initrd.gz cdroot-$ARCH/initrd
printf '\033[01;32m * \033[37mAdding kernel...\033[00;39m\n'
cp bzImage-$ARCH cdroot-$ARCH/bzImage
printf '\033[01;32m * \033[37mInstalling ISOLINUX...\033[00;39m\n'
mkdir cdroot-$ARCH/isolinux
cat >cdroot-$ARCH/isolinux/isolinux.cfg <<BOOTCFG
prompt 1
default adelie
label adelie
kernel /bzImage
append initrd=/initrd
BOOTCFG
cp /usr/share/syslinux/isolinux-debug.bin cdroot-$ARCH/isolinux/isolinux.bin
cp /usr/share/syslinux/ldlinux.c32 cdroot-$ARCH/isolinux/
printf '\033[01;32m * \033[37mCreating the CD...\033[00;39m\n'
mkisofs -o adelie-live-$ARCH-1.0-ALPHA-$(date +%Y%m%d).iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -joliet cdroot-$ARCH
File added
File added
File added
File added
/*
* cdinit - start up udev, find the squashfs, and get the hell out of dodge
* Copyright (c) 2016 Adélie Linux Team. All rights reserved.
* Licensed under the NCSA open source license.
* See LICENSE file included with this source for more information.
*/
#include <errno.h> /* errno */
#include <fcntl.h> /* ioctl */
#include <linux/loop.h> /* LOOP_SET_FD */
#include <stdbool.h> /* bool */
#include <stdio.h> /* stderr, fprintf */
#include <stdlib.h> /* EXIT_FAILURE */
#include <string.h> /* strlen */
#include <sys/mount.h> /* mount */
#include <sys/stat.h> /* mkdir */
#include <sys/wait.h> /* waitpid, W* macros */
#include <unistd.h> /* exec, fork, etc */
#include <blkid/blkid.h>/* blkid_get_tag_value */
#include <libudev.h> /* udev* */
/*!
* @brief Invoke a specified command. Return if it is run successfully.
* @param command User-readable description of what command is to run.
* @param path The full on-disk path to the executable to run.
* @param argv The full argument list to run.
* @returns true if command runs successfully, false otherwise.
*/
bool cdi_invoke(const char *command, const char *path, char * const argv[])
{
pid_t our_pid;
fprintf(stdout, " * Starting %s... ", command);
our_pid = fork();
if(our_pid == 0)
{
execv(path, argv);
fprintf(stderr, "could not start %s: %s\n", command,
strerror(errno));
return 255;
}
else if(our_pid == -1)
{
fprintf(stdout, "[ !! ] failed to fork: %s\n", strerror(errno));
return false;
}
else
{
int status, code;
waitpid(our_pid, &status, 0);
if(!WIFEXITED(status))
{
fprintf(stdout, "[ !! ] %s caught signal\n", command);
return false;
}
code = WEXITSTATUS(status);
if(code != 0)
{
fprintf(stdout, "[ !! ] %s exited with error code %d\n",
command, code);
return false;
}
}
fprintf(stdout, "[ ok ]\n");
return true;
}
/* We need to test each block device in the system, in case there are
* multiple drives that all have media present. We can narrow it down,
* however:
*
* - We know that our device will have 'adelie.squashfs'.
* - We know it will be mountable without external helpers, as ISO9660,
* FAT, and HFS+ are built in to the kernel.
*/
bool cdi_find_media(void)
{
struct udev *udev;
struct udev_enumerate *dev_list;
struct udev_list_entry *first, *candidate;
struct udev_device *device = NULL;
udev = udev_new();
if(udev == NULL)
{
fprintf(stderr, "Cannot establish link to udev.\n");
return false;
}
dev_list = udev_enumerate_new(udev);
if(dev_list == NULL)
{
fprintf(stderr, "Cannot create enumerator (memory?)\n");
return false;
}
udev_enumerate_add_match_subsystem(dev_list, "block");
#ifdef DISKONLY /* support booting off USB partition unless DISKONLY */
udev_enumerate_add_match_property(dev_list, "DEVTYPE", "disk");
#endif
udev_enumerate_scan_devices(dev_list);
first = udev_enumerate_get_list_entry(dev_list);
if(first == NULL)
{
fprintf(stdout, "No block devices found.\n");
fprintf(stdout, "This system cannot boot Adélie Linux "
"without additional drivers.\n");
return false;
}
udev_list_entry_foreach(candidate, first)
{
const char *path = udev_list_entry_get_name(candidate);
char *fstype = NULL;
if(device != NULL)
{
udev_device_unref(device);
}
device = udev_device_new_from_syspath(udev, path);
errno = 0;
const char *dev_node = udev_device_get_devnode(device);
if(dev_node == NULL)
{
continue; /* worthless */
}
#ifdef DEBUG
fprintf(stderr, "cdi_find_media: testing candidate %s\n",
dev_node);
#endif
if((fstype = blkid_get_tag_value(NULL, "TYPE", dev_node)) == NULL)
{
#ifdef DEBUG
fprintf(stderr, "cdi_find_media: %s has unknown FS\n",
dev_node);