summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-03 20:14:42 +0200
committerDave Reisner <dreisner@archlinux.org>2012-05-12 15:30:32 +0200
commit41a290ce22844ac6b1d021b04df5f7659547cc56 (patch)
treefb39185340dec265d0cc7f603718a3fa779f8521
parentb317b01465d81b2adadd5f8d964e59622a6a7a32 (diff)
downloadmkinitcpio-41a290ce22844ac6b1d021b04df5f7659547cc56.tar.gz
mkinitcpio-41a290ce22844ac6b1d021b04df5f7659547cc56.tar.xz
mkinitcpio: remove --basedir option
This option is just a bad idea. Initramfs creation is too important to get wrong, and running it from outside the root FS has too many gotchas, the worst of them being: - where do you pull hooks from? - how do you resolve binary dependencies within the root? In general, dealing with the extra luggage of the base directory makes the codebase more complicated than it needs to be (see all the '_' prefixed functions which are called from add functions). In favor of simplifying the code, and making it more maintainable, kill this off and force the sane option of chroot'ing into an install if the need arises. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r--bash-completion11
-rw-r--r--functions48
-rw-r--r--install/autodetect4
-rw-r--r--install/consolefont8
-rw-r--r--install/fsck4
-rw-r--r--install/keymap4
-rwxr-xr-xmkinitcpio40
-rw-r--r--mkinitcpio.8.txt14
8 files changed, 45 insertions, 88 deletions
diff --git a/bash-completion b/bash-completion
index 9732747..c37484c 100644
--- a/bash-completion
+++ b/bash-completion
@@ -54,20 +54,19 @@ _files_from_dirs() {
_mkinitcpio() {
local action cur prev opts
- opts=(-A --add -b --basedir -c --config -g --generate -H --hookhelp
- -h --help -k --kernel -L --listhooks -M --automods -n --nocolor
- -p --preset -S --skiphooks -s --save -t --builddir -v --verbose
- -z --compress)
+ opts=(-A --add -c --config -g --generate -H --hookhelp -h --help -k --kernel
+ -L --listhooks -M --automods -n --nocolor -p --preset -S --skiphooks
+ -s --save -t --builddir -v --verbose -z --compress)
_get_comp_words_by_ref cur prev
case $prev in
-[cg]|--config|--generate)
_filedir ;;
+ -t|--builddir)
+ _filedir -d ;;
-k|--kernel)
_find_kernel_versions ;;
- -[bt]|--basedir|--builddir)
- _filedir -d ;;
-p|--preset)
COMPREPLY=($(compgen -W "$(_files_from_dirs -s .preset /etc/mkinitcpio.d)" -- "$cur")) ;;
-[AHS]|--add|--hookhelp|--skiphooks)
diff --git a/functions b/functions
index 0fec85b..2576180 100644
--- a/functions
+++ b/functions
@@ -192,26 +192,6 @@ in_array() {
return 1 # Not Found
}
-pathlookup() {
- # a basedir aware 'type -P' (or which) for executables
- # $1: binary to find
-
- local path=
- local -a paths=
-
- IFS=: read -r -a paths <<< "$PATH"
-
- for path in "${paths[@]}"; do
- [[ ${path:0:1} = [.~] ]] && continue
- if [[ -x $BASEDIR$path/$1 ]]; then
- printf '%s' "$BASEDIR$path/$1"
- return 0
- fi
- done
-
- return 1
-}
-
_add_file() {
# add a file to $BUILDROOT
# $1: pathname on initcpio
@@ -266,7 +246,7 @@ auto_modules() {
IFS=$'\n' read -rd '' -a mods < \
<(find /sys/devices -name modalias -exec sort -u {} + |
# delimit each input by a newline, expanded in place
- xargs -d $'\n' modprobe -qd "$BASEDIR" -aRS "$KERNELVERSION" |
+ xargs -d $'\n' modprobe -qaRS "$KERNELVERSION" |
sort -u)
printf "%s\n" "${mods[@]//-/_}"
@@ -333,12 +313,12 @@ add_module() {
done
;;
firmware)
- if [[ -e "$BASEDIR/usr/lib/firmware/$value" ]]; then
- _add_file "/usr/lib/firmware/$value" "$BASEDIR/usr/lib/firmware/$value" 644
+ if [[ -e /usr/lib/firmware/$value ]]; then
+ _add_file "/usr/lib/firmware/$value" "/usr/lib/firmware/$value" 644
fi
;;
esac
- done < <(modinfo -b "$BASEDIR" -k "$KERNELVERSION" -0 "$module" 2>/dev/null)
+ done < <(modinfo -k "$KERNELVERSION" -0 "$module" 2>/dev/null)
if [[ -z $path ]]; then
(( ign_errors )) && return 0
@@ -410,7 +390,7 @@ add_file() {
# determine source and destination
local src= dest=${2:-$1} mode=
- src=$BASEDIR$1
+ src=$1
[[ -f "$src" ]] || { error "file not found: \`%s'" "$src"; return 1; }
@@ -420,7 +400,7 @@ add_file() {
return 1
fi
- _add_file "${dest#$BASEDIR}" "$src" "$mode"
+ _add_file "$dest" "$src" "$mode"
}
add_binary() {
@@ -433,9 +413,9 @@ add_binary() {
local line= regex= binary= dest= mode= sodep= resolved= dirname=
if [[ ${1:0:1} != '/' ]]; then
- binary=$(pathlookup "$1")
+ binary=$(type -P "$1")
else
- binary=$BASEDIR$1
+ binary=$1
fi
[[ -f "$binary" ]] || { error "file not found: \`%s'" "$1"; return 1; }
@@ -444,7 +424,7 @@ add_binary() {
mode=$(stat -c %a "$binary")
# always add the binary itself
- _add_file "${dest#$BASEDIR}" "$binary" "$mode"
+ _add_file "$dest" "$binary" "$mode"
lddout=$(ldd "$binary" 2>/dev/null) || return 0 # not a binary!
@@ -455,13 +435,13 @@ add_binary() {
if [[ -f $sodep && ! -e $BUILDROOT$sodep ]]; then
if [[ ! -L $sodep ]]; then
- _add_file "$sodep" "$BASEDIR$sodep" "$(stat -c %a "$sodep")"
+ _add_file "$sodep" "$sodep" "$(stat -c %a "$sodep")"
else
- resolved=$(readlink -e "$BASEDIR$sodep")
+ resolved=$(readlink -e "$sodep")
dirname=${resolved%/*}
- _add_dir "${dirname#$BASEDIR}" 755
- _add_symlink "$sodep" "${resolved#$BASEDIR}"
- _add_file "${resolved#$BASEDIR}" "$resolved" 755
+ _add_dir "$dirname" 755
+ _add_symlink "$sodep" "$resolved"
+ _add_file "$resolved" "$resolved" 755
fi
fi
done <<< "$lddout"
diff --git a/install/autodetect b/install/autodetect
index 4ed7ccf..1daa429 100644
--- a/install/autodetect
+++ b/install/autodetect
@@ -25,7 +25,7 @@ build() {
auto_modules >"$MODULE_FILE"
# detect filesystem for root
- if rootfstype=$(findmnt -uno fstype "${BASEDIR:-/}"); then
+ if rootfstype=$(findmnt -uno fstype '/'); then
add_if_avail "$rootfstype"
else
error "failed to detect root filesystem"
@@ -33,7 +33,7 @@ build() {
fi
# detect filesystem for separate /usr
- if usrfstype=$(findmnt -snero fstype --tab-file "$BASEDIR/etc/fstab" /usr); then
+ if usrfstype=$(findmnt -snero fstype --tab-file '/etc/fstab' /usr); then
add_if_avail "$usrfstype"
fi
diff --git a/install/consolefont b/install/consolefont
index 2d2d8ea..cefbc45 100644
--- a/install/consolefont
+++ b/install/consolefont
@@ -5,20 +5,20 @@ build() {
# subshell to avoid namespace pollution
(
- for cfg in etc/{rc,vconsole}.conf; do
- [[ -s $BASEDIR/$cfg ]] && . "$BASEDIR/$cfg"
+ for cfg in /etc/{rc,vconsole}.conf; do
+ [[ -s $cfg ]] && . "$cfg"
done
[[ $FONT ]] && CONSOLEFONT=$FONT
if [[ $CONSOLEFONT ]]; then
- for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do
+ for file in "/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do
if [[ -e $file ]]; then
[[ $file =~ \.(psfu?)(\.gz)?$ ]] && ext=${BASH_REMATCH[1]}
if [[ $file = *.gz ]]; then
gzip -cd "$file" > "$BUILDROOT/consolefont.$ext"
else
- add_file "${file#$BASEDIR}" "/consolefont.$ext"
+ add_file "$file" "/consolefont.$ext"
fi
exit 0
fi
diff --git a/install/fsck b/install/fsck
index baf1c3d..e8b5ea3 100644
--- a/install/fsck
+++ b/install/fsck
@@ -21,9 +21,9 @@ build() {
add_fsck $usrfstype && (( ++added ))
fi
else
- for fsck in "$BASEDIR"/{usr/,}{s,}bin/fsck.*; do
+ for fsck in /{usr/,}{s,}bin/fsck.*; do
[[ -f $fsck ]] || continue
- add_binary "${fsck#$BASEDIR}" && (( ++added ))
+ add_binary "$fsck" && (( ++added ))
done
fi
diff --git a/install/keymap b/install/keymap
index fe5e459..1dc25aa 100644
--- a/install/keymap
+++ b/install/keymap
@@ -7,8 +7,8 @@ build() {
l=$LANG
unset LANG
- for cfg in etc/{rc,vconsole,locale}.conf; do
- [[ -s $BASEDIR/$cfg ]] && . "$BASEDIR/$cfg"
+ for cfg in /etc/{rc,vconsole,locale}.conf; do
+ [[ -s $cfg ]] && . "$cfg"
done
[[ $LANG ]] && LOCALE=$LANG
diff --git a/mkinitcpio b/mkinitcpio
index 084dff7..1c92a27 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -22,7 +22,7 @@ INSTDIR=(install /usr/lib/initcpio/install /lib/initcpio/install)
PRESETDIR=mkinitcpio.d
COMPRESSION=gzip
-declare BASEDIR= MODULE_FILE= GENIMG= PRESET= COMPRESSION_OPTIONS= BUILDROOT=
+declare MODULE_FILE= GENIMG= PRESET= COMPRESSION_OPTIONS= BUILDROOT=
declare NC= BOLD= BLUE= GREEN= RED= YELLOW=
declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1
declare -a SKIPHOOKS ADDED_MODULES MODPATHS
@@ -42,7 +42,6 @@ usage: ${0##*/} [options]
Options:
-A, --add <hooks> Add specified hooks, comma separated, to image
- -b, --basedir <dir> Use alternate base directory. (default: /)
-c, --config <config> Use alternate config file. (default: /etc/mkinitcpio.conf)
-g, --generate <path> Generate cpio image and write to specified path
-H, --hookhelp <hookname> Display help for given hook and exit
@@ -87,18 +86,17 @@ get_kernver() {
return 0
fi
- if [[ ! -e $BASEDIR$kernel ]]; then
- error "Specified kernel image does not exist: \`%s'" "$BASEDIR$kernel"
+ if [[ ! -e $kernel ]]; then
+ error "Specified kernel image does not exist: \`%s'" "$kernel"
return 1
fi
- read _ kernver < <(file -Lb "$BASEDIR$kernel" | grep -o 'version [^ ]\+')
- if [[ $kernver && -e $BASEDIR/lib/modules/$kernver ]]; then
+ read _ kernver < <(file -Lb "$kernel" | grep -o 'version [^ ]\+')
+ if [[ $kernver && -e /lib/modules/$kernver ]]; then
echo "$kernver"
return 0
fi
- [[ ${optkver:0:1} == / ]] && optkver=$BASEDIR$optkver
error "invalid kernel specifier: \`%s'" "$optkver"
return 1
@@ -116,9 +114,9 @@ compute_hookset() {
trap 'cleanup 130' INT
trap 'cleanup 143' TERM
-OPT_SHORT='A:b:c:g:H:hk:mnLMp:S:st:vz:'
-OPT_LONG=('add:' 'basedir:' 'config:' 'generate:' 'hookhelp:' 'help' 'kernel:' 'listhooks'
- 'automods' 'nocolor' 'preset:' 'skiphooks:' 'save' 'builddir:' 'verbose' 'compress:')
+OPT_SHORT='A:c:g:H:hk:mnLMp:S:st:vz:'
+OPT_LONG=('add:' 'config:' 'generate:' 'hookhelp:' 'help' 'kernel:' 'listhooks' 'automods'
+ 'nocolor' 'preset:' 'skiphooks:' 'save' 'builddir:' 'verbose' 'compress:')
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
exit 1
@@ -141,9 +139,6 @@ while :; do
optkver=$1 ;;
-s|--save)
SAVELIST=1 ;;
- -b|--basedir)
- shift
- BASEDIR=$1 ;;
-g|--generate)
shift
GENIMG=$1 ;;
@@ -224,16 +219,6 @@ readonly NC BOLD BLUE GREEN RED YELLOW
[[ -e /proc/self/mountinfo ]] || die "/proc must be mounted!"
[[ -e /dev/fd ]] || die "/dev must be mounted!"
-if [[ $BASEDIR ]]; then
- # resolve the path. it might be a relative path and/or contain symlinks
- if ! pushd "$BASEDIR" &>/dev/null; then
- die "base directory does not exist or is not a directory: \`%s'" "$BASEDIR"
- fi
- BASEDIR=$(pwd -P)
- BASEDIR=${BASEDIR%/}
- popd &>/dev/null
-fi
-
KERNELVERSION=$(get_kernver "$optkver") || cleanup 1
if [[ $TMPDIR ]]; then
@@ -261,7 +246,6 @@ if [[ $PRESET ]]; then
if [[ -f "$PRESET" ]]; then
# Use -b, -m and -v options specified earlier
declare -a preset_mkopts preset_cmd
- [[ $BASEDIR ]] && preset_mkopts+=(-b "$BASEDIR")
(( QUIET )) || preset_mkopts+=(-v)
# Build all images
. "$PRESET"
@@ -279,7 +263,7 @@ if [[ $PRESET ]]; then
preset_config=${p}_config
if [[ ${!preset_config:-$ALL_config} ]]; then
- preset_cmd+=(-c "$BASEDIR${!preset_config:-$ALL_config}")
+ preset_cmd+=(-c "${!preset_config:-$ALL_config}")
else
warning "No configuration file specified. Skipping image \`%s'" "$p"
continue
@@ -287,7 +271,7 @@ if [[ $PRESET ]]; then
preset_image=${p}_image
if [[ ${!preset_image} ]]; then
- preset_cmd+=(-g "$BASEDIR${!preset_image}")
+ preset_cmd+=(-g "${!preset_image}")
else
warning "No image file specified. Skipping image \`%s'" "$p"
continue
@@ -327,7 +311,7 @@ if (( ${#hooks[*]} == 0 )); then
die "Invalid config: No hooks found"
fi
-MODULEDIR=$BASEDIR/lib/modules/$KERNELVERSION/
+MODULEDIR=/lib/modules/$KERNELVERSION/
if [[ ! -d $MODULEDIR ]]; then
die "'$MODULEDIR' is not a valid kernel module directory"
fi
@@ -416,7 +400,7 @@ if (( ${#ADDED_MODULES[*]} )); then
msg "Generating module dependencies"
install -m644 -t "$BUILDROOT/usr/lib/modules/$KERNELVERSION" \
- "$BASEDIR/lib/modules/$KERNELVERSION"/modules.{builtin,order}
+ "/lib/modules/$KERNELVERSION"/modules.{builtin,order}
depmod -b "$BUILDROOT" "$KERNELVERSION"
# remove all non-binary module.* files (except devname for on-demand module loading)
diff --git a/mkinitcpio.8.txt b/mkinitcpio.8.txt
index 4b0d770..f947514 100644
--- a/mkinitcpio.8.txt
+++ b/mkinitcpio.8.txt
@@ -29,10 +29,6 @@ Options
after all other hooks from the config file. Multiple hooks should be
comma-separated. This option can be specified multiple times.
-*-b, \--basedir* 'basedir'::
- Use 'basedir' as a starting point for gathering information about the
- currently running system. Default: /.
-
*-c, \--config* 'config'::
Use 'config' file to generate the ramdisk. Default: /etc/mkinitcpio.conf
@@ -48,8 +44,7 @@ Options
*-k, \--kernel* 'kernelversion'::
Use 'kernelversion', instead of the current running kernel. This may be a
- path to a kernel image or a specific kernel version. If specified as a path to
- an image, this will always be prefixed by the 'basedir'.
+ path to a kernel image or a specific kernel version.
*-L, \--listhooks*::
List all available hooks.
@@ -124,10 +119,9 @@ Examples
*mkinitcpio -p linux*::
Create an initial ramdisk based on the 'linux' preset.
-*mkinitcpio -b /mnt -g /mnt/boot/initramfs-linux.img -k /boot/vmlinuz-linux*::
- Create an initial ramdisk for the root at /mnt, with the kernel at
- /mnt/boot/vmlinuz-linux. The resulting image will be written to
- /mnt/boot/initramfs-linux.img.
+*mkinitcpio -g /boot/initramfs-linux.img -k /boot/vmlinuz-linux*::
+ Create an initial ramdisk for the kernel at /boot/vmlinuz-linux. The
+ resulting image will be written to /boot/initramfs-linux.img.
See also
--------