From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 5FAB658973 for ; Sun, 7 Feb 2016 12:53:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7DA23E07F1; Sun, 7 Feb 2016 12:53:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0BC5CE07F1 for ; Sun, 7 Feb 2016 12:53:31 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DBCE9340B0C for ; Sun, 7 Feb 2016 12:53:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D49DDCEB for ; Sun, 7 Feb 2016 12:53:27 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1454849597.0042cf39f3efd3ed14a9a8a363b82cb43117b4e4.robbat2@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: / X-VCS-Repository: proj/genkernel X-VCS-Files: gen_initramfs.sh X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 0042cf39f3efd3ed14a9a8a363b82cb43117b4e4 X-VCS-Branch: master Date: Sun, 7 Feb 2016 12:53:27 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 8f03dec0-6b29-401d-b251-4c0713f72db2 X-Archives-Hash: 98e616a53f44853a23d10d5e210e8812 commit: 0042cf39f3efd3ed14a9a8a363b82cb43117b4e4 Author: Robin H. Johnson gentoo org> AuthorDate: Sun Feb 7 12:53:17 2016 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Sun Feb 7 12:53:17 2016 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=0042cf39 gen_initramfs: drop usage of mknod, so we can almost run without root! Signed-off-by: Robin H. Johnson gentoo.org> gen_initramfs.sh | 61 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index a03f5b1..fdf2eb1 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -60,6 +60,25 @@ log_future_cpio_content() { fi } +append_devices() { + # WARNING, does NOT support appending to cpio! + cat >"${TEMP}/initramfs-base-temp.devices" <<-EOF + dir /dev 0755 0 0 + nod /dev/console 660 0 0 c 5 1 + nod /dev/null 660 0 0 c 1 3 + nod /dev/zero 660 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 + if [[ "${LOGLEVEL}" -gt 1 ]]; then + echo "Adding devices to cpio:" + cat "${TEMP}/initramfs-base-temp.devices" + fi + ${KERNEL_OUTPUTDIR}/usr/gen_init_cpio "${TEMP}/initramfs-base-temp.devices" >"${CPIO}" \ + || gen_die "Failed to add devices to cpio" +} + append_base_layout() { if [ -d "${TEMP}/initramfs-base-temp" ] then @@ -88,15 +107,6 @@ append_base_layout() { echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab - cd ${TEMP}/initramfs-base-temp/dev - # TODO: this will fail as non-root - mknod -m 660 console c 5 1 || gen_die "failed to mknod" - mknod -m 660 null c 1 3 || gen_die "failed to mknod" - mknod -m 660 zero c 1 5 || gen_die "failed to mknod" - mknod -m 600 tty0 c 4 0 || gen_die "failed to mknod" - mknod -m 600 tty1 c 4 1 || gen_die "failed to mknod" - mknod -m 600 ttyS0 c 4 64 || gen_die "failed to mknod" - date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id @@ -829,9 +839,7 @@ create_initramfs() { # Create empty cpio CPIO="${TMPDIR}/initramfs-${KV}" - echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ - || gen_die "Could not create empty cpio at ${CPIO}" - + append_data 'devices' # WARNING, must be first! append_data 'base_layout' append_data 'auxilary' "${BUSYBOX}" append_data 'busybox' "${BUSYBOX}" @@ -880,18 +888,26 @@ create_initramfs() { fi # Finalize cpio by removing duplicate files - print_info 1 " >> Finalizing cpio..." - local TDIR="${TEMP}/initramfs-final" - mkdir -p "${TDIR}" - cd "${TDIR}" - - cpio --quiet -i -F "${CPIO}" 2> /dev/null \ - || gen_die "extracting cpio for finalization" - find . -print | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ - || gen_die "recompressing cpio" + # 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 ]]; then + print_info 1 " >> Deduping cpio..." + local TDIR="${TEMP}/initramfs-final" + mkdir -p "${TDIR}" + cd "${TDIR}" + + cpio --quiet -i -F "${CPIO}" 2> /dev/null \ + || gen_die "extracting cpio for dedupe" + find . -print | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ + || gen_die "rebuilding cpio for dedupe" + cd "${TEMP}" + rm -rf "${TDIR}" + else + print_info 1 " >> Cannot deduping cpio contents without root; skipping" + fi cd "${TEMP}" - rm -r "${TDIR}" if isTrue "${INTEGRATED_INITRAMFS}" then @@ -998,6 +1014,7 @@ create_initramfs() { if [ -n "${compression}" ]; then print_info 1 " >> Compressing cpio data (${compress_ext})..." + print_info 5 " >> Compression command (${compress_cmd} $CPIO)..." ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed" mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed" else