Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/genkernel:master commit in: doc/, defaults/
Date: Thu, 18 Jul 2019 20:15:58
Message-Id: 1563480503.b3889e9bf7d486f83db3c182844b1217ce75d472.whissi@gentoo
1 commit: b3889e9bf7d486f83db3c182844b1217ce75d472
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jul 18 20:08:23 2019 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Thu Jul 18 20:08:23 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=b3889e9b
7
8 linuxrc: Load network modules only when needed
9
10 To avoid problems related to drivers requiring special firmware which
11 might be not available when loading the module because the user don't really
12 need that module but it was added based on genkernel's module_load file,
13 we will no longer load network modules on boot.
14
15 Instead we will only load network modules when needed, for example
16 when dosshd is set or NFS is used.
17
18 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
19
20 defaults/initrd.defaults | 5 +--
21 defaults/initrd.scripts | 83 +++++++++++++++++++++++++++++++++++++++++-------
22 doc/genkernel.8.txt | 3 ++
23 3 files changed, 78 insertions(+), 13 deletions(-)
24
25 diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
26 index fbbd214..c617064 100644
27 --- a/defaults/initrd.defaults
28 +++ b/defaults/initrd.defaults
29 @@ -80,6 +80,7 @@ GK_NET_ROUTES=
30 GK_NET_TIMEOUT_DAD=10
31 GK_NET_TIMEOUT_DECONFIGURATION=10
32 GK_NET_TIMEOUT_DHCP=10
33 +GK_NET_TIMEOUT_INTERFACE=10
34 GK_SHELL_LOCKFILE='/var/run/rescueshell.pid'
35 GK_SSHD_LOCKFILE='/tmp/remote-rescueshell.lock'
36 GK_SSHD_PIDFILE='/var/run/dropbear.pid'
37 @@ -119,8 +120,8 @@ DEFAULT_NFSOPTIONS="ro,nolock"
38 # - modules
39 HWOPTS_BLK='nvme pata sata scsi usb firewire waitscan'
40 HWOPTS_OBSOLETE='pcmcia ataraid' # Obsolete stuff that might be useful on old hardware, do$X only.
41 -HWOPTS="keymap cache modules virtio hyperv ${HWOPTS_BLK} bcache lvm dmraid multipath mdadm zfs fs net iscsi crypto"
42 +HWOPTS="keymap cache modules virtio hyperv ${HWOPTS_BLK} bcache lvm dmraid multipath mdadm zfs fs iscsi crypto"
43
44 # This is the set of default HWOPTS, in the order that they are loaded.
45 # This is whitespace aligned with HWOPTS above.
46 -MY_HWOPTS=" modules virtio hyperv ${HWOPTS_BLK} bcache lvm dmraid mdadm fs net crypto"
47 +MY_HWOPTS=" modules virtio hyperv ${HWOPTS_BLK} bcache lvm dmraid mdadm fs crypto"
48
49 diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
50 index bc19fff..61ae534 100644
51 --- a/defaults/initrd.scripts
52 +++ b/defaults/initrd.scripts
53 @@ -1597,6 +1597,10 @@ iface_name() {
54 }
55
56 start_network() {
57 + # Load network modules only when we need them to avoid possible
58 + # firmware problems for people not using network that early
59 + MY_HWOPTS=net load_modules
60 +
61 # At least gk.net.iface can only be processed after sysfs was
62 # mounted.
63 local x=
64 @@ -1620,17 +1624,21 @@ start_network() {
65 GK_NET_GW=${x#*=}
66 ;;
67 gk.net.iface=*)
68 - local tmp_iface=$(iface_name "${x#*=}")
69 - if [ -z "${tmp_iface}" ]
70 - then
71 - warn_msg "Interface specified by '${x}' not found, falling back to genkernel defaults ..."
72 - else
73 - GK_NET_IFACE=${tmp_iface}
74 - fi
75 + GK_NET_IFACE=${x#*=}
76 ;;
77 gk.net.routes=*)
78 GK_NET_ROUTES=${x#*=}
79 ;;
80 + gk.net.timeout.interface=*)
81 + local tmp_interface_timeout=${x#*=}
82 + if is_int "${tmp_interface_timeout}"
83 + then
84 + GK_NET_TIMEOUT_INTERFACE=${tmp_interface_timeout}
85 + else
86 + warn_msg "'${x}' does not look like a valid number -- will keep using default value ${GK_NET_TIMEOUT_INTERFACE}!"
87 + fi
88 + unset tmp_interface_timeout
89 + ;;
90 gk.net.timeout.dad=*)
91 local tmp_dad_timeout=${x#*=}
92 if is_int "${tmp_dad_timeout}"
93 @@ -1664,10 +1672,63 @@ start_network() {
94 esac
95 done
96
97 - if [ ! -d "/sys/class/net/${GK_NET_IFACE}" ]
98 + local interface_identifier=device
99 + if echo "${GK_NET_IFACE}" | grep -qE ':|-'
100 then
101 - warn_msg "Interface ${GK_NET_IFACE} not found; Will not try to start network ..."
102 - return
103 + interface_identifier=mac
104 + good_msg_n "Waiting for interface with MAC address ${GK_NET_IFACE} ..."
105 + else
106 + good_msg_n "Waiting for interface ${GK_NET_IFACE} ..."
107 + fi
108 +
109 + local tmp_interface=
110 + local have_interface=0
111 + local interface_time_waited=0
112 + local interface_timeout_100msec_modulo=
113 + local interface_timeout && let interface_timeout=$(date +%s)+1
114 + [ -n "${GK_NET_TIMEOUT_INTERFACE}" -a "${GK_NET_TIMEOUT_INTERFACE}" -gt 0 ] && let interface_timeout=${interface_timeout}+${GK_NET_TIMEOUT_INTERFACE}-1
115 +
116 + while [ "${have_interface}" != '1' -a $(date +%s) -le ${interface_timeout} ]
117 + do
118 + tmp_interface=$(iface_name "${GK_NET_IFACE}")
119 + if [ -n "${tmp_interface}" ]
120 + then
121 + # We got at least something to probe
122 + if [ -d "/sys/class/net/${tmp_interface}" ]
123 + then
124 + GK_NET_IFACE="${tmp_interface}"
125 + have_interface=1
126 + break
127 + fi
128 + fi
129 +
130 + if [ "${have_interface}" != '1' ]
131 + then
132 + let interface_time_waited=${interface_time_waited}+1
133 + sleep 0.1s
134 +
135 + let interface_timeout_100msec_modulo=${interface_time_waited}%10
136 + if [ ${interface_timeout_100msec_modulo} = 0 ]
137 + then
138 + printf "."
139 + fi
140 + fi
141 + done
142 +
143 + echo
144 +
145 + if [ "${have_interface}" != '1' ]
146 + then
147 + # Timeout!
148 + if [ "${interface_identifier}" = 'mac' ]
149 + then
150 + bad_msg "Interface with MAC address ${GK_NET_IFACE} not found!"
151 + else
152 + bad_msg "Interface ${GK_NET_IFACE} not found!"
153 + fi
154 +
155 + warn_msg "Will not try to start network ..."
156 + return 1
157 fi
158
159 if [ -z "${IP}" -o "${IP}" = 'dhcp' ]
160 @@ -1677,7 +1738,7 @@ start_network() {
161 if [ $? -ne 0 ]
162 then
163 bad_msg "Failed to start udhcpc for interface ${GK_NET_IFACE}!"
164 - return
165 + return 1
166 fi
167 else
168 good_msg "Bringing up interface ${GK_NET_IFACE} ..." ${QUIET}
169
170 diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
171 index da0f44e..3b96d8e 100644
172 --- a/doc/genkernel.8.txt
173 +++ b/doc/genkernel.8.txt
174 @@ -572,6 +572,9 @@ recognized by the kernel itself.
175 *gk.net.timeout.dhcp*=<...>::
176 By default we will wait up to 10 seconds for a DHCP server reply.
177
178 +*gk.net.timeout.interface*=<...>::
179 + By default we will wait up to 10 seconds for interface to show up.
180 +
181 *dosshd*::
182 Will start an SSH daemon within initramfs allowing to remotely unlock
183 encrypted devices or just for debugging purpose.