Merge branch 'test' into merge
commit
c15d160d09
|
@ -1,2 +1,5 @@
|
|||
test*.img
|
||||
modules.d/99base/switch_root
|
||||
test/initramfs.testing
|
||||
test/root.ext2
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -35,7 +35,7 @@ rpm: dracut-$(VERSION)-$(GITVERSION).tar.bz2
|
|||
test: test/root.ext2 all
|
||||
sudo test/test-initramfs
|
||||
|
||||
test/root.ext2: test/test-init test/make-test-root all
|
||||
test/root.ext2: test/test-init test/make-test-root
|
||||
sudo test/make-test-root
|
||||
|
||||
testimage: all
|
||||
|
|
6
dracut
6
dracut
|
@ -19,6 +19,7 @@ while (($# > 0)); do
|
|||
-c|--conf) conffile="$2"; shift;;
|
||||
-l|--local) allowlocal="yes" ;;
|
||||
-h|--hostonly) hostonly="-h" ;;
|
||||
-i|--include) include_src="$2"; include_target="$3"; shift 2;;
|
||||
--skip-missing) skipmissing="yes" ;;
|
||||
*) break ;;
|
||||
esac
|
||||
|
@ -102,4 +103,9 @@ unset moddir
|
|||
# make sure that library links are correct and up to date
|
||||
ldconfig -n -r "$initdir" /lib* /usr/lib*
|
||||
|
||||
[[ $include_src && $include_target ]] && {
|
||||
mkdir -p "$initdir$include_target"
|
||||
cp -a -t "$initdir$include_target" "$include_src"/*
|
||||
}
|
||||
|
||||
( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
|
||||
|
|
|
@ -140,8 +140,8 @@ find_rule() {
|
|||
# udev rules always get installed in the same place, so
|
||||
# create a function to install them to make life simpler.
|
||||
inst_rules() {
|
||||
local target="/lib/udev/rules.d"
|
||||
[[ -d $target ]] || target="/etc/udev/rules.d"
|
||||
local target="/etc/udev/rules.d"
|
||||
mkdir -p "$initdir/lib/udev/rules.d" "$initdir$target"
|
||||
for rule in "$@"; do
|
||||
rule=$(find_rule $rule) && \
|
||||
inst_simple "$rule" "$target/${rule##*/}"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/bin/bash
|
||||
# Prefer dash as /bin/sh if it is available.
|
||||
inst /bin/dash
|
||||
ln -sf /bin/dash "${initdir}/bin/sh"
|
||||
inst /bin/dash && ln -sf dash "${initdir}/bin/sh"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
exit 1
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
cp -a -t "$NEWROOT" /source/*
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
sfdisk /dev/sda <<EOF
|
||||
|
||||
;
|
||||
;
|
||||
;
|
||||
EOF
|
||||
cryptsetup -q luksFormat /dev/sda1 <<EOF
|
||||
test
|
||||
EOF
|
||||
cryptsetup luksOpen /dev/sda1 dracut_crypt_test <<EOF
|
||||
test
|
||||
EOF
|
||||
lvm pvcreate -ff -y /dev/mapper/dracut_crypt_test
|
||||
lvm vgcreate dracut /dev/mapper/dracut_crypt_test
|
||||
lvm lvcreate -l 100%FREE -n root dracut
|
||||
udevadm settle --timeout=4
|
||||
[ -b /dev/dracut/root ] || emergency_shell
|
||||
mke2fs /dev/dracut/root
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
umount "$NEWROOT"
|
||||
lvm lvchange -a n /dev/dracut/root
|
||||
cryptsetup luksClose /dev/mapper/dracut_crypt_test
|
||||
poweroff -f
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
dracut_install sfdisk mke2fs poweroff cp umount
|
||||
inst_hook pre-pivot 02 "$moddir/halt.sh"
|
||||
inst_hook pre-pivot 01 "$moddir/copy-root.sh"
|
||||
inst_hook pre-mount 01 "$moddir/create-root.sh"
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
inst cryptsetup
|
||||
instmods dm_crypt cbc aes sha256
|
||||
inst_rules "$moddir/63-luks.rules"
|
||||
inst "$moddir"/cryptroot-ask.sh /lib/udev/cryptroot-ask
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
# FIXME: hard-coded module list of doom.
|
||||
instmods ${modules:-=ata =block =drm dm-crypt aes sha256 cbc sd_mod}
|
||||
instmods ${modules:-=ata =block sd_mod =fs}
|
||||
|
||||
# Grab modules for all filesystem types we currently have mounted
|
||||
while read d mp t rest; do
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
inst_hook pre-udev 10 "$moddir/parse-resume.sh"
|
||||
inst_hook mount 90 "$moddir/resume.sh"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
if resume=$(getarg resume=) && ! getarg noresume; then
|
||||
export resume
|
||||
echo "$resume" >/.resume
|
||||
else
|
||||
unset resume
|
||||
fi
|
|
@ -1,7 +1,8 @@
|
|||
#!/bin/sh
|
||||
resume=$(getarg resume=) && ! getarg noresume && [ -b "$resume" ] && {
|
||||
[ -s /.resume -a -b "$resume" ] && {
|
||||
# parsing the output of ls is Bad, but until there is a better way...
|
||||
ls -lH "$resume" | (
|
||||
read x x x x maj min x;
|
||||
echo "${maj%,}:$min"> /sys/power/resume)
|
||||
>/.resume
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
resume=$(getarg resume=) && ! getarg noresume && [ -b "$resume" ] && {
|
||||
# parsing the output of ls is Bad, but until there is a better way...
|
||||
(
|
||||
echo -e 'KERNEL=="'${resume#/dev/}'", RUN+="/bin/sh -c \047 echo %M:%m > /sys/power/resume \047 "'
|
||||
echo -e 'SYMLINK=="'${resume#/dev/}'", RUN+="/bin/sh -c \047 echo %M:%m > /sys/power/resume \047 "'
|
||||
) >> /etc/udev/rules.d/99-resume.rules
|
||||
}
|
||||
|
||||
(
|
||||
echo -e 'KERNEL=="'${root#/dev/}'", RUN+="/bin/sh -c \047 mount '$fstype' -o '$rflags' '$root' '$NEWROOT' \047 " '
|
||||
echo -e 'SYMLINK=="'${root#/dev/}'", RUN+="/bin/sh -c \047 mount '$fstype' -o '$rflags' '$root' '$NEWROOT' \047 " '
|
||||
) >> /etc/udev/rules.d/99-mount.rules
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
inst_hook pre-udev 10 "$moddir/parse-root-opts.sh"
|
||||
inst_hook pre-udev 20 "$moddir/genrules.sh"
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
if resume=$(getarg resume=) && ! getarg noresume; then
|
||||
export resume
|
||||
echo "$resume" >/.resume
|
||||
else
|
||||
unset resume
|
||||
fi
|
||||
|
||||
root=$(getarg root=)
|
||||
case $root in
|
||||
LABEL=*) root=${root#LABEL=}
|
||||
root="$(echo $root |sed 's,/,\\x2f,g')"
|
||||
root="/dev/disk/by-label/${root}" ;;
|
||||
UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
|
||||
'') echo "Warning: no root specified"
|
||||
root="/dev/sda1" ;;
|
||||
esac
|
||||
|
||||
if rflags="$(getarg rootflags=)"; then
|
||||
getarg rw && rflags="${rflags},rw" || rflags="${rflags},ro"
|
||||
else
|
||||
getarg rw && rflags=rw || rflags=ro
|
||||
fi
|
||||
|
||||
fstype="$(getarg rootfstype=)" && fstype="-t ${fstype}"
|
||||
|
||||
export fstype rflags root
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
inst_hook pre-udev 10 "$moddir/parse-root-opts.sh"
|
||||
inst_hook mount 99 "$moddir/mount-root.sh"
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
if [ ! -s /.resume -a "$root" ]; then
|
||||
mount $fstype -o "$rflags" "$root" "$NEWROOT" && ROOTFS_MOUNTED=yes
|
||||
fi
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
if resume=$(getarg resume=) && ! getarg noresume; then
|
||||
export resume
|
||||
echo "$resume" >/.resume
|
||||
else
|
||||
unset resume
|
||||
fi
|
||||
|
||||
root=$(getarg root=)
|
||||
case $root in
|
||||
LABEL=*) root=${root#LABEL=}
|
||||
root="$(echo $root |sed 's,/,\\x2f,g')"
|
||||
root="/dev/disk/by-label/${root}" ;;
|
||||
UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
|
||||
'') echo "Warning: no root specified"
|
||||
root="/dev/sda1" ;;
|
||||
esac
|
||||
|
||||
if rflags="$(getarg rootflags=)"; then
|
||||
getarg rw && rflags="${rflags},rw" || rflags="${rflags},ro"
|
||||
else
|
||||
getarg rw && rflags=rw || rflags=ro
|
||||
fi
|
||||
|
||||
fstype="$(getarg rootfstype=)" && fstype="-t ${fstype}"
|
||||
|
||||
export fstype rflags root
|
|
@ -28,7 +28,6 @@ source_all() {
|
|||
for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done
|
||||
}
|
||||
|
||||
echo "Starting initrd..."
|
||||
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||
export TERM=linux
|
||||
NEWROOT="/sysroot"
|
||||
|
@ -43,7 +42,7 @@ mount -t sysfs /sys /sys >/dev/null 2>&1
|
|||
mount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1
|
||||
|
||||
read CMDLINE </proc/cmdline;
|
||||
|
||||
getarg ramfsdebug && set -x
|
||||
# Make some basic devices first, let udev handle the rest
|
||||
mknod /dev/ptmx c 5 2
|
||||
mknod /dev/console c 5 1
|
||||
|
@ -54,46 +53,10 @@ mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1
|
|||
getarg 'break=pre-udev' && emergency_shell
|
||||
source_all pre-udev
|
||||
|
||||
|
||||
[ "$root" ] || {
|
||||
root=$(getarg root=)
|
||||
case $root in
|
||||
LABEL=*) root=${root#LABEL=}
|
||||
root="$(echo $root |sed 's,/,\\x2f,g')"
|
||||
root="/dev/disk/by-label/${root}" ;;
|
||||
UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
|
||||
'') echo "Warning: no root specified"
|
||||
root="/dev/sda1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
[ "$rflags" ] || {
|
||||
if rflags="$(getarg rootflags=)"; then
|
||||
getarg rw && rflags="${rflags},rw" || rflags="${rflags},ro"
|
||||
else
|
||||
getarg rw && rflags=rw || rflags=ro
|
||||
fi
|
||||
}
|
||||
|
||||
[ "$fstype" ] || {
|
||||
fstype="$(getarg rootfstype=)" && fstype="-t ${fstype}"
|
||||
}
|
||||
|
||||
resume=$(getarg resume=) && ! getarg noresume && [ -b "$resume" ] && {
|
||||
# parsing the output of ls is Bad, but until there is a better way...
|
||||
(
|
||||
echo -e 'NAME=="'${resume#/dev/}'", RUN+="/bin/sh -c \047 echo %M:%m > /sys/power/resume \047 "'
|
||||
echo -e 'SYMLINK=="'${resume#/dev/}'", RUN+="/bin/sh -c \047 echo %M:%m > /sys/power/resume \047 "'
|
||||
) >> /lib/udev/rules.d/99-resume.rules
|
||||
}
|
||||
|
||||
(
|
||||
echo -e ' NAME=="'${root#/dev/}'", RUN+="/bin/sh -c \047 mount '$fstype' -o '$rflags' '$root' '$NEWROOT' \047 " '
|
||||
echo -e ' SYMLINK=="'${root#/dev/}'", RUN+="/bin/sh -c \047 mount '$fstype' -o '$rflags' '$root' '$NEWROOT' \047 " '
|
||||
) >> /lib/udev/rules.d/99-mount.rules
|
||||
|
||||
# start up udev and trigger cold plugs
|
||||
udevd --daemon
|
||||
getarg udevinfo && udevadm control --log_priority=info
|
||||
getarg udevdebug && udevadm control --log_priority=debug
|
||||
udevadm trigger >/dev/null 2>&1
|
||||
udevadm settle --timeout=30 >/dev/null 2>&1
|
||||
|
||||
|
@ -114,14 +77,18 @@ while :; do
|
|||
[ "$ROOTFS_MOUNTED" ] && break;
|
||||
done
|
||||
|
||||
sleep 1
|
||||
sleep 0.5
|
||||
i=$(($i+1))
|
||||
(
|
||||
flock -s 200
|
||||
[ $i -gt 10 ] && emergency_shell
|
||||
[ $i -gt 20 ] && emergency_shell
|
||||
) 200>/.console_lock
|
||||
done
|
||||
|
||||
# pre pivot scripts are sourced just before we switch over to the new root.
|
||||
getarg 'break=pre-pivot' && emergency_shell
|
||||
source_all pre-pivot
|
||||
|
||||
# by the time we get here, the root filesystem should be mounted.
|
||||
# Try to find init.
|
||||
for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
|
||||
|
@ -133,15 +100,13 @@ done
|
|||
emergency_shell
|
||||
}
|
||||
|
||||
# pre pivot scripts are sourced just before we switch over to the new root.
|
||||
getarg 'break=pre-pivot' && emergency_shell
|
||||
source_all pre-pivot
|
||||
getarg break && emergency_shell
|
||||
kill $(pidof udevd)
|
||||
echo "Switching to real root filesystem $root"
|
||||
initargs=""
|
||||
for x in $CMDLINE; do
|
||||
[ "${x%%=*}" = "console" -o "${x%%=*}" = "BOOT_IMAGE" ] && continue
|
||||
for x in "$@"; do
|
||||
[ "${x%%=*}" = "console" ] && continue
|
||||
[ "${x%%=*}" = "BOOT_IMAGE" ] && continue
|
||||
[ "${x%%=*}" = "break" ] && continue
|
||||
initargs="$initargs $x"
|
||||
done
|
||||
exec switch_root "$NEWROOT" "$INIT" $initargs || {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#!/bin/bash
|
||||
dracut_install mount mknod mkdir modprobe pidof sleep chroot echo sed sh ls flock
|
||||
dracut_install mount mknod mkdir modprobe pidof sleep chroot echo sed bash ls flock
|
||||
[ -e "${initdir}/bin/sh" ] || (ln -s bash "${initdir}/bin/sh" || :)
|
||||
# install our scripts and hooks
|
||||
inst "$moddir/init" "/init"
|
||||
inst "$moddir/switch_root" "/sbin/switch_root"
|
||||
inst_hook pre-mount 10 "$moddir/parse-root-opts.sh"
|
||||
inst_hook pre-pivot 50 "$moddir/selinux-loadpolicy.sh"
|
||||
inst_hook mount 90 "$moddir/resume.sh"
|
||||
inst_hook mount 99 "$moddir/mount-root.sh"
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
[ "$root" ] && mount $fstype -o "$rflags" "$root" "$NEWROOT" && \
|
||||
ROOTFS_MOUNTED=yes
|
|
@ -1,24 +0,0 @@
|
|||
#!/bin/sh
|
||||
[ "$root" ] || {
|
||||
root=$(getarg root=)
|
||||
case $root in
|
||||
LABEL=*) root=${root#LABEL=}
|
||||
root="$(echo $root |sed 's,/,\\x2f,g')"
|
||||
root="/dev/disk/by-label/${root}" ;;
|
||||
UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
|
||||
'') echo "Warning: no root specified"
|
||||
root="/dev/sda1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
[ "$rflags" ] || {
|
||||
if rflags="$(getarg rootflags=)"; then
|
||||
getarg rw && rflags="${rflags},rw" || rflags="${rflags},ro"
|
||||
else
|
||||
getarg rw && rflags=rw || rflags=ro
|
||||
fi
|
||||
}
|
||||
|
||||
[ "$fstype" ] || {
|
||||
fstype="$(getarg rootfstype=)" && fstype="-t ${fstype}"
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
dracutmodules="kernel-modules udev-rules base"
|
||||
dracutmodules="base dash crypt lvm kernel-modules resume rootfs-block 95rootfs-block-udev udev-rules"
|
||||
modules="ata_piix ext2 sd_mod"
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
#!/bin/bash
|
||||
. ./dracut-functions
|
||||
readonly initdir=$(mktemp -d -t initramfs-test-XXXXXXXX)
|
||||
readonly mnttarget=$(mktemp -d -t initramfs-test-target-XXXXXXXX)
|
||||
trap 'rm -rf "$initdir"' 0
|
||||
dracut_install sh df free ls shutdown poweroff stty cat ps ln \
|
||||
/lib/terminfo/l/linux mount dmesg
|
||||
inst test/test-init /sbin/init
|
||||
dd if=/dev/zero of=test/root.ext2 bs=1M count=10
|
||||
|
||||
dd if=/dev/zero of=test/root.ext2 bs=1M count=20
|
||||
mke2fs -F test/root.ext2
|
||||
mount -o loop -t ext2 test/root.ext2 "$mnttarget"
|
||||
cp -a -t "$mnttarget" "$initdir"/*
|
||||
(cd "$mnttarget"; mkdir -p dev sys proc etc)
|
||||
umount -l "$mnttarget"
|
||||
rm -rf "$mnttarget" "$initdir"
|
||||
mkdir test/mnt
|
||||
mount -o loop test/root.ext2 test/mnt
|
||||
|
||||
initdir=test/mnt
|
||||
kernel=$(uname -r)
|
||||
(
|
||||
. ./dracut-functions
|
||||
dracut_install sh df free ls shutdown poweroff stty cat ps ln \
|
||||
/lib/terminfo/l/linux mount dmesg
|
||||
inst test/test-init /sbin/init
|
||||
(cd "$initdir"; mkdir -p dev sys proc etc)
|
||||
)
|
||||
targetfs="$initdir"
|
||||
unset initdir
|
||||
|
||||
umount test/mnt
|
||||
rmdir test/mnt
|
||||
|
||||
#./dracut -l -i "$targetfs" /source \
|
||||
# -m "dash kernel-modules test crypt lvm udev-rules base rootfs-block" \
|
||||
# -d "ata_piix ext2 sd_mod" \
|
||||
# -f test/initramfs.makeroot
|
||||
#
|
||||
#qemu-kvm -hda test/root.ext2 -m 512M -nographic -net none \
|
||||
# -kernel "/boot/vmlinuz-$kernel" \
|
||||
# -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
|
||||
# -initrd test/initramfs.makeroot
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#!/bin/sh
|
||||
exec >/dev/console 2>&1
|
||||
export TERM=linux
|
||||
ln -s /proc/mounts /etc/mtab
|
||||
export PS1='initramfs-test:\w\$'
|
||||
export PS1='initramfs-test:\w\$ '
|
||||
[ -f /etc/fstab ] || ln -s /proc/mounts /etc/fstab
|
||||
stty sane
|
||||
echo "made it to the rootfs!"
|
||||
echo 3 >/proc/sys/vm/drop_caches
|
||||
free
|
||||
sh -i
|
||||
mount -o remount,ro /
|
||||
mount -n -o remount,ro /
|
||||
poweroff -f
|
|
@ -3,7 +3,7 @@ kernel=$(uname -r)
|
|||
[[ -f test/root.ext2 ]] || test/make-test-root
|
||||
./dracut -c test/dracut.conf.test -l -f test/initramfs.testing || exit
|
||||
|
||||
exec qemu-kvm -hda test/root.ext2 -nographic -net none \
|
||||
qemu-kvm -hda test/root.ext2 -m 512M -nographic -net none \
|
||||
-kernel /boot/vmlinuz-$kernel \
|
||||
-append "root=/dev/sda rw rootfstype=ext2 console=ttyS0,115200n81 quiet" \
|
||||
-initrd test/initramfs.testing
|
||||
-append "root=/dev/sda init=/init rw rootfstype=ext2 quiet ramfsdebug console=ttyS0,115200n81" \
|
||||
-initrd test/initramfs.testing
|
||||
|
|
Loading…
Reference in New Issue