This worked for me under vmware, where there are often these files (possibly you need the vmware kernel modules):
- /sys/bus/pci/devices/0000:.../label
- /sys/bus/pci/devices/0000:.../acpi_index
and this synmlink:
- /sys/bus/pci/devices/0000:.../firmware_node
The file label contains a line of text like: Ethernet0, Ethernet1, etc, and are numbered according to the original number in the OVF file.
The file acpi_index has a number (long int probably), and the numbers when sorted, match the original order of the interfaces in the OVF file, or order defined in the VM.
The filename part of the destination of the symlink firmware_node also collates in the same order as the interfaces in the original OVF file.
e.g ../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/device:8b/device:8c
You can read that with readlink
under the shell.
The most useful is probably the label file as it would be simple to extract the numeric part of the name and use it as a device name.
You can read the label for $dev
like this:
read label < /sys/bus/pci/devices/$dev/label
and then extract the numeric suffix like this: ${label#Ethernet}
As a couplet which does nothing if there was no label:
read label < /sys/bus/pci/devices/$dev/label && echo ${label#Ethernet}
If you want to process all devices to get the order, you can read your ethernet devices in bus order, like this:
lspci -D -mm | sed -n -e 's/ "Ethernet controller".*//;T;p'
then you can pipe it into this segment to prefix the label
while read dev ; do read label < /sys/bus/pci/devices/$dev/label ; echo ${label#Ethernet} $dev ; done
You can then sort, and remove the label like this: sort | sed -e 's/.* //'
The whole expression to emit all ethernet devices in VMWARE defined order is:
lspci -D -mm | sed -n -e 's/ "Ethernet controller".*//;T;p' | while read dev ; do read label < /sys/bus/pci/devices/$dev/label ; echo ${label#Ethernet} $dev ; done | sort | sed -e 's/.* //'