fs-lib/fs-lib.sh: add write_fs_tab()
authorHarald Hoyer <harald@redhat.com>
Wed, 6 Mar 2013 15:38:59 +0000 (16:38 +0100)
committerHarald Hoyer <harald@redhat.com>
Wed, 6 Mar 2013 16:29:11 +0000 (17:29 +0100)
modules.d/99fs-lib/fs-lib.sh

index b274935..838ffa6 100755 (executable)
@@ -201,3 +201,50 @@ det_fs() {
     fi
     echo "$_fs"
 }
+
+write_fs_tab() {
+    local _o
+    local _rw
+    local _root
+    local _rootfstype
+    local _rootflags
+    local _fspassno
+
+    _fspassno="0"
+    _root="$1"
+    _rootfstype="$2"
+    _rootflags="$3"
+    [ -z "$_rootfstype" ] && _rootfstype=$(getarg rootfstype=)
+    [ -z "$_rootflags" ] && _rootflags=$(getarg rootflags=)
+
+    [ -z "$_rootfstype" ] && _rootfstype="auto"
+
+    if [ -z "$_rootflags" ]; then
+        _rootflags="ro"
+    else
+        _rootflags="ro,$_rootflags"
+    fi
+
+    _rw=0
+    for _o in $CMDLINE; do
+        case $_o in
+            rw)
+                _rw=1;;
+            ro)
+                _rw=0;;
+        esac
+    done
+    if [ "$_rw" = "1" ]; then
+        _rootflags="$_rootflags,rw"
+        if ! getargbool 0 rd.skipfsck; then
+            _fspassno="1"
+        fi
+    fi
+
+    echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc/fstab
+
+    if type systemctl >/dev/null 2>/dev/null; then
+        systemctl daemon-reload
+        systemctl --no-block start initrd-fs.target
+    fi
+}