All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH] Expand fstab-sys, simplify rootfs-block
@ 2011-05-20 15:09 Michal Soltys
       [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Michal Soltys @ 2011-05-20 15:09 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

This patch moves code responsible for fsck'ing and determinig filesystem to
dracut-lib.sh, so it can be used by both fstab-sys and rootfs-block.

Adding fsck functionality to fstab-sys provides opportunity to move whole
separate /usr mount outside main initialization scripts - so real udev (with
different rules wanting /usr present) can work fine without any issues - having
/usr checked and mounted. At least that is the motivation behind these few
patches.

See respective commits for more details.

Note - I'm not sure if dracut-lib.sh is actually a proper place for those
functions - they were identical though, so to not repeat the code I stuffed
them there.

Haven't tested too much yet, so it's more RFC than a patch (code changes are
pretty simple though).



Michal Soltys (5):
  dracut-lib.sh: add vwarn() function
  dracut-lib.sh: Add det_fs() and wrap_fsck()
  95fstab-sys: use det_fs and wrap_fsck
  95rootfs-block/mount-root.sh: Rely on det_fs and wrap_fsck
  95rootfs-block/block-genrules.sh: Use > instead of >>

 modules.d/95fstab-sys/module-setup.sh      |    2 +
 modules.d/95fstab-sys/mount-sys.sh         |   23 +++++++++---
 modules.d/95rootfs-block/block-genrules.sh |    2 +-
 modules.d/95rootfs-block/mount-root.sh     |   47 +++++--------------------
 modules.d/99base/dracut-lib.sh             |   53 ++++++++++++++++++++++++++++
 5 files changed, 82 insertions(+), 45 deletions(-)

-- 
1.7.2.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/5] dracut-lib.sh: add vwarn() function
       [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
@ 2011-05-20 15:09   ` Michal Soltys
  2011-05-20 15:09   ` [PATCH 2/5] dracut-lib.sh: Add det_fs() and wrap_fsck() Michal Soltys
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Michal Soltys @ 2011-05-20 15:09 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Similary to vinfo()

Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
 modules.d/99base/dracut-lib.sh |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 4d03ed0..e376495 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -272,6 +272,12 @@ info() {
         echo "dracut: $@"
 }
 
+vwarn() {
+    while read line; do
+        warn $line;
+    done
+}
+
 vinfo() {
     while read line; do
         info $line;
-- 
1.7.2.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/5] dracut-lib.sh: Add det_fs() and wrap_fsck()
       [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
  2011-05-20 15:09   ` [PATCH 1/5] dracut-lib.sh: add vwarn() function Michal Soltys
@ 2011-05-20 15:09   ` Michal Soltys
  2011-05-20 15:09   ` [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck Michal Soltys
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Michal Soltys @ 2011-05-20 15:09 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Both functions will be used by rootfs-block and fstab-sys modules.

Both are based on code present in mount-root.sh, though few changes are
present.

det_fs:

will try to determine filesystem type for supplied device, even if it's
not auto. If fs cannot be detected, or if the detected one differs from
the supplied one - a warning is issued (so user can fix its stuff later)

wrap_fsck:

will call fsck for specific device with optionally additional
fsckoptions. The function returns fsck return value.

Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
 modules.d/99base/dracut-lib.sh |   47 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index e376495..10025bd 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -515,3 +515,50 @@ foreach_uuid_until() (
 
     return 1
 )
+
+# Wrap fsck call for device _dev with additional fsck options _fsckopts return
+# fsck's return code
+wrap_fsck() {
+    local _ret _out _dev="$1" _fsckopts="$2"
+
+    info "Checking filesystem."
+    info fsck -T $_fsckopts "$_dev"
+    _out=$(fsck -T $_fsckopts "$_dev") ; _ret=$?
+
+    # A return of 4 or higher means there were serious problems.
+    if [ $_ret -gt 3 ]; then
+        echo $_out|vwarn
+        warn "fsck returned with error code $_ret"
+        warn "*** An error occurred during the file system check."
+        warn "*** Dropping you to a shell; the system will try"
+        warn "*** to mount the filesystem, when you leave the shell."
+        emergency_shell -n "(Repair filesystem)"
+    else
+        echo $_out|vinfo
+        [ $_ret -gt 0 ] && warn "fsck returned with $_ret"
+    fi
+
+    return $_ret
+}
+
+# Verify supplied filesystem type, fix if it's invalid, warn user if
+# appropriate
+det_fs() {
+    local _dev="$1" _fs="${2:-auto}" _inf="$3" _orig
+
+    _orig="$_fs"
+    _fs=$(udevadm info --query=env --name="$_dev" | \
+    while read line; do
+        if str_starts $line "ID_FS_TYPE="; then
+            echo ${line#ID_FS_TYPE=}
+            break
+        fi
+    done)
+    _fs=${_fs:-auto}
+    if [ "$_fs" = "auto" ]; then
+        warn "Cannon detect filesystem type for device $_dev"
+    elif [ "$_orig" != "auto" -a "$_fs" != "$_orig" ]; then
+        warn "$_inf: detected filesystem '$_fs' instead of '$_orig' for device: $_dev"
+    fi
+    echo "$_fs"
+}
-- 
1.7.2.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
  2011-05-20 15:09   ` [PATCH 1/5] dracut-lib.sh: add vwarn() function Michal Soltys
  2011-05-20 15:09   ` [PATCH 2/5] dracut-lib.sh: Add det_fs() and wrap_fsck() Michal Soltys
@ 2011-05-20 15:09   ` Michal Soltys
       [not found]     ` <1305904167-14199-4-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
  2011-05-20 15:09   ` [PATCH 4/5] 95rootfs-block/mount-root.sh: Rely on " Michal Soltys
  2011-05-20 15:09   ` [PATCH 5/5] 95rootfs-block/block-genrules.sh: Use > instead of >> Michal Soltys
  4 siblings, 1 reply; 14+ messages in thread
From: Michal Soltys @ 2011-05-20 15:09 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

This patch mainly adds fsck functionality to fstab-sys, with additional
sanity checks (checking for device existence, verifying fstype via
det_fs).

Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
 modules.d/95fstab-sys/module-setup.sh |    2 ++
 modules.d/95fstab-sys/mount-sys.sh    |   23 +++++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/modules.d/95fstab-sys/module-setup.sh b/modules.d/95fstab-sys/module-setup.sh
index f46c037..1fbd55b 100755
--- a/modules.d/95fstab-sys/module-setup.sh
+++ b/modules.d/95fstab-sys/module-setup.sh
@@ -12,5 +12,7 @@ depends() {
 
 install() {
     dracut_install /etc/fstab.sys
+    dracut_install /sbin/fsck*
+    type -P e2fsck >/dev/null && dracut_install e2fsck
     inst_hook pre-pivot 00 "$moddir/mount-sys.sh"
 }
diff --git a/modules.d/95fstab-sys/mount-sys.sh b/modules.d/95fstab-sys/mount-sys.sh
index 266576e..b444071 100755
--- a/modules.d/95fstab-sys/mount-sys.sh
+++ b/modules.d/95fstab-sys/mount-sys.sh
@@ -2,14 +2,25 @@
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
 # ex: ts=8 sw=4 sts=4 et filetype=sh
 
-fstab_mount(){
-    local dev mp type opts rest
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+fstab_mount() {
+    local _dev _mp _fs _opts _dump _pass _rest
     test -e "$1" || return 1
     info "Mounting from $1"
-    while read dev mp type opts rest; do
-	[ -z "${dev%%#*}" ]&& continue # Skip comment lines
-	mount -v -t $type -o $opts $dev $NEWROOT/$mp
-    done < $1 | vinfo
+    while read _dev _mp _fs _opts _dump _pass _rest; do
+        [ -z "${_dev%%#*}" ] && continue # Skip comment lines
+        if [ ! -e "$_dev" ]; then
+            warn "Device $_dev doesn't exist, skipping mount."
+            continue
+        fi
+        if [ "$_pass" -gt 0 ] && ! strstr "$_opts" _netdev; then
+            wrap_fsck "$_dev"
+        fi
+        _fs=$(det_fs "$_dev" "$_fs" /etc/fstab.sys)
+        info "Mounting $_dev"
+        mount -v -t $_fs -o $_opts $_dev $NEWROOT/$_mp 2>&1 | vinfo
+    done < $1
     return 0
 }
 
-- 
1.7.2.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/5] 95rootfs-block/mount-root.sh: Rely on det_fs and wrap_fsck
       [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
                     ` (2 preceding siblings ...)
  2011-05-20 15:09   ` [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck Michal Soltys
@ 2011-05-20 15:09   ` Michal Soltys
  2011-05-20 15:09   ` [PATCH 5/5] 95rootfs-block/block-genrules.sh: Use > instead of >> Michal Soltys
  4 siblings, 0 replies; 14+ messages in thread
From: Michal Soltys @ 2011-05-20 15:09 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Use common fsck and det_fs code. Verify filesystem type more
aggressively, which has a chance to be more resistant to
accidental mistakes.

Also, there's no need to generate custom fstab for the sake of fsck
anymore.

Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
 modules.d/95rootfs-block/mount-root.sh |   47 ++++++-------------------------
 1 files changed, 9 insertions(+), 38 deletions(-)

diff --git a/modules.d/95rootfs-block/mount-root.sh b/modules.d/95rootfs-block/mount-root.sh
index 8e86024..9334323 100755
--- a/modules.d/95rootfs-block/mount-root.sh
+++ b/modules.d/95rootfs-block/mount-root.sh
@@ -26,8 +26,10 @@ filter_rootopts() {
 }
 
 if [ -n "$root" -a -z "${root%%block:*}" ]; then
-    mount -t ${fstype:-auto} -o "$rflags",ro "${root#block:}" "$NEWROOT" \
-        && ROOTFS_MOUNTED=yes
+
+    # sanity - determine/fix fstype
+    rootfs=$(det_fs "${root#block:}" "$fstype" "cmdline")
+    mount -t ${rootfs} -o "$rflags",ro "${root#block:}" "$NEWROOT"
 
     READONLY=
     fsckoptions=
@@ -71,7 +73,6 @@ if [ -n "$root" -a -z "${root%%block:*}" ]; then
         fsckoptions="-a $fsckoptions"
     fi
 
-    rootfs=${fstype:-auto}
     rootopts=
     if getargbool 1 rd.fstab -n rd_NO_FSTAB \
         && ! getarg rootflags \
@@ -86,7 +87,8 @@ if [ -n "$root" -a -z "${root%%block:*}" ]; then
             [ "${dev%%#*}" != "$dev" ] && continue
 
             if [ "$mp" = "/" ]; then
-                rootfs=$fs
+                # sanity - determine/fix fstype
+                rootfs=$(det_fs "${root#block:}" "$fs" "$NEWROOT/etc/fstab")
                 rootopts=$opts
                 break
             fi
@@ -96,41 +98,10 @@ if [ -n "$root" -a -z "${root%%block:*}" ]; then
     fi
 
     umount "$NEWROOT"
-    if [ "$rootfs" = "auto" ]; then
-        rootfs=$(udevadm info --query=env --name=${root#block:} | \
-            while read line; do
-                if strstr $line ID_FS_TYPE; then
-                    eval $line
-                    echo $ID_FS_TYPE
-                    break
-                fi
-            done)
-        rootfs=${rootfs:-auto}
-    fi
 
-    # backslashes are treated as escape character in fstab
-    esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
-    printf '%s %s %s %s,%s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" "$rootopts"  > /etc/fstab
-
-    if [ -z "$fastboot" -a "$READONLY" != "yes" ]; then
-        info "Checking filesystems"
-        info fsck -T -t noopts=_netdev -A $fsckoptions
-        out=$(fsck -T -t noopts=_netdev -A $fsckoptions)
-        export RD_ROOTFS_FSCK=$?
-        echo $RD_ROOTFS_FSCK > /run/initramfs/root-fsck
-
-        # A return of 4 or higher means there were serious problems.
-        if [ $RD_ROOTFS_FSCK -gt 3 ]; then
-            warn $out
-            warn "fsck returned with error code $RD_ROOTFS_FSCK"
-            warn "*** An error occurred during the file system check."
-            warn "*** Dropping you to a shell; the system will retry"
-            warn "*** to mount the system, when you leave the shell."
-            emergency_shell -n "(Repair filesystem)"
-        else
-            echo $out|vinfo
-            [ $RD_ROOTFS_FSCK -gt 0 ] && warn "fsck returned with $RD_ROOTFS_FSCK"
-        fi
+    if [ -z "$fastboot" -a "$READONLY" != "yes" ] && ! strstr "${rflags},${rootopts}" _netdev; then
+        wrap_fsck "${root#block:}" "$fsckoptions"
+        echo $? >/run/initramfs/root-fsck
     fi
 
     info "Remounting ${root#block:} with -o ${rflags},${rootopts}"
-- 
1.7.2.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 5/5] 95rootfs-block/block-genrules.sh: Use > instead of >>
       [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
                     ` (3 preceding siblings ...)
  2011-05-20 15:09   ` [PATCH 4/5] 95rootfs-block/mount-root.sh: Rely on " Michal Soltys
@ 2011-05-20 15:09   ` Michal Soltys
  4 siblings, 0 replies; 14+ messages in thread
From: Michal Soltys @ 2011-05-20 15:09 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

trivial, blocksymlink.sh shouldn't exist at this point.

Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
 modules.d/95rootfs-block/block-genrules.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/modules.d/95rootfs-block/block-genrules.sh b/modules.d/95rootfs-block/block-genrules.sh
index 41a220f..4a50aac 100755
--- a/modules.d/95rootfs-block/block-genrules.sh
+++ b/modules.d/95rootfs-block/block-genrules.sh
@@ -11,7 +11,7 @@ if [ "${root%%:*}" = "block" ]; then
     } >> $UDEVRULESD/99-root.rules
 
     printf '[ -e "%s" ] && { ln -s "%s" /dev/root 2>/dev/null; rm "$job"; }\n' \
-        "${root#block:}" "${root#block:}" >> $hookdir/initqueue/settled/blocksymlink.sh
+        "${root#block:}" "${root#block:}" > $hookdir/initqueue/settled/blocksymlink.sh
 
     echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/block.sh
 fi
-- 
1.7.2.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]     ` <1305904167-14199-4-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
@ 2011-05-23 23:05       ` Karel Zak
       [not found]         ` <20110523230507.GC2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Karel Zak @ 2011-05-23 23:05 UTC (permalink / raw)
  To: Michal Soltys; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

On Fri, May 20, 2011 at 05:09:25PM +0200, Michal Soltys wrote:
> +fstab_mount() {
> +    local _dev _mp _fs _opts _dump _pass _rest
>      test -e "$1" || return 1
>      info "Mounting from $1"
> -    while read dev mp type opts rest; do
> -	[ -z "${dev%%#*}" ]&& continue # Skip comment lines
> -	mount -v -t $type -o $opts $dev $NEWROOT/$mp
> -    done < $1 | vinfo
> +    while read _dev _mp _fs _opts _dump _pass _rest; do

 How does this code handle encoding in fstab? (e.g. /path/foo\x40bar)

> +        [ -z "${_dev%%#*}" ] && continue # Skip comment lines
> +        if [ ! -e "$_dev" ]; then
> +            warn "Device $_dev doesn't exist, skipping mount."
> +            continue
> +        fi
> +        if [ "$_pass" -gt 0 ] && ! strstr "$_opts" _netdev; then
> +            wrap_fsck "$_dev"
> +        fi
> +        _fs=$(det_fs "$_dev" "$_fs" /etc/fstab.sys)
> +        info "Mounting $_dev"
> +        mount -v -t $_fs -o $_opts $_dev $NEWROOT/$_mp 2>&1 | vinfo
> +    done < $1

 It means that fsck is not running in parallel if you have more
 devices in /ect/fstab.sys. Is it expected?

 It would be better to call one fsck instance for all devices
 
    fsck -T /dev/sda1 /dev/sda2 /dev/sdb1

 or use the "-l" option for more instances.

    Karel

-- 
 Karel Zak  <kzak-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]         ` <20110523230507.GC2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
