From 2da0544738ad3627901c62a2b72d243f886219d8 Mon Sep 17 00:00:00 2001 From: Cyril zarak duval_j Date: Tue, 1 May 2018 23:16:44 +0200 Subject: [PATCH 1/2] Add ---kernel Signed-off-by: Cyril zarak duval_j --- arch-creator.sh | 34 ++++++++++++++++++++++++++++++---- cri-pxe.conf | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 cri-pxe.conf diff --git a/arch-creator.sh b/arch-creator.sh index 44fa3bf..198d580 100755 --- a/arch-creator.sh +++ b/arch-creator.sh @@ -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" @@ -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...]" } @@ -42,6 +43,7 @@ info() { printf "${PREFIX}\033[32m*${C_RESET} %s\n" "$*" } + run_unless() { COND="$1" shift @@ -88,6 +90,23 @@ run_chroot() { run_chroot_unless "false" "$@" } + +update_kernel() { + echo "updating kernel && initramfs" + KVER=$(basename ${ROOTFS_DIR}/usr/lib/modules/[^e]*) + echo ${KVER} + 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" \ + "locale-gen; ./dracut.sh --kver ${KVER} -l --force --conf /tmp/cri-pxe.conf /tmp/cri.img" + mkdir initramfs + echo "done" + cp "${ROOTFS_DIR}/boot/*" initramfs + exit 0 +} + step() { info "$*..." PREFIX="${PREFIX} " @@ -218,7 +237,10 @@ build() { mount_bind bootstrap install_salt - conf + if ${GEN_KERNEL}; then + update_kernel + fi + conf call_salt clean_fs squashfs @@ -262,8 +284,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" -- "$@") @@ -280,6 +302,10 @@ while true; do usage exit 0 ;; + -k|--kernel) + GEN_KERNEL=true + shift + ;; -i|--ignore-fallures) IGNORE_FAILURES=true shift diff --git a/cri-pxe.conf b/cri-pxe.conf new file mode 100644 index 0000000..324356c --- /dev/null +++ b/cri-pxe.conf @@ -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" From be1ce541682b05f8a7c0f54e128732e97fd1be6f Mon Sep 17 00:00:00 2001 From: Cyril zarak duval_j Date: Wed, 2 May 2018 16:41:07 +0200 Subject: [PATCH 2/2] Add the kernel && initramfs generation option Signed-off-by: Cyril zarak duval_j --- .gitignore | 1 + README.md | 4 ++++ arch-creator.sh | 30 +++++++++--------------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 82bf241..914a8ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ tmp/ imgs/ +initramfs/ diff --git a/README.md b/README.md index 3baf5d4..6395e30 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/arch-creator.sh b/arch-creator.sh index 198d580..8c5531b 100755 --- a/arch-creator.sh +++ b/arch-creator.sh @@ -94,16 +94,19 @@ run_chroot() { update_kernel() { echo "updating kernel && initramfs" KVER=$(basename ${ROOTFS_DIR}/usr/lib/modules/[^e]*) - echo ${KVER} 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" \ - "locale-gen; ./dracut.sh --kver ${KVER} -l --force --conf /tmp/cri-pxe.conf /tmp/cri.img" - mkdir initramfs - echo "done" - cp "${ROOTFS_DIR}/boot/*" initramfs + "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 } @@ -207,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}"} @@ -234,7 +224,6 @@ build() { step "Building ${IMAGE_NAME}..." create_dirs - mount_bind bootstrap install_salt if ${GEN_KERNEL}; then @@ -258,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"