Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37561597
en ru br
Репозитории ALT
D:3.0.5-alt1.1
5.1: 3.0.10-alt1
4.1: 3.0.10-alt0.M40.1
4.0: 3.0.10-alt0.M40.1
3.0: 2.9.7-alt1
www.altlinux.org/Changes

Группа :: Система/Ядро и оборудование
Пакет: mkinitrd

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

pax_global_header00006660000000000000000000000064107117460240014514gustar00rootroot0000000000000052 comment=e59e2cd68b0bc29cc7a930d4ef9e0d30ef2de552
mkinitrd-3.0.5/000075500000000000000000000000001071174602400133405ustar00rootroot00000000000000mkinitrd-3.0.5/.gear-rules000064400000000000000000000000071071174602400154040ustar00rootroot00000000000000tar: .
mkinitrd-3.0.5/init000075500000000000000000000111521071174602400142310ustar00rootroot00000000000000#!/bin/sh

echo "Loading, please wait..."

[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock
mount -t sysfs -o nodev,noexec,nosuid none /sys
mount -t proc -o nodev,noexec,nosuid none /proc

mount -t tmpfs -o size=10M,mode=0755 udev /dev
[ -e /dev/console ] || mknod /dev/console c 5 1
[ -e /dev/null ] || mknod /dev/null c 1 3
mkdir /dev/.initramfs
mkdir /dev/pts
mkdir /dev/shm

echo > /proc/sys/kernel/hotplug

BOOT=local
if [ -r /conf/initramfs.conf ]; then
. /conf/initramfs.conf
fi

. /scripts/functions

# Parse command line options
break=
init=/sbin/init
quiet=n
readonly=y
rootmnt=/root
debug=
cryptopts=${CRYPTOPTS}
panic=

for x in $(cat /proc/cmdline); do
case $x in
init=*)
init=${x#init=}
;;
root=*)
ROOT=${x#root=}
;;
rootflags=*)
ROOTFLAGS="-o ${x#rootflags=}"
;;
rootfstype=*)
ROOTFSTYPE="${x#rootfstype=}"
;;
rootdelay=*)
ROOTDELAY="${x#rootdelay=}"
;;
cryptopts=*)
cryptopts="${x#cryptopts=}"
;;
nfsroot=*)
NFSROOT="${x#nfsroot=}"
;;
ip=*)
IPOPTS="${x#ip=}"
;;
boot=*)
BOOT=${x#boot=}
;;
resume=*)
RESUME="${x#resume=}"
;;
noresume)
NORESUME=y
;;
resume2=*)
RESUME2="${x#resume2=}"
;;
noresume2)
NORESUME2=y
;;
panic=*)
panic="${x#panic=}"
;;
quiet)
quiet=y
;;
ro)
readonly=y
;;
rw)
readonly=n
;;
debug)
debug=y
exec >/tmp/initramfs.debug 2>&1
set -x
;;
debug=*)
debug=y
set -x
;;
break=*)
break=${x#break=}
;;
break)
break=premount
;;
esac
done

if [ -z "${NORESUME}" ]; then
resume=${RESUME}
fi
if [ -z "${NORESUME2}" ]; then
resume2=${RESUME2}
fi

maybe_break top

case $ROOT in
LABEL=*)
echo "ENV{ID_FS_USAGE}==\"filesystem|other\", ENV{ID_FS_LABEL}==\"${ROOT#LABEL=}\", SYMLINK+=\"root\"" > /etc/udev/rules.d/99-root.rules
ROOT="/dev/root"
;;
UUID=*)
ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
;;
/dev/nfs)
BOOT=nfs
;;
esac

case "$resume" in
LABEL=*)
echo "ENV{ID_FS_USAGE}==\"filesystem|other\", ENV{ID_FS_LABEL}==\"${resume#LABEL=}\", SYMLINK+=\"resume\"" > /etc/udev/rules.d/99-resume.rules
resume="/dev/resume"
;;
UUID=*)
resume="/dev/disk/by-uuid/${resume#UUID=}"
;;
esac

if [ -r /scripts/init-top ]; then
. /scripts/init-top
fi

[ "$quiet" != "y" ] && log_begin_msg "Starting udevd"
mkdir -p /dev/.udev/db/
udevd --daemon
mkdir -p /dev/.udev/queue/
udevtrigger --attr-match dev
udevsettle || true
[ "$quiet" != "y" ] && log_end_msg

maybe_break modules
log_begin_msg "Loading essential drivers"
load_modules
log_end_msg

maybe_break premount

[ "$quiet" != "y" ] && log_begin_msg "Finishing udevd initialization"
udevtrigger
udevsettle || true
[ "$quiet" != "y" ] && log_end_msg

run_scripts /scripts/init-premount

maybe_break mount
log_begin_msg "Mounting root file system"
. /scripts/${BOOT}
parse_numeric ${ROOT}
mountroot
log_end_msg

maybe_break bottom

[ "$quiet" != "y" ] && log_begin_msg "Stopping udevd"

# Stop udevd, we'll miss a few events while we run init, but we catch up
udevsettle
kill `cat /dev/.udev/udevd.pid`
for proc in /proc/[0-9]*; do
[ -x $proc/exe ] || continue
[ "$(readlink $proc/exe 2>/dev/null)" != /sbin/udevd ] ||
kill ${proc#/proc/}
done

# ignore any failed event because the init script will trigger again all events
nuke /dev/.udev/queue/

# Read udev config from the real filesystem if possible
if [ -e $rootmnt/etc/udev/udev.conf ]; then
. $rootmnt/etc/udev/udev.conf
elif [ -e /etc/udev/udev.conf ]; then
. /etc/udev/udev.conf
fi

# Move /dev created in initramfs to the real filesystem if this is enabled
# in the udev configuration.
if [ "$use_initramfs_dev" = 1 ]; then

# Pass udev version from initramfs to the real system.
udev_version="$(/sbin/udevd --version 2>/dev/null)"
printf '%s\n' "${udev_version:-105}" >/dev/.initramfs/udev_version

# Optionally move the real filesystem's /dev to beneath our tmpfs
if [ -z "$no_static_dev" ]; then
mkdir -m 0700 /dev/.static/
mkdir /dev/.static/dev/
mount -o bind $rootmnt/dev /dev/.static/dev
fi

# Now move it all to the real filesystem
mount -o move /dev $rootmnt/dev

# create a temporary symlink to the final /dev for other initramfs
# scripts
nuke /dev
ln -s $rootmnt/dev /dev
fi

[ "$quiet" != "y" ] && log_end_msg

run_scripts /scripts/init-bottom

while [ ! -x ${rootmnt}${init} ]; do
panic "Target filesystem doesn't have ${init}"
done

umount /sys
umount /proc

# Chain to real filesystem
maybe_break init
# If /dev was not moved to the real filesystem, unmount it
[ "$use_initramfs_dev" = 1 ] || umount -l /dev
exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console
mkinitrd-3.0.5/mkinitrd000075500000000000000000001244411071174602400151150ustar00rootroot00000000000000#!/bin/sh

# mkinitrd
#
# Written by Erik Troan <ewt@redhat.com>
#
# Contributors:
# Elliot Lee <sopwith@cuc.edu>
# Miguel de Icaza <miguel@nuclecu.unam.mx>
# Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
# Michael K. Johnson <johnsonm@redhat.com>
# Pierre Habraken <Pierre.Habraken@ujf-grenoble.fr>
# Jakub Jelinek <jj@ultra.linux.cz>
# Carlo Arenas Belon (carenas@chasqui.lared.net.pe>
# Keith Owens <kaos@ocs.com.au>
#
# Rewritten by Dmitry V. Levin <ldv@altlinux.org>
# Initramfs support and other changes by Sergey Vlasov <vsu@altlinux.org>

PROG=mkinitrd
VERSION=@VERSION@
CATCHED=

# override PATH
export PATH="/bin:/sbin:/usr/bin:/usr/sbin"

umask 077

Exit()
{
local rc=$?
[ -z "$1" ] || rc="$1"
CATCHED=1
exit $rc
}

Warning()
{
echo "$PROG: warning: $*" >&2
}

Fatal()
{
echo "$PROG: $*" >&2
Exit 1
}

verbose=
Verbose()
{
[ -n "$verbose" ] || return 0
echo "$PROG: $*"
}

debug=
Debug()
{
[ -n "$debug" ] || return 0
echo "$PROG: $*"
}

is_yes()
{
# Test syntax
if [ $# = 0 ]; then
return 2
fi

# Check value
case "$1" in
yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
# true returns zero
return 0
;;
*)
# false returns one
return 1
;;
esac
}

is_no()
{
# Test syntax
if [ $# = 0 ] ; then
return 2
fi

case "$1" in
no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
# true returns zero
return 0
;;
*)
# false returns one
return 1
;;
esac
}

WORKDIR=
IMAGE=
MNTDIR=
MNTPOINT=
IMAGESIZE=
INODES=

exit_handler()
{
local rc=$?
trap - EXIT
[ -n "$CATCHED" -o $rc -eq 0 ] ||
echo "$PROG: unhandled error, exiting..."
[ -n "$MNTPOINT" ] && umount "$MNTPOINT" >/dev/null 2>&1 ||:
[ -z "$WORKDIR" ] || rm -rf "$WORKDIR"
exit $rc
}

signal_handler()
{
echo 'Interrupted!' >&2
Exit 1
}

trap exit_handler EXIT
trap signal_handler SIGHUP SIGPIPE SIGINT SIGTERM SIGQUIT

NormalizedName()
{
echo -n "X$1" | sed -e '1s/^X//' -e 'y/-/_/'
}

MODPROBE_TYPE=
IMAGE_TYPE=
USE_COMPRESS=1
TARGET=
KERNEL=
KERNEL_MAJOR=
KERNEL_MINOR=
KERNEL_PATCH=
strict=
noscsi=
noide=
noraid=
pause=
MODULES=
EXTRA_MODULES=
MODULES_DIR=
MODULES_CONF=
HAVE_RAID=
HAVE_EVMS=
RAID_MODULES=
SCSI_MODULES=
IDE_MODULES=
FOUND_NON_PCI_IDE=
ADD_FILES=
PRELOAD_MODNAMES=
POSTLOAD_MODNAMES=
EXTRA_MODNAMES=

FIRMWARE_DIRS="/lib/firmware /usr/lib/hotplug/firmware /usr/local/lib/firmware"

LSPCI=/usr/bin/lspci

MDADM=/sbin/mdadm
[ -x "$MDADM" ] || MDADM=/usr/sbin/mdadm

MDASSEMBLE=/sbin/mdassemble

FSTAB_FILE=/etc/fstab
MDADM_CONF=/etc/mdadm.conf

BIN_SPLASH=/sbin/splash
[ -x "$BIN_SPLASH" ] && ADD_BOOTSPLASH=1 || ADD_BOOTSPLASH=

PRE_SCSI_MODNAMES="scsi_mod sd_mod"
PRE_SCSI_MODNAMES_ADDED=
IGNORE_MODNAMES="`NormalizedName "$IGNORE_MODNAMES"`"
IGNORE_MODNAMES=" $IGNORE_MODNAMES ppa imm ide_scsi usb_storage"
LOADED_MODNAMES=

PRE_EVMS_MODNAMES="dm_mod"
EVMS_ACTIVATE="/sbin/evms_activate"
EVMS_CONFIG="/etc/evms.conf"
EVMS_PLUGINS_REG="/(aix)|(bbr)|(bsd)|(disk)|(dos)|(drivelink)|(gpt)|(lvm)|(md)|(os2)|(s390)|(snapshot)[^[:space:]]*\.so"

loopDev=
loopFs=
loopFile=
uname_r=`uname -r`

ParseKernelVersion()
{
KERNEL_MAJOR="${KERNEL%%.*}"
KERNEL_MINOR="${KERNEL#*.}"
KERNEL_MINOR="${KERNEL_MINOR%%.*}"
KERNEL_PATCH="${KERNEL#*.*.}"
KERNEL_PATCH="${KERNEL_PATCH%%[^0-9]*}"

if [ -z "${KERNEL_MAJOR##*[^0-9]*}" ] \
|| [ -z "${KERNEL_MINOR##*[^0-9]*}" ] \
|| [ -z "${KERNEL_PATCH##*[^0-9]*}" ] ; then
Fatal "Invalid kernel version \"$KERNEL\""
fi
}

KernelVersionAtLeast()
{
local major="$1" && shift
local minor="$1" && shift
local patch="$1" && shift

[ "$KERNEL_MAJOR" -ge "$major" ] || return 1
[ "$KERNEL_MAJOR" -eq "$major" ] || return 0

[ "$KERNEL_MINOR" -ge "$minor" ] || return 1
[ "$KERNEL_MINOR" -eq "$minor" ] || return 0

[ "$KERNEL_PATCH" -ge "$patch" ] || return 1
return 0
}

LIBS_REG="/lib\(\|64\)/[^[:space:]]*\.so\(\.[^[:space:]]*\|\)"
AddLibs()
{
local list="$@" i
(
ldd $list | \
grep -s "${LIBS_REG}[[:space:]]" | \
sed -e "s@^.*[[:space:]]\(${LIBS_REG}\)[[:space:]].*@\1@"
for i in $list; do
echo "$i"
done
) | sort | uniq
}

AddLibsAll()
{
local list="$@" newlist
newlist=`AddLibs "$list"`
while [ "x$list" != "x$newlist" ] ; do
list="$newlist"
newlist=`AddLibs "$list"`
done
echo $list
}

LinksAndFiles()
{
local list="$@" i
for i in $list ; do
echo "$i"
readlink -f "$i"
done | sort | uniq
}

EvmsLibdir()
{
local list="$@" i
for i in $list ; do
echo "$i"
done | sed -n '\@/lib\(\|64\)/libevms@s@.*\(/lib\(\|64\)\)/libevms.*@\1@p' | head -n1
}

EVMS_FILES_ALL=
ListEvmsFilesAll()
{
local list libdir list_plug list_all
list=`AddLibs $EVMS_ACTIVATE`
libdir=`EvmsLibdir $list`
list_plug=`find $libdir/evms -name '*.so' | egrep -s "$EVMS_PLUGINS_REG"`
list=`AddLibsAll $list_plug $list`
EVMS_FILES_ALL=`LinksAndFiles $list $EVMS_CONFIG`
}

InList()
{
local value="$1" list="$2" i
for i in $list; do
[ "$i" != "$value" ] || return 0
done
return 1
}

ModuleAlreadyLoaded()
{
local name="$1" m
for m in $LOADED_MODNAMES; do
[ "$m" != "$name" ] || return 0
done
LOADED_MODNAMES="$LOADED_MODNAMES
$name"
return 1
}

IgnoredModule()
{
local name="$1" m
for m in off null $IGNORE_MODNAMES; do
[ "$m" != "$name" ] || return 0
done
return 1
}

PreScsiModule()
{
local name="$1" m
for m in $PRE_SCSI_MODNAMES; do
[ "$m" != "$name" ] || return 0
done
return 1
}

ListModuleFiles()
{
case "$MODPROBE_TYPE" in
modutils)
modprobe --kernel-release "$KERNEL" \
--list-module-files "$@" 2>/dev/null
;;
module-init-tools)
modprobe --set-version="$KERNEL" --show-depends \
--ignore-all-commands "$@" 2>/dev/null
;;
*) Fatal "Unknown modprobe type '$MODPROBE_TYPE'" ;;
esac
}

ModuleExists()
{
local name="$1" list m
list=`ListModuleFiles "$name"`
if [ $? -ne 0 ]; then
Debug "Module \"$name\" does not exist"
return 1
fi
for m in $list; do
if [ -z "${m##/lib/modules/*}" ]; then
Debug "Module \"$name\" exists"
return 0
fi
done
Debug "Module \"$name\" seems to be aliased to null"
return 1
}

AddModuleFirmware()
{
local mod_name="$1" && shift
local mod_path="$1" && shift
local fw_list fw_name fw_dir fw_file

fw_list="$(modinfo -F firmware "$mod_path")" || return
[ -n "$fw_list" ] || return
[ "$IMAGE_TYPE" = initramfs ] || {
Warning "Module \"$mod_name\" uses external firmware - this is supported only for initramfs images"
return
}
for fw_name in $fw_list; do
fw_file=
for fw_dir in $FIRMWARE_DIRS; do
if [ -r "$fw_dir/$fw_name" ]; then
fw_file="$fw_dir/$fw_name"
break
fi
done
[ -n "$fw_file" ] || {
Warning "Firmware file \"$fw_name\" for module \"$mod_name\" not found"
continue
}
Verbose "Adding firmware file \"$fw_file\" for module \"$mod_name\""
ADD_FILES="$ADD_FILES
/lib/firmware/$fw_name=$fw_file"
done
}

AddModuleFile()
{
local path="$1" name="$1"
name="${name##*/}"
name="${name%.gz}"
name="${name%.o}"
name="${name%.ko}"
name="`NormalizedName "$name"`"

if ModuleAlreadyLoaded "$name"; then
return 0
fi

if IgnoredModule "$name"; then
Warning "Module \"$name\" cannot be ignored because other modules depend on it"
fi

Debug "Found module \"$name\" as $path"
MODULES="$MODULES $path"

AddModuleFirmware "$name" "$path"
}

FindModule()
{
local skip_errors= name="$1"
if [ -z "${name##-*}" ]; then
skip_errors=1
name="${name#-*}"
fi
name="${name%.gz}"
name="${name%.o}"
name="${name%.ko}"
name="`NormalizedName "$name"`"

if IgnoredModule "$name"; then
Debug "Ignoring \"$name\" module"
return 0
fi

Debug "Looking for \"$name\" module"

local list

list=`ListModuleFiles "$name"`
if [ $? -ne 0 ]; then
if [ -n "$skip_errors" ]; then
Debug "Ignoring missing \"$name\" module"
return 0
fi

if PreScsiModule "$name"; then
Debug "Ignoring missing \"$name\" SCSI module"
return 0
fi

echo "No module \"$name\" found for kernel $KERNEL" >&2
[ -z "$strict" ] && return 1 || Exit 1
fi

local m
for m in $list; do
[ -z "${m##/lib/modules/*}" ] || continue
AddModuleFile "$m"
done
}

FindModules()
{
local n
for n in "$@"; do
FindModule "$n"
done
}

FindModulesFromCommandLine()
{
local IGNORE_MODNAMES=
FindModules "$@"
}

FindExtraModulesFromCommandLine()
{
local MODULES=
FindModulesFromCommandLine "$@"
EXTRA_MODULES="$MODULES"
}

# Detect module kind by examining its dependencies.
# Currently these kinds are detected:
# - "block" - standalone block device driver;
# - "scsi" - SCSI host adapter driver;
# - "ide" - IDE controller driver;
# - "missing" - module does not exist at all;
# - "unknown" - none of the above.
#
# Note: Order of check is important here:
# - cciss is a block device driver, but it also registers a SCSI host adapter
# to access non-disk devices on its SCSI bus; it should be treated as
# "block" (no need to load sd_mod) - therefore "block" check comes before
# "scsi";
# - usb-storage uses functions from the IDE layer; it should be treated as
# "scsi" (sd_mod is needed) - therefore "scsi" check comes before "ide".
ModuleKind()
{
local name="$1" list
list=`ListModuleFiles "$name"`
if [ $? -ne 0 ]; then
echo "missing"
elif [ -z "$list" ]; then
echo "missing"
elif [ -z "${list##*/kernel/drivers/block/*}" ]; then
echo "block"
elif [ -z "${list##*/kernel/drivers/scsi/*}" ]; then
echo "scsi"
elif [ -z "${list##*/kernel/drivers/ide/*}" ]; then
echo "ide"
else
echo "unknown"
fi
}

AddScsiModules()
{
local n
for n in "$@"; do
n="`NormalizedName "$n"`"
if IgnoredModule "$n"; then
Debug "Ignoring \"$n\" module"
continue
fi

case `ModuleKind "$n"` in
ide)
# IDE was handled earlier - skip it
Debug "Ignoring IDE module \"$n\""
continue
;;

block)
# No additional modules needed
Debug "Adding block module \"$n\""
;;

scsi|unknown)
# SCSI needs sd_mod to be useful in initrd;
# also add it for unknown modules to be safe
# (maybe someone built scsi_mod into the kernel
# and tries to use an out-of-kernel driver)
if [ -z "$PRE_SCSI_MODNAMES_ADDED" ]; then
SCSI_MODULES="$SCSI_MODULES $PRE_SCSI_MODNAMES"
PRE_SCSI_MODNAMES_ADDED=1
fi
;;
esac

SCSI_MODULES="$SCSI_MODULES $n"
done
}

FindScsiModulesFromConfig()
{
local scsimodules
scsimodules=`egrep -s '(alias|probeall)[ ]+scsi_hostadapter' "$MODULES_CONF" |
grep -v '^[ ]*#' |
LC_COLLATE=C sort -u |
awk '{$1=$2="";print}'`

AddScsiModules $scsimodules

if [ -n "$SCSI_MODULES" ]; then
Verbose "SCSI modules from config:$SCSI_MODULES"
FindModules $SCSI_MODULES
else
Verbose "No SCSI modules specified in config"
fi
}

MatchPciMassStorageClass()
{
[ $(($pci_class & 0xff0000)) -eq $((0x010000)) ] || return 1
}

SortScsiModules()
{
local n all normal= ata_generic= pata_legacy=
for n in "$@"; do
case "$n" in
ata_piix)
# Move ahci before ata_piix (there is some PCI
# ID overlap between them, and using ata_piix
# loses NCQ support).
if InList ahci "$*"; then
normal="$normal ahci"
fi
normal="$normal $n"
;;
ata_generic)
# ata_generic must be after all other drivers...
ata_generic="$ata_generic $n"
;;
pata_legacy)
# ...except for pata_legacy, which must be even
# after ata_generic.
pata_legacy="$pata_legacy $n"
;;
*)
normal="$normal $n"
;;
esac
done
all="$normal$ata_generic$pata_legacy"

Verbose "Found SCSI modules:$all"
FindModules $all
}

FindScsiModules()
{
[ -z "$noscsi" ] || return

if ModuleExists scsi_hostadapter; then
# Manual configuration
FindScsiModulesFromConfig
return
fi

[ -x "$LSPCI" ] || {
Verbose "$LSPCI not found - skipping autodetection of SCSI adapters"
return
}

local scsimodules

# Look for modules for all "Mass storage controller" class devices.
# Looking only for SCSI and RAID subclasses is not sufficient - there
# are some SATA controllers which have IDE subclass, but Linux SATA
# drivers for them use the SCSI subsystem.
scsimodules=`ListPciModulesUsingLspci MatchPciMassStorageClass`

AddScsiModules $scsimodules

if [ -n "$SCSI_MODULES" ]; then
SortScsiModules $SCSI_MODULES
else
Verbose "No SCSI modules found"
fi
}

# Some PCI IDE devices have more than one matching driver in modules.pcimap;
# common conflicts are SATA and vendor-provided RAID drivers (although vendor
# drivers often do not have PCI ID tables at all). Adding such modules to
# initrd as IDE drivers can break booting, therefore they must be filtered out.
#
# This function assumes that IDE modules either reside in
# /lib/modules/$KERNEL/kernel/drivers/ide/, or depend on at least one module
# which is located there, and also do not depend on anything in
# /lib/modules/$KERNEL/kernel/drivers/scsi/.
#
AddIdeModule()
{
local name="$1" list
list=`ListModuleFiles "$name"`
if [ $? -ne 0 ]; then
Debug "Module \"$name\" does not exist - ignored"
elif [ -z "${list##*/kernel/drivers/scsi/*}" ]; then
Debug "Module \"$name\" looks like a SCSI driver, not IDE - skipping"
elif [ -n "${list##*/kernel/drivers/ide/*}" ]; then
Debug "Module \"$name\" does not look like an IDE driver - skipping"
else
Debug "Module \"$name\" looks like an IDE driver - adding"
IDE_MODULES="$IDE_MODULES $name"
fi
}

AddIdeModules()
{
local n
for n in "$@"; do
AddIdeModule "$n"
done
}

