Send in your Unix questions today! |
See additional Unix tips and tricks
Ever wish you could take a look at the device aliases on a Solaris system without having to descend all the way down to the ok prompt? Well, you can. By issuing the proper version of the prtconf (print system configuration) command, you can include a list of device aliases in your prtconf output.
The prtconf command, often used to do such things as display the amount of memory installed on a system (e.g., "prtconf | grep Mem") and copious details on system devices and peripherals. It also includes a number of options that can change the amount and format of the information provided.
The -D option, for example, displays system peripherals in an indented (referred to as a "device tree") fashion that allows you to identify the relationships between devices. The -P option displays information about pseudo devices. The -x option reports whether or not a system is 64-bit ready.
To include information about your device aliases in your prtconf output, the combination of the -v and -p options (i.e., -vp) can be used. Given these options, the output will include a section which looks more or less like this:
disk: '/pci@1f,0/ide@d/disk@2,0'
rtc: '/pci@1f,0/isa@7/rtc@0,70'
usb: '/pci@1f,0/usb@a'
flash: '/pci@1f,0/isa@7/flashprom@1f,0'
lom: '/pci@1f,0/isa@7/SUNW,lomh@0,8010'
i2c-nvram: '/pci@1f,0/pmu@3/i2c@0,0/i2c-nvram@0,aa'
net1: '/pci@1f,0/ethernet@5'
dload1: '/pci@1f,0/ethernet@5:,'
dload: '/pci@1f,0/ethernet@c:,'
net0: '/pci@1f,0/ethernet@c'
net: '/pci@1f,0/ethernet@c'
cdrom: '/pci@1f,0/ide@d/cdrom@3,0:f'
disk3: '/pci@1f,0/ide@d/disk@3,0'
disk2: '/pci@1f,0/ide@d/disk@2,0'
disk1: '/pci@1f,0/ide@d/disk@1,0'
disk0: '/pci@1f,0/ide@d/disk@0,0'
ide: '/pci@1f,0/ide@d'
floppy: '/pci@1f,0/isa@7/dma/floppy'
ttyb: '/pci@1f,0/isa@7/serial@0,2e8'
ttya: '/pci@1f,0/isa@7/serial@0,3f8'
name: 'aliases'
|
These lines represent the same device aliases that you would see if you were to issue the devalias command at the ok prompt.
To display this information while your system is in a normal operational state (like run state 3), you can issue the "prtconf -vp" command and page down to that portion that includes definitions like those shown above or you can use a script like the one I've included below to extract just those lines from the prtconf output.
#!/usr/bin/perl -w
@prtconf=`/usr/sbin/prtconf -vp`;
$e=0;
# find the end of the aliases section
foreach ( @prtconf ) {
if ( /aliases/ ) {
last;
}
$e++;
}
# find the start of the aliases section
for ( $s=$e-1; $s>1; $s-- ) {
if ( $prtconf[$s]=~/^$/ ) {
last;
}
}
# display the aliases
for ( $i=$s+2; $i<=$e; $i++ ) {
print "$prtconf[$i]";
}
|
This perl script works by looking for the last line in the output shown above -- the "name: 'aliases'" line. When it finds the line containing the word "aliases", it exits the foreach loop, leaving the line number in $e.
It then marches backward from $e toward the beginning of the file until it finds an empty line. While the output shown above doesn't make this obvious, the two lines preceding the desired information are a blank line followed by a line that starts with the word "Node" as shown below:
Node 0xf002cb2c
xnet2: '/pci@1d,700000/pci@1/SUNW,hme@0,1:dhcp,'
xnet1: '/pci@1e,600000/pci@3/SUNW,hme@0,1:dhcp,'
|
When the script finds the blank line, it saves that line number in $s.
When the script finally readies to print the desired information, it sets the start point for the aliases output to $s incremented by two (see the last for loop) and prints each line up to and including the one referred to by $e (the end line).
Since this script detects the end of the aliases section and then searches upwards in the output for the start of that section, it is able to accommodate whatever number of devaliases are defined on a system. If you're not sure whether a mirror of your boot drive has been defined as a devalias or your boot disk is set up as disk or disk0, this script should make it easy for you to extract that information from your system.