]> git.pld-linux.org Git - projects/geninitrd.git/blame - functions
- nfsroot patch from wolverine
[projects/geninitrd.git] / functions
CommitLineData
1cea325b
ER
1#!/bin/sh
2#
3# geninitrd functions
4
5# Find root device from fstab.
6#
7# @param string $fstab location of /etc/fstab
1cea325b
ER
8# @return false on failure
9#
10# Sets global variables:
11# - $rootdev
5101a385 12# - $rootdev_add
1cea325b
ER
13# - $rootFS
14#
15find_root() {
16 local fstab="$1"
ca2c2012 17 local function="${PROGRAM:+$PROGRAM: }find_root"
5101a385 18 local rootopt
1cea325b 19
8bc082c8 20 eval $(awk '!/^[\t ]*#/ && $2 == "/" {printf("rootdev=\"%s\"\nrootFs=\"%s\"\nrootopt=\"%s\"\n", $1, $3, $4)}' $fstab)
1cea325b 21 if [ -z "$rootdev" ]; then
8bc082c8 22 echo >&2 "$function: can't find fstab entry for root mountpoint"
1cea325b
ER
23 return 1
24 fi
25
5101a385
AM
26 # additional devices needed (xfs logdev)
27 rootdev_add=$(echo "$rootopt" | awk -F',' '{ for (i=1; i<=NF; i++) { if ($i ~ /^logdev=/) { gsub(/^logdev=/, NIL, $i); print $i; } } }')
28
1cea325b
ER
29 case $rootdev in
30 LABEL=*)
31 if [ ! -x /sbin/blkid ]; then
32 echo >&2 "$function: /sbin/blkid is missing"
33 return 2
34 fi
35
36 local label=${rootdev#"LABEL="}
37 local dev=$(/sbin/blkid -t LABEL="$label" -o device)
8bc082c8
ER
38 if [ "$dev" ]; then
39 if [ ! -r "$dev" ]; then
40 echo >&2 "$function: blkid returned device $dev which doesn't exist"
41 return 2
42 fi
1cea325b
ER
43 rootdev=$dev
44 fi
45 ;;
46
47 UUID=*)
48 if [ ! -x /sbin/blkid ]; then
49 echo >&2 "$function: /sbin/blkid is missing"
50 return 2
51 fi
52
53 local uuid=${rootdev#"UUID="}
54 local dev=$(/sbin/blkid -t UUID="$uuid" -o device)
55
8bc082c8
ER
56 if [ "$dev" ]; then
57 if [ ! -r "$dev" ]; then
58 echo >&2 "$function: blkid returned device $dev which doesn't exist"
59 return 2
60 fi
1cea325b
ER
61 rootdev=$dev
62 fi
63 ;;
f2581979 64 esac
65
66 case $rootdev in
d348a28e 67 /dev/dm-* | /dev/mapper/*)
b6c4aab1 68 local node
ada7e429 69 node=$(dm_lvm2_name "$rootdev") || return 1
b6c4aab1
ER
70 if [ "$node" ]; then
71 rootdev="$node"
72 fi
d348a28e 73 ;;
74 esac
b6c4aab1 75
6d2c63ed
ER
76 if [ "$rootFs" = "nfs" ]; then
77 rootdev="/dev/nfs"
78 return 0
79 fi
80
1cea325b
ER
81 if [ ! -r "$rootdev" ]; then
82 echo >&2 "$function: can't find real device for $rootdev"
83 return 1
84 fi
85
86 return 0
87}
b6c4aab1
ER
88
89# resolve /dev/dm-0 to lvm2 node
dc006e4d 90# which they got from blkid program fs was specifed as UUID= in fstab
b6c4aab1
ER
91dm_lvm2_name() {
92 local node="$1"
edecd1e2
ER
93 local dm_minor
94 case $node in
95 /dev/dm-*)
96 dm_minor=${node#/dev/dm-}
97 ;;
98 /dev/mapper/*)
99 dm_minor=$(ls -l $node | awk '{print $6}')
100 ;;
101 esac
102
a14a054a
ER
103 if [ ! -b "$node" ]; then
104 echo >&2 "dm_lvm2_name: $node is not a block device"
105 return 1
106 fi
107
8bc082c8
ER
108 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)
109 if [ -z "$lvm_path" ]; then
110 # XXX: this could happen also for non-lvm nodes?
a14a054a
ER
111 cat >&2 <<-EOF
112 LVM doesn't recognize device-mapper node with minor $dm_minor
113
114 In case your Physical Volumes are device mapper nodes, you should add to lvm.conf:
115 types = [ "device-mapper", 254 ]
116
117 In case the LVM nodes are not present yet, it could be fixed by running:
118 # vgscan --mknodes
119 EOF
8bc082c8
ER
120 return 2
121 fi
122 if [ ! -r "$lvm_path" ]; then
123 echo >&2 "lvdisplay returned $lvm_path which doesn't exist in filesystem; try running 'vgscan --mknodes'."
124 return 2
125 fi
18a69561 126 echo $lvm_path
b6c4aab1 127}
bc0d6f2d
ER
128
129# try to resolve /dev/dm-0 to item from /dev/mapper dir
130dm_longname() {
131 local node="$1"
132 local ret
14da5fc6
ER
133 local dm_major=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
134 local dm_minor=${node#/dev/dm-}
bc0d6f2d 135
6ef1a353 136 local dm_name=$(dmsetup info -c --noheadings -j $dm_major -m $dm_minor | awk -F: '{print $1}')
14da5fc6 137 echo "/dev/mapper/$dm_name"
bc0d6f2d 138}
This page took 0.525834 seconds and 4 git commands to generate.