# Look for PCI device driver in modules.pcimap. Code copied from hotplug
# (pci.agent).
#
# Parameters are passed in shell variables: pci_class, pci_id_vendor,
# pci_id_device, pci_subid_vendor, pci_subid_device. Names of matching modules
# are output to stdout.
#
ListPciModules()
{
local pcimap="/lib/modules/$KERNEL/modules.pcimap"
[ -r "$pcimap" ] || return 1

pci_class=$(($pci_class))
pci_id_vendor=$(($pci_id_vendor))
pci_id_device=$(($pci_id_device))
pci_subid_vendor=$(($pci_subid_vendor))
pci_subid_device=$(($pci_subid_device))

(
read ignored

PCI_ANY=$((0xffffffff))
while read module vendor device subvendor subdevice class class_mask ignored
do
case "$module" in
\#*) continue ;;
esac

vendor=$(($vendor)); device=$(($device))
subvendor=$(($subvendor)); subdevice=$(($subdevice))
class=$(($class)); class_mask=$(($class_mask))

if [ $vendor -ne $PCI_ANY ] && [ $vendor -ne $pci_id_vendor ]; then
continue
fi
if [ $device -ne $PCI_ANY ] && [ $device -ne $pci_id_device ]; then
continue
fi
if [ $subvendor -ne $PCI_ANY ] && [ $subvendor -ne $pci_subid_vendor ]; then
continue
fi
if [ $subdevice -ne $PCI_ANY ] && [ $subdevice -ne $pci_subid_device ]; then
continue
fi

class_temp=$(($pci_class & $class_mask))
if [ $class_temp -eq $class ]; then
echo "$module"
# There was "break" here in the hotplug code;
# this does not work if there can be more than
# one matching module for the given PCI IDs -
# and there can be (one example is sata_nv,
# which has PCI ID entry matching all IDE
# controllers made by nVidia).
fi
done
) < "$pcimap"
}

ListPciModulesUsingSysfs()
{
local dev="$1"
local pci_class pci_id_vendor pci_id_device pci_subid_vendor pci_subid_device

pci_class=`cat "$dev/class"`
pci_id_vendor=`cat "$dev/vendor"`
pci_id_device=`cat "$dev/device"`
pci_subid_vendor=`cat "$dev/subsystem_vendor"`
pci_subid_device=`cat "$dev/subsystem_device"`

ListPciModules
}

ListPciModulesUsingIdeConfig()
{
local config="$1"
local pci_class pci_id_vendor pci_id_device pci_subid_vendor pci_subid_device

eval `awk '
NR == 2 {
print "pci_id_vendor=0x" $2 $1;
print "pci_id_device=0x" $4 $3;
print "pci_class=0x" $12 $11 $10;
}
NR == 4 {
print "pci_subid_vendor=0x" $14 $13;
print "pci_subid_device=0x" $16 $15;
}
' <"$config"`

ListPciModules
}

# Usage: ListPciModulesForSlot <slot> [<match-function> [<parameters>...]]
#
ListPciModulesForSlot()
{
local slot="$1" && shift
local pci_class pci_id_vendor pci_id_device pci_subid_vendor pci_subid_device

# This lspci -x parsing crap is here because lspci -n does not output
# the prog-if byte which can be used in modules.pcimap entries
eval `$LSPCI -mnx -s "$slot" | awk '
NR == 2 {
print "pci_id_vendor=0x" $3 $2;
print "pci_id_device=0x" $5 $4;
print "pci_class=0x" $13 $12 $11;
}
NR == 4 {
print "pci_subid_vendor=0x" $15 $14;
print "pci_subid_device=0x" $17 $16;
}
'`

if [ "$#" -gt 0 ]; then
"$@" || return 0
fi

ListPciModules
}

# Usage: ListPciModulesUsingLspci [<match-function> [<parameters>...]]
#
ListPciModulesUsingLspci()
{
local slot ignored

$LSPCI -mn | \
while read slot ignored; do
ListPciModulesForSlot "$slot" "$@"
done
}

MatchPciIdeClass()
{
# Match only the "IDE Interface" class
[ $(($pci_class & 0xffff00)) -eq $((0x010100)) ] || return 1
}

ListPciIdeModulesUsingLspci()
{
ListPciModulesUsingLspci MatchPciIdeClass
}

# Usage: FindIdeModulesUsing <lister-function> [<parameters>...]
#
FindIdeModulesUsing()
{
local modules
Debug "Looking for IDE modules using $*"
modules=` "$@" `
Debug "Found matching modules: \"$modules\""
AddIdeModules $modules
}

# This function is called if an IDE controller which is not driven by a PCI IDE
# driver is found. This may happen in several different cases:
#
# - Really old ISA IDE: ide-generic will handle normal cases, manual
# configuration may be needed for some obscure cards.
#
# - ISA-PnP IDE: driver is built into ide-core (at least in 2.6.10).
#
# - Onboard PCI IDE unknown to the currently running kernel (and therefore
# driven by ide-generic). The newly installed kernel might have a driver
# for this hardware; this function attempts to find such drivers.
#
# - Kernel 2.6.x and /sys not mounted (on 2.6.x /proc/ide/ide*/config no
# longer exists) - this can be considered a broken configuration, but this
# function will make it work at least for plain PCI IDE (not RAID)
# controllers.
#
HandleNonPciIde()
{
# no point in scanning PCI bus multiple times
[ -z "$FOUND_NON_PCI_IDE" ] || return 0
FOUND_NON_PCI_IDE=1

Verbose "Found IDE controller driven by a non-PCI IDE driver"
[ -x "$LSPCI" ] || {
Verbose "$LSPCI not found - not looking for PCI IDE devices"
return 0
}

FindIdeModulesUsing ListPciIdeModulesUsingLspci
}

FindIdeModulesUsingSysfs()
{
local ide_device controller controllers=

for ide_device in /sys/bus/ide/devices/*; do
controller="$(readlink -ev "$ide_device"/../..)" || {
Warning "Unable to find IDE controller for $ide_device"
continue
}
InList "$controller" "$controllers" || \
controllers="$controllers
$controller"
done

local dev
for dev in $controllers; do
if [ -r "$dev/class" ] \
&& [ -r "$dev/vendor" ] \
&& [ -r "$dev/device" ] \
&& [ -r "$dev/subsystem_vendor" ] \
&& [ -r "$dev/subsystem_device" ] ; then
FindIdeModulesUsing ListPciModulesUsingSysfs "$dev"
else
HandleNonPciIde
fi
done
}

FindIdeModulesUsingProc()
{
local interface cfg

for interface in /proc/ide/ide*; do
cfg="$interface/config"
if [ -r "$cfg" ]; then
FindIdeModulesUsing ListPciModulesUsingIdeConfig "$cfg"
else
HandleNonPciIde
fi
done
}

SortIdeModules()
{
local n normal= last=
for n in "$@"; do
case "$n" in
generic)
last="$last $n" ;;
*)
normal="$normal $n" ;;
esac
done
Verbose "Found IDE modules:$normal$last"
FindModules $normal $last
}

FindIdeModules()
{
[ -z "$noide" ] || return

local ide
ide=`ls -d /proc/ide/ide* 2>/dev/null`
[ -n "$ide" ] || return

local new_ide_modules=
if [ "$KERNEL_MAJOR" -gt 2 ]; then
new_ide_modules=1
elif [ "$KERNEL_MAJOR" -eq 2 ]; then
if [ "$KERNEL_MINOR" -gt 4 ]; then
new_ide_modules=1
elif [ "$KERNEL_MINOR" -eq 4 ]; then
if [ "$KERNEL_PATCH" -gt 20 ]; then
new_ide_modules=1
fi
fi
fi

if [ -z "$new_ide_modules" ]; then
# For kernels <= 2.4.20 there were no per-chipset modules
FindModule -ide-mod
FindModule -ide-probe
FindModule -ide-probe-mod
FindModule -ide-disk
return
fi

if ModuleExists ide_hostadapter; then
# Manual configuration overrides even ide-generic
FindModule ide_hostadapter
FindModule -ide-detect
FindModule -ide-disk
return
fi

ModuleExists ide-core || \
ModuleExists ide-disk || \
ModuleExists ide-generic || \
ModuleExists generic || \
return

FindModule -ide-core

if [ -d /sys/bus/ide/devices ]; then
Debug "Looking for IDE devices in /sys"
FindIdeModulesUsingSysfs
else
Debug "Looking for IDE devices in /proc"
FindIdeModulesUsingProc
fi

if [ -n "$IDE_MODULES" ]; then
SortIdeModules $IDE_MODULES
else
Verbose "No IDE modules found"
fi

FindModule -ide-generic
FindModule -ide-detect
FindModule -ide-disk
}

FindRaidModuleForLevel()
{
local level="$1" module=

case "$level" in
[0156]|10)
module="raid$level"
;;
4)
module="raid5"
;;
-1|linear)
module="linear"
;;
-4|multipath)
module="multipath"
;;
-5|faulty)
module="faulty"
;;
esac

if [ -n "$module" ]; then
InList "$module" "$RAID_MODULES" || {
RAID_MODULES="$RAID_MODULES $module"
FindModule "$module"
}
else
echo "raid level \"$level\" not recognized" >&2
fi
}

ListRaidLevelsFromRaidtab()
{
grep '^[ ]*raid-level' /etc/raidtab | \
awk '{print $2}' | LC_COLLATE=C sort -u
}

MdadmScanForArrays()
{
$MDADM --detail --scan 2>/dev/null
$MDADM --examine --scan 2>/dev/null
}

ListRaidLevelsFromMdadm()
{
MdadmScanForArrays | \
sed -ne 's/^.* level=\([^ ]*\) .*$/\1/p' |
sed -e 's/^raid\([0-9]*\)$/\1/'
}

FindRaidModules()
{
[ -z "$noraid" ] || return

if egrep -s '^/dev/md(/?[0-9]+|[/_]d[0-9]+(p[0-9]+)?)[ ]' "$FSTAB_FILE" |
fgrep -qsv noauto; then
HAVE_RAID=1
fi

if [ -z "$HAVE_RAID" ] && [ -x $MDADM ]; then
if [ -n "$(MdadmScanForArrays)" ]; then
HAVE_RAID=1
fi
fi

if [ -n "$HAVE_RAID" ]; then
FindModule -md
if [ -r /etc/raidtab ]; then
for number in `ListRaidLevelsFromRaidtab`; do
FindRaidModuleForLevel "$number"
done
fi
if [ -x $MDADM ]; then
for number in `ListRaidLevelsFromMdadm`; do
FindRaidModuleForLevel "$number"
done
fi
if [ -z "$RAID_MODULES" ]; then
Warning "RAID support enabled, but used RAID levels not detected"
fi
fi

if grep -s '^/dev/ataraid' "$FSTAB_FILE" |fgrep -qsv noauto; then
local ataraidmodules
ataraidmodules=`egrep -s '(alias|probeall)[ ]+ataraid_hostadapter' "$MODULES_CONF" |
grep -v '^[ ]*#' |
LC_COLLATE=C sort -u |
awk '{$1=$2="";print}'`
local n
for n in $ataraidmodules; do
FindModule "$n"
done
fi
}

FindRootModules()
{
# In case the root filesystem is modular.
#rootdev=$(awk '{if (($2 == "/") && ($1 !~ /^[ \t]*#/) {print $1}}' "$FSTAB_FILE")
local rootfs
rootfs=$(awk '{if (($2 == "/") && ($1 !~ /^[ \t]*#/)) {print $3}}' "$FSTAB_FILE")
[ -z "$rootfs" ] || FindModule -"$rootfs"
}

FindLoopModules()
{
# check to see if we need to set up a loopback filesystem
local full
full=$(awk '$2 == "/" && $4 ~ "loop" {print $1}' "$FSTAB_FILE")
if [ -n "$full" ]; then
local dir="$full" line=
while [ -n "$dir" -a -z "$line" ]; do
dir="${dir%/*}"
line=$(awk -v "dir=$dir" '$2 == dir {print $0}' "$FSTAB_FILE")
done
[ -n "$line" -a "$dir" != / ] ||
Fatal "bad fstab, loopback file doesn't belong to any device."
loopDev=$(echo "$line" |awk '{print $1}')
loopFs=$(echo "$line" |awk '{print $3}')
loopFile=$(echo "$full" |sed "s|$dir||")

FindModule -loop
FindModule -"$loopFs"
fi
}

Install()
{
install -D $debug "$1" "$2" ||
Fatal "Failed to install \"$1\" file."
}

Cp()
{
cp $debug "$@"
}

Ln()
{
ln $debug "$@"
}

Mkdir()
{
mkdir $debug "$@"
}

Mknod()
{
file="$1"
shift
mknod "$file" "$@" &&
Debug "Created $file device" ||
Fatal "Failed to create \"$file\" device."
}

CreateLinuxrc()
{
cat >"$RCFILE" <<EOF
#!/bin/sh
EOF

for m in $MODULES; do
m="${m%.gz}"
local n
n="${m##*/}"
n="${n%.o}"
n="${n%.ko}"

