commit: cf851385321976893fc44c12cc0672ad6e8a9689 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> AuthorDate: Sat Jul 20 20:59:09 2019 +0000 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> CommitDate: Sun Jul 21 15:47:50 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=cf851385
initramfs: Don't call mknod when --busybox is used This will basically allow us to run genkernel as user. Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> defaults/linuxrc | 8 +++++++ gen_initramfs.sh | 68 +++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/defaults/linuxrc b/defaults/linuxrc index 41a53fc..4113b63 100644 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -9,6 +9,14 @@ splash() { [ -e /etc/initrd.splash ] && . /etc/initrd.splash +# Basic /dev content, we need it as fast as possible. +[ ! -e /dev/console ] && mknod /dev/console c 5 1 +[ ! -e /dev/null ] && mknod /dev/null c 1 3 +[ ! -e /dev/tty ] && mknod /dev/tty c 5 0 +[ ! -e /dev/urandom ] && mknod /dev/urandom c 1 9 +[ ! -e /dev/random ] && mknod /dev/random c 1 8 +[ ! -e /dev/zero ] && mknod /dev/zero c 1 5 + # Clean input/output exec >${CONSOLE} <${CONSOLE} 2>&1 diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 8419a20..55cf295 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -178,34 +178,52 @@ log_future_cpio_content() { } append_devices() { - local TFILE="${TEMP}/initramfs-base-temp.devices" - if [ -f "${TFILE}" ] + if isTrue "${BUSYBOX}" then - rm "${TFILE}" || gen_die "Failed to clean out existing '${TFILE}'!" - fi + local TDIR="${TEMP}/initramfs-devices-temp" + if [ -d "${TDIR}" ] + then + rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!" + fi - if [[ ! -x "${KERNEL_OUTPUTDIR}/usr/gen_init_cpio" ]]; then - compile_gen_init_cpio - fi + mkdir -p "${TDIR}/dev" || gen_die "Failed to create '${TDIR}/dev'!" + cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" - # WARNING, does NOT support appending to cpio! - cat >"${TFILE}" <<-EOF - dir /dev 0755 0 0 - nod /dev/console 660 0 0 c 5 1 - nod /dev/null 666 0 0 c 1 3 - nod /dev/zero 666 0 0 c 1 5 - nod /dev/tty0 600 0 0 c 4 0 - nod /dev/tty1 600 0 0 c 4 1 - nod /dev/ttyS0 600 0 0 c 4 64 - EOF + chmod 0755 dev || gen_die "Failed to chmod of '${TDIR}/dev' to 0755!" - print_info 3 "=================================================================" 1 0 1 - print_info 3 "Adding the following devices to cpio:" 1 0 1 - print_info 3 "$(cat "${TFILE}")" 1 0 1 - print_info 3 "=================================================================" 1 0 1 + log_future_cpio_content + find . -print0 | cpio ${CPIO_ARGS} -F "${CPIO}" \ + || gen_die "Failed to append devices to cpio!" + else + local TFILE="${TEMP}/initramfs-base-temp.devices" + if [ -f "${TFILE}" ] + then + rm "${TFILE}" || gen_die "Failed to clean out existing '${TFILE}'!" + fi + + if [[ ! -x "${KERNEL_OUTPUTDIR}/usr/gen_init_cpio" ]]; then + compile_gen_init_cpio + fi - "${KERNEL_OUTPUTDIR}"/usr/gen_init_cpio "${TFILE}" >"${CPIO}" \ - || gen_die "Failed to append devices to cpio!" + # WARNING, does NOT support appending to cpio! + cat >"${TFILE}" <<-EOF + dir /dev 0755 0 0 + nod /dev/console 660 0 0 c 5 1 + nod /dev/null 666 0 0 c 1 3 + nod /dev/zero 666 0 0 c 1 5 + nod /dev/tty0 600 0 0 c 4 0 + nod /dev/tty1 600 0 0 c 4 1 + nod /dev/ttyS0 600 0 0 c 4 64 + EOF + + print_info 3 "=================================================================" 1 0 1 + print_info 3 "Adding the following devices to cpio:" 1 0 1 + print_info 3 "$(cat "${TFILE}")" 1 0 1 + print_info 3 "=================================================================" 1 0 1 + + "${KERNEL_OUTPUTDIR}"/usr/gen_init_cpio "${TFILE}" >"${CPIO}" \ + || gen_die "Failed to append devices to cpio!" + fi } append_base_layout() { @@ -383,7 +401,7 @@ append_busybox() { done # Set up a few default symlinks - local required_applets='[ ash sh mount uname echo cut cat' + local required_applets='[ ash sh mknod mount uname echo cut cat' local required_applet= for required_applet in ${required_applets} do @@ -1576,7 +1594,7 @@ create_initramfs() { # TODO: maybe replace this with: # http://search.cpan.org/~pixel/Archive-Cpio-0.07/lib/Archive/Cpio.pm # as then we can dedupe ourselves... - if [[ $UID -eq 0 ]] + if isTrue "${BUSYBOX}" || [[ ${UID} -eq 0 ]] then print_info 1 "$(get_indent 1)>> Deduping cpio ..." local TDIR="${TEMP}/initramfs-final"