shell scripting question (mdconfig device choosing)

Ensel Sharon user at dhp.com
Tue Jan 24 13:56:01 PST 2006


Hello,

When I mdconfig a device and _do not_ specify a particular numbered md
device (with the -u flag), it just chooses an unused device number for
me.  Which makes me happy.

Unfortunately, mdconfig chooses the next available device, from the
highest device currently in use, regardless of whether or not there are
much lower devices unused.

For instance, if I have md0 and md1 in use, mdconfig will auto choose
md2.  Good.  However if I only have md10 and md11 in use, mdconfig will
NOT choose md0, it will choose md12.

I need it to choose the lowest available unused device.

How can I do this in a bit of /bin/sh shell code ?  I can check what
devices are in use with `mdconfig -l`, like so:

# mdconfig -l
md0

and I know how to use awk to strip away the leading "md" from each piece
of the output ... but I do not know how to take output like:

8 9 11 14

and decide that the lowest available number is "0".  How can I do this ?

Thank you.



More information about the freebsd-questions mailing list