Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Add kernel && initramfs generation #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tmp/
imgs/
initramfs/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ Dependencies
============

Having gcc-multilib and arch-install-scripts installed on the host, mktorrent is required to use the torrent generator.

--kernel:

Generate the img before using the --kernel option.
52 changes: 33 additions & 19 deletions arch-creator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ WORK_DIR="tmp"

DEBUG=false
IGNORE_FAILURES=false
GEN_KERNEL=false
KEEP_OUTPUT=false
RUN_CMD="sh -c"
RUN_LABEL="run"
Expand All @@ -33,7 +34,7 @@ C_CYAN="$E[36m"

usage() {
echo "Usage: $0 -h|--help"
echo "Usage: $0 build [-d|--debug] [-i|--ignore-failures] [-e SALT_ENV] [-m SALT_MASTER] IMAGE_NAME"
echo "Usage: $0 build [-d|--debug] [-i|--ignore-failures] [-e SALT_ENV] [-m SALT_MASTER] [-k|--kernel] IMAGE_NAME"
echo "Usage: $0 torrent [-t|--tracker ANNOUNCE_URL] [*|IMAGE_NAME...]"
echo "Usage: $0 clean [*|IMAGE_NAME...]"
}
Expand All @@ -42,6 +43,7 @@ info() {
printf "${PREFIX}\033[32m*${C_RESET} %s\n" "$*"
}


run_unless() {
COND="$1"
shift
Expand Down Expand Up @@ -88,6 +90,26 @@ run_chroot() {
run_chroot_unless "false" "$@"
}


update_kernel() {
echo "updating kernel && initramfs"
KVER=$(basename ${ROOTFS_DIR}/usr/lib/modules/[^e]*)
cp cri-pxe.conf "${ROOTFS_DIR}"/tmp
run_chroot "pacman -Sy --noconfirm --needed linux git dhclient cpio asciidoc;" \
"cd /tmp;"
run_chroot "cd /tmp && git clone https://github.com/epita/dracut.git;"\
"cd dracut; ./configure && make -j9;" \
"locale-gen; ./dracut.sh --kver ${KVER} -l --force --conf /tmp/cri-pxe.conf /tmp/cri.img;"\
"cp /tmp/cri.img /boot/cri.img"
IMG_NAME=$(basename $(dirname ${ROOTFS_DIR}))
cp "${ROOTFS_DIR}/boot/vmlinuz-linux" "initramfs/${IMG_NAME}-vmlinuz-linux"
cp "${ROOTFS_DIR}/boot/cri.img" "initramfs/${IMG_NAME}-initramfs.img"
echo "Done."
echo "Kernel and initramfs are in :"
echo "$(ls initramfs/${IMG_NAME}*)"
exit 0
}

step() {
info "$*..."
PREFIX="${PREFIX} "
Expand Down Expand Up @@ -188,19 +210,6 @@ squashfs() {
unstep
}

# arch-chroot does not create a mount point for / by default so the root
# directory must be already mounted before chrooting in
mount_bind() {
step "Mounting ROOTFS"
mount --bind ${ROOTFS_DIR} ${ROOTFS_DIR}
unstep
}

umount_bind() {
step "Unmounting ROOTFS"
umount ${ROOTFS_DIR}
unstep
}

build() {
IMAGE_NAME=${1:-"${DEFAULT_IMAGE}"}
Expand All @@ -215,10 +224,12 @@ build() {
step "Building ${IMAGE_NAME}..."

create_dirs
mount_bind
bootstrap
install_salt
conf
if ${GEN_KERNEL}; then
update_kernel
fi
conf
call_salt
clean_fs
squashfs
Expand All @@ -236,7 +247,6 @@ clean() {

step "Cleaning ${IMAGE_NAME}"

umount_bind
run rm -rf `dirname "${ROOTFS_DIR}"`
run rm -rf "${IMAGES_DIR}/${IMAGE_NAME}.squashfs"
run rm -rf "${IMAGES_DIR}/${IMAGE_NAME}_*.torrent"
Expand All @@ -262,8 +272,8 @@ torrent() {
unstep
}

GO_SHORT="hide:m:t:"
GO_LONG="help,ignore-failures,debug,environment,master:,tracker:"
GO_SHORT="hide:m:t:k:"
GO_LONG="kernel,help,ignore-failures,debug,environment,master:,tracker:"

GO_PARSED=$(getopt --options ${GO_SHORT} --longoptions ${GO_LONG} \
--name "$0" -- "$@")
Expand All @@ -280,6 +290,10 @@ while true; do
usage
exit 0
;;
-k|--kernel)
GEN_KERNEL=true
shift
;;
-i|--ignore-fallures)
IGNORE_FAILURES=true
shift
Expand Down
19 changes: 19 additions & 0 deletions cri-pxe.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

dracutmodules+="base "
dracutmodules+="bash "
dracutmodules+="dracut-systemd "
dracutmodules+="kernel-all-modules "
dracutmodules+="kernel-modules "
dracutmodules+="diskless "
#dracutmodules+="resume "
#dracutmodules+="shutdown "
dracutmodules+="systemd "
dracutmodules+="systemd-initrd "

drivers+="overlay"

hostonly="no"
hostonly_cmdline="no"
use_fstab="no"
mdadmconf="no"
nofscks="yes"