114 lines
3.6 KiB
Plaintext
114 lines
3.6 KiB
Plaintext
This document describes one way to create the initrd directory hierarchy
|
|
in order to allow an initrd to be built into your kernel. The trick
|
|
here is to steal the initrd file used on your Linux laptop, Ubuntu in
|
|
this case. There are probably much better ways of doing this.
|
|
|
|
That said, here are the commands:
|
|
|
|
------------------------------------------------------------------------
|
|
cd tools/testing/selftests/rcutorture
|
|
zcat /initrd.img > /tmp/initrd.img.zcat
|
|
mkdir initrd
|
|
cd initrd
|
|
cpio -id < /tmp/initrd.img.zcat
|
|
------------------------------------------------------------------------
|
|
|
|
Another way to create an initramfs image is using "dracut"[1], which is
|
|
available on many distros, however the initramfs dracut generates is a cpio
|
|
archive with another cpio archive in it, so an extra step is needed to create
|
|
the initrd directory hierarchy.
|
|
|
|
Here are the commands to create a initrd directory for rcutorture using
|
|
dracut:
|
|
|
|
------------------------------------------------------------------------
|
|
dracut --no-hostonly --no-hostonly-cmdline --module "base bash shutdown" /tmp/initramfs.img
|
|
cd tools/testing/selftests/rcutorture
|
|
mkdir initrd
|
|
cd initrd
|
|
/usr/lib/dracut/skipcpio /tmp/initramfs.img | zcat | cpio -id < /tmp/initramfs.img
|
|
------------------------------------------------------------------------
|
|
|
|
Interestingly enough, if you are running rcutorture, you don't really
|
|
need userspace in many cases. Running without userspace has the
|
|
advantage of allowing you to test your kernel independently of the
|
|
distro in place, the root-filesystem layout, and so on. To make this
|
|
happen, put the following script in the initrd's tree's "/init" file,
|
|
with 0755 mode.
|
|
|
|
------------------------------------------------------------------------
|
|
#!/bin/sh
|
|
|
|
[ -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 sysfs /sys
|
|
mount -t proc -o nodev,noexec,nosuid proc /proc
|
|
# Some things don't work properly without /etc/mtab.
|
|
ln -sf /proc/mounts /etc/mtab
|
|
|
|
# Note that this only becomes /dev on the real filesystem if udev's scripts
|
|
# are used; which they will be, but it's worth pointing out
|
|
if ! mount -t devtmpfs -o mode=0755 udev /dev; then
|
|
echo "W: devtmpfs not available, falling back to tmpfs for /dev"
|
|
mount -t tmpfs -o mode=0755 udev /dev
|
|
[ -e /dev/console ] || mknod --mode=600 /dev/console c 5 1
|
|
[ -e /dev/kmsg ] || mknod --mode=644 /dev/kmsg c 1 11
|
|
[ -e /dev/null ] || mknod --mode=666 /dev/null c 1 3
|
|
fi
|
|
|
|
mkdir /dev/pts
|
|
mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
|
|
mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
|
|
mkdir /run/initramfs
|
|
# compatibility symlink for the pre-oneiric locations
|
|
ln -s /run/initramfs /dev/.initramfs
|
|
|
|
# Export relevant variables
|
|
export ROOT=
|
|
export ROOTDELAY=
|
|
export ROOTFLAGS=
|
|
export ROOTFSTYPE=
|
|
export IP=
|
|
export BOOT=
|
|
export BOOTIF=
|
|
export UBIMTD=
|
|
export break=
|
|
export init=/sbin/init
|
|
export quiet=n
|
|
export readonly=y
|
|
export rootmnt=/root
|
|
export debug=
|
|
export panic=
|
|
export blacklist=
|
|
export resume=
|
|
export resume_offset=
|
|
export recovery=
|
|
|
|
for i in /sys/devices/system/cpu/cpu*/online
|
|
do
|
|
case $i in
|
|
'/sys/devices/system/cpu/cpu0/online')
|
|
;;
|
|
'/sys/devices/system/cpu/cpu*/online')
|
|
;;
|
|
*)
|
|
echo 1 > $i
|
|
;;
|
|
esac
|
|
done
|
|
|
|
while :
|
|
do
|
|
sleep 10
|
|
done
|
|
------------------------------------------------------------------------
|
|
|
|
References:
|
|
[1]: https://dracut.wiki.kernel.org/index.php/Main_Page
|
|
[2]: http://blog.elastocloud.org/2015/06/rapid-linux-kernel-devtest-with-qemu.html
|
|
[3]: https://www.centos.org/forums/viewtopic.php?t=51621
|