• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1This document describes one way to create the initrd directory hierarchy
2in order to allow an initrd to be built into your kernel.  The trick
3here is to steal the initrd file used on your Linux laptop, Ubuntu in
4this case.  There are probably much better ways of doing this.
5
6That said, here are the commands:
7
8------------------------------------------------------------------------
9cd tools/testing/selftests/rcutorture
10zcat /initrd.img > /tmp/initrd.img.zcat
11mkdir initrd
12cd initrd
13cpio -id < /tmp/initrd.img.zcat
14------------------------------------------------------------------------
15
16Another way to create an initramfs image is using "dracut"[1], which is
17available on many distros, however the initramfs dracut generates is a cpio
18archive with another cpio archive in it, so an extra step is needed to create
19the initrd directory hierarchy.
20
21Here are the commands to create a initrd directory for rcutorture using
22dracut:
23
24------------------------------------------------------------------------
25dracut --no-hostonly --no-hostonly-cmdline --module "base bash shutdown" /tmp/initramfs.img
26cd tools/testing/selftests/rcutorture
27mkdir initrd
28cd initrd
29/usr/lib/dracut/skipcpio /tmp/initramfs.img | zcat | cpio -id < /tmp/initramfs.img
30------------------------------------------------------------------------
31
32Interestingly enough, if you are running rcutorture, you don't really
33need userspace in many cases.  Running without userspace has the
34advantage of allowing you to test your kernel independently of the
35distro in place, the root-filesystem layout, and so on.  To make this
36happen, put the following script in the initrd's tree's "/init" file,
37with 0755 mode.
38
39------------------------------------------------------------------------
40#!/bin/sh
41
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
47mkdir -p /var/lock
48mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
49mount -t proc -o nodev,noexec,nosuid proc /proc
50# Some things don't work properly without /etc/mtab.
51ln -sf /proc/mounts /etc/mtab
52
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
55if ! 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
61fi
62
63mkdir /dev/pts
64mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
65mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
66mkdir /run/initramfs
67# compatibility symlink for the pre-oneiric locations
68ln -s /run/initramfs /dev/.initramfs
69
70# Export relevant variables
71export ROOT=
72export ROOTDELAY=
73export ROOTFLAGS=
74export ROOTFSTYPE=
75export IP=
76export BOOT=
77export BOOTIF=
78export UBIMTD=
79export break=
80export init=/sbin/init
81export quiet=n
82export readonly=y
83export rootmnt=/root
84export debug=
85export panic=
86export blacklist=
87export resume=
88export resume_offset=
89export recovery=
90
91for i in /sys/devices/system/cpu/cpu*/online
92do
93	case $i in
94	'/sys/devices/system/cpu/cpu0/online')
95		;;
96	'/sys/devices/system/cpu/cpu*/online')
97		;;
98	*)
99		echo 1 > $i
100		;;
101	esac
102done
103
104while :
105do
106	sleep 10
107done
108------------------------------------------------------------------------
109
110References:
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
114