@ 2011-05-24 20:50           ` Michal Soltys
       [not found]             ` <4DDC1A05.9030400-R61QfzASbfY@public.gmane.org>
  2011-05-25 14:31           ` [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck Karel Zak
  1 sibling, 1 reply; 14+ messages in thread
From: Michal Soltys @ 2011-05-24 20:50 UTC (permalink / raw)
  To: Karel Zak; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

On 11-05-24 01:05, Karel Zak wrote:
> On Fri, May 20, 2011 at 05:09:25PM +0200, Michal Soltys wrote:
>>  +fstab_mount() {
>>  +    local _dev _mp _fs _opts _dump _pass _rest
>>       test -e "$1" || return 1
>>       info "Mounting from $1"
>>  -    while read dev mp type opts rest; do
>>  -	[ -z "${dev%%#*}" ]&&  continue # Skip comment lines
>>  -	mount -v -t $type -o $opts $dev $NEWROOT/$mp
>>  -    done<  $1 | vinfo
>>  +    while read _dev _mp _fs _opts _dump _pass _rest; do
>
>   How does this code handle encoding in fstab? (e.g. /path/foo\x40bar)
>

Ah, I knew something went too easy. Though you mean - \040 as escape for 
space character in mountpoint, not any arbitrary \xNN or \0NN ?

Also, some standard handling uuid/label and watching for other stuff as 
well would be good too. Plain 'test -e' is not too proper either.

I'll get it done.

>>  +        [ -z "${_dev%%#*}" ]&&  continue # Skip comment lines
>>  +        if [ ! -e "$_dev" ]; then
>>  +            warn "Device $_dev doesn't exist, skipping mount."
>>  +            continue
>>  +        fi
>>  +        if [ "$_pass" -gt 0 ]&&  ! strstr "$_opts" _netdev; then
>>  +            wrap_fsck "$_dev"
>>  +        fi
>>  +        _fs=$(det_fs "$_dev" "$_fs" /etc/fstab.sys)
>>  +        info "Mounting $_dev"
>>  +        mount -v -t $_fs -o $_opts $_dev $NEWROOT/$_mp 2>&1 | vinfo
>>  +    done<  $1
>
>   It means that fsck is not running in parallel if you have more
>   devices in /ect/fstab.sys. Is it expected?
>

Actually, when you mentioned it - I didn't really think about actually 
parallelizing those fscks. I assumed fstab-sys use is more of an 
exception for special cases (as, "must have that mount at all cost 
before pivot"), than something "standard". Shouldn't be a problem to 
expand it in such direction though.

One point though - next step I wanted to do was to call proper 
fs-specific checker (if applicable, or fallback to generic one) - e.g. 
xfs wants xfs_check (xfs_db) or xfs_repair to be used (preferably 
including user intervention). So that would have to be done outside 
parallel run either way.

Also I wonder, if fsck stuff and det_fs wouldn't be better in its own 
module, on which fstab-sys and rootfs-block would depend (instead of 
sourcing fscks themselves, while relying on dracut-lib.sh, etc.).

>   It would be better to call one fsck instance for all devices
>
>      fsck -T /dev/sda1 /dev/sda2 /dev/sdb1
>
>   or use the "-l" option for more instances.
>
>      Karel
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]             ` <4DDC1A05.9030400-R61QfzASbfY@public.gmane.org>
@ 2011-05-24 22:39               ` Karel Zak
       [not found]                 ` <20110524223936.GG2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
       [not found]                 ` <4DDD0E48.3060607@rasengan.ppgk.com.pl>
  0 siblings, 2 replies; 14+ messages in thread
From: Karel Zak @ 2011-05-24 22:39 UTC (permalink / raw)
  To: Michal Soltys; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

On Tue, May 24, 2011 at 10:50:13PM +0200, Michal Soltys wrote:
> On 11-05-24 01:05, Karel Zak wrote:
>> On Fri, May 20, 2011 at 05:09:25PM +0200, Michal Soltys wrote:
>>>  +fstab_mount() {
>>>  +    local _dev _mp _fs _opts _dump _pass _rest
>>>       test -e "$1" || return 1
>>>       info "Mounting from $1"
>>>  -    while read dev mp type opts rest; do
>>>  -	[ -z "${dev%%#*}" ]&&  continue # Skip comment lines
>>>  -	mount -v -t $type -o $opts $dev $NEWROOT/$mp
>>>  -    done<  $1 | vinfo
>>>  +    while read _dev _mp _fs _opts _dump _pass _rest; do
>>
>>   How does this code handle encoding in fstab? (e.g. /path/foo\x40bar)
>>
>
> Ah, I knew something went too easy. Though you mean - \040 as escape for  
> space character in mountpoint, not any arbitrary \xNN or \0NN ?

 from mount(8) code:

   need_escaping[] = { ' ', '\t', '\n', '\\' };

 It's used for all strings in fstab (so not for mountpoints only).

> Also, some standard handling uuid/label and watching for other stuff as  
> well would be good too. Plain 'test -e' is not too proper either.

 From my point of view it would be ideal to avoid fstab parsing in the
 script at all. 

 export FSTAB_FILE=/etc/fstab.sys

 for $dev in $(findmnt --fstab -o SOURCE -e -n -O no_netdev); do

    fsck -T $dev
    mount $dev --target-prefix $NEWROOT

 done

 Unfortunately mount(8) does not allow to read info about mountpoints
 from alternative fstab file and it does not support --target-prefix
 now.  I'll add this to my TODO list.

    Karel

-- 
 Karel Zak  <kzak-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]                 ` <20110524223936.GG2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
