xref: /linux/tools/testing/selftests/rcutorture/doc/initrd.txt (revision e5731b584b3e521e3db6fda9cdfe10646d3413a3)
1c87b9c60SPaul E. McKenneyThis document describes one way to create the initrd directory hierarchy
2c87b9c60SPaul E. McKenneyin order to allow an initrd to be built into your kernel.  The trick
3c87b9c60SPaul E. McKenneyhere is to steal the initrd file used on your Linux laptop, Ubuntu in
4c87b9c60SPaul E. McKenneythis case.  There are probably much better ways of doing this.
5c87b9c60SPaul E. McKenney
6c87b9c60SPaul E. McKenneyThat said, here are the commands:
7c87b9c60SPaul E. McKenney
8c87b9c60SPaul E. McKenney------------------------------------------------------------------------
9616fd166SPaul E. McKenneycd tools/testing/selftests/rcutorture
10c87b9c60SPaul E. McKenneyzcat /initrd.img > /tmp/initrd.img.zcat
11c87b9c60SPaul E. McKenneymkdir initrd
12c87b9c60SPaul E. McKenneycd initrd
13c87b9c60SPaul E. McKenneycpio -id < /tmp/initrd.img.zcat
14c87b9c60SPaul E. McKenney------------------------------------------------------------------------
15c87b9c60SPaul E. McKenney
16*e5731b58SBoqun FengAnother way to create an initramfs image is using "dracut"[1], which is
17*e5731b58SBoqun Fengavailable on many distros, however the initramfs dracut generates is a cpio
18*e5731b58SBoqun Fengarchive with another cpio archive in it, so an extra step is needed to create
19*e5731b58SBoqun Fengthe initrd directory hierarchy.
20*e5731b58SBoqun Feng
21*e5731b58SBoqun FengHere are the commands to create a initrd directory for rcutorture using
22*e5731b58SBoqun Fengdracut:
23*e5731b58SBoqun Feng
24*e5731b58SBoqun Feng------------------------------------------------------------------------
25*e5731b58SBoqun Fengdracut --no-hostonly --no-hostonly-cmdline --module "base bash shutdown" /tmp/initramfs.img
26*e5731b58SBoqun Fengcd tools/testing/selftests/rcutorture
27*e5731b58SBoqun Fengmkdir initrd
28*e5731b58SBoqun Fengcd initrd
29*e5731b58SBoqun Feng/usr/lib/dracut/skipcpio /tmp/initramfs.img | zcat | cpio -id < /tmp/initramfs.img
30*e5731b58SBoqun Feng------------------------------------------------------------------------
31*e5731b58SBoqun Feng
32c87b9c60SPaul E. McKenneyInterestingly enough, if you are running rcutorture, you don't really
33c87b9c60SPaul E. McKenneyneed userspace in many cases.  Running without userspace has the
34c87b9c60SPaul E. McKenneyadvantage of allowing you to test your kernel independently of the
35c87b9c60SPaul E. McKenneydistro in place, the root-filesystem layout, and so on.  To make this
36c87b9c60SPaul E. McKenneyhappen, put the following script in the initrd's tree's "/init" file,
37c87b9c60SPaul E. McKenneywith 0755 mode.
38c87b9c60SPaul E. McKenney
39c87b9c60SPaul E. McKenney------------------------------------------------------------------------
40c87b9c60SPaul E. McKenney#!/bin/sh
41c87b9c60SPaul E. McKenney
42c87b9c60SPaul E. McKenney[ -d /dev ] || mkdir -m 0755 /dev
43c87b9c60SPaul E. McKenney[ -d /root ] || mkdir -m 0700 /root
44c87b9c60SPaul E. McKenney[ -d /sys ] || mkdir /sys
45c87b9c60SPaul E. McKenney[ -d /proc ] || mkdir /proc
46c87b9c60SPaul E. McKenney[ -d /tmp ] || mkdir /tmp
47c87b9c60SPaul E. McKenneymkdir -p /var/lock
48c87b9c60SPaul E. McKenneymount -t sysfs -o nodev,noexec,nosuid sysfs /sys
49c87b9c60SPaul E. McKenneymount -t proc -o nodev,noexec,nosuid proc /proc
50c87b9c60SPaul E. McKenney# Some things don't work properly without /etc/mtab.
51c87b9c60SPaul E. McKenneyln -sf /proc/mounts /etc/mtab
52c87b9c60SPaul E. McKenney
53c87b9c60SPaul E. McKenney# Note that this only becomes /dev on the real filesystem if udev's scripts
54c87b9c60SPaul E. McKenney# are used; which they will be, but it's worth pointing out
55c87b9c60SPaul E. McKenneyif ! mount -t devtmpfs -o mode=0755 udev /dev; then
56c87b9c60SPaul E. McKenney	echo "W: devtmpfs not available, falling back to tmpfs for /dev"
57c87b9c60SPaul E. McKenney	mount -t tmpfs -o mode=0755 udev /dev
58c87b9c60SPaul E. McKenney	[ -e /dev/console ] || mknod --mode=600 /dev/console c 5 1
59c87b9c60SPaul E. McKenney	[ -e /dev/kmsg ] || mknod --mode=644 /dev/kmsg c 1 11
60c87b9c60SPaul E. McKenney	[ -e /dev/null ] || mknod --mode=666 /dev/null c 1 3
61c87b9c60SPaul E. McKenneyfi
62c87b9c60SPaul E. McKenney
63c87b9c60SPaul E. McKenneymkdir /dev/pts
64c87b9c60SPaul E. McKenneymount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
65c87b9c60SPaul E. McKenneymount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
66c87b9c60SPaul E. McKenneymkdir /run/initramfs
67c87b9c60SPaul E. McKenney# compatibility symlink for the pre-oneiric locations
68c87b9c60SPaul E. McKenneyln -s /run/initramfs /dev/.initramfs
69c87b9c60SPaul E. McKenney
70c87b9c60SPaul E. McKenney# Export relevant variables
71c87b9c60SPaul E. McKenneyexport ROOT=
72c87b9c60SPaul E. McKenneyexport ROOTDELAY=
73c87b9c60SPaul E. McKenneyexport ROOTFLAGS=
74c87b9c60SPaul E. McKenneyexport ROOTFSTYPE=
75c87b9c60SPaul E. McKenneyexport IP=
76c87b9c60SPaul E. McKenneyexport BOOT=
77c87b9c60SPaul E. McKenneyexport BOOTIF=
78c87b9c60SPaul E. McKenneyexport UBIMTD=
79c87b9c60SPaul E. McKenneyexport break=
80c87b9c60SPaul E. McKenneyexport init=/sbin/init
81c87b9c60SPaul E. McKenneyexport quiet=n
82c87b9c60SPaul E. McKenneyexport readonly=y
83c87b9c60SPaul E. McKenneyexport rootmnt=/root
84c87b9c60SPaul E. McKenneyexport debug=
85c87b9c60SPaul E. McKenneyexport panic=
86c87b9c60SPaul E. McKenneyexport blacklist=
87c87b9c60SPaul E. McKenneyexport resume=
88c87b9c60SPaul E. McKenneyexport resume_offset=
89c87b9c60SPaul E. McKenneyexport recovery=
90c87b9c60SPaul E. McKenney
91c87b9c60SPaul E. McKenneyfor i in /sys/devices/system/cpu/cpu*/online
92c87b9c60SPaul E. McKenneydo
93c87b9c60SPaul E. McKenney	case $i in
94c87b9c60SPaul E. McKenney	'/sys/devices/system/cpu/cpu0/online')
95c87b9c60SPaul E. McKenney		;;
96c87b9c60SPaul E. McKenney	'/sys/devices/system/cpu/cpu*/online')
97c87b9c60SPaul E. McKenney		;;
98c87b9c60SPaul E. McKenney	*)
99c87b9c60SPaul E. McKenney		echo 1 > $i
100c87b9c60SPaul E. McKenney		;;
101c87b9c60SPaul E. McKenney	esac
102c87b9c60SPaul E. McKenneydone
103c87b9c60SPaul E. McKenney
104c87b9c60SPaul E. McKenneywhile :
105c87b9c60SPaul E. McKenneydo
106c87b9c60SPaul E. McKenney	sleep 10
107c87b9c60SPaul E. McKenneydone
108*e5731b58SBoqun Feng------------------------------------------------------------------------
109*e5731b58SBoqun Feng
110*e5731b58SBoqun FengReferences:
111*e5731b58SBoqun Feng[1]: https://dracut.wiki.kernel.org/index.php/Main_Page
112*e5731b58SBoqun Feng[2]: http://blog.elastocloud.org/2015/06/rapid-linux-kernel-devtest-with-qemu.html
113*e5731b58SBoqun Feng[3]: https://www.centos.org/forums/viewtopic.php?t=51621
114