1 This document describes one way to create the initrd directory hierarchy
2 in order to allow an initrd to be built into your kernel. The trick
3 here is to steal the initrd file used on your Linux laptop, Ubuntu in
4 this case. There are probably much better ways of doing this.
6 That said, here are the commands:
8 ------------------------------------------------------------------------
9 cd tools/testing/selftests/rcutorture
10 zcat /initrd.img > /tmp/initrd.img.zcat
13 cpio -id < /tmp/initrd.img.zcat
14 ------------------------------------------------------------------------
16 Another way to create an initramfs image is using "dracut"[1], which is
17 available on many distros, however the initramfs dracut generates is a cpio
18 archive with another cpio archive in it, so an extra step is needed to create
19 the initrd directory hierarchy.
21 Here are the commands to create a initrd directory for rcutorture using
24 ------------------------------------------------------------------------
25 dracut --no-hostonly --no-hostonly-cmdline --module "base bash shutdown" /tmp/initramfs.img
26 cd tools/testing/selftests/rcutorture
29 /usr/lib/dracut/skipcpio /tmp/initramfs.img | zcat | cpio -id < /tmp/initramfs.img
30 ------------------------------------------------------------------------
32 Interestingly enough, if you are running rcutorture, you don't really
33 need userspace in many cases. Running without userspace has the
34 advantage of allowing you to test your kernel independently of the
35 distro in place, the root-filesystem layout, and so on. To make this
36 happen, put the following script in the initrd's tree's "/init" file,
39 ------------------------------------------------------------------------
42 [ -d /dev ] || mkdir -m 0755 /dev
43 [ -d /root ] || mkdir -m 0700 /root
44 [ -d /sys ] || mkdir /sys
45 [ -d /proc ] || mkdir /proc
46 [ -d /tmp ] || mkdir /tmp
48 mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
49 mount -t proc -o nodev,noexec,nosuid proc /proc
50 # Some things don't work properly without /etc/mtab.
51 ln -sf /proc/mounts /etc/mtab
53 # Note that this only becomes /dev on the real filesystem if udev's scripts
54 # are used; which they will be, but it's worth pointing out
55 if ! mount -t devtmpfs -o mode=0755 udev /dev; then
56 echo "W: devtmpfs not available, falling back to tmpfs for /dev"
57 mount -t tmpfs -o mode=0755 udev /dev
58 [ -e /dev/console ] || mknod --mode=600 /dev/console c 5 1
59 [ -e /dev/kmsg ] || mknod --mode=644 /dev/kmsg c 1 11
60 [ -e /dev/null ] || mknod --mode=666 /dev/null c 1 3
64 mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
65 mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
67 # compatibility symlink for the pre-oneiric locations
68 ln -s /run/initramfs /dev/.initramfs
70 # Export relevant variables
80 export init=/sbin/init
91 for i in /sys/devices/system/cpu/cpu*/online
94 '/sys/devices/system/cpu/cpu0/online')
96 '/sys/devices/system/cpu/cpu*/online')
108 ------------------------------------------------------------------------
111 [1]: https://dracut.wiki.kernel.org/index.php/Main_Page
112 [2]: http://blog.elastocloud.org/2015/06/rapid-linux-kernel-devtest-with-qemu.html
113 [3]: https://www.centos.org/forums/viewtopic.php?t=51621