]> git.pld-linux.org Git - projects/geninitrd.git/blame - functions
- export functions so other programs could reuse code
[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
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#
15find_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}
This page took 0.105263 seconds and 4 git commands to generate.