@ 2011-05-25 13:16                   ` Harald Hoyer
  2011-05-25 14:32                   ` Michal Soltys
  1 sibling, 0 replies; 14+ messages in thread
From: Harald Hoyer @ 2011-05-25 13:16 UTC (permalink / raw)
  To: Karel Zak; +Cc: Michal Soltys, initramfs-u79uwXL29TY76Z2rM5mHXA

Am 25.05.2011 00:39, schrieb Karel Zak:
>   Unfortunately mount(8) does not allow to read info about mountpoints
>   from alternative fstab file and it does not support --target-prefix
>   now.  I'll add this to my TODO list.
>
>      Karel
>

That would be really cool! Thank you!

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]         ` <20110523230507.GC2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
  2011-05-24 20:50           ` Michal Soltys
@ 2011-05-25 14:31           ` Karel Zak
  1 sibling, 0 replies; 14+ messages in thread
From: Karel Zak @ 2011-05-25 14:31 UTC (permalink / raw)
  To: Michal Soltys; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

On Tue, May 24, 2011 at 01:05:07AM +0200, Karel Zak wrote:
> On Fri, May 20, 2011 at 05:09:25PM +0200, Michal Soltys wrote:
> > +fstab_mount() {
> > +    local _dev _mp _fs _opts _dump _pass _rest
> >      test -e "$1" || return 1
> >      info "Mounting from $1"
> > -    while read dev mp type opts rest; do
> > -	[ -z "${dev%%#*}" ]&& continue # Skip comment lines
> > -	mount -v -t $type -o $opts $dev $NEWROOT/$mp
> > -    done < $1 | vinfo
> > +    while read _dev _mp _fs _opts _dump _pass _rest; do
> 
>  How does this code handle encoding in fstab? (e.g. /path/foo\x40bar)

 Sorry, should be "/path/foo\040bar".

 The mount(8) and friends use octal escapes only. 
 
    Karel

-- 
 Karel Zak  <kzak-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]                 ` <20110524223936.GG2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
  2011-05-25 13:16                   ` Harald Hoyer
@ 2011-05-25 14:32                   ` Michal Soltys
  1 sibling, 0 replies; 14+ messages in thread
