Przy okazji niedawnych problemów z roboczym komputerem zdarzyło mi się (a) wymienić płytę główną w nie zmienianym poza tym komputerze (b) przełożyć dyski do całkiem nowej maszyny. W obu wypadkach nie reinstalowałem systemu i w obu po restarcie spotkałem się z tym samym problemem: w trakcie uruchamiania następowała ok. 2-minutowa pauza przy próbie inicjalizacji sieci, a po nim system nie odnajdywał karty sieciowej.
Problem
Wyglądało to następująco: ifconfig
po prostu nie widział eth0
::
# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
(...)
virbr0 Link encap:Ethernet HWaddr 16:c8:cc:cb:8a:e4
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
(...)
(virbr0
to interfejs kreowany na potrzeby wirtualnych maszyn, w tym wypadku KVM).
Także próba ręcznego podniesienia karty kończyła się błędem:
# ifup eth0
Cannot find device "eth0"
Failed to bring up eth0.
(ten sam błąd pojawiał się też przy akcjach wyższego poziomu takich
jak /etc/init.d/networking restart
)
Co ciekawe, był to inny błąd niż prezentowany dla faktycznie nie istniejących interfejsów:
# ifup eth2
Ignoring unknown interface eth2=eth2.
Przyczyna
Winny okazał się plik /etc/udev/rules.d/70-persistent-net.rules
,
który na twardo zakładał fizyczny adres karty sieciowej - według
starej, wymienionej karty. Wyglądał mniej więcej tak:
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
# (...)
# PCI device 0x10ec:/sys/devices/pci0000:00/0000:00:1c.4/0000:02:00.0 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="70:2d:34:ca:08:e2", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
a niezgodnosć zadeklarowanego tu MACa karty (ATTR{address}
) z aktualnym
adresem sieciówki powodowała problemy przy jej uruchamianiu.
Rozwiązanie
Aby przywrócić działanie sieci wystarczyło powyższy plik skasować:
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules
i zrestartować komputer. Po restarcie plik powstał na nowo, z poprawioną zawartością, a sieć działała.
Nie udało mi się znaleźć sposobu na przeładowanie tego bez restartu. W szczególności nie pomogło(jak informuje man reload-rules does not apply changes to existing devices...). Zapewne pomogłoby usunięcie i ponowne załadowanie modułu jądra ale obsługa Ethernetu była u mnie wkompilowana na twardo.$ sudo udevadm control --reload-rules
Jak widać sprawa jest trywialna ale ... dobrze wiedzieć, zwłaszcza przy uruchamianiu nowego sprzętu przyczyna problemów jest dalece nieoczywista.
Drobiazgi uzupełniające
-
Krótki i zrozumiały dokument opisujący zasadę działania
udev
: Writing udev rules. Cytowane polecenia nieco się w najnowszych linuksach zmieniły (np. nie ma jużudevinfo
czyudevtest
, jest za toudevadm info
alboudevadm test
) ale cała idea działania jest opisana przyjaźniej niż w udevowych manach. -
Pobieranie informacji o urządzeniu (cytuję dla sieciówki ale podobnie jest z innymi):
$ udevadm info --query=path --path=/sys/class/net/eth0
/devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0
albo bardziej kompleksowo
$ udevadm info --query=all --path=/sys/class/net/eth0
P: /devices/pci0000:00/0000:00:1c.1/0000:02:00.0/net/eth0
E: COMMENT=PCI device 0x10ec:/sys/devices/pci0000:00/0000:00:1c.1/0000:02:00.0 (r8169)
E: DEVPATH=/devices/pci0000:00/0000:00:1c.1/0000:02:00.0/net/eth0
E: ID_BUS=pci
E: ID_MM_CANDIDATE=1
E: ID_MODEL_FROM_DATABASE=RTL8111/8168B PCI Express Gigabit Ethernet controller
E: ID_MODEL_ID=/sys/devices/pci0000:00/0000:00:1c.1/0000:02:00.0
E: ID_VENDOR_FROM_DATABASE=Realtek Semiconductor Co., Ltd.
E: ID_VENDOR_ID=0x10ec
E: IFINDEX=2
E: INTERFACE=eth0
E: MATCHADDR=d7:3a:7e:3f:89:1e
E: MATCHDEVID=0x0
E: MATCHIFTYPE=1
E: SUBSYSTEM=net
E: UDEV_LOG=3
E: USEC_INITIALIZED=16444959
- Sprawdzanie jakie reguły przeszukuje udev przy uruchamianiu urządzenia (te z
/etc
to wcale nie wszystko):
$ sudo udevadm test /class/net/eth0
run_command: calling: test
adm_test: version 175
This program is for debugging only, it does not run any program,
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
parse_file: reading '/lib/udev/rules.d/40-crda.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-gnupg.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-gnupg2.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-gpsd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-hplip.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-ia64.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-inputattach.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-libgphoto2-2.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-libsane.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-ppc.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-usb-media-players.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-usb_modeswitch.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-xdiagnose.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-xserver-xorg-video-intel.rules' as rules file
parse_file: reading '/lib/udev/rules.d/42-qemu-usb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/50-firmware.rules' as rules file
parse_file: reading '/lib/udev/rules.d/50-udev-default.rules' as rules file
parse_file: reading '/lib/udev/rules.d/55-dm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/56-hpmud_support.rules' as rules file
parse_file: reading '/lib/udev/rules.d/56-lvm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-cdrom_id.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-pcmcia.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-alsa.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-input.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-serial.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage-dm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage-lvm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage-tape.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-v4l.rules' as rules file
parse_file: reading '/lib/udev/rules.d/61-accelerometer.rules' as rules file
parse_file: reading '/lib/udev/rules.d/61-gnome-bluetooth-rfkill.rules' as rules file
parse_file: reading '/lib/udev/rules.d/64-xorg-xkb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/66-xorg-synaptics-quirks.rules' as rules file
parse_file: reading '/lib/udev/rules.d/69-cd-sensors.rules' as rules file
add_rule: IMPORT found builtin 'usb_id', replacing /lib/udev/rules.d/69-cd-sensors.rules:85
parse_file: reading '/lib/udev/rules.d/69-libmtp.rules' as rules file
parse_file: reading '/lib/udev/rules.d/69-xorg-vmmouse.rules' as rules file
parse_file: reading '/lib/udev/rules.d/69-xserver-xorg-input-wacom.rules' as rules file
parse_file: reading '/etc/udev/rules.d/70-persistent-cd.rules' as rules file
parse_file: reading '/etc/udev/rules.d/70-persistent-net.rules' as rules file
parse_file: reading '/lib/udev/rules.d/70-printers.rules' as rules file
parse_file: reading '/lib/udev/rules.d/70-uaccess.rules' as rules file
parse_file: reading '/lib/udev/rules.d/70-udev-acl.rules' as rules file
parse_file: reading '/lib/udev/rules.d/71-seat.rules' as rules file
parse_file: reading '/lib/udev/rules.d/73-seat-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-cd-aliases-generator.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-net-description.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-persistent-net-generator.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-probe_mtd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-tty-description.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-ericsson-mbm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-longcheer-port-types.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-nokia-port-types.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-pcmcia-device-blacklist.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-platform-serial-whitelist.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-qdl-device-blacklist.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-simtech-port-types.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-usb-device-blacklist.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-x22x-port-types.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-mm-zte-port-types.rules' as rules file
parse_file: reading '/lib/udev/rules.d/77-nm-olpc-mesh.rules' as rules file
parse_file: reading '/lib/udev/rules.d/78-graphics-card.rules' as rules file
parse_file: reading '/lib/udev/rules.d/78-sound-card.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-drivers.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-mm-candidate.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-udisks.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-udisks2.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-brltty.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-hdparm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-hplj10xx.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-keyboard-configuration.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-lvm2.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-regulatory.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-usbmuxd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-alsa-restore.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-alsa-ucm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-libgpod.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-pulseaudio.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-cd-devices.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-keyboard-force-release.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-keymap.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-kpartx.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-udev-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-battery-recall-dell.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-battery-recall-fujitsu.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-battery-recall-gateway.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-battery-recall-ibm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-battery-recall-lenovo.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-battery-recall-toshiba.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-csr.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-hid.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-upower-wup.rules' as rules file
parse_file: reading '/lib/udev/rules.d/96-dell-recovery-partition.rules' as rules file
parse_file: reading '/lib/udev/rules.d/97-bluetooth-hid2hci.rules' as rules file
parse_file: reading '/lib/udev/rules.d/99-bt-service-restart.rules' as rules file
parse_file: reading '/lib/udev/rules.d/99-laptop-mode.rules' as rules file
udev_rules_new: ignore empty '/etc/udev/rules.d/z80_user.rules'
udev_rules_new: rules use 304944 bytes tokens (25412 * 12 bytes), 48727 bytes buffer
udev_rules_new: temporary index used 84120 bytes (4206 * 20 bytes)
udev_device_new_from_syspath: device 0x7fe5709492d0 has devpath '/devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'
udev_device_new_from_syspath: device 0x7fe57095b520 has devpath '/devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'
udev_device_read_db: device 0x7fe57095b520 filled with db file data
udev_device_new_from_syspath: device 0x7fe57095bf80 has devpath '/devices/pci0000:00/0000:00:1c.0/0000:07:00.0'
udev_device_new_from_syspath: device 0x7fe57095c940 has devpath '/devices/pci0000:00/0000:00:1c.0'
udev_device_new_from_syspath: device 0x7fe57095cf20 has devpath '/devices/pci0000:00'
udev_rules_apply_to_event: NAME 'eth0' /etc/udev/rules.d/70-persistent-net.rules:8
udev_device_read_db: no db file to read /run/udev/data/+pci:0000:07:00.0: No such file or directory
udev_rules_apply_to_event: IMPORT 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0' /lib/udev/rules.d/75-net-description.rules:11
udev_event_spawn: starting 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'
spawn_read: 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'(err) 'libudev: udev_device_new_from_syspath: device 0x7fe416c2c580 has devpath '/devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0''
spawn_read: 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'(err) 'libudev: udev_device_new_from_syspath: device 0x7fe416c2c9e0 has devpath '/devices/pci0000:00/0000:00:1c.0/0000:07:00.0''
spawn_read: 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'(out) 'ID_VENDOR_FROM_DATABASE=Realtek Semiconductor Co., Ltd.'
spawn_read: 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0'(out) 'ID_MODEL_FROM_DATABASE=RTL8111/8168 PCI Express Gigabit Ethernet controller'
spawn_wait: 'pci-db /devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0' [32170] exit with return code 0
udev_device_new_from_syspath: device 0x7fe57095f480 has devpath '/devices/pci0000:00/0000:00:1c.0/0000:07:00.0'
udev_device_update_db: unable to create temporary db file '/run/udev/data/n2.tmp': Permission denied
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1c.0/0000:07:00.0/net/eth0
ID_BUS=pci
ID_MM_CANDIDATE=1
ID_MODEL_FROM_DATABASE=RTL8111/8168 PCI Express Gigabit Ethernet controller
ID_MODEL_ID=/sys/devices/pci0000:00/0000:00:1c.0/0000:07:00.0
ID_VENDOR_FROM_DATABASE=Realtek Semiconductor Co., Ltd.
ID_VENDOR_ID=0x10ec
IFINDEX=2
INTERFACE=eth0
SUBSYSTEM=net
UDEV_LOG=6
USEC_INITIALIZED=28170548