From 2f2fdcb58f3a1f7ad13f9506041c8a075c7fc855 Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 25 Jan 2013 01:54:18 +0900 Subject: [PATCH 1/9] tar refuses to extract into a non-existent directory This helps if trying to use a new directory as the temporary directory. --- gen_determineargs.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gen_determineargs.sh b/gen_determineargs.sh index ac0a43a..f8448e6 100755 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -4,6 +4,7 @@ get_KV() { if [ "${KERNEL_SOURCES}" = '0' -a -e "${KERNCACHE}" ] then + mkdir -p ${TEMP} /bin/tar -xj -C ${TEMP} -f ${KERNCACHE} kerncache.config if [ -e ${TEMP}/kerncache.config ] then From 90a394350dc92c18628441c73760a9717ed5d8ba Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 25 Jan 2013 01:54:41 +0900 Subject: [PATCH 2/9] LVM has read-only files that would prompt for deletion This only happens when testing as a non-root user, but even so, it doesn't hurt to make this less annoying. --- gen_initramfs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index bd22bfd..ed49e01 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -273,7 +273,7 @@ append_iscsi(){ append_lvm(){ if [ -d "${TEMP}/initramfs-lvm-temp" ] then - rm -r "${TEMP}/initramfs-lvm-temp/" + rm -rf "${TEMP}/initramfs-lvm-temp/" fi cd ${TEMP} mkdir -p "${TEMP}/initramfs-lvm-temp"/{bin,sbin} @@ -305,7 +305,7 @@ append_lvm(){ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ || gen_die "compressing lvm cpio" cd "${TEMP}" - rm -r "${TEMP}/initramfs-lvm-temp/" + rm -rf "${TEMP}/initramfs-lvm-temp/" } append_mdadm(){ From a8de812595b33018edb4a20e5130569340f77228 Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 25 Jan 2013 02:26:59 +0900 Subject: [PATCH 3/9] NO_KERNEL_SOURCES left behind This looks like a leftover from a141d71531669dc888911c9141fd98ade753d200. All occurrences of NO_KERNEL_SOURCES should have been replaced by the negated KERNEL_SOURCES. Though probably isTrue should be used for all boolean options, to avoid confusion when setting them in the config file (some of them should be set to 0 or 1, while others support yes/no/0/1/true/false). --- gen_package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen_package.sh b/gen_package.sh index 1970a85..9f88278 100755 --- a/gen_package.sh +++ b/gen_package.sh @@ -155,7 +155,7 @@ gen_kerncache_extract_config() gen_kerncache_is_valid() { KERNCACHE_IS_VALID=0 - if [ "${NO_KERNEL_SOURCES}" = '1' ] + if [ "${KERNEL_SOURCES}" = '0' ] then BUILD_KERNEL=0 From a7d7711cb552ce47f4b9d91a43b1867b432569d7 Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 25 Jan 2013 02:41:52 +0900 Subject: [PATCH 4/9] Fix a typo LCV -> LOV --- gen_determineargs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gen_determineargs.sh b/gen_determineargs.sh index f8448e6..aa885c0 100755 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -60,8 +60,8 @@ get_KV() { KV=${VER}.${PAT}.${SUB}${EXV}${LOV} else determine_config_file - LCV=`grep ^CONFIG_LOCALVERSION= "${KERNEL_CONFIG}" | sed -r -e "s/.*=\"(.*)\"/\1/"` - KV=${VER}.${PAT}.${SUB}${EXV}${LCV} + LOV=`grep ^CONFIG_LOCALVERSION= "${KERNEL_CONFIG}" | sed -r -e "s/.*=\"(.*)\"/\1/"` + KV=${VER}.${PAT}.${SUB}${EXV}${LOV} fi fi } From 037070b547c5e0de162600b3733232760c36c005 Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 25 Jan 2013 02:46:06 +0900 Subject: [PATCH 5/9] Fix the kerncache parsing of CONFIG_LOCALVERSION A couple of problems here. 1. CONFIG_LOCALVERSION was never added the kerncache.config. 2. Parsing of CONFIG_LOCALVERSION expects kernel .config style syntax. For this point I opted for the extra space, to make the kerncache.config syntax consistent. There is no good reason to even keep the CONFIG_LOCALVERSION name. --- gen_determineargs.sh | 2 +- gen_package.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gen_determineargs.sh b/gen_determineargs.sh index aa885c0..dea0d0f 100755 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -12,7 +12,7 @@ get_KV() { PAT=`grep ^PATCHLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` SUB=`grep ^SUBLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` EXV=`grep ^EXTRAVERSION\ \= ${TEMP}/kerncache.config | sed -e "s/EXTRAVERSION =//" -e "s/ //g"` - LOV=`grep ^CONFIG_LOCALVERSION\= ${TEMP}/kerncache.config | sed -e "s/CONFIG_LOCALVERSION=\"\(.*\)\"/\1/"` + LOV=`grep ^CONFIG_LOCALVERSION\ \= ${TEMP}/kerncache.config | sed -e "s/CONFIG_LOCALVERSION =//" -e "s/ //g"` KV=${VER}.${PAT}.${SUB}${EXV}${LOV} else gen_die "Could not find kerncache.config in the kernel cache! Exiting." diff --git a/gen_package.sh b/gen_package.sh index 9f88278..fc77f9c 100755 --- a/gen_package.sh +++ b/gen_package.sh @@ -95,6 +95,7 @@ gen_kerncache() echo "PATCHLEVEL = ${PAT}" >> "${TEMP}/kerncache/kerncache.config" echo "SUBLEVEL = ${SUB}" >> "${TEMP}/kerncache/kerncache.config" echo "EXTRAVERSION = ${EXV}" >> "${TEMP}/kerncache/kerncache.config" + echo "CONFIG_LOCALVERSION = ${LOV}" >> "${TEMP}/kerncache/kerncache.config" mkdir -p "${TEMP}/kerncache/lib/modules/" From 65b63acb914c0045fefabfaea3804e7d150db08b Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 25 Jan 2013 04:18:58 +0900 Subject: [PATCH 6/9] Trying to build a binary package, so leave the system alone Trying to build everything (and package it in a pbin) as a non-root user, so leave the filesystem alone. --- gen_package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen_package.sh b/gen_package.sh index fc77f9c..0dae3c0 100755 --- a/gen_package.sh +++ b/gen_package.sh @@ -144,7 +144,7 @@ gen_kerncache_extract_modules() gen_kerncache_extract_config() { - if [ -e "${KERNCACHE}" ] + if [ -e "${KERNCACHE}" -a "${SAVE_CONFIG}" = '1' ] then print_info 1 'Extracting kerncache config to /etc/kernels' mkdir -p /etc/kernels From b60ba28d196a11635c8a810b5ee74ba470c87b81 Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Wed, 18 Dec 2013 18:11:33 +0900 Subject: [PATCH 7/9] ldconfig -r requires "root" (chroot) privileges This would not do the right thing when running as a non-root user but anyone running this as non-root should be aware that things could break. --- gen_initramfs.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index ed49e01..1cd1acc 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -1001,8 +1001,10 @@ create_initramfs() { append_data 'overlay' fi - # keep this at the very end, generates /etc/ld.so.conf* and cache - append_data 'ld_so_conf' + if [[ $(id -u) == 0 ]]; then + # keep this at the very end, generates /etc/ld.so.conf* and cache + append_data 'ld_so_conf' + fi # Finalize cpio by removing duplicate files print_info 1 " >> Finalizing cpio..." From 00a83a5f57d01a72f83a76c17f3e38d3ae6bdb29 Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Wed, 18 Dec 2013 18:23:13 +0900 Subject: [PATCH 8/9] Also detect "fakeroot" --- gen_initramfs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 1cd1acc..3278629 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -1001,7 +1001,7 @@ create_initramfs() { append_data 'overlay' fi - if [[ $(id -u) == 0 ]]; then + if [[ $(id -u) == 0 && -z ${FAKED_MODE:-} ]]; then # keep this at the very end, generates /etc/ld.so.conf* and cache append_data 'ld_so_conf' fi From 517929fe877e9fdb22cf10e7c32c63375f7eff9f Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Fri, 27 Dec 2013 00:06:00 +0900 Subject: [PATCH 9/9] Only skip the "ldconfig -r" step, which needs root privileges Since we now have ldconfig which can run during the boot, make sure we unconditionally copy all the other configuration files (ld.so.conf and relatives), while only skipping the "cache" step. --- gen_initramfs.sh | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 3278629..a323ba2 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -690,25 +690,33 @@ append_ld_so_conf() { # but we need to generate a valid ld.so.conf. So we extract the # current CPIO archive, run ldconfig -r against it and append the # last bits. - local tmp_dir_ext="${tmp_dir}/extracted" - mkdir -p "${tmp_dir_ext}" - mkdir -p "${tmp_dir}/etc" - cd "${tmp_dir_ext}" || gen_die "cannot cd into ${tmp_dir_ext}" - cpio -id --quiet < "${CPIO}" || gen_die "cannot re-extract ${CPIO}" - - cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" - ldconfig -r "${tmp_dir_ext}" || \ - gen_die "cannot run ldconfig on ${tmp_dir_ext}" - cp -a "${tmp_dir_ext}/etc/ld.so.cache" "${tmp_dir}/etc/ld.so.cache" || \ - gen_die "cannot copy ld.so.cache" - rm -rf "${tmp_dir_ext}" + # + # We only do this if we are "root", because "ldconfig -r" requires + # root privileges to chroot. If we are not root we don't generate the + # ld.so.cache here, but expect that ldconfig would regenerate it when the + # machine boots. + if [[ $(id -u) == 0 && -z ${FAKED_MODE:-} ]]; then + local tmp_dir_ext="${tmp_dir}/extracted" + mkdir -p "${tmp_dir_ext}" + mkdir -p "${tmp_dir}/etc" + cd "${tmp_dir_ext}" || gen_die "cannot cd into ${tmp_dir_ext}" + cpio -id --quiet < "${CPIO}" || gen_die "cannot re-extract ${CPIO}" + + cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" + ldconfig -r "${tmp_dir_ext}" || \ + gen_die "cannot run ldconfig on ${tmp_dir_ext}" + cp -a "${tmp_dir_ext}/etc/ld.so.cache" "${tmp_dir}/etc/ld.so.cache" || \ + gen_die "cannot copy ld.so.cache" + rm -rf "${tmp_dir_ext}" + + cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing ld.so.cache cpio" + cd "$(dirname "${tmp_dir}")" + rm -rf "${tmp_dir}" + fi - cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing ld.so.cache cpio" - cd "$(dirname "${tmp_dir}")" - rm -rf "${tmp_dir}" } print_list() @@ -1001,10 +1009,8 @@ create_initramfs() { append_data 'overlay' fi - if [[ $(id -u) == 0 && -z ${FAKED_MODE:-} ]]; then - # keep this at the very end, generates /etc/ld.so.conf* and cache - append_data 'ld_so_conf' - fi + # keep this at the very end, generates /etc/ld.so.conf* and cache + append_data 'ld_so_conf' # Finalize cpio by removing duplicate files print_info 1 " >> Finalizing cpio..."