]>
Commit | Line | Data |
---|---|---|
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 | |
8 | # @output string root device: /dev/hda1, /dev/sys/rootfs, etc | |
9 | # @return false on failure | |
10 | # | |
11 | # Sets global variables: | |
12 | # - $rootdev | |
13 | # - $rootFS | |
14 | # | |
15 | find_root() { | |
16 | local fstab="$1" | |
17 | local function='find_root' | |
18 | ||
19 | eval $(awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab) | |
20 | if [ -z "$rootdev" ]; then | |
21 | echo >&2 "$function: can't find real device for rootfs" | |
22 | return 1 | |
23 | fi | |
24 | ||
25 | case $rootdev in | |
26 | LABEL=*) | |
27 | if [ ! -x /sbin/blkid ]; then | |
28 | echo >&2 "$function: /sbin/blkid is missing" | |
29 | return 2 | |
30 | fi | |
31 | ||
32 | local label=${rootdev#"LABEL="} | |
33 | local dev=$(/sbin/blkid -t LABEL="$label" -o device) | |
34 | if [ "$dev" -a -r "$dev" ]; then | |
35 | rootdev=$dev | |
36 | fi | |
37 | ;; | |
38 | ||
39 | UUID=*) | |
40 | if [ ! -x /sbin/blkid ]; then | |
41 | echo >&2 "$function: /sbin/blkid is missing" | |
42 | return 2 | |
43 | fi | |
44 | ||
45 | local uuid=${rootdev#"UUID="} | |
46 | local dev=$(/sbin/blkid -t UUID="$uuid" -o device) | |
47 | ||
48 | if [ "$dev" -a -r "$dev" ]; then | |
49 | rootdev=$dev | |
50 | fi | |
51 | ;; | |
52 | esac | |
53 | ||
54 | if [ ! -r "$rootdev" ]; then | |
55 | echo >&2 "$function: can't find real device for $rootdev" | |
56 | return 1 | |
57 | fi | |
58 | ||
59 | return 0 | |
60 | } |