options=`sed -ne "s/^options[ ]\\+$n[ ]\\+//p" "$MODULES_CONF"`

Debug "Loading module \"$m\" with options \"$options\""
cat >>"$RCFILE" <<EOF
/bin/insmod -f $m $options
EOF
done

if [ -n "$HAVE_EVMS" ]; then
Mkdir -p "$MNTDIR/dev/evms/"
Mkdir -p "$MNTDIR/var/lock/"
ListEvmsFilesAll
Cp --parents -d $EVMS_FILES_ALL "$MNTDIR/"

cat >>"$RCFILE" <<EOF
echo mounting /dev/evms
/bin/mount -t tmpfs -o size=16k evms /dev/evms
echo mounting /var/lock
/bin/mount -t tmpfs -o size=16k tmpfs /var/lock
echo Starting EVMS
/sbin/evms_activate
EOF
fi

if [ -n "$HAVE_RAID" ]; then
Mknod "$MNTDIR/safedev/md255" b 9 255
Ln -s sh "$MNTDIR/bin/raidautorun"
cat >>"$RCFILE" <<EOF
/bin/raidautorun /safedev/md255
EOF
fi

if [ -n "$loopDev" ]; then
Cp -aL "$loopDev" $MNTDIR/safedev
Cp -aL /dev/loop7 $MNTDIR/safedev
loopDev=`echo "$loopDev" |sed -e 's|/dev/|/safedev/|'`
cat >>"$RCFILE" <<EOF
echo Mounting device containing loopback root filesystem
/bin/mount -t $loopFs $loopDev /loopfs
echo Setting up loopback file $loopFile
/bin/losetup /safedev/loop7 /loopfs/$loopFile
EOF
fi

cat >>"$RCFILE" <<'EOF'
FindDev()
{
local dev="$1"
test -z "${dev##/dev/*}" || return 1
dev="${dev#/dev/}"
(
read ignored
read ignored
while read major minor size name ignored; do
if test "$name" = "$dev" ; then
echo $major $minor
exit 0
fi
done
exit 1
) </proc/partitions
}
EncodeDev()
{
echo $(( ($2 & 0xff) | ($1 << 8) | (($2 & ~0xff) << 12) ))
}
/bin/mount -t proc proc /proc
read cmdline </proc/cmdline
cmdline=" $cmdline "
if test -z "${cmdline##*[ ]resume=*}" && test -n "${cmdline##*[ ]noresume*}"; then
resume="${cmdline##*[ ]resume=}"
resume="${resume%%[ ]*}"
if dev="$(FindDev "$resume")"; then
dev="$(set - $dev; echo "$1:$2")"
if /bin/mount -t sysfs sysfs /sys; then
if test -f /sys/power/resume; then
echo "$dev" >/sys/power/resume
else
echo "Resume failed: kernel does not support /sys/power/resume"
fi
/bin/umount /sys
else
echo "Resume failed: unable to mount sysfs"
fi
else
echo "Resume failed: cannot find resume device \"$resume\""
fi
fi
if test -z "${cmdline##*[ ]resume2=*}" && test -n "${cmdline##*[ ]noresume2*}"; then
/bin/mount -t sysfs sysfs /sys || break
test -f /sys/power/suspend2/do_resume && echo > /sys/power/suspend2/do_resume
/bin/umount /sys
fi
ParseNumber()
{
local n="$1"
eval 'echo $((n))' 2>/dev/null ||:
}
DecodeRoot()
{
local dev= major minor root="$1"
if dev="$(FindDev "$root")"; then
echo "$dev"
return 0
fi
if test -z "${root##*:*}"; then
major="$(ParseNumber "${root%%:*}")"
minor="$(ParseNumber "${root#*:}")"
if test -n "$major" && test -n "$minor"; then
echo "$major" "$minor"
return 0
fi
fi
if test -z "${root##0[Xx]*}"; then
dev="$(ParseNumber "$root")"
else
dev="$(ParseNumber "0x$root")"
fi
if test -n "$dev"; then
major=$(( (dev & 0xfff00) >> 8 ))
minor=$(( (dev & 0xff) | ((dev >> 12) & 0xfff00) ))
echo "$major" "$minor"
return 0
fi
if dev="$(FindDev "/dev/$root")"; then
echo "$dev"
return 0
fi
return 1
}
if test -z "${cmdline##*[ ]root=*}" ; then
root="${cmdline##*[ ]root=}"
root="${root%%[ ]*}"
if dev="$(DecodeRoot "$root")"; then
EncodeDev $dev >/proc/sys/kernel/real-root-dev
else
echo "Cannot find root device \"$root\""
fi
fi
EOF

if [ -n "$HAVE_EVMS" ]; then
cat >>"$RCFILE" <<'EOF'
/bin/umount /var/lock
/bin/umount /dev/evms
EOF
fi

cat >>"$RCFILE" <<'EOF'
/bin/umount /proc
EOF
}

CopyFileToInitramfs()
{
local source="$1" && shift
local target="$1" && shift

if grep -qs '@NO_INITRAMFS@' "$source"; then
Debug "Skipped '$source' marked with @NO_INITRAMFS@"
else
Mkdir -p "${target%/*}"
Cp -aL "$source" "$target"
fi
}

CopyDirToInitramfs()
{
local source="$1" && shift
local target="$1" && shift

local f
for f in "$source"/*; do
# Ignore *.rpm* and *~ files
[ "${f%.rpm*}" = "$f" -a "${f%\~}" = "$f" ] || continue
CopyFileToInitramfs "$f" "$target/${f##*/}"
done
}

ConfigInitramfsForEvms()
{
ListEvmsFilesAll
Cp --parents -d $EVMS_FILES_ALL "$MNTDIR/"
Mkdir -p "$MNTDIR/var/lock/"
cat >>"$MNTDIR"/scripts/local-top <<'EOF'
log_begin_msg "Starting up EVMS devices"
/sbin/evms_activate
log_end_msg
EOF
}

ConfigInitramfsForRaid()
{
# /scripts/local-top runs before swsusp resume - start RAID in
# read-only mode to avoid messing up resume state. Actually the
# start_ro parameter sets the "read-auto" mode - arrays initially
# start read-only, but are switched to the normal read-write mode on
# the first write request, so there is no need to switch arrays to
# the read-write mode explicitly.
#
# "echo add > /sys/block/md0/uevent" after md_run is a workaround for
# an unavoidable race between md_run invoking RAID_AUTORUN ioctl on
# /dev/md0 and udevd probing the started md devices (one of which may
# be /dev/md0): probing fails if it starts when md_run still has
# /dev/md0 open. The extra uevent makes sure that /dev/md0 is probed
# properly, which is important when the root fs is specified by UUID.
cat >>"$MNTDIR"/scripts/local-top <<'EOF'
log_begin_msg "Starting up RAID devices"
modprobe -q md_mod
echo 1 > /sys/module/md_mod/parameters/start_ro
md_run `cat /proc/cmdline`
echo add > /sys/block/md0/uevent ||:
log_end_msg
EOF

# /scripts/local-premount runs after resume - restore start_ro
# to its default value.
cat >>"$MNTDIR"/scripts/local-premount <<'EOF'
echo 0 > /sys/module/md_mod/parameters/start_ro
EOF
}

CopyExtraFiles()
{
local old_IFS="$IFS" old_options="-$-"
IFS='
'
set -f

local f target source tmp
for f in $ADD_FILES; do
target="${f%%=*}"
[ "$target" != "$f" ] ||
Fatal "Invalid --add argument '$f': missing '='."
[ -n "$target" ] ||
Fatal "Invalid --add argument '$f': empty target."
[ -n "${target%%*/}" ] ||
Fatal "Invalid --add argument '$f': target ends with '/'."
tmp="/$target/"
[ -n "${tmp##*/./*}" ] && [ -n "${tmp##*/../*}" ] ||
Fatal "Invalid --add argument '$f': target contains '.' or '..'."

source="${f#*=}"
[ -n "$source" ] ||
Fatal "Invalid --add argument '$f': empty source."
[ -n "${source%%*/}" ] ||
Fatal "Invalid --add argument '$f': source ends with '/'."
[ -e "$source" ] ||
Fatal "Invalid --add argument '$f': source does not exist."

target="/$target"
Mkdir -p "$MNTDIR/${target%/*}" ||
Fatal "Failed to make directories for '--add $f'."
Cp -aLT "$source" "$MNTDIR/$target" ||
Fatal "Failed to copy files for '--add $f'."
done

[ -n "${old_options##*f*}" ] || set +f
IFS="$old_IFS"
}

