genkernel: add simple udev support, include udev into initramfs if --udev

cleanup-cruft
Fabio Erculiani 12 years ago
parent cbee01a7f9
commit 3fec6febc4

@ -55,6 +55,8 @@ ROOT_LINKS='bin sbin lib lib32 lib64 boot usr opt emul'
ROOT_TREES='etc root home var' ROOT_TREES='etc root home var'
KSUFF='.ko' KSUFF='.ko'
UDEVD='/sbin/udevd'
MDEVD='/sbin/mdev'
REAL_ROOT='' REAL_ROOT=''
CONSOLE='/dev/console' CONSOLE='/dev/console'
NEW_ROOT='/newroot' NEW_ROOT='/newroot'

@ -344,6 +344,19 @@ fs_type_in_use() {
cut -d ' ' -f 3 < /proc/mounts | fgrep -q "${fs_type}" cut -d ' ' -f 3 < /proc/mounts | fgrep -q "${fs_type}"
} }
is_udev() {
[ -x "${UDEVD}" ] && [ -z "${USE_MDEV}" ] && return 0
return 1
}
is_mdev() {
if [ ! -x "${UDEVD}" ] || [ -n "${USE_MDEV}" ]
then
return 0
fi
return 1
}
mount_devfs () { mount_devfs () {
# Use devtmpfs if enabled in kernel, # Use devtmpfs if enabled in kernel,
# else tmpfs. Always run mdev just in case # else tmpfs. Always run mdev just in case
@ -736,6 +749,8 @@ startVolumes() {
fi fi
fi fi
fi fi
is_udev && udevadm settle
} }
startiscsi() { startiscsi() {

@ -22,6 +22,7 @@ fi
mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1 mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1
mount -o remount,rw / >/dev/null 2>&1 mount -o remount,rw / >/dev/null 2>&1
mount -t tmpfs -o rw,nosuid,nodev,relatime,mode=755 none /run 2>&1
# Set up symlinks # Set up symlinks
/bin/busybox --install -s /bin/busybox --install -s
@ -87,6 +88,9 @@ do
isoboot=*) isoboot=*)
ISOBOOT=${x#*=} ISOBOOT=${x#*=}
;; ;;
domdev)
USE_MDEV=1
;;
# Start Volume manager options # Start Volume manager options
dolvm) dolvm)
USE_LVM_NORMAL=1 USE_LVM_NORMAL=1
@ -327,14 +331,18 @@ mount_devfs
# Mount sysfs # Mount sysfs
mount_sysfs mount_sysfs
# Initialize mdev
good_msg 'Activating mdev'
# Serialize hotplug events
touch /dev/mdev.seq
# Setup hotplugging for firmware loading # Setup hotplugging for firmware loading
echo /sbin/mdev > /proc/sys/kernel/hotplug if is_udev
then
good_msg 'Activating udev'
echo "${UDEVD}" > /proc/sys/kernel/hotplug
echo "" > /sys/kernel/uevent_helper
else
good_msg 'Activating mdev'
# Serialize hotplug events
touch /dev/mdev.seq
echo "${MDEVD}" > /proc/sys/kernel/hotplug
fi
# Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
if [ -z "${DO_modules}" ] if [ -z "${DO_modules}" ]
@ -357,8 +365,19 @@ else
good_msg 'Skipping module load; no modules in the ramdisk!' good_msg 'Skipping module load; no modules in the ramdisk!'
fi fi
# Ensure that device nodes are properly configured if is_udev
mdev -s || bad_msg "mdev -s failed" then
# Initialize udev
"${UDEVD}" --daemon --resolve-names=never && \
udevadm trigger --action=add && \
udevadm settle || bad_msg "udevd failed to run"
elif is_mdev
then
# Ensure that device nodes are properly configured
"${MDEVD}" -s || bad_msg "mdev -s failed"
else
bad_msg "Cannot find either udev or mdev"
fi
# Apply scan delay if specified # Apply scan delay if specified
sdelay sdelay
@ -375,7 +394,7 @@ fi
setup_btrfsctl setup_btrfsctl
# Setup md device nodes if they dont exist # Setup md device nodes if they dont exist
setup_md_device is_mdev && setup_md_device
# Scan volumes # Scan volumes
startVolumes startVolumes
@ -914,10 +933,16 @@ good_msg "Booting (initramfs)"
cd "${CHROOT}" cd "${CHROOT}"
mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null
is_udev && udevadm settle
if is_udev
then
udevadm control --exit || bad_msg "Unable to terminate udevd"
fi
# If devtmpfs is mounted, try move it to the new root # If devtmpfs is mounted, try move it to the new root
# If that fails, try to unmount all possible mounts of # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
# devtmpfs as stuff breaks otherwise for fs in /run /dev /sys /proc
for fs in /dev /sys /proc
do do
if grep -qs "$fs" /proc/mounts if grep -qs "$fs" /proc/mounts
then then