From: Michal Soltys @ 2011-05-25 14:32 UTC (permalink / raw)
  To: Karel Zak; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

W dniu 25.05.2011 00:39, Karel Zak pisze:
>
>   from mount(8) code:
>
>     need_escaping[] = { ' ', '\t', '\n', '\\' };
>
>   It's used for all strings in fstab (so not for mountpoints only).
>
>> Also, some standard handling uuid/label and watching for other stuff as
>> well would be good too. Plain 'test -e' is not too proper either.
>
>    From my point of view it would be ideal to avoid fstab parsing in the
>   script at all.
>
>   export FSTAB_FILE=/etc/fstab.sys
>
>   for $dev in $(findmnt --fstab -o SOURCE -e -n -O no_netdev); do
>
>      fsck -T $dev
>      mount $dev --target-prefix $NEWROOT
>
>   done
>
>   Unfortunately mount(8) does not allow to read info about mountpoints
>   from alternative fstab file and it does not support --target-prefix
>   now.  I'll add this to my TODO list.
>
>      Karel
>

Ok, thanks for info (btw, findmnt seems to only handle octal escapes).

I'll update fstab-sys & co. and send new set of patches.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck
       [not found]                   ` <4DDD0E48.3060607-dAhJnYnFfKxY6LDf3zcCrARSaAK4NQh3@public.gmane.org>
@ 2011-05-25 14:33                     ` Karel Zak
       [not found]                       ` <20110525143311.GA14298-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Karel Zak @ 2011-05-25 14:33 UTC (permalink / raw)
  To: rasengan rootish; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

On Wed, May 25, 2011 at 04:12:24PM +0200, rasengan rootish wrote:
> W dniu 25.05.2011 00:39, Karel Zak pisze:
>>
>>    From my point of view it would be ideal to avoid fstab parsing in the
>>   script at all.
>>
>>   export FSTAB_FILE=/etc/fstab.sys
>>
>>   for $dev in $(findmnt --fstab -o SOURCE -e -n -O no_netdev); do
>>
>>      fsck -T $dev
>>      mount $dev --target-prefix $NEWROOT
>>
>>   done
>>
>>   Unfortunately mount(8) does not allow to read info about mountpoints
>>   from alternative fstab file and it does not support --target-prefix
>>   now.  I'll add this to my TODO list.
>>
>>      Karel
>>
>
> Ok, thanks for info (btw, findmnt seems to only handle octal escapes).

 That's correct. 
 
 The hex (e.g. \x40) escapes are used by udev for /dev/disk/by-*
 symlinks only. 

    Karel

-- 
 Karel Zak  <kzak-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [RFC] fstab-sys: concept
       [not found]                       ` <20110525143311.GA14298-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
