3 TEST_DESCRIPTION
="root filesystem on NBD"
5 KVERSION
=${KVERSION-$(uname -r)}
7 # Uncomment this to debug failures
8 #DEBUGFAIL="rd.shell rd.break rd.debug systemd.log_target=console loglevel=7 systemd.log_level=debug"
9 #SERIAL="tcp:127.0.0.1:9999"
12 if ! type -p nbd-server
2>/dev
/null
; then
13 echo "Test needs nbd-server... Skipping"
17 if ! modinfo
-k $KVERSION nbd
&>/dev
/null
; then
18 echo "Kernel module nbd does not exist"
27 echo "NBD TEST SETUP: Starting DHCP/NBD server"
30 -drive format
=raw
,index
=0,media
=disk
,file=$TESTDIR/server.ext2 \
31 -drive format
=raw
,index
=1,media
=disk
,file=$TESTDIR/nbd.ext2 \
32 -drive format
=raw
,index
=2,media
=disk
,file=$TESTDIR/encrypted.ext2 \
35 -net nic
,macaddr
=52:54:00:12:34:56,model
=e1000 \
36 -net socket
,listen
=127.0.0.1:12340 \
37 ${SERIAL:+-serial "$SERIAL"} \
38 ${SERIAL:--serial file:"$TESTDIR"/server.log} \
40 -append "panic=1 systemd.crash_reboot root=/dev/sda rootfstype=ext2 rw quiet console=ttyS0,115200n81 selinux=0" \
41 -initrd $TESTDIR/initramfs.server
-pidfile $TESTDIR/server.pid
-daemonize ||
return 1
42 sudo
chmod 644 $TESTDIR/server.pid ||
return 1
44 # Cleanup the terminal if we have one
47 if ! [[ $SERIAL ]]; then
48 echo "Waiting for the server to startup"
50 grep Serving
"$TESTDIR"/server.log
&& break
54 echo Sleeping
10 seconds to give the server a
head start
65 local found opts nbdinfo
67 [[ $fstype ]] || fstype
=ext3
68 [[ $fsopt ]] || fsopt
="ro"
70 echo "CLIENT TEST START: $test_name"
72 # Clear out the flags for each test
73 if ! dd if=/dev
/zero of
=$TESTDIR/flag.img bs
=1M count
=1; then
74 echo "Unable to make client sda image" 1>&2
79 -drive format
=raw
,index
=0,media
=disk
,file=$TESTDIR/flag.img \
82 -net nic
,macaddr
=$mac,model
=e1000 \
83 -net socket
,connect
=127.0.0.1:12340 \
85 -append "panic=1 systemd.crash_reboot rd.shell=0 $cmdline $DEBUGFAIL rd.auto rd.info rd.retry=10 ro console=ttyS0,115200n81 selinux=0 " \
86 -initrd $TESTDIR/initramfs.testing
88 if [[ $?
-ne 0 ]] ||
! grep -F -m 1 -q nbd-OK
$TESTDIR/flag.img
; then
89 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
93 # nbdinfo=( fstype fsoptions )
94 nbdinfo
=($
(awk '{print $2, $3; exit}' $TESTDIR/flag.img
))
96 if [[ "${nbdinfo[0]}" != "$fstype" ]]; then
97 echo "CLIENT TEST END: $test_name [FAILED - WRONG FS TYPE] \"${nbdinfo[0]}\" != \"$fstype\""
102 while [[ $opts ]]; do
103 if [[ ${opts%%,*} = $fsopt ]]; then
110 if [[ ! $found ]]; then
111 echo "CLIENT TEST END: $test_name [FAILED - BAD FS OPTS] \"${nbdinfo[1]}\" != \"$fsopt\""
115 echo "CLIENT TEST END: $test_name [OK]"
119 if ! run_server
; then
120 echo "Failed to start server" 1>&2
128 # The default is ext3,errors=continue so use that to determine
129 # if our options were parsed and used
130 client_test
"NBD root=nbd:IP:port" 52:54:00:12:34:00 \
131 "root=nbd:192.168.50.1:raw rd.luks=0" ||
return 1
133 client_test
"NBD root=nbd:IP:port::fsopts" 52:54:00:12:34:00 \
134 "root=nbd:192.168.50.1:raw::errors=panic rd.luks=0" \
135 ext3 errors
=panic ||
return 1
137 client_test
"NBD root=nbd:IP:port:fstype" 52:54:00:12:34:00 \
138 "root=nbd:192.168.50.1:raw:ext2 rd.luks=0" ext2 ||
return 1
140 client_test
"NBD root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
141 "root=nbd:192.168.50.1:raw:ext2:errors=panic rd.luks=0" \
142 ext2 errors
=panic ||
return 1
144 client_test
"NBD Bridge root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
145 "root=nbd:192.168.50.1:raw:ext2:errors=panic bridge rd.luks=0" \
146 ext2 errors
=panic ||
return 1
149 # FIXME! These fail, but probably shouldn't
152 # There doesn't seem to be a good way to validate the NBD options, so
153 # just check that we don't screw up the other options
155 # client_test "NBD root=nbd:IP:port:::NBD opts" 52:54:00:12:34:00 \
156 # "root=nbd:192.168.50.1:raw:::bs=2048 rd.luks=0" || return 1
158 # client_test "NBD root=nbd:IP:port:fstype::NBD opts" 52:54:00:12:34:00 \
159 # "root=nbd:192.168.50.1:raw:ext2::bs=2048 rd.luks=0" ext2 || return 1
161 # client_test "NBD root=nbd:IP:port:fstype:fsopts:NBD opts" \
162 # 52:54:00:12:34:00 \
163 # "root=nbd:192.168.50.1:raw:ext2:errors=panic:bs=2048 rd.luks=0" \
164 # ext2 errors=panic || return 1
166 # DHCP root-path parsing
168 # client_test "NBD root=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
169 # "root=dhcp rd.luks=0" || return 1
171 # client_test "NBD Bridge root=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
172 # "root=dhcp bridge rd.luks=0" || return 1
174 # client_test "NBD root=dhcp DHCP root-path nbd:srv:port:fstype" \
175 # 52:54:00:12:34:02 "root=dhcp rd.luks=0" ext2 || return 1
177 # client_test "NBD root=dhcp DHCP root-path nbd:srv:port::fsopts" \
178 # 52:54:00:12:34:03 "root=dhcp rd.luks=0" ext3 errors=panic || return 1
180 # client_test "NBD root=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
181 # 52:54:00:12:34:04 "root=dhcp rd.luks=0" ext2 errors=panic || return 1
185 # client_test "NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
186 # "netroot=nbd:192.168.50.1:raw rd.luks=0" || return 1
188 # client_test "NBD netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
189 # 52:54:00:12:34:04 "netroot=dhcp rd.luks=0" ext2 errors=panic || return 1
191 # Encrypted root handling via LVM/LUKS over NBD
193 # . $TESTDIR/luks.uuid
195 # client_test "NBD root=LABEL=dracut netroot=nbd:IP:port" \
196 # 52:54:00:12:34:00 \
197 # "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=nbd:192.168.50.1:encrypted" || return 1
199 # XXX This should be ext2,errors=panic but that doesn't currently
200 # XXX work when you have a real root= line in addition to netroot=
201 # XXX How we should work here needs clarification
202 # client_test "NBD root=LABEL=dracut netroot=dhcp (w/ fstype and opts)" \
203 # 52:54:00:12:34:05 \
204 # "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=dhcp" || return 1
206 if [[ -s server.pid
]]; then
207 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
208 rm -f -- $TESTDIR/server.pid
213 make_encrypted_root
() {
214 # Create the blank file to use as a root filesystem
215 dd if=/dev
/null of
=$TESTDIR/encrypted.ext2 bs
=1M seek
=80
216 dd if=/dev
/null of
=$TESTDIR/flag.img bs
=1M seek
=1
219 # Create what will eventually be our root filesystem onto an overlay
221 export initdir
=$TESTDIR/overlay
/source
222 .
$basedir/dracut-init.sh
226 mkdir
-p dev sys proc etc var tmp run root usr
/bin usr
/lib usr
/lib64 usr
/sbin
227 for i
in bin sbin lib lib64
; do
232 inst_multiple sh df free
ls shutdown poweroff stty
cat ps
ln ip \
233 mount dmesg mkdir
cp ping
234 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
235 [ -f ${_terminfodir}/l
/linux
] && break
237 inst_multiple
-o ${_terminfodir}/l
/linux
238 inst .
/client-init.sh
/sbin
/init
239 inst_simple
/etc
/os-release
240 find_binary plymouth
>/dev
/null
&& inst_multiple plymouth
241 cp -a /etc
/ld.so.conf
* $initdir/etc
242 sudo ldconfig
-r "$initdir"
245 # second, install the files needed to make the root filesystem
247 export initdir
=$TESTDIR/overlay
248 .
$basedir/dracut-init.sh
251 mkdir
-p dev sys proc etc tmp var run root usr
/bin usr
/lib usr
/lib64 usr
/sbin
252 for i
in bin sbin lib lib64
; do
257 inst_multiple mke2fs poweroff
cp umount tune2fs
258 inst_hook shutdown-emergency
000 .
/hard-off.sh
259 inst_hook emergency
000 .
/hard-off.sh
260 inst_hook initqueue
01 .
/create-root.sh
261 inst_hook initqueue
/finished
01 .
/finished-false.sh
262 inst_simple .
/99-idesymlinks.rules
/etc
/udev
/rules.d
/99-idesymlinks.rules
265 # create an initramfs that will create the target root filesystem.
266 # We do it this way so that we do not risk trashing the host mdraid
267 # devices, volume groups, encrypted partitions, etc.
268 $basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
269 -m "dash crypt lvm mdraid udev-rules base rootfs-block fs-lib kernel-modules qemu" \
270 -d "piix ide-gd_mod ata_piix ext2 ext3 sd_mod" \
271 --no-hostonly-cmdline -N \
272 -f $TESTDIR/initramfs.makeroot
$KVERSION ||
return 1
273 rm -rf -- $TESTDIR/overlay
275 # Invoke KVM and/or QEMU to actually create the target filesystem.
277 -drive format
=raw
,index
=0,media
=disk
,file=$TESTDIR/flag.img \
278 -drive format
=raw
,index
=1,media
=disk
,file=$TESTDIR/encrypted.ext2 \
280 -nographic -net none \
281 -append "root=/dev/fakeroot rw quiet console=ttyS0,115200n81 selinux=0" \
282 -initrd $TESTDIR/initramfs.makeroot ||
return 1
283 grep -F -m 1 -q dracut-root-block-created
$TESTDIR/flag.img ||
return 1
284 grep -F -a -m 1 ID_FS_UUID
$TESTDIR/flag.img
> $TESTDIR/luks.uuid
288 dd if=/dev
/null of
=$TESTDIR/nbd.ext2 bs
=1M seek
=120
289 mke2fs
-F -j $TESTDIR/nbd.ext2
291 sudo mount
-o loop
$TESTDIR/nbd.ext2
$TESTDIR/mnt
295 export initdir
=$TESTDIR/mnt
296 .
$basedir/dracut-init.sh
300 mkdir
-p dev sys proc etc var tmp run root usr
/bin usr
/lib usr
/lib64 usr
/sbin
301 for i
in bin sbin lib lib64
; do
306 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
308 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
309 [ -f ${_terminfodir}/l
/linux
] && break
311 inst_multiple
-o ${_terminfodir}/l
/linux
312 inst .
/client-init.sh
/sbin
/init
313 inst_simple
/etc
/os-release
314 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
315 inst
/etc
/passwd
/etc
/passwd
316 inst
/etc
/group
/etc
/group
317 for i
in /usr
/lib
*/libnss_files
* /lib
*/libnss_files
*;do
318 [ -e "$i" ] ||
continue
321 cp -a /etc
/ld.so.conf
* $initdir/etc
322 sudo ldconfig
-r "$initdir"
325 sudo umount
$TESTDIR/mnt
326 rm -fr -- $TESTDIR/mnt
330 dd if=/dev
/null of
=$TESTDIR/server.ext2 bs
=1M seek
=120
331 mke2fs
-F $TESTDIR/server.ext2
333 sudo mount
-o loop
$TESTDIR/server.ext2
$TESTDIR/mnt
337 export initdir
=$TESTDIR/mnt
338 .
$basedir/dracut-init.sh
342 mkdir
-p run dev sys proc etc var var
/lib
/dhcpd tmp etc
/nbd-server
345 cat > "$initdir/etc/nbd-server/config" <<EOF
348 exportname = /dev/sdb
352 exportname = /dev/sdc
356 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
357 dmesg mkdir
cp ping grep \
358 sleep nbd-server
chmod modprobe vi
359 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
360 [ -f ${_terminfodir}/l
/linux
] && break
362 inst_multiple
-o ${_terminfodir}/l
/linux
364 type -P dhcpd
>/dev
/null
&& inst_multiple dhcpd
365 [ -x /usr
/sbin
/dhcpd3
] && inst
/usr
/sbin
/dhcpd3
/usr
/sbin
/dhcpd
366 inst .
/server-init.sh
/sbin
/init
367 inst_simple
/etc
/os-release
368 inst .
/hosts
/etc
/hosts
369 inst .
/dhcpd.conf
/etc
/dhcpd.conf
370 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
371 inst
/etc
/passwd
/etc
/passwd
372 inst
/etc
/group
/etc
/group
373 for i
in /usr
/lib
*/libnss_files
* /lib
*/libnss_files
*;do
374 [ -e "$i" ] ||
continue
378 cp -a /etc
/ld.so.conf
* $initdir/etc
379 sudo ldconfig
-r "$initdir"
382 sudo umount
$TESTDIR/mnt
383 rm -fr -- $TESTDIR/mnt
387 make_encrypted_root ||
return 1
388 make_client_root ||
return 1
389 make_server_root ||
return 1
391 # Make the test image
393 export initdir
=$TESTDIR/overlay
394 .
$basedir/dracut-init.sh
395 inst_multiple poweroff shutdown
396 inst_hook shutdown-emergency
000 .
/hard-off.sh
397 inst_simple .
/99-idesymlinks.rules
/etc
/udev
/rules.d
/99-idesymlinks.rules
398 inst .
/cryptroot-ask.sh
/sbin
/cryptroot-ask
400 # inst ./debug-shell.service /lib/systemd/system/debug-shell.service
401 # mkdir -p "${initdir}/lib/systemd/system/sysinit.target.wants"
402 # ln -fs ../debug-shell.service "${initdir}/lib/systemd/system/sysinit.target.wants/debug-shell.service"
405 mkdir
-p $initdir/etc
406 echo "luks-$ID_FS_UUID /dev/nbd0 /etc/key" > $initdir/etc
/crypttab
407 echo -n test > $initdir/etc
/key
410 sudo
$basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
411 -m "dash udev-rules rootfs-block fs-lib base debug kernel-modules" \
412 -d "af_packet piix ide-gd_mod ata_piix ext2 ext3 sd_mod e1000" \
413 --no-hostonly-cmdline -N \
414 -f $TESTDIR/initramfs.server
$KVERSION ||
return 1
416 sudo
$basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
418 -a "debug watchdog" \
419 -d "af_packet piix ide-gd_mod ata_piix ext2 ext3 sd_mod e1000 i6300esb ib700wdt" \
420 --no-hostonly-cmdline -N \
421 -f $TESTDIR/initramfs.testing
$KVERSION ||
return 1
425 if [[ -s $TESTDIR/server.pid
]]; then
426 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
427 rm -f -- $TESTDIR/server.pid
435 .
$testdir/test-functions