summaryrefslogtreecommitdiffstats
path: root/source/installer/sources/initrd/dev/makedevs.sh
blob: 8ecdb756ebed2346e73eaee33d120881a72769a6 (plain) (blame)
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
#!/bin/sh
# This script makes /dev entries for hard drives listed in /proc/partitions.
# Written by Patrick Volkerding, licensed under the GPL (any version).
# Copyright 2001, 2002  Slackware Linux, Inc., Concord, CA

# Many thanks to Vincent Rivellino for contributing the patches to support
# Mylex and Compaq RAID controllers.

# Devfs enabled kernels don't use the old familiar device names in
# /proc/partitions, so we need to be able to figure them out on the
# basis of only the major/minor numbers.  This will require some
# maintainance for a while, but we expect to require devfs soon enough,
# and that will help generalize the installation to new types of
# devices without requiring fixes from us.

# Also, we're not yet ready to install with devfs _mounted_, so don't
# try that. :)

# Main loop:
# First, determine if we are using old or new device names.  The old format
# will never contain a '/'  (Well, some RAID controllers could have them,
# but luckily we can handle those in the same way)

# Make a device:
makedev() {
  if [ ! -b $1 ]; then
    mknod $1 b $2 $3
    chown root.disk $1
    chmod 640 $1
  fi  
}

# Make ide device
# makeide major minor hd1 hd2 (2 base devs for major)
make_ide() {
  # Handle base devices:
  if [ "$2" = "0" ]; then
    makedev /dev/$3 $1 $2
    return 0
  elif [ "$2" = "64" ]; then
    makedev /dev/$4 $1 $2
    return 0
  fi
  # Must be a partition:
  if [ "`expr $2 / 64`" = "0" ]; then
    DEV=$3
    NUM=$2
  else
    DEV=$4
    NUM=`expr $2 - 64`
  fi
  makedev /dev/$DEV$NUM $1 $2
}

# Make SCSI device
make_scsi() {
  # find drive # 0 - 15
  DRV=`expr $1 / 16`
  NUM=`expr $1 % 16`
  if [ "$NUM" = "0" ]; then
    NUM=""
  fi
  if [ "$DRV" = "0" ]; then
    makedev /dev/sda$NUM 8 $1
  elif [ "$DRV" = "1" ]; then
    makedev /dev/sdb$NUM 8 $1
  elif [ "$DRV" = "2" ]; then
    makedev /dev/sdc$NUM 8 $1
  elif [ "$DRV" = "3" ]; then
    makedev /dev/sdd$NUM 8 $1
  elif [ "$DRV" = "4" ]; then
    makedev /dev/sde$NUM 8 $1
  elif [ "$DRV" = "5" ]; then
    makedev /dev/sdf$NUM 8 $1
  elif [ "$DRV" = "6" ]; then
    makedev /dev/sdg$NUM 8 $1
  elif [ "$DRV" = "7" ]; then
    makedev /dev/sdh$NUM 8 $1
  elif [ "$DRV" = "8" ]; then
    makedev /dev/sdi$NUM 8 $1
  elif [ "$DRV" = "9" ]; then
    makedev /dev/sdj$NUM 8 $1
  elif [ "$DRV" = "10" ]; then
    makedev /dev/sdk$NUM 8 $1
  elif [ "$DRV" = "11" ]; then
    makedev /dev/sdl$NUM 8 $1
  elif [ "$DRV" = "12" ]; then
    makedev /dev/sdm$NUM 8 $1
  elif [ "$DRV" = "13" ]; then
    makedev /dev/sdn$NUM 8 $1
  elif [ "$DRV" = "14" ]; then
    makedev /dev/sdo$NUM 8 $1
  elif [ "$DRV" = "15" ]; then
    makedev /dev/sdp$NUM 8 $1
  fi
}

# Make Mylex RAID device
make_rd() {
  if [ ! -d /dev/rd ]; then
    mkdir /dev/rd
  fi
  # find drive
  DRV=`expr $3 / 8`
  NUM="p`expr $3 % 8`"
  if [ "$NUM" = "p0" ]; then
    NUM=""
  fi
  makedev /dev/rd/c$1d$DRV$NUM $2 $3
}

# Make Cpq SMART/2 RAID device
make_ida() {
  if [ ! -d /dev/ida ]; then
    mkdir /dev/ida
  fi
  # find drive
  DRV=`expr $3 / 16`
  NUM="p`expr $3 % 16`"
  if [ "$NUM" = "p0" ]; then
    NUM=""
  fi
  makedev /dev/ida/c$1d$DRV$NUM $2 $3
}

# Make Compaq Next Generation RAID device
make_cciss() {
  if [ ! -d /dev/cciss ]; then
    mkdir /dev/cciss
  fi
  # find drive
  DRV=`expr $3 / 16`
  NUM="p`expr $3 % 16`"
  if [ "$NUM" = "p0" ]; then
    NUM=""
  fi
  makedev /dev/cciss/c$1d$DRV$NUM $2 $3
}

# Make ATA RAID device
make_ataraid() {
  if [ ! -d /dev/ataraid ]; then
     mkdir /dev/ataraid
  fi
  # find drive
  DRV=`expr $2 / 16`
  NUM=`expr $2 % 16`
  if [ "$NUM" = "0" ]; then
     makedev /dev/ataraid/d$DRV $1 $2
  else
     makedev /dev/ataraid/d${DRV}p$NUM $1 $2
  fi
}


