2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 TEST_DESCRIPTION
="root filesystem on NBD"
6 KVERSION
=${KVERSION-$(uname -r)}
8 # Uncomment this to debug failures
9 #DEBUGFAIL="rd.shell rd.break"
10 #SERIAL="udp:127.0.0.1:9999"
15 echo "NBD TEST SETUP: Starting DHCP/NBD server"
18 -hda $TESTDIR/server.ext2 \
19 -hdb $TESTDIR/nbd.ext2 \
20 -hdc $TESTDIR/encrypted.ext2 \
23 -net nic
,macaddr
=52:54:00:12:34:56,model
=e1000 \
24 -net socket
,listen
=127.0.0.1:12340 \
26 -kernel /boot
/vmlinuz-
$KVERSION \
27 -append "root=/dev/sda rootfstype=ext2 rw quiet console=ttyS0,115200n81 selinux=0" \
28 -initrd $TESTDIR/initramfs.server
-pidfile $TESTDIR/server.pid
-daemonize ||
return 1
29 sudo
chmod 644 $TESTDIR/server.pid ||
return 1
31 # Cleanup the terminal if we have one
34 echo Sleeping
10 seconds to give the server a
head start
44 local found opts nbdinfo
46 [[ $fstype ]] || fstype
=ext3
47 [[ $fsopt ]] || fsopt
="ro"
49 echo "CLIENT TEST START: $test_name"
51 # Clear out the flags for each test
52 if ! dd if=/dev
/zero of
=$TESTDIR/flag.img bs
=1M count
=1; then
53 echo "Unable to make client sda image" 1>&2
58 -hda $TESTDIR/flag.img \
61 -net nic
,macaddr
=$mac,model
=e1000 \
62 -net socket
,connect
=127.0.0.1:12340 \
63 -kernel /boot
/vmlinuz-
$KVERSION \
64 -append "$cmdline $DEBUGFAIL rd.auto rd.info rd.retry=10 ro console=ttyS0,115200n81 selinux=0 " \
65 -initrd $TESTDIR/initramfs.testing
67 if [[ $?
-ne 0 ]] ||
! grep -F -m 1 -q nbd-OK
$TESTDIR/flag.img
; then
68 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
72 # nbdinfo=( fstype fsoptions )
73 nbdinfo
=($
(awk '{print $2, $3; exit}' $TESTDIR/flag.img
))
75 if [[ "${nbdinfo[0]}" != "$fstype" ]]; then
76 echo "CLIENT TEST END: $test_name [FAILED - WRONG FS TYPE] \"${nbdinfo[0]}\" != \"$fstype\""
82 if [[ ${opts%%,*} = $fsopt ]]; then
89 if [[ ! $found ]]; then
90 echo "CLIENT TEST END: $test_name [FAILED - BAD FS OPTS] \"${nbdinfo[1]}\" != \"$fsopt\""
94 echo "CLIENT TEST END: $test_name [OK]"
98 modinfo nbd
&>/dev
/null ||
{ echo "Kernel does not support nbd"; exit 1; }
100 echo "Failed to start server" 1>&2
108 # The default is ext3,errors=continue so use that to determine
109 # if our options were parsed and used
110 client_test
"NBD root=nbd:IP:port::fsopts" 52:54:00:12:34:00 \
111 "root=nbd:192.168.50.1:2000::errors=panic rd.luks=0" \
112 ext3 errors
=panic ||
return 1
114 client_test
"NBD root=nbd:IP:port" 52:54:00:12:34:00 \
115 "root=nbd:192.168.50.1:2000 rd.luks=0" ||
return 1
117 client_test
"NBD root=nbd:IP:port:fstype" 52:54:00:12:34:00 \
118 "root=nbd:192.168.50.1:2000:ext2 rd.luks=0" ext2 ||
return 1
120 client_test
"NBD root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
121 "root=nbd:192.168.50.1:2000:ext2:errors=panic rd.luks=0" \
122 ext2 errors
=panic ||
return 1
124 client_test
"NBD Bridge root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
125 "root=nbd:192.168.50.1:2000:ext2:errors=panic bridge rd.luks=0" \
126 ext2 errors
=panic ||
return 1
128 # There doesn't seem to be a good way to validate the NBD options, so
129 # just check that we don't screw up the other options
131 client_test
"NBD root=nbd:IP:port:::NBD opts" 52:54:00:12:34:00 \
132 "root=nbd:192.168.50.1:2000:::bs=2048 rd.luks=0" ||
return 1
134 client_test
"NBD root=nbd:IP:port:fstype::NBD opts" 52:54:00:12:34:00 \
135 "root=nbd:192.168.50.1:2000:ext2::bs=2048 rd.luks=0" ext2 ||
return 1
137 client_test
"NBD root=nbd:IP:port:fstype:fsopts:NBD opts" \
139 "root=nbd:192.168.50.1:2000:ext2:errors=panic:bs=2048 rd.luks=0" \
140 ext2 errors
=panic ||
return 1
142 # DHCP root-path parsing
144 client_test
"NBD root=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
145 "root=dhcp rd.luks=0" ||
return 1
147 client_test
"NBD Bridge root=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
148 "root=dhcp bridge rd.luks=0" ||
return 1
150 client_test
"NBD root=dhcp DHCP root-path nbd:srv:port:fstype" \
151 52:54:00:12:34:02 "root=dhcp rd.luks=0" ext2 ||
return 1
153 client_test
"NBD root=dhcp DHCP root-path nbd:srv:port::fsopts" \
154 52:54:00:12:34:03 "root=dhcp rd.luks=0" ext3 errors
=panic ||
return 1
156 client_test
"NBD root=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
157 52:54:00:12:34:04 "root=dhcp rd.luks=0" ext2 errors
=panic ||
return 1
161 client_test
"NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
162 "netroot=nbd:192.168.50.1:2000 rd.luks=0" ||
return 1
164 client_test
"NBD netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
165 52:54:00:12:34:04 "netroot=dhcp rd.luks=0" ext2 errors
=panic ||
return 1
167 # Encrypted root handling via LVM/LUKS over NBD
171 client_test
"NBD root=LABEL=dracut netroot=nbd:IP:port" \
173 "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=nbd:192.168.50.1:2001" ||
return 1
175 # XXX This should be ext2,errors=panic but that doesn't currently
176 # XXX work when you have a real root= line in addition to netroot=
177 # XXX How we should work here needs clarification
178 client_test
"NBD root=LABEL=dracut netroot=dhcp (w/ fstype and opts)" \
180 "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=dhcp" ||
return 1
182 if [[ -s server.pid
]]; then
183 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
184 rm -f -- $TESTDIR/server.pid
189 make_encrypted_root
() {
190 # Create the blank file to use as a root filesystem
191 dd if=/dev
/null of
=$TESTDIR/encrypted.ext2 bs
=1M seek
=20
192 dd if=/dev
/null of
=$TESTDIR/flag.img bs
=1M seek
=1
195 # Create what will eventually be our root filesystem onto an overlay
197 export initdir
=$TESTDIR/overlay
/source
198 .
$basedir/dracut-functions.sh
201 cd "$initdir"; mkdir
-p dev sys proc etc var
/run tmp
202 mkdir
-p root usr
/bin usr
/lib usr
/lib64 usr
/sbin
203 for i
in bin sbin lib lib64
; do
207 inst_multiple sh df free
ls shutdown poweroff stty
cat ps
ln ip \
208 mount dmesg mkdir
cp ping
209 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
210 [ -f ${_terminfodir}/l
/linux
] && break
212 inst_multiple
-o ${_terminfodir}/l
/linux
213 inst .
/client-init.sh
/sbin
/init
214 inst_simple
/etc
/os-release
215 find_binary plymouth
>/dev
/null
&& inst_multiple plymouth
216 cp -a /etc
/ld.so.conf
* $initdir/etc
217 sudo ldconfig
-r "$initdir"
220 # second, install the files needed to make the root filesystem
222 export initdir
=$TESTDIR/overlay
223 .
$basedir/dracut-functions.sh
225 cd "$initdir"; mkdir
-p dev sys proc etc var
/run tmp
226 mkdir
-p root usr
/bin usr
/lib usr
/lib64 usr
/sbin
227 for i
in bin sbin lib lib64
; do
231 inst_multiple mke2fs poweroff
cp umount tune2fs
232 inst_hook emergency
000 .
/hard-off.sh
233 inst_hook initqueue
01 .
/create-root.sh
234 inst_hook initqueue
/finished
01 .
/finished-false.sh
235 inst_simple .
/99-idesymlinks.rules
/etc
/udev
/rules.d
/99-idesymlinks.rules
238 # create an initramfs that will create the target root filesystem.
239 # We do it this way so that we do not risk trashing the host mdraid
240 # devices, volume groups, encrypted partitions, etc.
241 $basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
242 -m "dash crypt lvm mdraid udev-rules base rootfs-block kernel-modules" \
243 -d "piix ide-gd_mod ata_piix ext2 ext3 sd_mod" \
244 -f $TESTDIR/initramfs.makeroot
$KVERSION ||
return 1
245 rm -rf -- $TESTDIR/overlay
247 # Invoke KVM and/or QEMU to actually create the target filesystem.
249 -hda $TESTDIR/flag.img \
250 -hdb $TESTDIR/encrypted.ext2 \
252 -nographic -net none \
253 -kernel "/boot/vmlinuz-$kernel" \
254 -append "root=/dev/fakeroot rw quiet console=ttyS0,115200n81 selinux=0" \
255 -initrd $TESTDIR/initramfs.makeroot ||
return 1
256 grep -F -m 1 -q dracut-root-block-created
$TESTDIR/flag.img ||
return 1
257 grep -F -a -m 1 ID_FS_UUID
$TESTDIR/flag.img
> $TESTDIR/luks.uuid
261 dd if=/dev
/null of
=$TESTDIR/nbd.ext2 bs
=1M seek
=30
262 mke2fs
-F -j $TESTDIR/nbd.ext2
264 sudo mount
-o loop
$TESTDIR/nbd.ext2
$TESTDIR/mnt
268 export initdir
=$TESTDIR/mnt
269 .
$basedir/dracut-functions.sh
272 cd "$initdir"; mkdir
-p dev sys proc etc var
/run tmp
273 mkdir
-p root usr
/bin usr
/lib usr
/lib64 usr
/sbin
274 for i
in bin sbin lib lib64
; do
278 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
280 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
281 [ -f ${_terminfodir}/l
/linux
] && break
283 inst_multiple
-o ${_terminfodir}/l
/linux
284 inst .
/client-init.sh
/sbin
/init
285 inst_simple
/etc
/os-release
286 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
287 inst
/etc
/passwd
/etc
/passwd
288 inst
/etc
/group
/etc
/group
289 for i
in /usr
/lib
*/libnss_files
* /lib
*/libnss_files
*;do
290 [ -e "$i" ] ||
continue
293 cp -a /etc
/ld.so.conf
* $initdir/etc
294 sudo ldconfig
-r "$initdir"
297 sudo umount
$TESTDIR/mnt
298 rm -fr -- $TESTDIR/mnt
302 dd if=/dev
/null of
=$TESTDIR/server.ext2 bs
=1M seek
=30
303 mke2fs
-F $TESTDIR/server.ext2
305 sudo mount
-o loop
$TESTDIR/server.ext2
$TESTDIR/mnt
309 export initdir
=$TESTDIR/mnt
310 .
$basedir/dracut-functions.sh
314 mkdir
-p dev sys proc etc var
/run var
/lib
/dhcpd tmp
316 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
317 dmesg mkdir
cp ping grep \
318 sleep nbd-server
chmod
319 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
320 [ -f ${_terminfodir}/l
/linux
] && break
322 inst_multiple
-o ${_terminfodir}/l
/linux
324 type -P dhcpd
>/dev
/null
&& inst_multiple dhcpd
325 [ -x /usr
/sbin
/dhcpd3
] && inst
/usr
/sbin
/dhcpd3
/usr
/sbin
/dhcpd
326 inst .
/server-init.sh
/sbin
/init
327 inst_simple
/etc
/os-release
328 inst .
/hosts
/etc
/hosts
329 inst .
/dhcpd.conf
/etc
/dhcpd.conf
330 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
331 inst
/etc
/passwd
/etc
/passwd
332 inst
/etc
/group
/etc
/group
333 for i
in /usr
/lib
*/libnss_files
* /lib
*/libnss_files
*;do
334 [ -e "$i" ] ||
continue
338 cp -a /etc
/ld.so.conf
* $initdir/etc
339 sudo ldconfig
-r "$initdir"
342 sudo umount
$TESTDIR/mnt
343 rm -fr -- $TESTDIR/mnt
348 modinfo nbd
&>/dev
/null ||
{ echo "Kernel does not support nbd"; exit 1; }
350 make_encrypted_root ||
return 1
351 make_client_root ||
return 1
352 make_server_root ||
return 1
354 # Make the test image
356 export initdir
=$TESTDIR/overlay
357 .
$basedir/dracut-functions.sh
358 inst_multiple poweroff shutdown
359 inst_hook emergency
000 .
/hard-off.sh
360 inst_simple .
/99-idesymlinks.rules
/etc
/udev
/rules.d
/99-idesymlinks.rules
361 inst .
/cryptroot-ask.sh
/sbin
/cryptroot-ask
363 # inst ./debug-shell.service /lib/systemd/system/debug-shell.service
364 # mkdir -p "${initdir}/lib/systemd/system/sysinit.target.wants"
365 # ln -fs ../debug-shell.service "${initdir}/lib/systemd/system/sysinit.target.wants/debug-shell.service"
368 mkdir
-p $initdir/etc
369 echo "luks-$ID_FS_UUID /dev/nbd0 /etc/key" > $initdir/etc
/crypttab
370 echo -n test > $initdir/etc
/key
373 sudo
$basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
374 -m "dash udev-rules rootfs-block base debug kernel-modules" \
375 -d "af_packet piix ide-gd_mod ata_piix ext2 ext3 sd_mod e1000" \
376 -f $TESTDIR/initramfs.server
$KVERSION ||
return 1
378 sudo
$basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
380 -a "debug watchdog" \
381 -d "af_packet piix ide-gd_mod ata_piix ext2 ext3 sd_mod e1000 i6300esb ib700wdt" \
382 -f $TESTDIR/initramfs.testing
$KVERSION ||
return 1
386 if [[ -s $TESTDIR/server.pid
]]; then
387 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
388 rm -f -- $TESTDIR/server.pid
396 .
$testdir/test-functions