@ -247,6 +247,10 @@ INITIALIZATION
*--*[*no-*]*keymap*:: *--*[*no-*]*keymap*::
Enables or disables keymap selection at boot. Enables or disables keymap selection at boot.
*--*[*no-*]*udev*::
Adds or exclude in udev support from static binaries if they exist on
the system.
*--*[*no-*]*lvm*:: *--*[*no-*]*lvm*::
Adds or skips in LVM support from static binaries if they exist on the Adds or skips in LVM support from static binaries if they exist on the
system, or compile static LVM binaries if static ones do not exist. system, or compile static LVM binaries if static ones do not exist.

@ -86,6 +86,8 @@ longusage() {
echo " --do-keymap-auto Forces keymap selection at boot" echo " --do-keymap-auto Forces keymap selection at boot"
echo " --keymap Enables keymap selection support" echo " --keymap Enables keymap selection support"
echo " --no-keymap Disables keymap selection support" echo " --no-keymap Disables keymap selection support"
echo " --udev Include udev and use it instead of mdev"
echo " --no-udev Exclude udev and use it instead of mdev"
echo " --lvm Include LVM support" echo " --lvm Include LVM support"
echo " --no-lvm Exclude LVM support" echo " --no-lvm Exclude LVM support"
echo " --mdadm Include MDADM/MDMON support" echo " --mdadm Include MDADM/MDMON support"
@ -270,6 +272,10 @@ parse_cmdline() {
CMD_KEYMAP=`parse_optbool "$*"` CMD_KEYMAP=`parse_optbool "$*"`
print_info 2 "CMD_KEYMAP: ${CMD_KEYMAP}" print_info 2 "CMD_KEYMAP: ${CMD_KEYMAP}"
;; ;;
--udev|--no-udev)
CMD_UDEV=`parse_optbool "$*"`
print_info 2 "CMD_UDEV: ${CMD_UDEV}"
;;
--lvm|--no-lvm) --lvm|--no-lvm)
CMD_LVM=`parse_optbool "$*"` CMD_LVM=`parse_optbool "$*"`
print_info 2 "CMD_LVM: ${CMD_LVM}" print_info 2 "CMD_LVM: ${CMD_LVM}"

@ -111,6 +111,7 @@ determine_real_args() {
set_config_with_override BOOL SYMLINK CMD_SYMLINK set_config_with_override BOOL SYMLINK CMD_SYMLINK
set_config_with_override STRING INSTALL_MOD_PATH CMD_INSTALL_MOD_PATH set_config_with_override STRING INSTALL_MOD_PATH CMD_INSTALL_MOD_PATH
set_config_with_override BOOL OLDCONFIG CMD_OLDCONFIG set_config_with_override BOOL OLDCONFIG CMD_OLDCONFIG
set_config_with_override BOOL UDEV CMD_UDEV
set_config_with_override BOOL LVM CMD_LVM set_config_with_override BOOL LVM CMD_LVM
set_config_with_override BOOL DMRAID CMD_DMRAID set_config_with_override BOOL DMRAID CMD_DMRAID
set_config_with_override BOOL ISCSI CMD_ISCSI set_config_with_override BOOL ISCSI CMD_ISCSI

@ -563,6 +563,39 @@ append_gpg() {
rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
} }
append_udev() {
if [ -d "${TEMP}/initramfs-udev-temp" ]
then
rm -r "${TEMP}/initramfs-udev-temp"
fi
udev_files="
/lib/udev/rules.d/50-udev-default.rules
/lib/udev/rules.d/60-persistent-storage.rules
/lib/udev/rules.d/80-drivers.rules
/lib/udev/rules.d/99-systemd.rules
/etc/udev/udev.conf
"
for f in ${udev_files}; do
mkdir -p "${TEMP}/initramfs-udev-temp"/$(dirname "${f}") || \
gen_die "cannot create rules.d directory"
cp "${f}" "${TEMP}/initramfs-udev-temp/${f}" || \
gen_die "cannot copy ${f} from system"
done
# Copy binaries
copy_binaries "${TEMP}/initramfs-udev-temp" \
/sbin/udevd /bin/udevadm /lib/udev/scsi_id \
/lib/udev/ata_id /lib/udev/mtd_probe
cd "${TEMP}/initramfs-udev-temp/"
log_future_cpio_content
find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
|| gen_die "compressing udev cpio"
cd "${TEMP}"
rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null
}
print_list() print_list()
{ {
local x local x
@ -773,6 +806,7 @@ create_initramfs() {
|| gen_die "Could not create empty cpio at ${CPIO}" || gen_die "Could not create empty cpio at ${CPIO}"
append_data 'base_layout' append_data 'base_layout'
append_data 'udev' "${UDEV}"
append_data 'auxilary' "${BUSYBOX}" append_data 'auxilary' "${BUSYBOX}"
append_data 'busybox' "${BUSYBOX}" append_data 'busybox' "${BUSYBOX}"
isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs' isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs'

Loading…
Cancel
Save