Fix an issue with parted on partitions without filesystems
[bootimage-initfs.git] / etc / hardware.sh
1 #!/bin/ash
2
3 . /etc/library.sh
4
5 # -----------------------------------------------------------------------
6 # load the output file created by the breakin program
7 # -----------------------------------------------------------------------
8 if [ -e /var/run/breakin.dat ]
9 then
10         . /var/run/breakin.dat
11 fi
12
13 # FIXME:
14
15 NET_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/net"
16 SCSI_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/scsi"
17 LIBATA_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/ata"
18 MD_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/md"
19 FUSIONMPT_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/message/fusion"
20 MODULE_PREFIX="/lib/modules/`uname -r`/kernel/drivers"
21 SENSOR_ENABLE=0
22
23 dhcp_on_interface() {
24         INTERFACE=${1}
25
26
27         # this is a stop gap for my laptop
28         if [ "${INTERFACE}" = "ath0" ]
29         then
30                 return 1
31         fi
32
33
34         # work around Cisco portfast implementation not being fast
35
36         if [ "${spantree}" != "" ]
37         then
38                 msg "Sleeping for ${spantree} seconds for spanning tree"
39                 sleep ${spantree}
40         fi
41
42         msg -n "Trying DHCP on ${i} interface"
43
44         /sbin/udhcpc -i ${INTERFACE} -T 5 -n -s /etc/ifup.udhcp.sh \
45                 -p /tmp/dhcp.${INTERFACE}.pid >> /tmp/stdout.log 2>> /tmp/stderr.log
46
47         if [ "$?" = 0 ]
48         then
49                 . /tmp/network.dhcp
50                 ok_msg
51                 return 0
52         else
53                 fail_msg
54                 return 1
55         fi
56 }
57
58
59
60 header "Loading network card modules"
61 for i in `find ${NET_MODULE_PATH} -name \*.ko`
62 do
63         load_module "${i}"
64 done
65
66 header "Switching mlx4 devices to ethernet"
67
68 for i in `find /sys/ -name mlx4_port* 2> /dev/null`
69 do
70
71         msg "Setting ${i} to eth"
72         echo "eth" > $i
73 done
74
75 header "Finding ethernet devices"
76
77 NET_DEVICES=`/sbin/ifconfig -a | grep "^[a-z]" | cut -d" " -f1`
78 NET_DEVICE_COUNT=0
79 NET_DEVICE=""
80
81 for i in ${NET_DEVICES}
82 do
83
84         # we want to skip the loopback interfaces since they don't really count
85         if [ "${i}" = "lo" ]
86         then
87                 continue
88         fi
89
90         NET_DEVICE_COUNT=`expr ${NET_DEVICE_COUNT} + 1`
91
92         /bin/ip link set dev ${i} up
93         /sbin/ifconfig ${i} up
94
95         if [ "${_mtu}" != "" ]
96         then
97                 msg "Setting MTU to ${_mtu} for ${i}"
98                 /bin/ip link set dev ${i} mtu ${_mtu} up
99         fi
100
101         msg "Sleeping for 15 seconds for link to come up on ${i}"
102         sleep 15
103
104         msg -n "Checking link status for ${i}"
105         LINK=`/usr/bin/ethtool ${i} | grep Link | awk '{print $3}' 2> /dev/null`
106
107         if [ "${LINK}" != "yes" ];
108         then
109                 fail_msg
110         else
111                 ok_msg
112                 dhcp_on_interface ${i}
113                 if [ "$?" = "0" ]
114                 then
115                         NET_DEVICE="${i}"
116                 fi
117         fi
118 done
119
120 if [ "${NET_DEVICE}" = "" ];
121 then
122         msg ""
123         msg "Unable to find interface with link, manually trying each interface"
124         for i in ${NET_DEVICES}
125         do
126                 if [ "${i}" = "lo" ]
127                 then
128                         continue
129                 fi
130
131                 dhcp_on_interface ${i}
132                 if [ "$?" = "0" ]
133                 then
134                         NET_DEVICE="${i}"
135                         break
136                 fi
137         done
138 fi
139
140 #msg -n "Setting hostname to be HW address  "
141 #HOST=`echo ${NET_MACADDR} | sed 's/://g'`
142 #msg -n " ${NET_MACADDR}"
143 #hostname ${HOST} >> /tmp/stdout.log 2> /tmp/stderr.log
144 #if [ "$?" = 0 ]
145 #then
146         #ok_msg
147 #else
148         #fail_msg
149 #fi
150
151 for i in /lib/modules/`uname -r`/kernel/drivers/edac/*
152 do
153         MOD_NAME=`basename ${i} | cut -d"." -f1`
154         modprobe_module ${MOD_NAME}
155 done
156
157 for i in /lib/modules/`uname -r`/kernel/drivers/i2c/busses/*
158 do
159         MOD_NAME=`basename ${i} | cut -d"." -f1`
160         modprobe_module ${MOD_NAME}
161 done
162
163 # XXX: this may cause lockups, if so we need a better way
164 header "Loading all SCSI/SATA disk modules"
165
166 for i in `find ${LIBATA_MODULE_PATH} ${SCSI_MODULE_PATH} ${FUSIONMPT_MODULE_PATH} ${MD_MODULE_PATH} -name \*.ko`
167 do
168         MOD_NAME=`basename ${i} | cut -d"." -f1`
169         modprobe_module ${MOD_NAME}
170 done
171
172 header "Loading other modules"
173 for i in `cat /etc/modules_other.conf`
174 do
175         modprobe_module ${i}    
176 done
177
178 msg "Waiting 10 seconds for block devices to settle."
179 sleep 10
180
181 # mount a logging device
182 . /etc/logdev.sh
183
184 . /etc/hardware_output.sh