-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathHOTPLUG-UDEV.txt
More file actions
1488 lines (1287 loc) · 60 KB
/
HOTPLUG-UDEV.txt
File metadata and controls
1488 lines (1287 loc) · 60 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Sane network interface management with Hotplug or uDev
------------------------------------------------------
INTRODUCTION
------------
In the old days all wireless cards were managed by the
excellent Pcmcia subsystem and its rich configuration scripts, and
life was good. Then came the wireless PCI cards, then the wireless
USB dongles. Some unification was needed, and rather than adapt the
Pcmcia subsystem for PCI and USB, it was decided to create the much
simpler Hotplug system.
The USB subsystem already uses Hotplug. The Pcmcia subsystem
is migrating to it : CardBus cards (32 bits) already use Hotplug,
whereas Pcmcia cards (16 bits) often still use the old Pcmcia scripts.
The Hotplug system is now very mature. Most users comming from
the old Pcmcia scripts are disappointed at first by its apparent lack
of features, however it is very flexible and powerful. The new uDev
system depend on Hotplug and integrates tightly with it.
In this document, we will show how to fully exploit the
Hotplug system and try to implement the equivalent of all the
functionality of the Pcmcia scripts.
ASSUMPTIONS
-----------
The target audience of this document is mostly power users and
distribution maintainers, but it should give enough clues to help
newbies. You should have read and understood DISTRIBUTIONS.txt. The
procedures described here are more advanced than the simple
configuration described in DISTRIBUTIONS.txt.
The main focus is of course on removable wireless interfaces,
but we will to talk about network interface management in general, so
this should apply also to built-in Ethernet cards.
PROBLEM STATEMENT
-----------------
Let's assume a Linux system and two or more network devices,
Device A and Device B. Those devices may be built-in or removable,
they may be present or absent from the system at any time, and they
may activated in any particular order.
The user wants to assign Configuration A to Device A and
Configuration B to Device B, without the possibility that Device A
gets assigned Configuration B.
Different users may have different definitions of what is
Device A. For some, it's a specific instance of a specific hardware,
for others any hardware that meets some criteria (a wireless card, an
Ethernet card).
The user may also want to have multiple configurations for a
given device such that the chosen configuration depends on various
factors, just as with the old Pcmcia schemes. Device A may need
Configuration A1 or Configuration A2 depending on those factors.
By default, all network interfaces are created using default
interface names (starting at "eth0" and going up). I call that the
"all my cards are eth0" problem : im most distributions, "eth0" points
to a single fixed configuration in the configuration
database. Clearly, this won't satisfy our requirements.
EXAMPLE SYSTEM
--------------
The distribution I use is Debian 3.0, and some parts of what I
say here will be specific to it. However, it should be easy to
translate this material to other distributions and I welcome additions
to this document.
The example system is as follows :
o Linux 2.6.X SMP kernel with hotplug support
o Fully modular system (all network drivers as modules)
o PCI Ethernet card : AMD PCnet LANCE (pcnet32 - eth4)
o PCI Ethernet card : HP 100VG J2585B (hp100 - eth2)
o ISA Wireless card : Old AT&T Wavelan (wavelan - eth3)
o ISA-Pcmcia bridge : VADEM VG-469 (i82365 - slot 0)
o PCI-CardBus bridge : Ricoh RL5c475 (yenta_socket - slot 2)
o Pcmcia 802.11 card : Aironet 350 (airo_cs - eth0)
o Pcmcia 802.11 card : Lucent Orinoco (orinoco_cs - eth0)
o CardBus 802.11 card : SMC 2835W (prism54 - prism0)
This system just happens to be my Linux development box. It
has enough interfaces to make it interesting. All the examples I
present in this document are extracted from this system.
BASIC CONCEPTS
--------------
Most of the concept and tricks presented here are not really
new. The main contribution is to integrate them.
1) Removable network interfaces are managed by Hotplug
(Pcmcia, CardBus, USB...). We can't assume that those interfaces are
always present in this system and available at boot time (Pcmcia cards
were not made to be soldered in the Pcmcia slot). Therefore Hotplug is
the way to go.
2) The Hotplug system can use either the original Hotplug
scripts or the uDev daemon with the uDev scripts.
3) Built-in PCI and ISA cards are managed by the init scripts,
as they have always been. The ISA subsystem will never have Hotplug
support, and hotplug is not necessary for PCI cards.
4) Built-in devices that are disable most of the time should
be enabled manually by the user. Therefore both Hotplug and the init
scripts should ignore those devices by default.
5) (1), (3) and (4) must be compatible on the same system and
play nice with each other.
6) A well defined and consistent network interface name is
assigned to each network hardware interface using 'ifrename'. Device A
is always named 'ethA' (or whatever name you like such as
'mynetworkcard').
7) No interface is called 'eth0' (or 'wlan0'). Any unknown
device would be 'eth0', so known devices should be called something
else. There are also other issues with using 'eth0'.
8) Multiple configurations for a single interface (schemes)
are managed by the ifup/ifdown subsystem.
CONFIGURATION FROM INIT SCRIPTS
-------------------------------
It may seem paradoxical, but before setting up Hotplug, we
need to make sure that the initialisation of network cards via init
scripts is done properly and doesn't get in the way of the Hotplug
subsystem.
The configuration of network cards via init scripts is the
traditional way networking is initialised in Linux. The advantage of
this method is that it's very well documented and understood, and has
not changed much over the years. Unfortunately, it doesn't adequately
support removable cards.
The init scripts perform the following 3 functions in order :
1) Load necessary driver modules
2) Rename interface to name chosen by the user
3) Configure those network interfaces
1) Applicability
----------------
Configuration from init scripts is applicable to any built-in
network interface (ISA, PCI...), i.e., interfaces available at boot
time and that will never be removed from the system.
The Hotplug subsystem also has the ability to configure some
of the built-in network interfaces, such as PCI cards. However, there
is a class of devices that will never have Hotplug support, such as
ISA and EISA cards.
2) Loading driver modules (if/as needed)
----------------------------------------
Most distributions build the kernel drivers as modules. This
modular setup allows to minimise the amount of memory used by the
system and the flexible loading/unloading of drivers.
You can also compile your kernel with static drivers
(non-modular). In that case, the driver will always be available in
the kernel, you don't need to configure the module subsystem, so you
can skip directly to the next section.
There are 3 alternatives to manage device drivers as
modules.
1) Some distributions have an explicit list of modules
that are loaded at boot time, usuall in /etc/modules. If you want to
use that feature you need to check the documentation of your
distribution.
2) Some system, such as Hotplug, Discover or Kudzu,
can scan the various buses of the PC and load the appropriate
drivers. This is mostly configuration-free, but may not support all
devices and may load unnecessary modules.
3) The module subsystem also allows to load modules
'on-demand'. When an application try to access or configure a network
interface, the corresponding module is loaded.
I personally prefer to use the 'on-demand' feature of the
module subsystem, as this allow you to not have to specify a static
list of modules that need to be loaded, and only modules really needed
are loaded which saves kernel memory. You can also choose which module
to load when there are multiple modules available that support your
hardware (which happens quite often).
With kernel 2.6.X the module subsystem is configured in the
file /etc/modprobe.conf or files in the directory /etc/modprobe.d/. To
configure 'on-demand' module loading, on my test system I need to add
to the following lines to the configuration :
--------- /etc/modprobe.d/local or /etc/modprobe.conf ------
# HP 100VG J2585B PCI card
alias eth2 hp100
# AMD AMD PCnet LANCE PCI card
alias eth4 pcnet32
# Old AT&T Wavelan ISA card
alias eth3 wavelan
options wavelan io=0x390 irq=15
------------------------------------------------------------
Your distribution may already have lines for your interfaces,
either replace these or make sure they are correct (some distributions
are notorious for picking the wrong driver name in some cases). This
file also contains configuration for lot of other subsystems,
obviously you don't want to touch that.
In this file, you put the name you would like the interface to
have (we'll fix that in a minute). Note that for modern PCI cards this
is much more straightforward than for old ISA cards.
When loading modules on-demand, you usually can not use the
name 'eth0' or other 'ethX' with a low number for your interfaces, as
on-demand module may fail to load them. If there is a unknown
interface or an interface not yet renamed on the system, it will be
eth0, and the system will assume the module for eth0 is already loaded
and will fail to load the proper module.
To test on-demand loading of module, you can do :
--------------------------
> /sbin/modprobe -r eth2
> /sbin/modprobe eth2
--------------------------
3) Installing 'ifrename'
------------------------
You will need to install ifrename on your system. 'ifrename'
is part of the Wireless Tools package (version 27 and later) and is a
complete rewrite of the now obsolete 'nameif'.
Some distributions, such as Debian 3.1/4.0, offer a separate
package for 'ifrename', and in this case you should just install this
package. Other distributions may include ifrename as part of their
'wireless-tools' package (this should be the case for Gentoo, Fedora
and Mandrake). Other distributions, such as Debian 3.0 and Unbuntu
7.10, don't include ifrename at all, so you should compile yourself a
recent version of Wireless Tools (v29 or later) and install it.
The installation of Wireless Tools is described in the INSTALL
file of the Wireless Tools package. If you plan to only use ifrename,
a good option is to compile a static version of Wireless Tools and
only copy the resulting ifrename executable.
In any case, you should verify that 'ifrename' is properly
installed and check the path needed to call it :
--------------------------
> which ifrename
/sbin/ifrename
> whereis ifrename
ifrename: /sbin/ifrename /usr/man/man8/ifrename.8 /usr/share/man/man8/ifrename.8.gz
--------------------------
Most distributions will install 'ifrename' in '/sbin', while
if you compile your own wireless tools, by default it will be in
'/usr/local/sbin' (see Makefile on how to change that).
If you are upgrading ifrename from a previous version, you
should make sure that the new version of ifrename is either installed
in the same location (overwrite old version) or in a place earlier in
the PATH (check with whereis).
4) Making the boot scripts call 'ifrename'
------------------------------------------
You need to make sure 'ifrename' is run at boot time. Most
distributions don't do that yet by default.
This is a part that is distribution-specific, so you will need
to look into your own init files, or ask people familiar with your
distribution. It will need to run just before the call to 'ifup' or
'ifconfig' command.
In Debian 4.0 (Etch) and later, the 'ifrename' package adds it
own init script at the right place, called /etc/init.d/ifrename. You
don't have to do anything.
In Debian 3.0 (Woody) and Debian 3.1 (Sarge), ifrename needs
to be run from /etc/init.d/networking, which is not the default. The
necessary patch to the init script is below :
----------------------------------------------------------------
--- networking-orig Wed Feb 18 13:56:23 2004
+++ networking Fri Feb 20 14:51:06 2004
@@ -120,6 +120,15 @@ case "$1" in
doopt syncookies no
doopt ip_forward no
+ # Optionally remap interface names based on MAC address.
+ # '/sbin/ifrename' is part of wireless-tools package.
+ # /etc/iftab is currently not created by default. Jean II
+ if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
+ echo -n "Remapping network interfaces name: "
+ ifrename -p
+ echo "done."
+ fi
+
echo -n "Configuring network interfaces: "
ifup -a
echo "done."
----------------------------------------------------------------
Don't forget to set the appropriate path to the ifrename
command (see step (3) above).
You may also want to also set the proper options for ifrename
(check the man page).
The option '-p' enables module autoloading compatibility.
The default version of 'ifrename' also includes some special
Debian support : using "ifrename -p -d", only the proper modules are
loaded. If you are using Debian, you should use this option.
5) Renaming interfaces
----------------------
As stated above, we use 'ifrename' to assign names to
interfaces.
First, you need to get the MAC address of each of your
interfaces. You can read the MAC address on the label of the card, or
display it using the 'ifconfig -a' command. Remember that the
interface won't load yet with the proper name, so you may need to do a
bit looking around :
-----------------------------
# modprobe pcnet32
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:10:83:34:BA:E5
[...]
-----------------------------
The configuration of 'ifrename' is simple, you just specify
which name should be used for each MAC address in the file
/etc/iftab :
--------- /etc/iftab ------------------------
# HP 100VG J2585B PCI card
eth2 mac 08:00:09:*
# Old AT&T Wavelan ISA card
eth3 mac 08:00:0E:*
# AMD AMD PCnet LANCE PCI card
eth4 mac 00:10:83:*
---------------------------------------------
The '*' in the MAC address is a wildcard and allows me to
replicate my configuration between multiple identical computers. If
you have to manage large number of computers (like a rack of servers
or clusters), then you may want to look at other selectors offered by
'ifrename'.
In this example, we used the MAC address of the card. Using
the MAC address is not always an option, there is a section at the end
of this document dedicated to those cases.
To test that ifrename works, do the following :
o Load all your drivers, see section (2)
o Check /proc/net/dev to see which interface exist
o Bring all interfaces down : ifconfig ethX down
o Run ifrename
o Check each interface with ifconfig
o Bring all interfaces up : ifconfig ethX up
6) Configuring interfaces
-------------------------
Most likely, your distribution is already doing this part
properly. Just assign the proper IP and wireless configuration to each
of the interface names you have chosen.
This part is distribution specific, and I already document it
in the file DISTRIBUTIONS.txt.
In Debian, you would need to modify the file
/etc/network/interfaces so that it looks something like this :
--------- /etc/network/interfaces -----------
# AMD PCnet LANCE PCI card
auto eth4
iface eth4 inet dhcp
# HP 100VG J2585B PCI card
auto eth2
iface eth2 inet static
address 10.0.0.2
netmask 255.255.255.0
broadcast 10.0.0.255
gateway 10.0.0.1
---------------------------------------------
This was the last part. Now, at your next boot, all your
interfaces should be assigned the proper name and the proper
configuration.
If this is not the case, there is a troubleshooting section at
the end of this document.
CONFIGURATION VIA UDEV
----------------------
Dealing with removable interfaces is similar to dealing with
built-in interfaces, the main difference is that we will use Hotplug
event with the uDev system instead of the init scripts. This requires
a fairly recent distributions, older distributions don't have uDev or
uDev system not capable enough.
Note that you can also use removable interfaces with the
original Hotplug scripts. This is detailed in the next section. The
installation of uDev changes a lot of things on a system, so may not
be for everybody, however recent version of Gnome and KDE seem to
require it.
1) Applicability
----------------
The Hotplug configuration method is the best choice for any
removable network interface, such as :
o Pcmcia (16 bits) network cards
o CardBus (32 bits) network cards
o USB network dongles
o Hot-PCI network cards
It may also be used to manage other types of network
interfaces, although it may not be the best choice for them.
2) How Hotplug works with the uDev scripts
------------------------------------------
When using uDev, the concept is similar to the original
Hotplug scripts, however the implementation is slightly less
transparent. Also, the name of the rules and the location of scripts
vary from distribution from distribution.
When something interesting happens, the Linux kernel generates
an Hotplug event. The uDev deamon (udevd) receive the event, does some
processing on its own, use the rules in /etc/udev/rules.d/, and
finally run the proper script in /lib/udev/.
There are 3 types of Hotplug events we care about :
o PCI event : a CardBus device is added or removed
from the system. The hotplug rule loads the driver, in my case
/etc/udev/rules.d/z55_hotplug.rules.
o USB event : a USB device is added or removed from
the system. The hotplug rule loads the driver, in my case
/etc/udev/rules.d/z55_hotplug.rules.
o Network event : a network interface is added or
removed from the system. The script /lib/udev/net.agent is run.
If we insert a CardBus network card in the system, the
following happens :
1) Kernel detects new CardBus device
2) Kernel generates PCI Hotplug event
3) udevd receive the event, runs the Hotplug rule.
4) The Hotplug rule find the proper driver module and loads it.
5) Driver module initialises, creates new network device
6) Kernel detects new network device
7) Kernel generates Network Hotplug event
8) /lib/udev/net.agent runs, configures network device
The sequence of events is similar for USB devices and for removals.
3) Installing uDev for Debian Lenny
-----------------------------------
Thanks to the great work of many people, Debian Lenny has all
the necessary packages and complete udev support, and will work mostly
'out of the box'.
You will need to install the following packages :
o udev
o ifrename
The configuration of Hotplug and uDev is simple. You only have
to modify the file /etc/network/interfaces to enable your interfaces
to be managed with Hotplug and uDev.
By default, ifup ignore all hotplug network events, as it
assume network interfaces are configured using the static init
scripts. To enable ifup to configure specific network interfaces on
hotplug events, you need to list those interface in a "allow-hotplug"
statement.
For example, your /etc/network/interfaces would include :
--------- /etc/network/interfaces -----------
# Enable Hotplug support (Etch and later)
#
allow-hotplug prism0 acx0
---------------------------------------------
4) Installing uDev for Debian Etch (4.0)
----------------------------------------
The uDev system provided with Debian Etch (4.0) is fully
functional, except for one missing feature. This version of uDev can
not integrate with ifrename. The version of ifrename provided also
lacks uDev support.
If you want to use uDev with Debian Etch (4.0), there are two
possibilities. The first solution is use the uDev system to rename
interfaces, loosing some of the power of ifrename. The second solution
is to upgrade both udevd and ifrename.
This is the procedure I personally use to upgrade udevd on
Debian Etch (4.0) :
o Get the canonical version of udev 107 from :
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html
o Compile it with "make".
o Do not "make install" !
o Run "strip udevd"
o Save a copy of the original udevd "cp /sbin/udevd /sbin/udevd.orig"
o Copy the new udevd with "cp udevd /sbin/udevd".
Note that udevd is an essential component of the OS. This
procedure should be safe, but I do not guarantee it will always be
safe.
Upgrading ifrename is simple, this is like installing ifrename
and is described above in this document.
Once those two packages are upgraded, you can go follow the
procedure going back to step (3).
5) Installing uDev for Debian Sarge (3.1)
-----------------------------------------
The uDev system provided with Debian Sarge (3.1) is a very old
version of uDev that is not integrated with the Hotplug scripts. In
other words, if you install uDev with Sarge, you will still need to
use the original Hotplug scripts and configure your system with them.
6) Installing uDev on other distributions
--------------------------------------------
The canonical version of hotplug is available at :
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html
The mailing list for udev is the Hotplug mailins list :
http://linux-hotplug.sourceforge.net/
http://marc.theaimsgroup.com/?l=linux-hotplug-devel&r=1&w=2
Most distributions have highly customized uDev packages and
most likely the canonical version won't completely work on your
system. The udevd deamon is has usually little changes, however the
rules and scripts are very different.
To be able to use uDev with ifrename, you will need uDev
version 107 and later, which has support for calling ifrename. You
will also need ifrename version 29.pre17 or later (I recommend version
29). Most modern distributions should already have those versions.
If this is the case, you only need to install the uDev and
ifrename package. If there is no ifrename package, it's easy to
compile it from source and install it.
7) Making uDev call ifrename
----------------------------
We need to make sure that 'ifrename' is run by the uDev
subsystem at the right time. Because of the complex way uDev works,
the smooth integration can only be done one way. Other methods may
leave the uDev system in a confused state, which may be a problem when
the card/interface is removed.
Most often, the only thing to do it to copy the file
'19-udev-ifrename.rules' from the Wireless Tools package to the
directory "/etc/udev/rules.d/". It should work on most system.
What follow is a detailed explanation of what this additional
rules does.
uDev needs to call ifrename as an IMPORT rule, and with the
right parameter. As I said, this requires uDev version 107 and later
and ifrename version 29.pre17 or later.
The ifrename rule need to be called *before* the 'persistent'
rules. I also like the ifrename rule to happen after local rules. The
uDev rules are processed in alphabetical orders, which is why the
rules filename start usually with numbers. However, those name vary
betwen distributions. Make sure the ifrename rule has a proper
filename for your distribution.
The rules we add looks like this :
------ /etc/udev/rules.d/19-udev-ifrename.rules ------
# Main ifrename rule.
# If interface is found in /etc/iftab, subsequent rename rules are bypassed.
# If interface is not found in /etc/iftab, subsequent rename rules applies.
SUBSYSTEM=="net", ACTION=="add", IMPORT="/sbin/ifrename -u -i %k", NAME:="%k"
------------------------------------------------------
Lastly, make sure the rule has the right path for ifrename :
--------------------------
> which ifrename
/sbin/ifrename
--------------------------
8) Loading driver modules
-------------------------
Wow ! The most difficult part is done.
In theory, you don't need to do any specific configuration for
the driver modules to be loaded. The uDev system should load the right
driver module for you.
Also, you don't need to define aliases in /etc/modprobe.d/* or
in /etc/modprobe.conf, it's useless and may be counterproductive.
If you use a driver compiled statically in the kernel, you
also have nothing to do.
9) Renaming interfaces
-----------------------
We still use ifrename to assign names to interfaces. The
configuration of 'ifrename' is the same. To keep the possibility of
having multiple wireless cards (one in each CardBus slot), we use
wildcards in both the MAC address and the name :
--------- /etc/iftab -----------------------
# SMC 2835W wireless CardBus card
prism* mac 00:30:B4:*
---------------------------------------------
If you insert two cards, they would be named prism0 and
prism1. If you want to control which card get each name, you should
not use wildcards and set a specific line for each card :
--------- /etc/iftab -----------------------
# SMC 2835W wireless CardBus card
prism0 mac 00:30:B4:64:27:8B
prism1 mac 00:30:B4:64:27:8D
---------------------------------------------
10) Configuring interfaces
--------------------------
At this point, configuration of uDev network interfaces is done
just like their built-in counterparts. This part is still distribution
specific, and still already documented in the file DISTRIBUTIONS.txt.
In Debian, you would need to modify the file
/etc/network/interfaces like this :
--------- /etc/network/interfaces -----------
# Enable Hotplug support (Etch and later)
#
allow-hotplug prism0
# SMC 2835W wireless CardBus card
iface prism0 inet static
address 10.0.1.2
netmask 255.255.255.0
broadcast 10.0.1.255
wireless-essid THE_ESSID
wireless-mode ad-hoc
wireless-channel 5
---------------------------------------------
Note that you can also use graphical tools such as
NetworkManager to configure interfaces at this point.
Now, just cross your fingers and plug the card in the slot...
If it does not work, there is a troubleshooting section at the
end of this document.
CONFIGURATION VIA THE ORIGINAL HOTPLUG SCRIPTS
----------------------------------------------
The previous section was dealing with removable interfaces
with Hotplug events and the uDev system. In various cases, or for old
distributions, it's preferable to use the original Hotplug
scripts. The original Hotplug scripts are much less invasive on the
system than uDev.
Using the original Hotplug scripts is similar to using uDev or
dealing with built-in interfaces, the main difference is that the
script used are different. Another difference is that it will likely
require more work on your part because most distributions do not have
all part properly integrated.
1) Applicability
----------------
The Hotplug configuration method is the best choice for any
removable network interface, such as :
o Pcmcia (16 bits) network cards
o CardBus (32 bits) network cards
o USB network dongles
o Hot-PCI network cards
It may also be used to manage other types of network
interfaces, although it may not be the best choice for them.
2) How the original Hotplug scripts works
-----------------------------------------
Conceptually, Hotplug is very simple, and the Hotplug scripts
are quite easy to follow.
When something interesting happens, the Linux kernel generates
an Hotplug event. This runs the main Hotplug script, which in turn
runs the appropriate script from the /etc/hotplug directory.
There are 3 types of Hotplug events we care about :
o PCI event : a CardBus device is added or removed
from the system. The script /etc/hotplug/pci.agent is run.
o USB event : a USB device is added or removed
from the system. The script /etc/hotplug/usb.agent is run.
o Network event : a network interface is added or
removed from the system. The script /etc/hotplug/net.agent is run.
If we insert a CardBus network card in the system, the
following happens :
1) Kernel detects new CardBus device
2) Kernel generates PCI Hotplug event
3) /etc/hotplug/pci.agent runs, finds proper driver module
4) /etc/hotplug/pci.agent loads driver module
5) Driver module initialises, creates new network device
6) Kernel detects new network device
7) Kernel generates Network Hotplug event
8) /etc/hotplug/net.agent runs, configures network device
The sequence of events is similar for USB devices and for removals.
3) Make sure ifup does not deadlock
-----------------------------------
<Most people should ignore this part>
<This applies only to Debian 3.0 and earlier>
The first problem is that we need to make sure the command
'ifup' does not deadlock by calling itself re-entrantly. If the system
has built-in interfaces, the 'ifup' may reenter itself at boot time
via Hotplug :
1) Init scripts start running
2) Init script calls 'ifup -a' to initialise built-in
network interfaces
3) 'ifup' auto-loads driver module for built-in network
interface 'eth4'
4) Driver module initialises, creates new network device
5) Kernel generates Network hotplug event
6) /etc/hotplug/net.agent runs, call 'ifup eth4'
Note that you can produce the same reentrancy if you call ifup
manually on an interface which module is not yet loaded.
The default version of 'ifup' for Debian 3.0 and Debian 3.1
is not reentrant and can therefore deadlock if not used properly. The
patch to make 'ifup' properly reentrant is available here :
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=231197
Contemporary versions of Debian (3.1 and later) have a
net.agent script that contains workarounds to prevents deadlock
situations, so for normal use the default 'ifup' should work fine.
Modern version of Debian (4.0 and later) have a version of
'ifup' that is reentrant and that won't deadlock.
Other distributions have very different ifup programs and I
have not tried those (tell me about it !).
4) Installing uDev for Debian Etch (4.0) or Lenny
-------------------------------------------------
Thanks to the great work of many people, Debian Etch and Lenny
has all the necessary packages and hotplug support, and will work
mostly 'out of the box'.
You will need to install the following packages :
o hotplug
o ifrename
The configuration of network Hotplug has been much simplified
compared to Debian Sarge (3.0). You only have
to modify the file /etc/network/interfaces to enable your interfaces
to be managed with Hotplug and uDev.
By default, ifup ignore all hotplug network events, as it
assume network interfaces are configured using the static init
scripts. To enable ifup to configure specific network interfaces on
hotplug events, you need to list those interface in a "allow-hotplug"
statement.
For example, your /etc/network/interfaces would include :
--------- /etc/network/interfaces -----------
# Enable Hotplug support (Etch and later)
#
allow-hotplug prism0 acx0
---------------------------------------------
5) Installing Hotplug for Debian Sarge (3.1)
--------------------------------------------
Thanks to the great work of many people, Debian Sarge has all
the necessary packages and hotplug support, and will work mostly 'out
of the box'.
You will need to install the following packages :
o hotplug
o ifrename
While the installation of Hotplug is simple, its configuration
may seem complex. The current network Hotplug script has 3 modes :
'all', 'auto' and 'hotplug'. However for our purpose they all produce
the same results when configured. This mode is controlled by the
variable NET_AGENT_POLICY in /etc/default/hotplug.
In the mode "all", Hotplug will run ifup for all network
events. This will result in failure messages if some interfaces have
already been configured by the init scripts. This mode is not
recommended.
In the mode "auto", Hotplug will run ifup only for those
interfaces listed in a auto stanza in /etc/network/interfaces. If
you choose this mode, you need to put in /etc/network/interfaces a
"auto" line for the interfaces you want to control with hotplug.
--------- /etc/network/interfaces -----------
# Enable Hotplug support for "auto" mode (Sarge and later)
auto eth0 eth1 eth2 eth3 eth4 wlan0 wlan1 prism0 prism1 airo0 airo1
---------------------------------------------
This will result in some failure message at boot time, the
init script will attempt to enable all those interfaces, and generate
an error for all those not available at this time. It will also
generate an error messages for interface which have already been
configured by the init scripts. This mode is also not recommended.
In the mode "hotplug", hotplug network events are ignored by
ifup by default. To enable them you will need to add the following
lines to /etc/network/interfaces :
--------- /etc/network/interfaces -----------
# Enable Hotplug support for "hotplug" mode (Sarge and later)
mapping hotplug
script echo
---------------------------------------------
To enable them for only selected interfaces, e.g., ethA, make
/etc/network/interfaces look like this :
--------- /etc/network/interfaces -----------
# Enable Hotplug support for "hotplug" mode (Sarge and later)
mapping hotplug
script grep
map ethA
---------------------------------------------
6) Installing Hotplug for Debian 3.0
------------------------------------
Debian 3.0 doesn't come by default with hotplug, but the
hotplug package is available as regular Debian package (on the CD or
downloadable in Debian archive), so you can just install that.
Unfortunately, this version of hotplug is not fully compatible
with kernel 2.6.X. You will need to do the following modifications to
the file /etc/hotplug/net.agent.
------- /etc/hotplug/net.agent ------------------
--- net.agent-d1 Fri Feb 20 18:18:05 2004
+++ net.agent Fri Feb 20 18:22:50 2004
@@ -26,7 +26,7 @@ if [ "$INTERFACE" = "" ]; then
fi
case $ACTION in
-register)
+add|register)
case $INTERFACE in
# interfaces that are registered after being "up" (?)
@@ -52,7 +52,7 @@ register)
mesg $1 $ACTION event not handled
;;
-unregister)
+remove|unregister)
# Assume that we want to run ifdown no matter what,
# because it is not going to remove the data from the
# ifstate database otherwise.
-------------------------------------------------
Compared to the version in Sarge, this older version of
hotplug is much more basic, and doesn't have any scanning at boot time
and doesn't need to be enabled in /etc/network/interfaces.
7) Installing hotplug on other distributions
--------------------------------------------
The canonical version of hotplug is available at :
http://linux-hotplug.sourceforge.net/
Most distributions have customized hotplug packages and
chances are that the canonical version won't completely work on your
system. All these various changing versions make it difficult for me
to tell what exactly needs to be changed in the hotplug scripts to
make them work. However, most should work out of the box.
Remember also that in most cases, you can not have the
original Hotplug scripts and uDev together. If uDev is already
installed on your system, downgrading to the original Hotplug scripts
may be tricky.
My guess is that in a few releases, all these problems will
sort themselves out. Just be patient.
8) Dealing with 'init' hotplug
------------------------------
In addition to the standard kernel Hotplug events, modern
versions of the Hotplug scripts add init scripts that scan the system
buses and generate pseudo Hotplug events at boot time. For the PCI
buses, the script /etc/hotplug/pci.rc is run, for the USB bus,
/etc/hotplug/usb.rc is run.
The end result is that the Hotplug subsystem will also attempt
to configure built-in devices :
1) Kernel boots
2) Init runs, start to initialise the OS
3) /etc/hotplug/pci.rc runs, generates pseudo Hotplug event
4) /etc/hotplug/pci.agent loads driver module
5) Driver module initialises, creates new network device
6) Kernel generates Network Hotplug event
7) /etc/hotplug/net.agent runs, configures network device
At this point, you realise that at initialisation, both
Hotplug and the regular init scripts (see "CONFIGURATION FROM INIT
SCRIPTS") are trying to configure the same devices in parallel. This
may create problems and is totally redundant.
Another reason I don't like this mechanism is that it blindly
attempts to load drivers for all hardware present on the system and
doesn't use the module loader configuration files to select preferred
drivers. It's fairly common to have multiple drivers for a given
hardware, and because of Murphy's law, Hotplug will usually load the
wrong one. It's also fairly common to have hardware on the system that
doesn't need enabling (for example, the IDE controller on my SCSI
machine), not loading the driver makes your kernel smaller and boot
faster.
Hotplug does have a way of disabling the loading of drivers
on a case by case basis. Drivers listed in /etc/hotplug/blacklist
will not be loaded.
Hotplug can be disabled for a whole subsystem by editing the
appropriate .rc script in /etc/hotplug, or just deleting/renaming
those files.
9) Making hotplug scripts call ifrename
---------------------------------------
The last hotplug step is to make sure that 'ifrename' is run
by the hotplug subsystem at the right time. As before, we want to run
it just before calling 'ifup'.
The latest version of the hotplug scripts have this feature
integrated. However, you need to check that the path used for calling
'ifrename' is the proper one on your system. And, for older versions
of hotplug scripts, you will need to add this support yourself.
Check the path for ifrename :
--------------------------
> which ifrename
/sbin/ifrename
--------------------------
The patch to add 'ifrename' to hotplug looks like :
------- /etc/hotplug/net.agent ------------------
--- net.agent-s2 Fri Feb 20 17:18:46 2004
+++ net.agent Fri Feb 20 17:32:43 2004
@@ -40,6 +40,21 @@ add|register)
# we can't do much here without distro-specific knowledge
# such as whether/how to invoke DHCP, set up bridging, etc.
+ # Run ifrename as needed - Jean II
+ # Remap interface names based on MAC address. This works around
+ # the dreaded configuration problem "all my cards are 'eth0'"...
+ # This needs to be done before ifup, otherwise ifup will get
+ # confused by the name change and because iface needs to be
+ # down to change its name.
+ if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
+ debug_mesg invoke ifrename for $INTERFACE
+ NEWNAME=`/sbin/ifrename -i $INTERFACE`
+ if [ -n "$NEWNAME" ]; then
+ debug_mesg iface $INTERFACE is remapped to $NEWNAME
+ INTERFACE=$NEWNAME
+ fi;
+ fi
+
# RedHat and similar
export IN_HOTPLUG=1
if [ -x /sbin/ifup ]; then
-------------------------------------------------
If your hotplug scripts already include ifrename support then
you should find a section in /etc/hotplug/net.agent looking like the
patch above. Otherwise, just cut'n'paste the patch above in the right
place.
The path for 'ifrename' is used twice above, so don't forget
to modify both occurences.
9) Loading driver modules
-------------------------
Wow ! The most difficult part is done.
In theory, you don't need to do any specific configuration for
the driver modules to be loaded. The 'pci.agent' and 'usb.agent'
should load the right driver module for you.
Also, you don't need to define aliases in /etc/modprobe.d/* or
in /etc/modprobe.conf, it's useless and may be counterproductive.
If you use a driver compiled statically in the kernel, you
also have nothing to do.
10) Renaming interfaces
-----------------------
We still use ifrename to assign names to interfaces. The
configuration of 'ifrename' is the same. To keep the possibility of
having multiple wireless cards (one in each CardBus slot), we use
wildcards in both the MAC address and the name :
--------- /etc/iftab -----------------------
# SMC 2835W wireless CardBus card
prism* mac 00:30:B4:*
---------------------------------------------
If you insert two cards, they would be named prism0 and
prism1. Note that 'name wildcarding' is a feature only available in
2.6.X and 2.4.30 and later, so if you use older version of 2.4.X you
will need to be explicit and list each card separatly :
--------- /etc/iftab -----------------------
# SMC 2835W wireless CardBus card
prism0 mac 00:30:B4:64:27:8B
prism1 mac 00:30:B4:64:27:8D
---------------------------------------------
11) Configuring interfaces
-------------------------
At this point, configuration of Hotplug network interfaces is
done just like their built-in counterparts. This part is still
distribution specific, and still already documented in the file
DISTRIBUTIONS.txt.
In Debian, you would need to modify the file
/etc/network/interfaces like this :
--------- /etc/network/interfaces -----------
# Enable Hotplug support (Etch and later)
#
allow-hotplug prism0 acx0
# Enable Hotplug support (Sarge and later)
mapping hotplug
script grep
map prism0
# SMC 2835W wireless CardBus card
iface prism0 inet static
address 10.0.1.2
netmask 255.255.255.0
broadcast 10.0.1.255
wireless-essid THE_ESSID
wireless-mode ad-hoc
wireless-channel 5
---------------------------------------------
Note that you should not have wireless-* lines if you are
using waproamd to set these parameters.
Now, just cross your fingers and plug the card in the slot...
PCMCIA INTERFACES (16 bits)
---------------------------
The Pcmcia subsystem has quite some legacy, and can use
various configuration procedures. The Pcmcia subsystem exclusively
uses hotplug for 32 bits cards (if you are using the kernel Pcmcia
modules, which is the only option for 2.6.X). For 16 bit cards cardmgr