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 "$function: rootfs device file $rootdev doesn't exist"
119 # resolve /dev/dm-0 to lvm2 node
120 # which they got from blkid program fs was specifed as UUID= in fstab
125 if [ ! -b "$node" ]; then
126 echo >&2 "dm_lvm2_name: $node is not a block device"
132 dm_minor=${node#/dev/dm-}
135 stat=$(stat -L -c %T "$node") || die "stat failed: $node"
136 dm_minor=$((0x$stat))
140 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)
141 if [ -z "$lvm_path" ]; then
142 # XXX: this could happen also for non-lvm nodes?
144 LVM doesn't recognize device-mapper node with minor $dm_minor
146 In case your Physical Volumes are device mapper nodes, you should add to lvm.conf:
147 types = [ "device-mapper", 254 ]
149 In case the LVM nodes are not present yet, it could be fixed by running:
154 if [ ! -r "$lvm_path" ]; then
155 echo >&2 "lvdisplay returned $lvm_path which doesn't exist in filesystem; try running 'vgscan --mknodes'."
161 # resolve /dev/dm-0, /dev/mapper/name
165 dmsetup info -c --noheadings -o name $node
168 # get subsystem name for DM node
169 # node can be /dev/dm-0, /dev/mapper/name
170 # @return subsystem name
173 out=$(dmsetup info -c --noheadings -o subsystem $node)
174 if [ $? -eq 0 -a -n "$out" ]; then
179 # for very old kernels (2.6.16), subsystem is empty, assume LVM
180 # TODO: fix this if needed to have crypt as well
184 # resolve any dm node to it's full path in /dev/mapper
187 printf "/dev/mapper/%s" $(dm_name "$node")
190 # find modules by class
191 # find_modules_by_class 0106 - finds modules for SATA devices in the system
192 # find_modules_by_class 0c03 - finds modules for USB controllers
193 find_modules_by_class() {
194 if modprobe --version | grep -q "^kmod"; then
195 find_modules_by_class_kmod $@
197 find_modules_by_class_mit $@
201 # find modules by class (kmod version)
202 # find_modules_by_class 0106 - finds modules for SATA devices in the system
203 # find_modules_by_class 0c03 - finds modules for USB controllers
204 find_modules_by_class_kmod() {
205 local req_class="$1" i j modaliases
207 if [ ! -d "/sys/devices" ]; then
208 warn "No /sys/devices/ found. Is /sys mounted?"
212 for i in $(grep -li "^0x${req_class}" /sys/devices/pci*/*/class); do
214 modaliases="$modaliases $(cat $j/modalias)"
217 if [ -z "$modaliases" ]; then
221 echo $modaliases | xargs modprobe --set-version $kernel -aRn | awk '
222 BEGIN { skip_modules[notexisting_module]=""; modules[1]=""; xhci=""; ehci_pci=""; ehci_hcd=""; ehci_platform=""; ohci=""; uhci="" }
225 if (module == "xhci_hcd") {
227 } else if (module == "ehci_hcd") {
229 } else if (module == "ehci_pci") {
231 } else if (module == "ehci_platform") {
232 ehci_platform="ehci_platform"
233 } else if (module == "ohci_hcd") {
235 } else if (module == "uhci_hcd") {
237 } else if (!(module in skip_modules)) {
240 skip_modules[module]=1;
243 # ehci/ohci/uhci/xhci hack to preserve such order
244 printf "%s %s %s %s %s %s ", ehci_hcd, ehci_pci, ehci_platform, ohci, uhci, xhci;
245 for (i in modules) { printf "%s ", modules[i]; };
250 # find modules by class (module-init-tools version)
251 # find_modules_by_class 0106 - finds modules for SATA devices in the system
252 # find_modules_by_class 0c03 - finds modules for USB controllers
253 find_modules_by_class_mit() {
254 local req_class="$1" pcimap lspci
256 pcimap="/lib/modules/$kernel/modules.pcimap"
258 lspci=$(find_tool /sbin/lspci)
259 if [ ! -x "$lspci" ]; then
260 warn "Failed to execute lspci. Is pciutils package installed?"
263 # no pcimap, nothing to lookup from
264 if [ ! -f "$pcimap" ]; then
265 warn "No $pcimap file. Cannot find modules for desired class!"
269 if [ -z "$lspci" ]; then
273 LC_ALL=C lspci -p "$pcimap" -kvmmn | awk -vreq_class="${req_class}" '
274 BEGIN { skip_modules[notexisting_module]=""; modules[1]=""; xhci=""; ehci_pci=""; ehci_hcd=""; ehci_platform=""; ohci=""; uhci="" }
276 /^Class:/ { if (req_class == $2) { found = 1 } }
277 /^Driver:/ { if (found) {
279 if (module == "xhci_hcd") {
281 } else if (module == "ehci_hcd") {
282 ehci_hcd = "ehci_hcd"
283 } else if (module == "ehci_pci") {
285 } else if (module == "ehci_platform") {
286 ehci_platform="ehci_platform"
287 } else if (module == "ohci_hcd") {
289 } else if (module == "uhci_hcd") {
291 } else if (!(module in skip_modules)) {
292 modules[cnt] = module
294 skip_modules[module] = 1;
299 # ehci/ohci/uhci/xhci hack to preserve such order
300 printf "%s %s %s %s %s %s ", ehci_hcd, ehci_pci, ehci_platform, ohci, uhci, xhci;
301 for (i in modules) { printf "%s ", modules[i]; }
306 # get possible paths for specifed patter containing LIBDIR
308 for dir in lib lib64 libx32; do
309 echo -n "${1/LIBDIR/$dir} "