# Make AMI HyperRAID device:
make_amiraid() {
  if [ ! -d /dev/amiraid ]; then
     mkdir /dev/amiraid
  fi
  # find drive
  DRV=`expr $2 / 16`
  NUM=`expr $2 % 16`
  if [ "$NUM" = "0" ]; then
     makedev /dev/amiraid/ar$DRV $1 $2
  else
     makedev /dev/amiraid/ar${DRV}p$NUM $1 $2
  fi
}

if cat /proc/partitions | grep / 1> /dev/null 2> /dev/null ; then # new
  cat /proc/partitions | grep / | while read line ; do
    SMASHED_LINE=$line
    MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
    MINOR=`echo $SMASHED_LINE | cut -f 2 -d ' '`
    if [ "$MAJOR" = "3" ]; then
      make_ide $MAJOR $MINOR hda hdb
    elif [ "$MAJOR" = "8" ]; then
      make_scsi $MINOR
    elif [ "$MAJOR" = "22" ]; then
      make_ide $MAJOR $MINOR hdc hdd
    elif [ "$MAJOR" = "33" ]; then
      make_ide $MAJOR $MINOR hde hdf
    elif [ "$MAJOR" = "34" ]; then
      make_ide $MAJOR $MINOR hdg hdh
    elif [ "$MAJOR" = "48" ]; then
      make_rd 0 $MAJOR $MINOR
    elif [ "$MAJOR" = "49" ]; then
      make_rd 1 $MAJOR $MINOR
    elif [ "$MAJOR" = "50" ]; then
      make_rd 2 $MAJOR $MINOR
    elif [ "$MAJOR" = "51" ]; then
      make_rd 3 $MAJOR $MINOR
    elif [ "$MAJOR" = "52" ]; then
      make_rd 4 $MAJOR $MINOR
    elif [ "$MAJOR" = "53" ]; then
      make_rd 5 $MAJOR $MINOR
    elif [ "$MAJOR" = "54" ]; then
      make_rd 6 $MAJOR $MINOR
    elif [ "$MAJOR" = "55" ]; then
      make_rd 7 $MAJOR $MINOR
    elif [ "$MAJOR" = "56" ]; then
      make_ide $MAJOR $MINOR hdi hdj
    elif [ "$MAJOR" = "57" ]; then
      make_ide $MAJOR $MINOR hdk hdl
    elif [ "$MAJOR" = "72" ]; then
      make_ida 0 $MAJOR $MINOR
    elif [ "$MAJOR" = "73" ]; then
      make_ida 1 $MAJOR $MINOR
    elif [ "$MAJOR" = "74" ]; then
      make_ida 2 $MAJOR $MINOR
    elif [ "$MAJOR" = "75" ]; then
      make_ida 3 $MAJOR $MINOR
    elif [ "$MAJOR" = "76" ]; then
      make_ida 4 $MAJOR $MINOR
    elif [ "$MAJOR" = "77" ]; then
      make_ida 5 $MAJOR $MINOR
    elif [ "$MAJOR" = "78" ]; then
      make_ida 6 $MAJOR $MINOR
    elif [ "$MAJOR" = "79" ]; then
      make_ida 7 $MAJOR $MINOR
    elif [ "$MAJOR" = "88" ]; then
      make_ide $MAJOR $MINOR hdm hdn
    elif [ "$MAJOR" = "89" ]; then
      make_ide $MAJOR $MINOR hdo hdp
    elif [ "$MAJOR" = "90" ]; then
      make_ide $MAJOR $MINOR hdq hdr
    elif [ "$MAJOR" = "91" ]; then
      make_ide $MAJOR $MINOR hds hdt
    elif [ "$MAJOR" = "101" ]; then
      make_amiraid $MAJOR $MINOR
    elif [ "$MAJOR" = "104" ]; then
      make_cciss 0 $MAJOR $MINOR
    elif [ "$MAJOR" = "105" ]; then
      make_cciss 1 $MAJOR $MINOR
    elif [ "$MAJOR" = "106" ]; then
      make_cciss 2 $MAJOR $MINOR
    elif [ "$MAJOR" = "107" ]; then
      make_cciss 3 $MAJOR $MINOR
    elif [ "$MAJOR" = "108" ]; then
      make_cciss 4 $MAJOR $MINOR
    elif [ "$MAJOR" = "109" ]; then
      make_cciss 5 $MAJOR $MINOR
    elif [ "$MAJOR" = "110" ]; then
      make_cciss 6 $MAJOR $MINOR
    elif [ "$MAJOR" = "111" ]; then
      make_cciss 7 $MAJOR $MINOR
    elif [ "$MAJOR" = "114" ]; then
      make_ataraid $MAJOR $MINOR
    fi
  done
else # old format
  cat /proc/partitions | grep d | while read line ; do
    SMASHED_LINE=$line
    MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
    MINOR=`echo $SMASHED_LINE | cut -f 2 -d ' '`
    DEVNAME=`echo $SMASHED_LINE | cut -f 4 -d ' '`
    makedev /dev/$DEVNAME $MAJOR $MINOR
  done
fi