@ 2011-05-29  0:38                         ` Michal Soltys
  0 siblings, 0 replies; 14+ messages in thread
From: Michal Soltys @ 2011-05-29  0:38 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA
  Cc: kzak-H+wXaHxf7aLQT0dZR+AlfA, harald.hoyer-Re5JQEeQqe8AvxtiuMwx3w

This is a concept of how the fstab.sys could be implemented. The "trickery"
relies on using /bin/echo (so we can handle octal codes and to guarantee echo
-e is actually functional) and \v as a field separator, which is unlikely to be
ever used in practice...

fstab-sys would consist of cmdline hook:

- producing initqueue/finished check for all the /dev/* stuff
- producing \v separated description of what to fsck later and what to
  mount

and pre-pivot hook:

- fscking in parallel per pass
- specially handling xfs (perhaps others ?)
- mounting

If such approach is fine, I'll turn it into usable form, along with
det_fs/wrap_fsck updates.

---
 modules.d/95fstab-sys/module-setup.sh        |   12 ++++-
 modules.d/95fstab-sys/parse-fstab-sys.sh     |   59 ++++++++++++++++++++++++++
 modules.d/95fstab-sys/pre-pivot-fstab-sys.sh |   45 +++++++++++++++++++
 3 files changed, 113 insertions(+), 3 deletions(-)
 create mode 100755 modules.d/95fstab-sys/parse-fstab-sys.sh
 create mode 100755 modules.d/95fstab-sys/pre-pivot-fstab-sys.sh

diff --git a/modules.d/95fstab-sys/module-setup.sh b/modules.d/95fstab-sys/module-setup.sh
index 1fbd55b..f514571 100755
--- a/modules.d/95fstab-sys/module-setup.sh
+++ b/modules.d/95fstab-sys/module-setup.sh
@@ -7,12 +7,18 @@ check() {
 }
 
 depends() {
+    # echo fs-lib
     return 0
 }
 
 install() {
+    # will be moved away to fs-lib
+    # dracut_install /sbin/fsck*
+    # type -P e2fsck >/dev/null && dracut_install e2fsck
+    # +xfs stuff
+
     dracut_install /etc/fstab.sys
-    dracut_install /sbin/fsck*
-    type -P e2fsck >/dev/null && dracut_install e2fsck
-    inst_hook pre-pivot 00 "$moddir/mount-sys.sh"
+    dracut_install echo
+    inst_hook cmdline 10 "$moddir/parse-fstab-sys.sh"
+    inst_hook pre-pivot 00 "$moddir/pre-pivot-fstab-sys.sh"
 }
diff --git a/modules.d/95fstab-sys/parse-fstab-sys.sh b/modules.d/95fstab-sys/parse-fstab-sys.sh
new file mode 100755
index 0000000..4847766
--- /dev/null
+++ b/modules.d/95fstab-sys/parse-fstab-sys.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+local _dev _mp _fs _opts _dump _pass _rest _fsck
+
+while read _dev _mp _fs _opts _dump _pass _rest; do
+    [ -z "${_dev%%#*}" ] && continue # Skip comment lines
+
+    # handling block: is an overkill, but let's be consistent
+    # a little trickery - we will use \v as a separator to simplify our
+    # life; whole stuff will of course break, if someone actually uses that
+    # in fstab.sys ...
+
+    # parse special stuff
+    _dev=$(/bin/echo -en "$_dev")
+    _mp=$(/bin/echo -en "$_mp")
+    _opts=$(/bin/echo -en "$_opts")
+    _fs=$(/bin/echo -en "$_fs")
+    [ "$_pass" -gt 0 ] && _fsck="$_pass" || _fsck=0
+
+    case "$_dev" in
+        block:LABEL=*|LABEL=*)
+        _dev="${_dev#block:}"
+        _dev="$(echo -n "$_dev" | sed 's,/,\\x2f,g')"
+        _dev="/dev/disk/by-label/${_dev#LABEL=}"
+        ;;
+        block:UUID=*|UUID=*)
+        _dev="${_dev#block:}"
+        _dev="/dev/disk/by-uuid/${_dev#UUID=}"
+        ;;
+    esac
+
+    # allow only actual /dev devices to be waited for and fscked
+    if [ -z "${_dev#/dev/*}" ]; then
+        echo "[ -b \"$_dev\" ] || return 1" >>/tmp/fstab-sys.sh
+    else
+        _fsck=0
+    fi
+
+    # prepare "compiled" fstab we will use later
+    /bin/echo -e "$_dev\v$_mp\v\$_fs\v$_opts" >>/tmp/fstab-sys.compiled
+
+    # export fsck passes
+    # don't bother with printf to handle $_fsck > 9 alignment,
+    # but verify that in module-setup.sh
+    if [ "$_fsck" -gt 0 ]; then
+        /bin/echo "$_dev\v$_fs" >>/tmp/fstab-sys.pass.$_fsck
+    fi
+
+done </etc/fstab.sys
+
+# add initqueue/finished, only if there's something to add though
+if [ -e /tmp/fstab-sys.sh ]; then
+    echo "return 0" >>/tmp/fstab-sys.sh
+    mv /tmp/fstab-sys.sh $hookdir/initqueue/finished/fstab-sys.sh
+fi
diff --git a/modules.d/95fstab-sys/pre-pivot-fstab-sys.sh b/modules.d/95fstab-sys/pre-pivot-fstab-sys.sh
new file mode 100755
index 0000000..1a4b9b7
--- /dev/null
+++ b/modules.d/95fstab-sys/pre-pivot-fstab-sys.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+local _dev _mp _fs _opts _auto _manual _oldIFS _x
+
+oldIFS="$IFS"
+IFS=$(/bin/echo -ne "\v")
+
+# fsck pass
+_manual=
+for _x in /tmp/fstab-sys.pass.[0-9]; do
+    _auto=
+    while read _dev _fs; do
+        _fs=$(IFS="$oldIFS" det_fs "$_dev" "$_fs" "fstab-sys")
+        if [ $_fs = xfs ]; then
+            # xfs is special, so treat is specially ;)
+            _manual=$(/bin/echo -e "${_manual:+${_manual}\v}$_dev")
+            continue
+        fi
+        _auto=$(/bin/echo -e "${_auto:+${_auto}\v}$_dev")
+    done <$_x
+    # use updated wrap_fsck in full version
+    fsck -M -T $_auto
+done
+
+# special fsck pass for xfs and perhaps others
+for _dev in $_manual; do
+    # use updated wrap_fsck in full version
+    if ! xfs_check "$_dev"; then
+        warn "*** XFS on '$_dev' is damaged, please assist."
+        emergency_shell -n "(Repair filesystem)"
+    fi
+done
+
+# mount pass
+while read _dev _mp _fs _opts; do
+    _fs=$(IFS="$oldIFS" det_fs "$_dev" "$_fs" "fstab-sys")
+    info "Mounting $_dev"
+    mount -v -t "$_fs" -o "$_opts" "$_dev" "$NEWROOT/$_mp" 2>&1 | vinfo
+done </tmp/fstab-sys.compiled
+
+IFS="$_oldIFS"
-- 
1.7.4.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-05-29  0:38 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-20 15:09 [RFC/PATCH] Expand fstab-sys, simplify rootfs-block Michal Soltys
     [not found] ` <1305904167-14199-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
2011-05-20 15:09   ` [PATCH 1/5] dracut-lib.sh: add vwarn() function Michal Soltys
2011-05-20 15:09   ` [PATCH 2/5] dracut-lib.sh: Add det_fs() and wrap_fsck() Michal Soltys
2011-05-20 15:09   ` [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck Michal Soltys
     [not found]     ` <1305904167-14199-4-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
2011-05-23 23:05       ` Karel Zak
     [not found]         ` <20110523230507.GC2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
2011-05-24 20:50           ` Michal Soltys
     [not found]             ` <4DDC1A05.9030400-R61QfzASbfY@public.gmane.org>
2011-05-24 22:39               ` Karel Zak
     [not found]                 ` <20110524223936.GG2659-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
2011-05-25 13:16                   ` Harald Hoyer
2011-05-25 14:32                   ` Michal Soltys
     [not found]                 ` <4DDD0E48.3060607@rasengan.ppgk.com.pl>
     [not found]                   ` <4DDD0E48.3060607-dAhJnYnFfKxY6LDf3zcCrARSaAK4NQh3@public.gmane.org>
2011-05-25 14:33                     ` Karel Zak
     [not found]                       ` <20110525143311.GA14298-sHeGUpI7y9L/9pzu0YdTqQ@public.gmane.org>
2011-05-29  0:38                         ` [RFC] fstab-sys: concept Michal Soltys
2011-05-25 14:31           ` [PATCH 3/5] 95fstab-sys: use det_fs and wrap_fsck Karel Zak
2011-05-20 15:09   ` [PATCH 4/5] 95rootfs-block/mount-root.sh: Rely on " Michal Soltys
2011-05-20 15:09   ` [PATCH 5/5] 95rootfs-block/block-genrules.sh: Use > instead of >> Michal Soltys

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.