From 77b46e6aefb509cf88ab29d316407227ffd493d8 Mon Sep 17 00:00:00 2001 From: Eric Edgar Date: Mon, 11 Jul 2005 20:02:22 +0000 Subject: [PATCH] ENHANCEMENT bug 83771. Add support for LABEL= and UUID= git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@249 67a159dc-881f-0410-a524-ba9dfbe2cb84 --- gen_cmdline.sh | 5 +++++ gen_compile.sh | 30 ++++++++++++++++++++++++++++++ gen_determineargs.sh | 9 +++++++++ gen_initramfs.sh | 25 +++++++++++++++++++++++++ gen_initrd.sh | 8 ++++++++ generic/initrd.scripts | 15 ++++++++++++++- generic/linuxrc | 36 +++++++++++++++++++++++++++++++++++- genkernel | 2 ++ genkernel.conf | 6 ++++++ 9 files changed, 134 insertions(+), 2 deletions(-) diff --git a/gen_cmdline.sh b/gen_cmdline.sh index 3d031f1..3d8f36b 100755 --- a/gen_cmdline.sh +++ b/gen_cmdline.sh @@ -71,6 +71,7 @@ longusage() { echo " --dmraid Include DMRAID support" echo " --bootloader=grub Add new kernel to GRUB configuration" echo " --linuxrc= Specifies a user created linuxrc" + echo " --disklabel Include disk label and uuid support in your initrd" echo " Internals" echo " --arch-override= Force to arch instead of autodetect" echo " --cachedir= Override the default cache location" @@ -399,6 +400,10 @@ parse_cmdline() { GENERATE_Z_IMAGE=1 print_info 2 "GENERATE_Z_IMAGE: $GENERATE_Z_IMAGE" ;; + --disklabel) + CMD_DISKLABEL=1 + print_info 2 "CMD_DISKLABEL: $CMD_DISKLABEL" + ;; all) BUILD_KERNEL=1 BUILD_MODULES=1 diff --git a/gen_compile.sh b/gen_compile.sh index b0f7b8d..d2b9f95 100644 --- a/gen_compile.sh +++ b/gen_compile.sh @@ -745,3 +745,33 @@ compile_udev() { fi } +compile_e2fsprogs() { + if [ ! -f "${BLKID_BINCACHE}" ] + then + [ ! -f "${E2FSPROGS_SRCTAR}" ] && + gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!" + cd "${TEMP}" + rm -rf "${E2FSPROGS_DIR}" + tar -zxpf "${E2FSPROGS_SRCTAR}" + [ ! -d "${E2FSPROGS_DIR}" ] && + gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid" + cd "${E2FSPROGS_DIR}" + print_info 1 'e2fsprogs: >> Configuring...' + ./configure --with-ldopts=-static >> ${DEBUGFILE} 2>&1 || + gen_die 'Configuring e2fsprogs failed!' + print_info 1 'e2fsprogs: >> Compiling...' + MAKE=${UTILS_MAKE} compile_generic "" "" + print_info 1 'blkid: >> Copying to cache...' + [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] || + gen_die 'Blkid executable does not exist!' + strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" || + gen_die 'Could not strip blkid binary!' + bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" || + gen_die 'bzip2 compression of blkid failed!' + mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" || + gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?' + + cd "${TEMP}" + rm -rf "${E2FSPROGS_DIR}" > /dev/null + fi +} diff --git a/gen_determineargs.sh b/gen_determineargs.sh index f6ce924..e2484fc 100644 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -54,6 +54,13 @@ get_KV() { fi fi + + if isTrue "${CMD_DISKLABEL}" + then + DISKLABEL=1 + else + DISKLABEL=0 + fi } determine_real_args() { @@ -176,6 +183,7 @@ determine_real_args() { DMRAID_BINCACHE=`cache_replace "${DMRAID_BINCACHE}"` UNIONFS_BINCACHE=`cache_replace "${UNIONFS_BINCACHE}"` UNIONFS_MODULES_BINCACHE=`cache_replace "${UNIONFS_MODULES_BINCACHE}"` + BLKID_BINCACHE=`cache_replace "${BLKID_BINCACHE}"` DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"` BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"` @@ -192,6 +200,7 @@ determine_real_args() { DMRAID_BINCACHE=`arch_replace "${DMRAID_BINCACHE}"` UNIONFS_BINCACHE=`arch_replace "${UNIONFS_BINCACHE}"` UNIONFS_MODULES_BINCACHE=`arch_replace "${UNIONFS_MODULES_BINCACHE}"` + BLKID_BINCACHE=`arch_replace "${BLKID_BINCACHE}"` if [ "${CMD_BOOTSPLASH}" != '' ] then diff --git a/gen_initramfs.sh b/gen_initramfs.sh index bd52559..389ee18 100644 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -99,6 +99,21 @@ create_udev_cpio(){ rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null } +create_blkid_cpio(){ + if [ -d "${TEMP}/initramfs-blkid-temp" ] + then + rm -r "${TEMP}/initramfs-blkid-temp/" + fi + cd ${TEMP} + mkdir -p "${TEMP}/initramfs-blkid-temp/bin/" + [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" || + gen_die "Could not extract blkid binary cache!"; } + chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid" + cd "${TEMP}/initramfs-blkid-temp/" + find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_DIR}/cpio/initramfs-blkid-${E2FSPROGS_VER}.cpio.gz + rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null +} + create_devfs_cpio(){ if [ -d "${TEMP}/initramfs-devfs-temp" ] then @@ -419,6 +434,10 @@ merge_initramfs_cpio_archives(){ then MERGE_LIST="${MERGE_LIST} initramfs-udev-${UDEV_VER}.cpio.gz" fi + if [ "${DISKLABEL}" -eq '1' -a -e ${CACHE_DIR}/cpio/initramfs-blkid-${E2FSPROGS_VER}.cpio.gz ] + then + MERGE_LIST="${MERGE_LIST} initramfs-blkid-${E2FSPROGS_VER}.cpio.gz" + fi if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_DIR}/cpio/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz ] then MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz" @@ -549,6 +568,12 @@ create_initramfs() { print_info 1 "initramfs: Not copying modules..." fi + if [ "${DISKLABEL}" -eq '1' ] + then + print_info 1 " >> Creating blkid cpio archive..." + create_blkid_cpio + fi + create_gensplash if [ "${INITRAMFS_OVERLAY}" != '' ] diff --git a/gen_initrd.sh b/gen_initrd.sh index 18ae940..25896a6 100644 --- a/gen_initrd.sh +++ b/gen_initrd.sh @@ -57,6 +57,14 @@ create_base_initrd_sys() { MAKEDEV std MAKEDEV console + if [ "${DISKLABEL}" -eq '1' ]; then + cp "${BLKID_BINCACHE}" "${TEMP}/initrd-temp/bin/blkid.bz2" || + gen_die 'Could not copy blkid from bincache!' + bunzip2 "${TEMP}/initrd-temp/bin/blkid.bz2" || + gen_die 'Could not uncompress blkid!' + chmod +x "${TEMP}/initrd-temp/bin/blkid" + fi + cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.bz2" || gen_die 'Could not copy busybox from bincache!' bunzip2 "${TEMP}/initrd-temp/bin/busybox.bz2" || diff --git a/generic/initrd.scripts b/generic/initrd.scripts index a060523..100648c 100644 --- a/generic/initrd.scripts +++ b/generic/initrd.scripts @@ -5,10 +5,23 @@ backup() { echo -ne "\033[0G\033[0K" } +strlen() +{ + if [ -z "$1" ] + then + echo "usage: strlen " + die + fi + eval echo "\${#${1}}" +} + parse_opt() { case "$1" in *\=*) - echo "$1" | cut -f2 -d= + local key_name="`echo "$1" | cut -f1 -d=`" + local key_len=`strlen key_name` + local value_start=$((key_len+2)) + echo "$1" | cut -c ${value_start}- ;; esac } diff --git a/generic/linuxrc b/generic/linuxrc index 7087227..859345a 100644 --- a/generic/linuxrc +++ b/generic/linuxrc @@ -256,7 +256,41 @@ while true do while [ "${got_good_root}" != '1' ] do - + case "${REAL_ROOT}" in + LABEL\=*|UUID\=*) + + ROOT_DEV="" + retval=1 + + if [ "${retval}" -ne '0' ]; then + ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null` + retval=$? + fi + + if [ "$retval" -ne '0' ]; then + ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null` + retval=$? + fi + + if [ "${retval}" -ne '0' ]; then + ROOT_DEV=`blkid -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null` + retval=$? + fi + + if [ "${retval}" -eq '0' ] && [ -n "${ROOT_DEV}" ]; then + good_msg "Detected real_root=${ROOT_DEV}" + REAL_ROOT="${ROOT_DEV}" + else + bad_msg "Could not find root block device: ${REAL_ROOT}" + echo ' Please specify a device to boot, or "shell" for a shell...' + echo -n 'boot() :: ' + read REAL_ROOT + got_good_root=0 + continue + fi + ;; + esac + if [ "${REAL_ROOT}" = 'shell' ] then run_shell diff --git a/genkernel b/genkernel index 62a8914..64ee5b5 100755 --- a/genkernel +++ b/genkernel @@ -267,6 +267,8 @@ then compile_modutils fi fi + + [ "${DISKLABEL}" -eq '1' ] && compile_e2fsprogs if [ "${PAT}" -gt '4' -a "${UDEV}" -eq '1' ] then diff --git a/genkernel.conf b/genkernel.conf index 8955c40..37891cd 100755 --- a/genkernel.conf +++ b/genkernel.conf @@ -115,3 +115,9 @@ UNIONFS_DIR="unionfs-${UNIONFS_VER}" UNIONFS_SRCTAR="${GK_SHARE}/pkg/unionfs-${UNIONFS_VER}.tar.gz" UNIONFS_BINCACHE="%%CACHE%%/unionfs-${UNIONFS_VER}-tools-%%ARCH%%.tar.bz2" UNIONFS_MODULES_BINCACHE="%%CACHE%%/unionfs-${UNIONFS_VER}-modules-%%KV%%-%%ARCH%%.tar.bz2" + +E2FSPROGS_VER="1.38" +E2FSPROGS_DIR="e2fsprogs-${E2FSPROGS_VER}" +E2FSPROGS_SRCTAR="${GK_SHARE}/pkg/e2fsprogs-${E2FSPROGS_VER}.tar.gz" +BLKID_BINCACHE="%%CACHE%%/blkid-${E2FSPROGS_VER}-%%ARCH%%.bz2" + -- 2.26.2