diff options
author | Harald Hoyer <harald@redhat.com> | 2013-08-15 10:44:20 +0200 |
---|---|---|
committer | Harald Hoyer <harald@redhat.com> | 2013-08-15 10:44:20 +0200 |
commit | 69f7ed96109095c8d3c39c1f741598119b602936 (patch) | |
tree | 4352bca2e91f6c6c9887de0e0eb241f631934b45 | |
parent | 67b4a9ea173b78fa5ce6be471891a433e629e097 (diff) | |
download | dracut-69f7ed96109095c8d3c39c1f741598119b602936.tar.gz dracut-69f7ed96109095c8d3c39c1f741598119b602936.tar.bz2 dracut-69f7ed96109095c8d3c39c1f741598119b602936.zip |
Create initramfs without using udevadm
This enables building a hostonly image, without the udev database
populated.
-rwxr-xr-x | dracut-functions.sh | 70 | ||||
-rwxr-xr-x | dracut.sh | 4 | ||||
-rwxr-xr-x | modules.d/90crypt/module-setup.sh | 13 | ||||
-rwxr-xr-x | modules.d/90dmraid/module-setup.sh | 33 | ||||
-rwxr-xr-x | modules.d/90lvm/module-setup.sh | 19 |
5 files changed, 63 insertions, 76 deletions
diff --git a/dracut-functions.sh b/dracut-functions.sh index 7fab2b88..9a12eb45 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -260,22 +260,6 @@ else } fi -get_persistent_dev() { - local i _tmp _dev - - _dev=$(udevadm info --query=name --name="$1" 2>/dev/null) - [ -z "$_dev" ] && return - - for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do - [[ $i == /dev/mapper/mpath* ]] && continue - _tmp=$(udevadm info --query=name --name="$i" 2>/dev/null) - if [ "$_tmp" = "$_dev" ]; then - printf -- "%s" "$i" - return - fi - done -} - # get_fs_env <device> # Get and set the ID_FS_TYPE variable from udev for a device. # Example: @@ -287,33 +271,16 @@ get_fs_env() { [[ $1 ]] || return unset ID_FS_TYPE - if ID_FS_TYPE=$(udevadm info --query=env --name="$1" \ - | { while read line; do - [[ "$line" == DEVPATH\=* ]] && found=1; - if [[ "$line" == ID_FS_TYPE\=* ]]; then - printf "%s" "${line#ID_FS_TYPE=}"; - exit 0; - fi - done; [[ $found ]] && exit 0; exit 1; }) ; then - if [[ $ID_FS_TYPE ]]; then - printf "%s" "$ID_FS_TYPE" - return 0 - fi - fi - - # Fallback, if we don't have udev information - if find_binary blkid >/dev/null; then - ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \ - | while read line; do - if [[ "$line" == TYPE\=* ]]; then - printf "%s" "${line#TYPE=}"; - exit 0; - fi - done) - if [[ $ID_FS_TYPE ]]; then - printf "%s" "$ID_FS_TYPE" - return 0 - fi + ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \ + | while read line; do + if [[ "$line" == TYPE\=* ]]; then + printf "%s" "${line#TYPE=}"; + exit 0; + fi + done) + if [[ $ID_FS_TYPE ]]; then + printf "%s" "$ID_FS_TYPE" + return 0 fi return 1 } @@ -329,6 +296,23 @@ get_maj_min() { printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" } +# get a persistent path from a device +get_persistent_dev() { + local i _tmp _dev + + _dev=$(get_maj_min "$1") + [ -z "$_dev" ] && return + + for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do + [[ $i == /dev/mapper/mpath* ]] && continue + _tmp=$(get_maj_min "$i") + if [ "$_tmp" = "$_dev" ]; then + printf -- "%s" "$i" + return + fi + done +} + # find_block_device <mountpoint> # Prints the major and minor number of the block device # for a given mountpoint. @@ -828,10 +828,6 @@ if [[ $hostonly ]]; then unset hostonly fi done - if ! [[ -d /run/udev/data ]]; then - dwarning "Turning off host-only mode: udev database not found!" - unset hostonly - fi fi declare -A host_fs_types diff --git a/modules.d/90crypt/module-setup.sh b/modules.d/90crypt/module-setup.sh index 1e87559f..bb014b98 100755 --- a/modules.d/90crypt/module-setup.sh +++ b/modules.d/90crypt/module-setup.sh @@ -29,19 +29,18 @@ installkernel() { install() { check_crypt() { - local dev=$1 fs=$2 + local dev=$1 fs=$2 UUID [[ $fs = "crypto_LUKS" ]] || return 1 - ID_FS_UUID=$(udevadm info --query=property --name=$dev \ + UUID=$(blkid -u crypto -o export $dev \ | while read line; do - [[ ${line#ID_FS_UUID} = $line ]] && continue - eval "$line" - echo $ID_FS_UUID + [[ ${line#UUID} = $line ]] && continue + printf "%s" "${line#UUID=}" break done) - [[ ${ID_FS_UUID} ]] || return 1 + [[ ${UUID} ]] || return 1 if ! [[ $kernel_only ]]; then - echo " rd.luks.uuid=luks-${ID_FS_UUID} " >> "${initdir}/etc/cmdline.d/90crypt.conf" + echo " rd.luks.uuid=luks-${UUID} " >> "${initdir}/etc/cmdline.d/90crypt.conf" fi return 0 } diff --git a/modules.d/90dmraid/module-setup.sh b/modules.d/90dmraid/module-setup.sh index cea7bd87..87465d93 100755 --- a/modules.d/90dmraid/module-setup.sh +++ b/modules.d/90dmraid/module-setup.sh @@ -27,25 +27,26 @@ install() { local _i check_dmraid() { - local dev=$1 fs=$2 holder DEVPATH DM_NAME + local dev=$1 fs=$2 holder DEVPATH DM_NAME majmin [[ "$fs" != *_raid_member ]] && return 1 - DEVPATH=$(udevadm info --query=property --name=$dev \ - | while read line; do - [[ ${line#DEVPATH} = $line ]] && continue - eval "$line" - echo $DEVPATH - break - done) - for holder in /sys/$DEVPATH/holders/*; do - [[ -e $holder ]] || continue - DM_NAME=$(udevadm info --query=property --path=$holder \ - | while read line; do - [[ ${line#DM_NAME} = $line ]] && continue - eval "$line" - echo $DM_NAME + + majmin=$(get_maj_min $dev) + DEVPATH=$( + for i in /sys/block/*; do + [[ -e "$i/dev" ]] || continue + if [[ $a == $(<"$i/dev") ]]; then + printf "%s" "$i" break - done) + fi + done + ) + + for holder in "$DEVPATH"/holders/*; do + [[ -e "$holder" ]] || continue + dev="/dev/${holder##*/}" + DM_NAME="$(/usr/sbin/dmsetup info -c --noheadings -o name "$dev" 2>/dev/null)" + [[ ${DM_NAME} ]] && break done [[ ${DM_NAME} ]] || return 1 diff --git a/modules.d/90lvm/module-setup.sh b/modules.d/90lvm/module-setup.sh index 00eb66dc..4b774c9c 100755 --- a/modules.d/90lvm/module-setup.sh +++ b/modules.d/90lvm/module-setup.sh @@ -29,15 +29,12 @@ install() { inst lvm check_lvm() { - local DM_VG_NAME DM_LV_NAME DM_UDEV_DISABLE_DISK_RULES_FLAG + local DM_VG_NAME DM_LV_NAME - eval $(udevadm info --query=property --name=$1 | egrep '(DM_VG_NAME|DM_LV_NAME|DM_UDEV_DISABLE_DISK_RULES_FLAG)=') - [[ "$DM_UDEV_DISABLE_DISK_RULES_FLAG" = "1" ]] && return 1 + eval $(/usr/sbin/dmsetup splitname --nameprefixes --noheadings --rows $1 2>/dev/null) [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1 if ! [[ " ${_activated[*]} " == *\ ${DM_VG_NAME}/${DM_LV_NAME}\ * ]]; then - if ! [[ $kernel_only ]]; then - echo " rd.lvm.lv=${DM_VG_NAME}/${DM_LV_NAME} " >> "${initdir}/etc/cmdline.d/90lvm.conf" - fi + echo " rd.lvm.lv=${DM_VG_NAME}/${DM_LV_NAME} " >> "${initdir}/etc/cmdline.d/90lvm.conf" push _activated "${DM_VG_NAME}/${DM_LV_NAME}" fi if ! [[ $_needthin ]]; then @@ -61,6 +58,16 @@ install() { fi fi + if ! [[ -e ${initdir}/etc/lvm/lvm.conf ]]; then + mkdir -p "${initdir}/etc/lvm" + { + echo 'global {' + echo 'locking_type = 4' + echo 'use_lvmetad = 0' + echo '}' + } > "${initdir}/etc/lvm/lvm.conf" + fi + inst_rules 11-dm-lvm.rules # Gentoo ebuild for LVM2 prior to 2.02.63-r1 doesn't install above rules # files, but provides the one below: |