I’ve used the /proc
and /sys
filesystems for a variety of tasks, but it’s always interesting to discover a new use. For example, if you want to completely remove an ethernet device from the system (not just disable the ethernet link) it can be done from /sys
. In almost all cases, you simply want to use ifconfig down
or ifdown
to de-activate the port (allowing you to reactivate later). But there are instances where you want to remove the eth device. In this case, you can use /sys
to remove a single device.
In my case, it worked even though there are two ethernet devices on the same Intel gigabit ethernet chip and are both served by the same Linux kernel module.
To get a list of all ethernet devices in the server:
lspci | grep -i eth
09:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
To find the proper location in /sys
, you can search by PCI address:
find /sys -name *09:00.0
/sys/devices/pci0000:00/0000:00:1c.0/0000:09:00.0 /sys/bus/pci/devices/0000:09:00.0 /sys/bus/pci/drivers/e1000e/0000:09:00.0
You can also search by ethernet device name:
find /sys -name *eth0
/sys/devices/pci0000:00/0000:00:1c.0/0000:09:00.0/net/eth0 /sys/class/net/eth0
Once you’ve found the device you wish to disable, take a look at the /sys
directory for that PCI device:
ls /sys/devices/pci0000:00/0000:00:1c.0/0000:09:00.0
broken_parity_status class config device driver enable irq local_cpulist local_cpus modalias msi_bus msi_irqs net numa_node power remove rescan reset resource resource0 resource2 resource3 subsystem subsystem_device subsystem_vendor uevent vendor
Now, write a 1
to the magic file and remove the device:
echo 1 > /sys/devices/pci0000:00/0000:00:1c.0/0000:09:00.0/remove
You can verify everything was successful by looking at the kernel message log:
dmesg | tail
e1000e 0000:09:00.0: PCI INT A disabled
After more poking around, it became clear that the remove command is available for any PCI device. You ought to be able to remove anything you like.
It works only temporarily.
After reboot the network device is there again.
I’m afraid that’s the way commands in /sys work – they only persist until the Linux kernel is restarted. There are sometimes ways to re-run such commands every boot (for example, by putting these commands into one of the Linux start-up scripts). There has been such a tool for quite some time which operates on the /proc filesystem (it is called sysctl). I know some people have also written their own versions for /sys (search for sysfsctl).
use udev to echo 1 > remove disable device permanent.
http://www.reactivated.net/writing_udev_rules.html