5 # Get device name from UUID/LABEL
6 # @param string device path or UUID/LABEL name
7 # @return false on failure
10 local outname name="$1"
11 local function="${PROGRAM:+$PROGRAM: }find_devname"
16 if [ ! -x /sbin/blkid ]; then
17 echo >&2 "$function: /sbin/blkid is missing"
21 local label=${name#"LABEL="}
22 local dev=$(/sbin/blkid -l -t LABEL="$label" -o device)
24 if [ ! -r "$dev" ]; then
25 echo >&2 "$function: blkid returned device $dev which doesn't exist"
33 if [ ! -x /sbin/blkid ]; then
34 echo >&2 "$function: /sbin/blkid is missing"
38 local uuid=${name#"UUID="}
39 local dev=$(/sbin/blkid -l -t UUID="$uuid" -o device)
42 if [ ! -r "$dev" ]; then
43 echo >&2 "$function: blkid returned device $dev which doesn't exist"
53 # Find root device from fstab.
55 # @param string $fstab location of /etc/fstab
56 # @return false on failure
58 # Sets global variables:
65 local function="${PROGRAM:+$PROGRAM: }find_root"
68 eval $(awk '!/^[\t ]*#/ && $2 == "/" {printf("rootdev=\"%s\"\nrootFs=\"%s\"\nrootopt=\"%s\"\n", $1, $3, $4)}' $fstab)
69 if [ -z "$rootdev" ]; then
70 echo >&2 "$function: can't find fstab entry for root mountpoint"
74 # additional devices needed (xfs logdev)
75 rootdev_add=$(echo "$rootopt" | awk -F',' '{ for (i=1; i<=NF; i++) { if ($i ~ /^logdev=/) { gsub(/^logdev=/, NIL, $i); print $i; } } }')
77 rootdev=$(find_devname "$rootdev")
81 node=$(dm_node "$rootdev") || return 1
90 local dm_subsystem=$(dm_subsystem "$rootdev")
94 node=$(dm_lvm2_name "$rootdev") || return 1
106 if [ "$rootFs" = "nfs" ]; then
111 if [ ! -r "$rootdev" ]; then
112 echo >&2 "WARNING: $function: rootfs device file $rootdev doesn't exist"
118 # resolve /dev/dm-0 to lvm2 node
119 # which they got from blkid program fs was specifed as UUID= in fstab
124 if [ ! -b "$node" ]; then
125 echo >&2 "dm_lvm2_name: $node is not a block device"
131 dm_minor=${node#/dev/dm-}
134 stat=$(stat -L -c %T "$node") || die "stat failed: $node"
135 dm_minor=$((0x$stat))
139 local lvm_path=$(/sbin/lvdisplay -c 2>/dev/null | awk -F: -vn=$dm_minor '{node=$1; major=$12; minor=$13; if (n == minor) print node}' | xargs)
140 if [ -z "$lvm_path" ]; then
141 # XXX: this could happen also for non-lvm nodes?
143 LVM doesn't recognize device-mapper node with minor $dm_minor
145 In case your Physical Volumes are device mapper nodes, you should add to lvm.conf:
146 types = [ "device-mapper", 254 ]
148 In case the LVM nodes are not present yet, it could be fixed by running:
153 if [ ! -r "$lvm_path" ]; then
154 echo >&2 "lvdisplay returned $lvm_path which doesn't exist in filesystem; try running 'vgscan --mknodes'."
160 # resolve /dev/dm-0, /dev/mapper/name
164 dmsetup info -c --noheadings -o name $node
167 # get subsystem name for DM node
168 # node can be /dev/dm-0, /dev/mapper/name
169 # @return subsystem name
172 out=$(dmsetup info -c --noheadings -o subsystem $node)
173 if [ $? -eq 0 -a -n "$out" ]; then
178 # for very old kernels (2.6.16), subsystem is empty, assume LVM
179 # TODO: fix this if needed to have crypt as well
183 # resolve any dm node to it's full path in /dev/mapper
186 printf "/dev/mapper/%s" $(dm_name "$node")
190 modprobe --version | grep -q "^kmod"
193 # find modules by class
194 # find_modules_by_class 0106 - finds modules for SATA devices in the system
195 # find_modules_by_class 0c03 - finds modules for USB controllers
196 find_modules_by_class() {
198 find_modules_by_class_kmod $@
200 find_modules_by_class_mit $@
204 # find modules by class (kmod version)
205 # find_modules_by_class 0106 - finds modules for SATA devices in the system
206 # find_modules_by_class 0c03 - finds modules for USB controllers
207 find_modules_by_class_kmod() {
208 local req_class="$1" i j modaliases
210 if [ ! -d "/sys/devices" ]; then
211 warn "No /sys/devices/ found. Is /sys mounted?"
215 if ls /sys/devices | grep -q '^pci'; then
216 for i in $(grep -li "^0x${req_class}" /sys/devices/pci*/*/class); do
218 modaliases="$modaliases $(cat $j/modalias)"
222 if [ -z "$modaliases" ]; then
226 echo $modaliases | xargs modprobe --set-version $kernel -aRn | awk '
227 BEGIN { skip_modules[notexisting_module]=""; modules[1]=""; xhci=""; ehci_pci=""; ehci_hcd=""; ehci_platform=""; ohci=""; uhci="" }
230 if (module == "xhci_hcd") {
232 } else if (module == "ehci_hcd") {
234 } else if (module == "ehci_pci") {
236 } else if (module == "ehci_platform") {
237 ehci_platform="ehci_platform"
238 } else if (module == "ohci_hcd") {
240 } else if (module == "uhci_hcd") {
242 } else if (!(module in skip_modules)) {
245 skip_modules[module]=1;
248 # ehci/ohci/uhci/xhci hack to preserve such order
249 printf "%s %s %s %s %s %s ", ehci_hcd, ehci_pci, ehci_platform, ohci, uhci, xhci;
250 for (i in modules) { printf "%s ", modules[i]; };
255 # find modules by class (module-init-tools version)
256 # find_modules_by_class 0106 - finds modules for SATA devices in the system
257 # find_modules_by_class 0c03 - finds modules for USB controllers
258 find_modules_by_class_mit() {
259 local req_class="$1" pcimap lspci
261 pcimap="/lib/modules/$kernel/modules.pcimap"
263 lspci=$(find_tool /sbin/lspci)
264 if [ ! -x "$lspci" ]; then
265 warn "Failed to execute lspci. Is pciutils package installed?"
268 # no pcimap, nothing to lookup from
269 if [ ! -f "$pcimap" ]; then
270 warn "No $pcimap file. Cannot find modules for desired class!"
274 if [ -z "$lspci" ]; then
278 LC_ALL=C lspci -p "$pcimap" -kvmmn | awk -vreq_class="${req_class}" '
279 BEGIN { skip_modules[notexisting_module]=""; modules[1]=""; xhci=""; ehci_pci=""; ehci_hcd=""; ehci_platform=""; ohci=""; uhci="" }
281 /^Class:/ { if (req_class == $2) { found = 1 } }
282 /^Driver:/ { if (found) {
284 if (module == "xhci_hcd") {
286 } else if (module == "ehci_hcd") {
287 ehci_hcd = "ehci_hcd"
288 } else if (module == "ehci_pci") {
290 } else if (module == "ehci_platform") {
291 ehci_platform="ehci_platform"
292 } else if (module == "ohci_hcd") {
294 } else if (module == "uhci_hcd") {
296 } else if (!(module in skip_modules)) {
297 modules[cnt] = module
299 skip_modules[module] = 1;
304 # ehci/ohci/uhci/xhci hack to preserve such order
305 printf "%s %s %s %s %s %s ", ehci_hcd, ehci_pci, ehci_platform, ohci, uhci, xhci;
306 for (i in modules) { printf "%s ", modules[i]; }
311 # get possible paths for specifed patter containing LIBDIR
313 for dir in lib lib64 libx32; do
314 echo -n "${1/LIBDIR/$dir} "