CreateInitramfsConfigs()
{
Mkdir -p "$MNTDIR"/{conf,etc/udev/rules.d}

for m in $MODULES; do
m="${m%.gz}"
m="${m##*/}"
m="${m%.o}"
m="${m%.ko}"

printf '%s\n' "$m" >>"$MNTDIR"/conf/modules
done

if [ -f /etc/modprobe.conf ]; then
CopyFileToInitramfs /etc/modprobe.conf \
"$MNTDIR"/etc/modprobe.conf
fi
if [ -d /etc/modprobe.d ]; then
CopyDirToInitramfs /etc/modprobe.d "$MNTDIR"/etc/modprobe.d
fi
if [ -d /etc/udev/initramfs-rules.d ]; then
for f in /etc/udev/initramfs-rules.d/*.rules; do
[ -f "$f" ] || continue
Cp -aL "$f" "$MNTDIR"/etc/udev/rules.d/
done
fi

if [ -n "$HAVE_EVMS" ]; then
ConfigInitramfsForEvms
elif [ -n "$HAVE_RAID" ]; then
ConfigInitramfsForRaid
fi

if [ -n "$ADD_FILES" ]; then
CopyExtraFiles
fi
}

MakeMountDir()
{
MNTDIR="$WORKDIR/tree"
RCFILE="$MNTDIR/linuxrc"

Mkdir -p $MNTDIR/{etc,dev,safedev,loopfs,sys,proc} ||
Fatal "Failed to create directories."

if [ "$IMAGE_TYPE" = initramfs ]; then
Mkdir "$MNTDIR/tmp"
Cp -aL /lib/mkinitrd/initramfs-base/* "$MNTDIR/"
Cp -aL /lib/mkinitrd/klibc/* "$MNTDIR/"
Cp -aL /lib/mkinitrd/module-init-tools/* "$MNTDIR/"
Cp -aL /lib/mkinitrd/udev/* "$MNTDIR/"
else
Install /lib/mkinitrd/busybox "$MNTDIR/bin/sh"
Ln -s sh "$MNTDIR/bin/echo"
Ln -s sh "$MNTDIR/bin/insmod"
Ln -s sh "$MNTDIR/bin/modprobe"
Ln -s sh "$MNTDIR/bin/mount"
Ln -s sh "$MNTDIR/bin/umount"
Ln -s sh "$MNTDIR/bin/losetup"
Ln -s sh "$MNTDIR/bin/test"
fi

local m
for m in $MODULES $EXTRA_MODULES; do
Install "$m" "$MNTDIR/$m" ||
Fatal "Failed to install $m module."
m="$MNTDIR/$m"
if [ -z "${m%%*.gz}" ]; then
gunzip $debug "$m" ||
Fatal "Failed to uncompress \"$m\" module."
fi
done
if [ "$IMAGE_TYPE" = initramfs ]; then
depmod -a -F "/boot/System.map-$KERNEL" -b "$MNTDIR" "$KERNEL" ||
Fatal "Failed to generate module dependencies."
fi

Mknod "$MNTDIR/dev/console" c 5 1
Mknod "$MNTDIR/dev/null" c 1 3
Mknod "$MNTDIR/dev/ram" b 1 1
Mknod "$MNTDIR/dev/systty" c 4 0
Mknod "$MNTDIR/dev/tty1" c 4 1

if [ "$IMAGE_TYPE" = initramfs ]; then
CreateInitramfsConfigs
else
CreateLinuxrc
fi

if [ -n "$pause" ]; then
cat >&2 <<__EOF__

You can now edit initrd manually.
WORKDIR: $WORKDIR

Press ENTER to continue automatic initrd generation.

__EOF__
read
fi

if [ "$IMAGE_TYPE" != initramfs ]; then
chmod +x "$RCFILE"

if [ -n "$verbose" ]; then
echo "Contents of linuxrc:"
cat "$RCFILE"
fi
fi

INODES=`find "$MNTDIR" |wc -l` ||
Fatal "Failed to calculate inodes."
INODES=$[INODES+20]
Verbose "Inode count: $[INODES]"
IMAGESIZE=`du -ks --block-size=4096 "$MNTDIR" |cut -f1` ||
Fatal "Failed to calculate image size."
# Add more 20%
IMAGESIZE=$[IMAGESIZE*6/5 + INODES/32]
Verbose "Image size: $[IMAGESIZE*4]K"
}

MakeImageFile_ext2()
{
dd if=/dev/zero of="$IMAGE" bs=4k count="$IMAGESIZE" 2>/dev/null &&
Verbose "Created image file" ||
Fatal "Failed to create image file."

mke2fs -b 4096 -q -m 0 -F -N "$INODES" "$IMAGE" &&
Verbose "Created filesystem for ramdisk" ||
Fatal "Failed to create filesystem."

mount $verbose -t ext2 "$IMAGE" "$MNTPOINT" -o loop,noexec,nosuid,nodev ||
Fatal "Failed to mount loopback device."

# We don't need this directory, so let's save space.
rmdir "$MNTPOINT/lost+found"

(cd "$MNTDIR"; tar cf - .) | (cd "$MNTPOINT"; tar xf -) &&
Verbose "Installed directory tree: $MNTDIR --> $MNTPOINT" ||
Fatal "Failed to copy directory tree."

umount "$MNTPOINT" || Fatal "Failed to unmount loopback device."

Verbose "Created ext2 image file"
}

MakeImageFile_romfs()
{
genromfs -f "$IMAGE" -d "$MNTDIR" &&
Verbose "Created image from tree: $MNTDIR --> $IMAGE" ||
Fatal "Failed to create romfs image."

Verbose "Created romfs image file"
}

MakeImageFile_initramfs()
{
( cd "$MNTDIR" && find -print0 | cpio -o0 -H newc --quiet > "$IMAGE" ) &&
Verbose "Created image from tree: $MNTDIR --> $IMAGE" ||
Fatal "Failed to create initramfs image."

Verbose "Created initramfs image file"
}

KernelSupportsInitramfs()
{
# udevd used in initramfs does not support kernels older than 2.6.15
KernelVersionAtLeast 2 6 15 || return 1

# Assume that CONFIG_BLK_DEV_INITRD is on (otherwise no type of
# initrd/initramfs image will work).
return 0
}

SelectImageType()
{
case "$IMAGE_TYPE" in
''|initramfs|romfs|ext2)
;;
*)
Fatal "Unsupported image type \"$IMAGE_TYPE\""
;;
esac

if KernelSupportsInitramfs; then
[ -n "$IMAGE_TYPE" ] || IMAGE_TYPE=initramfs
[ "$IMAGE_TYPE" != initramfs ] || return
fi
if fgrep -qs romfs "/boot/System.map-$KERNEL"; then
[ -n "$IMAGE_TYPE" ] || IMAGE_TYPE=romfs
[ "$IMAGE_TYPE" != romfs ] || return
fi
if fgrep -qs ext2 "/boot/System.map-$KERNEL"; then
[ -n "$IMAGE_TYPE" ] || IMAGE_TYPE=ext2
[ "$IMAGE_TYPE" != ext2 ] || return
fi

[ -z "$IMAGE_TYPE" ] ||
Fatal "Unable to create image file: $IMAGE_TYPE support not found in your kernel"
Fatal "Unable to create image file: no initramfs, romfs or ext2 support found in your kernel"
}

MakeImageFile()
{
MakeImageFile_"$IMAGE_TYPE"
}

KernelSupportsBootSplash()
{
grep -qs '[[:space:]]splash_' "/boot/System.map-$KERNEL" ||
return 1
return 0
}

PrepareBootSplashData()
{
local config="/etc/sysconfig/bootsplash"
local fbresolution=
[ -s "$config" ] || return
. "$config" || return
is_yes "$SPLASH" || return
[ -n "$THEME" ] || return
fbresolution=`fbresolution 2>/dev/null` || return
local themefile
themefile="/etc/bootsplash/themes/$THEME/config/bootsplash-$fbresolution.cfg"
if [ -f "$themefile" ]; then
KernelSupportsBootSplash || {
Verbose "No bootsplash support in kernel"
return
}
if "$BIN_SPLASH" -f -s "$themefile" >"$WORKDIR/bootsplash"; then
Verbose "Prepared bootsplash \"$themefile\""
if [ "$IMAGE_TYPE" = initramfs ]; then
ADD_FILES="bootsplash=$WORKDIR/bootsplash
$ADD_FILES"
fi
else
Verbose "Failed to prepare bootsplash \"$themefile\"."
rm -f "$WORKDIR/bootsplash"
fi
fi
}

AddBootSplash()
{
[ "$IMAGE_TYPE" != initramfs ] || return
[ -f "$WORKDIR/bootsplash" ] || return

cat "$WORKDIR/bootsplash" >>"$TARGET" &&
Verbose "Added bootsplash to $TARGET" ||
Verbose "Failed to add bootsplash to $TARGET."
}

Usage()
{
cat >&2 <<EOF
mkinitrd - creates an initial ramdisk image for preloading modules.

mkinitrd is free software, covered by the GNU General Public License.
mkinitrd comes with ABSOLUTELY NO WARRANTY, see license for details.

Usage: $PROG [options] <initrd-image> <kernel-version>

Valid options are:
--type TYPE select image type (initramfs, romfs, ext2).
--fstab FILENAME use FILENAME instead of /etc/fstab.
--preload MODULES load MODULES before all found automatically.
--with MODULES load MODULES after all found automatically.
--extra MODULES add MODULES to be loaded only if needed.
--with-raid enable software RAID (md) support.
--with-evms enable EVMS (/dev/evms) support.
--omit-scsi-modules do not load any SCSI modules.
--omit-ide-modules do not load any IDE modules.
--omit-raid-modules do not load any raid modules.
--pause pause for manual initrd editing.
--nocompress do not compress initrd image.
--nobootsplash do not add bootsplash to the initrd image.
--strict abort on errors.
--image-version make image name based on kernel name.
--ifneeded create initrd image only if needed.
--version print version number and exit.
-a, --add INITRAMFS_FILE=FILE add FILE to initramfs as INITRAMFS_FILE.
-f, --force force initrd image creation.
-v, --verbose be more verbose.
-d, --debug print debug information.
-h, --help show this text.

Example: $PROG /boot/initrd-$uname_r.img $uname_r

EOF
[ -n "$1" ] && Exit "$1" || Exit
}

TEMP=`getopt -n "$PROG" -o a:fhvd -l help,version,verbose,debug,force,ifneeded,omit-scsi-modules,omit-ide-modules,omit-raid-modules,with-raid,with-evms,pause,image-version,nocompress,nobootsplash,strict,fstab:,before:,preload:,with:,after:,extra:,type:,add: -- "$@"` || Usage 1
eval set -- "$TEMP"

img_vers=
force=
while :; do
case "$1" in
-a|--add)
shift
ADD_FILES="$ADD_FILES
$1"
shift
;;
--type)
shift
IMAGE_TYPE="$1"
shift
;;
--fstab)
shift
FSTAB_FILE=$1
shift
;;
--before|--preload)
shift
PRELOAD_MODNAMES="$PRELOAD_MODNAMES $1"
shift
;;
--after|--with)
shift
POSTLOAD_MODNAMES="$POSTLOAD_MODNAMES $1"
shift
;;
--extra)
shift
EXTRA_MODNAMES="$EXTRA_MODNAMES $1"
shift
;;
--strict)
strict=1
shift
;;
--ifneeded)
ifneeded=1
shift
;;
--nocompress)
USE_COMPRESS=
shift
;;
--nobootsplash)
ADD_BOOTSPLASH=
shift
;;
--omit-scsi-modules)
noscsi=1
shift
;;
--omit-ide-modules)
noide=1
shift
;;
--omit-raid-modules)
noraid=1
shift
;;
--with-raid)
HAVE_RAID=1
shift
;;
--with-evms)
HAVE_EVMS=1
PRELOAD_MODNAMES="$PRE_EVMS_MODNAMES $PRELOAD_MODNAMES"
shift
;;
--pause)
pause=1
shift
;;
--image-version)
img_vers=1
shift
;;
-v|--verbose)
verbose=-v
shift
;;
-d|--debug)
verbose=-v
debug=-v
shift
;;
-f|--force)
force=1
shift
;;
--version)
echo "$PROG: version $VERSION"
exit 0
;;
-h|--help)
Usage 0
;;
--)
shift
break
;;
*)
Fatal "$PROG: unrecognized option: $1"
;;
esac
done

case "$(modprobe --version 2>/dev/null ||:)" in
*module-init-tools*version*)
MODPROBE_TYPE=module-init-tools
;;
*modprobe*version*)
MODPROBE_TYPE=modutils
;;
*)
Fatal "Unable to detect modprobe type (modutils or module-init-tools)"
;;
esac

# /proc needs to be mounted for the hardware autodetection to work properly.
# 2.6.x kernels also need /sys for that.
if [ -r /proc/filesystems ]; then
if grep -qs '^.*[[:space:]]sysfs$' /proc/filesystems; then
[ -d /sys/bus ] ||
Warning "/sys not available - hardware autodetection will not work"
fi
else
Warning "/proc not available - hardware autodetection will not work"
fi

TARGET=$1
[ -n "$TARGET" ] || Fatal "Target image not specified."
shift

KERNEL=$1
[ -n "$KERNEL" ] || Fatal "Kernel version not specified."
ParseKernelVersion
shift

if [ -n "$img_vers" ]; then
TARGET="$TARGET-$KERNEL.img"
fi

[ -n "$force" -o ! -f "$TARGET" ] || Fatal "$TARGET already exists."

MODULES_DIR="/lib/modules/$KERNEL"
[ -d "$MODULES_DIR" ] ||
Fatal "Directory \"$MODULES_DIR\" doesn't exist or not accessible."

WORKDIR=`mktemp -td initrd.XXXXXXXXXX` ||
Fatal "Failed to create working directory."

Verbose "Generating module dependencies..."
depmod -a -F "/boot/System.map-$KERNEL" "$KERNEL" &&
Verbose "...done." ||
Fatal "Failed to generate module dependencies."

MODULES_CONF="$WORKDIR/modules.conf"
case "$MODPROBE_TYPE" in
modutils)
modprobe --kernel-release "$KERNEL" -c >"$MODULES_CONF" ||
Fatal "Failed to parse modutils configuration."
;;
module-init-tools)
modprobe --set-version="$KERNEL" -c >"$MODULES_CONF" ||
Fatal "Failed to parse module-init-tools configuration."
;;
*) Fatal "Unknown modprobe type '$MODPROBE_TYPE'" ;;
esac

SelectImageType

[ -z "$ADD_FILES" ] || [ "$IMAGE_TYPE" = initramfs ] ||
Fatal "Adding extra files supported only for initramfs images."
[ -z "$EXTRA_MODNAMES" ] || [ "$IMAGE_TYPE" = initramfs ] ||
Fatal "Adding extra modules supported only for initramfs images."

### Begin module lookup.

FindModulesFromCommandLine $PRELOAD_MODNAMES

FindIdeModules

FindScsiModules

FindRaidModules

FindRootModules

FindLoopModules

FindModulesFromCommandLine $POSTLOAD_MODNAMES

FindExtraModulesFromCommandLine $EXTRA_MODNAMES

### End module lookup.

if [ -n "$ifneeded" -a -z "$MODULES$EXTRA_MODULES" ]; then
Verbose "No modules are needed - not building initrd image."
exit 0
fi

Verbose "Using modules: $MODULES"
if [ -n "$EXTRA_MODULES" ]; then
Verbose "Extra modules: $EXTRA_MODULES"
fi

PrepareBootSplashData

MakeMountDir

MNTPOINT="$WORKDIR/mnt"
Mkdir -p "$MNTPOINT" || Fatal "Failed to create mount point."

IMAGE="$WORKDIR/img"
:>"$IMAGE" || Fatal "Failed to create image file."

MakeImageFile

if [ -n "$USE_COMPRESS" ]; then
gzip -9n <"$IMAGE" >"$TARGET" &&
Verbose "Installed ramdisk into $TARGET" ||
Fatal "Failed to install ramdisk into $TARGET."
else
Cp "$IMAGE" "$TARGET" &&
Verbose "Installed ramdisk into $TARGET" ||
Fatal "Failed to install ramdisk into $TARGET."
fi

if [ -n "$ADD_BOOTSPLASH" ]; then
AddBootSplash
fi

if [ -n "$verbose" ]; then
size=`du -hs $TARGET |cut -f1`
echo "Ramdisk size: $size"
fi
mkinitrd-3.0.5/mkinitrd.8000064400000000000000000000120621071174602400152530ustar00rootroot00000000000000.TH mkinitrd 8 "Thu Feb 8 2007" "ALT Linux Team" "ALT Linux"
.
.
.SH NAME
mkinitrd \- creates initial ramdisk images for preloading modules
.
.
.SH SYNOPSIS
.PD 0
.HP 9
.na
.nh
.B mkinitrd
.RB [ \-\-type
.IR type ]
.RB [ \-\-fstab
.IR filename ]
.RB [ \-\-preload
.IR modules ]
.RB [ \-\-with
.IR modules ]
.RB [ \-\-extra
.IR modules ]
.RB [ \-\-add
.IR initramfs_filename = filename ]
.RB [ \-\-omit\-scsi\-modules ]
.RB [ \-\-omit\-ide\-modules ]
.RB [ \-\-omit\-raid\-modules ]
.RB [ \-\-pause ]
.RB [ \-\-nocompress ]
.RB [ \-\-nobootsplash ]
.RB [ \-\-strict ]
.RB [ \-\-image\-version ]
.RB [ \-\-ifneeded ]
.RB [ \-f | \-\-force ]
.RB [ \-v | \-\-verbose ]
.RB [ \-d | \-\-debug ]
.I image
.I kernel-version
.HP
.B mkinitrd \-\-version
.HP
.B mkinitrd \-\-help
.PD
.ad
.hy
.
.
.SH DESCRIPTION
.B mkinitrd
creates filesystem images which are suitable for use as
Linux initial ramdisk (initrd) images.
Such images are often used for preloading the block device
modules (such as IDE, SCSI or RAID) which are needed to
access the root filesystem.
.B mkinitrd
automatically loads IDE modules, all
.B scsi_hostadapter
entries in
.IR /etc/modules.conf ,
and raid modules if the system's root partition is on raid,
which makes it simple to build and use kernels using modular
device drivers.
.PP
Any module options specified in
.I /etc/modules.conf
are passed to the modules as they are loaded by the initial
ramdisk.
.
.
.SH OPTIONS
.TP
.BI \-\-type= type
Select image type to create:
.BR initramfs ,
.B romfs
or
.BR ext2 .
By default
.B mkinitrd
uses the first format from the above list which is supported
by the kernel.
.
.TP
.BI \-\-fstab= filename
Use
.I filename
to automatically determine what type of filesystem the root
device is on.
Normally,
.B /etc/fstab
is used.
.
.TP
.BI \-\-preload= modules
Load
.I modules
in the initrd image before any SCSI modules which are specified in
.IR /etc/modules.conf .
Multiple module names must be separated by whitespace characters.
If this option is used multiple times, all specified lists are
concatenated.
.
.TP
.BI \-\-with= modules
Load
.I modules
in the initrd image after any SCSI modules which are specified in
.IR /etc/modules.conf .
Multiple module names must be separated by whitespace characters.
If this option is used multiple times, all specified lists are
concatenated.
.
.TP
.BI \-\-extra= modules
Add
.I modules
to the initramfs image, but do not load them unless they are needed
(unlike modules specified with the
.B \-\-preload
or
.B \-\-with
options, which are always loaded).
The
.BR udevd (8)
instance in initramfs will load the subset of modules appropriate
for the detected hardware.
.
.TP
.BI "\-a " initramfs_filename\fB=\fPfilename
.PD 0
.TP
.PD
.BI "\-\-add=" initramfs_filename\fB=\fPfilename
Add
.I filename
to the initramfs image as
.IR initramfs_filename .
If
.I initramfs_filename
contains multiple directory parts, intermediate directories will be
created automatically.
This option may be used as many times as necessary.
.
.TP
.B \-\-omit\-scsi\-modules
Do not load any scsi modules, including 'scsi_mod' and 'sd_mod'
modules, even if they are present.
.
.TP
.B \-\-omit\-ide\-modules
Do not load any ide modules, even if they are present.
.
.TP
.B \-\-omit\-raid\-modules
Do not load any raid modules, even if
.I /etc/fstab
and
.I /etc/raidtab
expect them.
.
.TP
.B \-\-with\-raid
Add software RAID (md) autorun support to initrd even if
there are no
.I /dev/md*
entries in
.IR /etc/fstab .
If
.I /etc/raidtab
exists, the list of used RAID levels is obtained from there;
otherwise the needed RAID level support modules must be
specified manually using the
.BI \-\-with= module
option.
.
.TP
.B \-\-pause
Pause for manual initrd editing.
.
.TP
.B \-\-nocompress
Do not compress initrd image.
.
.TP
.B \-\-nobootsplash
Do not add bootsplash to the initrd image.
.
.TP
.B \-\-strict
Abort if some required modules were not found.
.
.TP
.B \-\-image\-version
Make image name based on kernel name.
.
.TP
.B \-\-ifneeded
Only builds the image if there are modules that need to be
loaded at boot time.
.
.TP
.B \-\-version
Prints the version of
.B mkinitrd
that's being used and then exits.
.
.TP
.B \-f
.PD 0
.TP
.PD
.B \-\-force
Allows
.B mkinitrd
to overwrite an existing image file.
.
.TP
.B \-v
.PD 0
.TP
.PD
.B \-\-verbose
Prints out verbose information while creating the image
(normally the
.B mkinitrd
runs silently).
.
.TP
.B \-d
.PD 0
.TP
.PD
.B \-\-debug
Prints debug information.
.
.
.SH FILES
.TP
.I /dev/loop*
A block loopback device is used to create the ext2 image.
Block loopback support is not required to create a romfs image.
.TP
.I /etc/modules.conf
Specified SCSI modules to be loaded and module options to be used.
.
.
.SH "SEE ALSO"
.BR fstab (5),
.BR insmod (8),
.BR lilo (8)
.
.
.SH AUTHOR
.nf
Erik Troan <ewt@redhat.com>
Dmitry V. Levin <ldv@altlinux.org>
Sergey Vlasov <vsu@altlinux.org>
.fi
.P
Startup scripts used in initramfs images are derived from the Ubuntu
initramfs-tools package by:
.PP
.RS 4
.nf
Jeff Bailey <jbailey@ubuntu.com>
Adam Conrad <adconrad@ubuntu.com>
Scott James Remnant <scott@ubuntu.com>
maximilian attems <maks@sternwelten.at>
.fi
.RE
mkinitrd-3.0.5/mkinitrd.spec000064400000000000000000000465471071174602400160550ustar00rootroot00000000000000Name: mkinitrd
Version: 3.0.5
Release: alt1.1
Serial: 1

Summary: Creates an initial ramdisk image for preloading modules
License: GPL
Group: System/Kernel and hardware
BuildArch: noarch

Packager: Sergey Vlasov <vsu@altlinux.ru>

Source: %name-%version.tar

PreReq: module-init-tools >= 3.1, mktemp >= 1:1.3.1
PreReq: mkinitrd-busybox >= 1.3.0-alt2
PreReq: coreutils findutils gawk genromfs getopt sed
PreReq: %name-initramfs = %serial:%version-%release
PreReq: klibc-utils-initramfs
PreReq: module-init-tools-initramfs
PreReq: udev-initramfs

# lspci is used for device detection in some cases
Requires: pciutils

%description
Mkinitrd creates filesystem images which are suitable for use as
Linux initial ramdisk (initrd) images. Such images are often used
for preloading the block device modules (such as IDE, SCSI or RAID)
which are needed to access the root filesystem. Mkinitrd automatically
loads IDE modules, all scsi_hostadapter entries in /etc/modules.conf,
and raid modules if the system's root partition is on raid, which
makes it simple to build and use kernels using modular device drivers.

In other words, generic kernels can be built without drivers for any
IDE/SCSI/RAID adapters which load appropriate driver as a module.
Since the kernel needs to read those modules, but in this case it
isn't able to address the IDE/SCSI/RAID adapter, an initial ramdisk
is used. The initial ramdisk is loaded by the operating system loader
(such as LILO or GRUB) and is available to the kernel as soon as the
ramdisk is loaded. The ramdisk image loads the proper IDE/SCSI/RAID
adapter and allows the kernel to mount the root filesystem.
The %name program creates such a ramdisk using information found in
the /etc/modules.conf file.

%package initramfs
Summary: Scripts for initramfs images created by mkinitrd
Group: System/Kernel and hardware
AutoReq: no

%description initramfs
This package contains scripts for initramfs images created by mkinitrd.

%prep
%setup -q

%build
subst -p 's/@VERSION@/%version/g' -- %name

%install
install -pD -m755 %name $RPM_BUILD_ROOT/sbin/%name
install -pD -m644 %name.8 $RPM_BUILD_ROOT%_man8dir/%name.8

mkdir -p %buildroot/lib/mkinitrd/initramfs-base/scripts
install -p -m755 init %buildroot/lib/mkinitrd/initramfs-base/
install -p -m644 scripts/{functions,local,nfs} \
%buildroot/lib/mkinitrd/initramfs-base/scripts/

%files
/sbin/*
%_man8dir/*

%files initramfs
/lib/mkinitrd

%changelog
* Wed Oct 31 2007 Aleksey Avdeev <solo@altlinux.ru> 1:3.0.5-alt1.1
- NMU
- Add --with-evms opion for EVMS activate (#9958)

* Sat Oct 20 2007 Sergey Vlasov <vsu@altlinux.ru> 1:3.0.5-alt1
- Add --extra=MODULES option to add modules to initramfs without loading
(legion@).
- Do not use IGNORE_MODNAMES for modules specified on the command line
(#11956).
- Fix IGNORE_MODNAMES check to avoid broken dependencies (now a module which
is required by other modules cannot be ignored).
- initramfs init: Pass udev version from initramfs to the real system.
- Fix module load ordering issues:
+ load generic IDE module after all other IDE drivers;
+ load ahci before ata_piix if both were detected;
+ load ata_generic and pata_legacy last.
- Use "mdadm --examine --scan" in addition to "mdadm --detail --scan" in RAID
detection; fixes missing RAID 0 modules when using EVMS if arrays were added
to /etc/mdadm.conf (#11282).
- If ext3 root mount failed, try ext2 before giving up (#11174).
- Replace /usr/bin/realpath usage with /bin/readlink -ev.

* Fri Jun 01 2007 Sergey Vlasov <vsu@altlinux.ru> 1:3.0.4-alt1
- Fix NFS root problems (#11374, patch by led@altlinux):
+ create /tmp in initramfs;
+ use DEVICE=eth0 by default;
+ accept root path with explicit server address from DHCP server.

* Thu Mar 29 2007 Sergey Vlasov <vsu@altlinux.ru> 1:3.0.3-alt1
- Fix boot problems with root on /dev/md0 specified by UUID or LABEL
(another part of bug #11190 - race between md_run opening /dev/md0 to
invoke RAID_AUTORUN ioctl and vol_id invoked by udevd).

* Thu Mar 08 2007 Sergey Vlasov <vsu@altlinux.ru> 1:3.0.2-alt1
- Fix compatibility with mdadm >= 2.6.1-alt2: look for the mdadm binary in
/sbin/mdadm before /usr/sbin/mdadm.

* Wed Feb 21 2007 Sergey Vlasov <vsu@altlinux.ru> 1:3.0.1-alt1
- Added firmware loading support for initramfs images (required at least by
the qla2xxx module since kernel 2.6.18). Firmware files listed by
"modinfo -F firmware" are automatically copied to the generated initramfs
image (works with kernels since 2.6.18-std-*-alt4; for older kernels the
"-a" option can be used to add firmware files manually). Fixes #10598.
- Enable RAID support if "mdadm --detail --scan" finds any arrays (fixes
missing RAID support if /dev/md* devices are not listed in fstab
explicitly). Fixes #4997, partially fixes #5955.
- Added warning when RAID support is enabled without any RAID levels.
- Removed "N blocks" garbage output from cpio (added --quiet option).
- Removed garbage output from fbresolution if no framebuffer is present.
- Do not add bootsplash to initrd if the kernel does not support it.

* Thu Feb 08 2007 Sergey Vlasov <vsu@altlinux.ru> 1:3.0.0-alt1
- Added support for creating initramfs images. Now using udevd inside
initramfs; this adds support for mounting root by label or UUID and other
useful features.
- Added mkinitrd-initramfs subpackage with scripts for initramfs.
- Added dependencies on klibc-utils-initramfs, module-init-tools-initramfs,
udev-initramfs packages which contain binaries for initramfs.
- Added support for more software RAID levels: raid10, multipath, faulty.
- Added support for determining used RAID levels with mdadm instead of
obsolete /etc/raidtab file from raidtools.
- Updated software RAID detection by fstab contents to handle partitionable
arrays (/dev/md/dN[pN], /dev/md_dN[pN]).
- Added software RAID support for initramfs images (uses md_run utility from
the klibc-utils-initramfs package, should be compatible with in-kernel
RAID autorun support, but supports only old 0.90 RAID superblocks).
- Added "-a INITRAMFS_FILENAME=FILENAME" option to add extra files to the
generated initramfs image.
- Made initramfs the default image type for kernels >= 2.6.15.

* Sun Jan 21 2007 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.12-alt1
- Always use /lib/mkinitrd for initrd binaries (previously /lib64/mkinitrd
was used on x86_64).
- Require mkinitrd-busybox >= 1.3.0-alt2 due to the /lib/mkinitrd path change.

* Wed Jan 10 2007 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.11-alt1
- Added support for the module-init-tools implementation of modprobe.
Requires ALT-specific modification to module-init-tools which adds the
--ignore-all-commands option to modprobe (without this option module
dependencies may be broken by "install" commands in the configuration).
- Changed autodetection of SCSI modules to use lspci instead of pciscan;
removed dependency on libhw-tools.
- Added Packager: tag.
- Added BuildArch: noarch (the arch-dependent part is in mkinitrd-busybox
for a long time, and this package contains just a shell script).
- Changed dependency on modutils >= 0:2.4.27-alt1 to module-init-tools >= 3.1
(module-init-tools = 3.1 is provided by modutils since 2.4.27-alt3).

* Tue Dec 26 2006 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.10-alt1
- Fixed man page formatting and several typos.
- Added --type=TYPE option to specify initrd filesystem type (#8533).
- Added support for suspend2 2.2.7.2+ (/sys/power/suspend2/do_resume) to
linuxrc (by Andrey Rahmatullin <wrar at altlinux>).
- Refactored root=... and resume=... parsing code in linuxrc in preparation for
initramfs support.
- Added support for all forms of root=... parameter accepted by the kernel
(root=MAJOR:MINOR, root=NUMBER (used by LILO), root=NAME without /dev/).
- Added explicit dependencies on libhw-tools >= 0.2.12-alt1 and pciutils.
- Added warnings about missing /proc and /sys to avoid silently creating an
initrd image without proper drivers.

* Mon Jun 12 2006 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.9-alt1
- Fixed resume= option parser.
- Fixed ext2 size calculation (#8539).
- Fixed rpmbuild warnings due to broken '%%' usage in old changelog entries.
- Removed all %%__* macro abuse from spec.

* Thu Jun 01 2006 Anton Farygin <rider@altlinux.ru> 1:2.9.8-alt1
- Added resume= option parser for swsuspend

* Tue May 17 2005 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.7-alt1
- Added '--kernel-version "$KERNEL"' to the 'modprobe -c' invocation (#6827).

* Fri May 06 2005 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.6-alt1
- Fixed autodetection of SCSI modules:
+ find drivers for all PCI mass storage controllers (class 01) instead of
limiting to 01:00 and 01:04 subclasses (fixes problems with Intel ICHx SATA
controllers, which have IDE subclass, but the driver uses SCSI subsystem);
+ filter out IDE drivers which may be found by the search;
+ do not add sd_mod for other non-SCSI storage drivers which may be found.
- Added Conflicts for old libhw-tools versions (not Requires, because this
dependency is optional - if scsi_hostadapter is specified expicitly in the
configuration file, libhw-tools is not needed).

* Thu Apr 28 2005 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.5-alt1
- Added autodetection of SCSI modules. Autodetection is performed only if no
(alias|probeall) scsi_hostadapter is specified in /etc/modules.conf. Modules
for all PCI devices with classes 01:00 (SCSI storage controller) and 01:04
(RAID bus controller) are added to initrd; /usr/bin/pciscan is used to find
modules in the driver database.

* Tue Mar 22 2005 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.4-alt1
- Load IDE modules before SCSI to keep old configurations with ICH5/6 in
combined mode working (IDE modules must be loaded before ata_piix, otherwise
ata_piix grabs the whole device including legacy IDE ports, and parallel ATA
does not work).
- Updated bootsplash support for new location of utilities (/sbin/splash) and
theme files (/etc/bootsplash).

* Mon Feb 14 2005 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.3-alt1
- Fixed bug in kernel version check.

* Tue Feb 08 2005 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.2-alt1
- Added modular IDE support for kernels >= 2.4.21 (with per-chipset modules).
Both manual configuration with "probeall ide_hostadapter MODULE..." and
automatic detection of required modules for the current system configuration
are supported.
- Added "--with-raid" option to force software RAID autorun support even if
there are no /dev/md* entries in /etc/fstab.
- Added software RAID level 6 support.
- Added /lib64 support for x86_64 (#4888).
- Added /sys to initrd (#5387).
- Fixed problems with unrecognized "root=/dev/..." on 2.6.x kernels: added root
device searching in /proc/partition to the linuxrc script in generated
initrd. In 2.6.x the builtin "root=..." parser works only for drivers which
are built into the kernel.

* Thu Mar 11 2004 Sergey Vlasov <vsu@altlinux.ru> 1:2.9.1-alt1
- Package busybox separately.
- Use "--kernel-release" and "--list-module-files" options from modutils >=
2.4.26-alt1.
- Require modutils >= 2.4.27-alt1 because of bugs in previous versions.
- Removed module tree copying.
- Added module name normalization (y/-/_/) needed for 2.6.x kernels.

* Thu Feb 19 2004 Dmitry V. Levin <ldv@altlinux.org> 1:2.9.0-alt1
- Do not use full path for well-known utilities.
- Look for .ko/.ko.gz modules as well.

* Sun Nov 09 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.9-alt3
- busybox/insmod: backported GPLONLY_ prefix support.

* Fri Oct 17 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.9-alt2
- busybox/insmod: set TAINT_FORCED_MODULE flag only when load is really forced.

* Thu Aug 28 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.9-alt1
- Updated software raid root support (Sergey Vlasov, #2082).
- Updated bootsplash support (fixes #2442).
- Updated busybox to stable-20030828.
- busybox/insmod: added more licenses to gpl compatibility list,
to match modutils >= 2.4.15-alt1 behaviour.

* Tue Aug 12 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.8-alt1
- Added software raid root support (Sergey Vlasov).
- Enhanced modutils config parser (uses "modprobe -c").

* Fri May 02 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.7-alt2
- Updated busybox to 0.60.5, updated busybox patches.

* Mon Mar 24 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.7-alt1
- Updated mkinitrd(8).

* Wed Mar 12 2003 Peter Novodvorsky <nidd@altlinux.com> 1:2.8.6-alt2
- Increased extra initrd image size by 10%%.

* Mon Feb 10 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.6-alt1
- Added bootsplash support (rider).

* Mon Feb 03 2003 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.5-alt1
- Added --pause option (Vladimir Kholmanov <fmfm@symmetron.msk.ru>).

* Tue Oct 29 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.4-alt2
- Rebuilt with new dietlibc.

* Mon Aug 19 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.4-alt1
- Added romfs image support (goldhead).

* Tue Jul 16 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.3-alt2
- Fixed build with new dietlibc.

* Mon Apr 08 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.3-alt1
- Corrected scsimodules/ataraidmodules calculation.

* Fri Feb 22 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.2-alt1
- Copy modules with full path.

* Sat Jan 19 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.1-alt1
- Added "--debug" option for debug messages.
- Cleaned up script to avoid using /usr.
- Updated dependencies.

* Fri Jan 18 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.8.0-alt1
- Use busybox(echo,insmod,losetup,mount,msh) as linuxrc parser.

* Fri Jan 18 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.8-alt1
- Avoid "build" symlinks.

* Wed Jan 16 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.7-alt1
- Added more module namings for new master installer.

* Tue Jan 15 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.6-alt1
- Fixed scsi autodetection for new master installer.

* Mon Jan 14 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.5-alt1
- Use ash.static as linuxrc parser.

* Wed Jan 09 2002 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.4-alt1
- Fixed pre_scsi_modules handling.

* Tue Dec 25 2001 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.3-alt1
- Fixed depmod generation for 2.4 kernels.

* Mon Dec 24 2001 Dmitry V. Levin <ldv@altlinux.org> 1:2.7.2-alt1
- Regular mkinitrd cleanup.
- Forked completely due to patch size.

* Fri Dec 14 2001 Konstantin Volckov <goldhead@altlinux.ru> 2.7.1-alt7
- Added ataraid patch

* Fri Nov 23 2001 Dmitry V. Levin <ldv@altlinux.org> 2.7.1-alt6
- Updates package requires.

* Thu Nov 22 2001 Dmitry V. Levin <ldv@altlinux.org> 2.7.1-alt5
- Added support for nested module dependencies.

* Thu Oct 11 2001 Dmitry V. Levin <ldv@altlinux.ru> 2.7.1-alt4
- Updated versioned dependence on mktemp package.

* Wed Aug 22 2001 Dmitry V. Levin <ldv@altlinux.ru> 2.7.1-alt3
- Removed versioned dependence on glibc package.
- Updated versioned dependence on mktemp package.

* Tue Jul 31 2001 Dmitry V. Levin <ldv@altlinux.ru> 2.7.1-alt2
- IMAGESIZE reservation increased from 2%% to 10%% (goldhead).

* Tue Jul 24 2001 Dmitry V. Levin <ldv@altlinux.ru> 2.7.1-alt1
- Implemented ramdisk size guessing.
- Rewritten command line options parsing.

* Wed Jul 11 2001 Dmitry V. Levin <ldv@altlinux.ru> 2.7-ipl3mdk
- Added --strict option.
- Changed IGNOREMODS list.

* Mon May 07 2001 Dmitry V. Levin <ldv@altlinux.ru> 2.7-ipl2mdk
- Do not load ide-cd module.

* Sun Dec 24 2000 Dmitry V. Levin <ldv@fandra.org> 2.7-ipl1mdk
- 2.7 (added modular ide support).

* Tue Nov 28 2000 Dmitry V. Levin <ldv@fandra.org> 2.6-ipl1mdk
- 2.6
- Merged recent MDK changes into out patch.
- Added unobvious requires.

* Tue Nov 14 2000 Dmitry V. Levin <ldv@fandra.org> 2.5-ipl2mdk
- RE adaptions.

* Wed Aug 23 2000 Thierry Vignaud <tvignaud@mandrakesoft.com> 2.5-2mdk
- bug fix

* Mon Aug 21 2000 Thierry Vignaud <tvignaud@mandrakesoft.com> 2.5-1mdk
- update for hackkernel (new modules layout)
- remove exclusiveos:linux (rms'll be happy)
- make it noarch

* Fri Jul 28 2000 Pixel <pixel@mandrakesoft.com> 2.4.3-3mdk
- modified the mdk patch: don't do "insmod the.o || insmod -f the.o" because
sash doesn't handle it :(

* Wed Jul 19 2000 Pixel <pixel@mandrakesoft.com> 2.4.3-2mdk
- BM

* Sun Jun 25 2000 Pixel <pixel@mandrakesoft.com> 2.4.3-1mdk
- merge with redhat (mainly modules.conf by default)

* Thu Jun 1 2000 Bill Nottingham <notting@redhat.com>
- build on ia64
- bump up initrd size on ia64
- modules.confiscation, /usr/man -> /usr/share/man

* Thu May 25 2000 Chmouel Boudjnah <chmouel@mandrakesoft.com> 2.3.2-16mdk
- Thanks my god initrd work on alpha !!!.

* Tue May 9 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-15mdk
- add possibility to modules to ignore via env var IGNOREMODS

* Wed May 3 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-14mdk
- patch for skipping usb-storage

* Tue Apr 18 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-13mdk
- add handling of non-ext2 root filesytems (again :()

* Mon Apr 17 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-12mdk
- insmod -f instead of insmod

* Sat Mar 25 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-11mdk
- new group

* Sun Mar 19 2000 John Buswell <johnb@mandrakesoft.com> 2.3.2-10mdk
- Added ppc and k7 arch
- Fixed bzipping of man pages

* Mon Mar 13 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-9mdk
- do not require ash.static but sash
- add requires sash >= 3.4

* Mon Mar 13 2000 Pixel <pixel@mandrakesoft.com> 2.3.2-8mdk
- add loopback handling

* Thu Jan 6 2000 Pixel <pixel@mandrakesoft.com>
- fix *buggy* grep scsi_hostadapter on conf.modules

* Mon Jan 3 2000 Pixel <pixel@mandrakesoft.com>
- fix to skip ide-scsi.o (overkill :)

* Tue Dec 28 1999 Pixel <pixel@mandrakesoft.com>
- fix to skip ppa.o and imm.o
- fix a typo

* Tue Oct 19 1999 Chmouel Boudjnah <chmouel@mandrakesoft.com>
- 2.3.2.

* Tue Apr 13 1999 Chmouel Boudjnah <chmouel@mandrakesoft.com>
- Upgrade to 2.0.

* Sat Apr 10 1999 Bernhard Rosenkraenzer <bero@linux-mandrake.com>
- Mandrake adaptions
- bzip2 man/info pages
- add de locale

* Thu Feb 25 1999 Matt Wilson <msw@redhat.com>
- updated description

* Mon Jan 11 1999 Matt Wilson <msw@redhat.com>
- Ignore the absence of scsi modules, include them if they are there, but
don't complain if they are not.
- changed --no-scsi-modules to --omit-scsi-modules (as it should have been)

* Thu Nov 5 1998 Jeff Johnson <jbj@redhat.com>
- import from ultrapenguin 1.1.

* Tue Oct 20 1998 Jakub Jelinek <jj@ultra.linux.cz>
- fix for combined sparc/sparc64 insmod, also pluto module is really
fc4:soc:pluto and we don't look at deps, so special case it.

* Sat Aug 29 1998 Erik Troan <ewt@redhat.com>
- replaced --needs-scsi-mods (which is now the default) with
--omit-scsi-mods

* Fri Aug 7 1998 Jeff Johnson <jbj@redhat.com>
- correct obscure regex/shell interaction (hardwires tabs on line 232)

* Mon Jan 12 1998 Erik Troan <ewt@redhat.com>
- added 'make archive' rule to Makefile
- rewrote install procedure for more robust version handling
- be smarter about grabbing options from /etc/conf.modules

* Mon Oct 20 1997 Erik Troan <ewt@redhat.com>
- made it use /bin/ash.static

* Wed Apr 16 1997 Erik Troan <ewt@redhat.com>
- Only use '-s' to install binaries if /usr/bin/strip is present.
- Use an image size of 2500 if binaries can't be stripped (1500 otherwise)
- Don't use "mount -o loop" anymore -- losetup the proper devices manually
- Requires losetup, e2fsprogs

* Wed Mar 12 1997 Michael K. Johnson <johnsonm@redhat.com>
- Fixed a bug in parsing options.
- Changed to use a build tree, then copy the finished tree into the
image after it is built.
- Added patches derived from ones written by Christian Hechelmann which
add an option to put the kernel version number at the end of the module
name and use install -s to strip binaries on the fly.
mkinitrd-3.0.5/scripts/000075500000000000000000000000001071174602400150275ustar00rootroot00000000000000mkinitrd-3.0.5/scripts/functions000064400000000000000000000036331071174602400167670ustar00rootroot00000000000000# -*- shell-script -*-

_log_msg()
{
if [ "$quiet" = "y" ]; then return; fi
echo "$@"
}

log_success_msg()
{
_log_msg "Success: $@"
}

log_failure_msg()
{
_log_msg "Failure: $@"
}

log_warning_msg()
{
_log_msg "Warning: $@"
}

log_begin_msg()
{
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "TEXT $@"
fi
_log_msg "Begin: $@ ..."
}

log_end_msg()
{
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "SUCCESS ok"
fi
_log_msg "Done."
update_progress
}

update_progress()
{
[ -d /dev/.initramfs ] || return

if [ -z "$PROGRESS_STATE" ]; then
export PROGRESS_STATE=0
fi

PROGRESS_STATE=$(($PROGRESS_STATE + 1))
echo "PROGRESS_STATE=${PROGRESS_STATE}" > /dev/.initramfs/progress_state

if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "PROGRESS $PROGRESS_STATE"
fi
}

panic()
{
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "QUIT"
fi
# Disallow console access
if [ "${panic}" = 0 ]; then
reboot
fi
modprobe -q i8042
modprobe -q atkbd
echo $@
PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1
}

maybe_break()
{
if [ x$1 = x${break} ]; then
panic "Spawning shell within the initramfs"
fi
}

run_scripts()
{
if [ -r "$1" ]; then
[ "$quiet" != "y" ] && log_begin_msg "Running $1"
. "$1"
[ "$quiet" != "y" ] && log_end_msg
fi
}

# Load custom modules first
load_modules()
{
if [ -e /conf/modules ]; then
cat /conf/modules | while read m; do
# Skip empty lines
if [ -z "$m" ]; then
continue
fi
# Skip comments - d?ash removes whitespace prefix
com=$(printf "%.1s" "${m}")
if [ "$com" = "#" ]; then
continue
fi
modprobe -q $m
done
fi
}

# lilo compatibility
parse_numeric() {
case $1 in
"")
return
;;
/*)
return
;;
*:*)
minor=${1#*:}
major=${1%:*}
;;
*)
value=$(( 0x${1} ))
minor=$(( ${value} % 256 ))
major=$(( ${value} / 256 ))
;;
esac

mknod /dev/root b ${major} ${minor}
ROOT=/dev/root
}
mkinitrd-3.0.5/scripts/local000064400000000000000000000053211071174602400160450ustar00rootroot00000000000000# Local filesystem mounting -*- shell-script -*-

# wait_for_device <filename> <text>
wait_for_device ()
{
if [ ! -e "$1" ]; then
log_begin_msg "$2"

# Default delay is 180s
if [ -z "${ROOTDELAY}" ]; then
slumber=180
else
slumber=${ROOTDELAY}
fi
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "TIMEOUT ${slumber}" || true
fi

slumber=$(( ${slumber} * 10 ))
while [ ${slumber} -gt 0 ] && [ ! -e "${ROOT}" ]; do
/bin/sleep 0.1
slumber=$(( ${slumber} - 1 ))
done

if [ ${slumber} -gt 0 ]; then
log_end_msg 0
else
log_end_msg 1 || true
fi
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "TIMEOUT 15" || true
fi
fi
}

try_to_resume ()
{
[ -n "$resume" ] || return 0

[ -e /sys/power/resume ] || {
log_warning_msg "Kernel does not support resume - doing normal boot"
return 0
}

if [ ! -e "${resume}" ]; then
wait_for_device "$resume" "Waiting for resume device"
fi

if [ -e "$resume" ]; then
# hardcode path, uswsusp ships an resume binary too
/bin/resume "$resume"
else
log_warning_msg "Resume device $resume not found - doing normal boot"
fi
}

try_to_resume2 ()
{
[ -n "$resume2" ] || return 0

[ -e /sys/power/suspend2/do_resume ] || {
log_warning_msg "Kernel does not support resume"
return 0
}

echo > /sys/power/suspend2/do_resume
}

# Parameter: Where to mount the filesystem
mountroot ()
{
run_scripts /scripts/local-top

# Try to resume before touching the root device
try_to_resume
try_to_resume2

# If the root device hasn't shown up yet, give it a little while
# to deal with removable devices
wait_for_device "$ROOT" "Waiting for root file system"

# We've given up, but we'll let the user fix matters if they can
while [ ! -e "${ROOT}" ]; do
echo " Check root= bootarg cat /proc/cmdline"
echo " or missing modules, devices: cat /proc/modules ls /dev"
panic "ALERT! ${ROOT} does not exist. Dropping to a shell!"
done

# Get the root filesystem type if not set
if [ -z "${ROOTFSTYPE}" ]; then
eval $(fstype < ${ROOT})
else
FSTYPE=${ROOTFSTYPE}
fi
if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then
FSTYPE=$(/lib/udev/vol_id -t ${ROOT})
[ -z "$FSTYPE" ] && FSTYPE="unknown"
fi

run_scripts /scripts/local-premount

if [ ${readonly} = y ]; then
roflag=-r
else
roflag=-w
fi

# FIXME This has no error checking
modprobe -qb ${FSTYPE}

# Mount root
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt} || {
[ "${FSTYPE}" = "ext3" ] && {
log_warning_msg "Trying to mount $ROOT as ext2 instead of ext3"
modprobe -qb ext2
mount ${roflag} -t ext2 ${ROOTFLAGS} ${ROOT} ${rootmnt}
}
} ||
panic "Unable to mount $ROOT as $FSTYPE. Dropping to a shell!"

run_scripts /scripts/local-bottom
}
mkinitrd-3.0.5/scripts/nfs000064400000000000000000000042541071174602400155450ustar00rootroot00000000000000# NFS filesystem mounting -*- shell-script -*-

# FIXME This needs error checking

retry_nr=0
DEVICE=${DEVICE:-eth0}

# parse nfs bootargs + launch ipconfig and nfsmount
do_nfsmount()
{
# support ip options see linux sources Documentation/nfsroot.txt
case ${IPOPTS} in
none|off)
# Do nothing
;;
""|on|any)
# Bring up device
ipconfig ${DEVICE}
;;
dhcp|bootp|rarp|both)
ipconfig -c ${IPOPTS} -d ${DEVICE}
;;
*)
ipconfig -d $IPOPTS

# grab device entry from ip option
NEW_DEVICE=${IPOPTS#*:*:*:*:*:*}
if [ "${NEW_DEVICE}" != "${IPOPTS}" ]; then
NEW_DEVICE=${NEW_DEVICE%:*}
else
# wrong parse, possibly only a partial string
NEW_DEVICE=
fi
if [ -n "${NEW_DEVICE}" ]; then
DEVICE="${NEW_DEVICE}"
fi
;;
esac

# source relevant ipconfig output
. /tmp/net-${DEVICE}.conf

# get nfs root from dhcp
if [ "x${NFSROOT}" = "xauto" ]; then
NFSROOT="${ROOTPATH}"
if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then
NFSROOT="${ROOTSERVER}:${ROOTPATH}"
fi
# nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
elif [ -n "${NFSROOT}" ]; then
# nfs options are an optional arg
if [ "${NFSROOT#*,}" != "${NFSROOT}" ]; then
NFSOPTS="-o ${NFSROOT#*,}"
fi
NFSROOT=${NFSROOT%%,*}
if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then
NFSROOT=${ROOTSERVER}:${NFSROOT}
fi
fi

if [ -z "${NFSOPTS}" ]; then
NFSOPTS="-o retrans=10"
fi

run_scripts /scripts/nfs-premount

if [ ${readonly} = y ]; then
roflag="-o ro"
else
roflag="-o rw"
fi

nfsmount -o nolock ${roflag} ${NFSOPTS} ${NFSROOT} ${rootmnt}
}

# NFS root mounting
mountroot()
{
run_scripts /scripts/nfs-top

modprobe -q nfs
# For DHCP
modprobe -q af_packet

# Default delay is around 180s
# FIXME: add usplash_write info
if [ -z "${ROOTDELAY}" ]; then
delay=180
else
delay=${ROOTDELAY}
fi

# loop until nfsmount succeds
while [ ${retry_nr} -lt ${delay} ] && [ ! -e ${rootmnt}${init} ]; do
[ ${retry_nr} -gt 0 ] && \
[ "$quiet" != "y" ] && log_begin_msg "Retrying nfs mount"
do_nfsmount
retry_nr=$(( ${retry_nr} + 1 ))
[ ! -e ${rootmnt}${init} ] && /bin/sleep 1
[ ${retry_nr} -gt 0 ] && [ "$quiet" != "y" ] && log_end_msg
done

run_scripts /scripts/nfs-bottom
}
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin