>Synopsis: rc calls grep before /usr is mounted in diskless setup (nfs)
>Category: system
>Environment:
System : OpenBSD 4.9
Details : OpenBSD 4.9-current (GENERIC) #22: Tue Jun 28 01:50:07
MDT 2011
[email protected]:/usr/src/sys/arch/sparc/compile/GENERIC
Architecture: OpenBSD.sparc
Machine : sparc
>Description:
If you create a diskless setup with / and /usr separated (like if
you intented to reuse /usr between multiple computer of the same
arch), you get these error when booting:
...
Automatic boot in progress: starting file system checks.
setting tty flags
pf enabled
/etc/rc[295]: grep: not found
/etc/rc[296]: grep: not found
net.inet6.ip6.accept_rtadv: 0 -> 1
starting network
...
Those are from the calls to grep found in the function fill_baddynamic
which is called twice between these 2 groups of command taken from rc:
mount -a -t nonfs,vnd
mount -uw / # root on nfs requires this, others aren't hurt
and
mount -s /usr >/dev/null 2>&1
mount -s /var >/dev/null 2>&1
Basicaly, rc use /var and /usr before they are mounted in some rare
diskless setup (or for someone with an hard-disk so small, he decided
to network /usr).
(In the same vein, function random_seed plays with /var before
"mount -s /var". There's also a call to "touch /etc/resolv.conf"
for dhclient users but a diskless client wouldn't use DHCP.)
The errors causes net.inet.{tcp,udp}.baddynamic to not be filled
with the content from /etc/service.
>How-To-Repeat:
Create a diskless setup where / and /usr are distinct:
cpaq:/exports/sparc/root on / type nfs (v2, udp, timeo=100, retrans=101)
cpaq:/exports/sparc/usr on /usr type nfs (v3, udp, timeo=100, retrans=101)
cpaq:/exports/sparc/swap on /swap type nfs (v3, udp, timeo=100, retrans=101)
On the NFS server, /exports/sparc/root/usr is an empty directory.
>Fix:
I'm not really sure why grep is used in fill_baddynamic. The while
loop already filter for the right _service. It catch the case where
the word tcp or udp in lowercase would be the 3rd word in a comment
line, I guess.
It can be done by sh (slightly slower and tested on that system).
--- rc.r1.485 Thu Jul 14 21:06:17 2011
+++ rc Sat Jul 16 13:24:27 2011
@@ -120,10 +120,10 @@
local _sysctl="net.inet.${_service}.baddynamic"
local _name _port _srv _junk _ban
local _i=0
- grep "/${_service}" /etc/services | {
+ local _ifs="${IFS}"
IFS=" /"
while read _name _port _srv _junk; do
- [ "x${_srv}" = "x${_service}" ] || continue;
+ [ "x${_srv}" = "x${_service}" ] && [ "x${_name}" =
"x${_name#\#}" ] || continue;
if [ "x${_ban}" = "x" ]; then
_ban="+${_port}"
else
@@ -135,11 +135,11 @@
_ban=""
_i=0
fi
- done;
+ done < /etc/services;
if [ "x${_ban}" != "x" ]; then
sysctl ${_sysctl}=${_ban} >/dev/null
fi
- }
+ IFS="${_ifs}"
}
start_daemon()
dmesg:
OpenBSD 4.9-current (GENERIC) #22: Tue Jun 28 01:50:07 MDT 2011
[email protected]:/usr/src/sys/arch/sparc/compile/GENERIC
real mem = 24793088 (23MB)
avail mem = 20336640 (19MB)
mainbus0 at root: SUNW,SPARCclassic
cpu0 at mainbus0: TMS390S10 @ 50 MHz, on-chip FPU
cpu0: physical 4K instruction (32 b/l), 2K data (16 b/l) cache enabled
obio0 at mainbus0
clock0 at obio0 addr 0x71200000: mk48t08 (eeprom)
timer0 at obio0 addr 0x71d00000 delay constant 23
zs0 at obio0 addr 0x71100000 pri 12, softpri 6
zstty0 at zs0 channel 0: console
zstty1 at zs0 channel 1
zs1 at obio0 addr 0x71000000 pri 12, softpri 6
zskbd0 at zs1 channel 0: no keyboard
zsms0 at zs1 channel 1
wsmouse0 at zsms0 mux 0
slavioconfig at obio0 addr 0x71800000 not configured
auxreg0 at obio0 addr 0x71900000
power0 at obio0 addr 0x71910000
fdc0 at obio0 addr 0x71400000 pri 11, softpri 4: chip 82077
fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
iommu0 at mainbus0 addr 0x10000000: version 0x1/0x4, page-size 4096, range 64MB
sbus0 at iommu0: 25 MHz
dma0 at sbus0 slot 4 offset 0x8400000: rev 2
esp0 at dma0 offset 0x8800000 pri 4: ESP200, 40MHz
scsibus0 at esp0: 8 targets, initiator 7
sd0 at scsibus0 targ 0 lun 0: <SEAGATE, ST32151N, HP02> SCSI2 0/direct fixed
sd0: 2048MB, 512 bytes/sec, 4194685 sec total
audioamd0 at sbus0 slot 4 offset 0x1300000 pri 13, softpri 4
audio0 at audioamd0
bpp0 at sbus0 slot 4 offset 0xc800000: DMA2
ledma0 at sbus0 slot 4 offset 0x8400010: rev 2
le0 at ledma0 offset 0x8c00000 pri 6: address 08:00:20:04:d1:40
le0: 16 receive buffers, 4 transmit buffers
qec0 at sbus0 slot 1 offset 0x20000: 128K memory 1 channel
be0 at qec0 offset 0x10000 pri 7: rev 1 address 08:00:20:04:d1:40
cgthree0 at sbus0 slot 3 offset 0x0 pri 9: SUNW,501-1718, 1152x900
wsdisplay0 at cgthree0 mux 1
wsdisplay0: screen 0 added (std, sun emulation)
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
bootpath: /iommu@0,10000000/sbus@0,10001000/ledma@4,8400010/le@4,8c00000
nfs_boot: using interface le0, with revarp & bootparams
nfs_boot: client_addr=192.168.12.20
nfs_boot: server_addr=192.168.12.70 hostname=sparc
root on cpaq:/exports/sparc/root
swap on cpaq:/exports/sparc/swap
usbdevs:
usbdevs: no USB controllers found
pcidump:
acpidump: