orangesquid (os) wrote,
orangesquid
os

rc.fsck2

it's handy to have a slackware rc.d file to fsck+mount xfs and jfs partitions referred to by LABEL= in fstab, esp. loopback.

#!/bin/bash

shopt -s extglob

xfslabel=$(
  for b in /dev/block/* /dev/mapper/!(control) \
           $(cat /proc/partitions |
             tail +2 |
             awk '{print "/dev/" $4}' |
             grep -v '/dev/\?$')
  do
    echo xfs_admin on $b 1>&2
    xfs_admin -l $b 2>/dev/null && readlink -f $b
  done |
    sed 's,^/dev.*,&*,' |
    tr '\n*' ' \n' |
    grep -v 'label = "\(\|(null)\)"' |
    sed 's/^ \?label = \("[^"]\+"\) /LABEL=\1:/'
)

jfslabel=$(
  for b in /dev/block/* /dev/mapper/!(control) \
           $(cat /proc/partitions |
             tail +2 |
             awk '{print "/dev/" $4}' |
             grep -v '/dev/\?$')
  do
    echo jfs_tune on $b 1>&2
    jfs_tune -l $b 2>/dev/null && echo "device: $(readlink -f $b)"
  done |
    grep '^\(Volume label\|device\):' |
    sed 's,^device: /dev.*,&*,' |
    tr '\n*' ' \n' |
    sed 's/^ \?Volume label:[ \t]\+'"'\\([^']\\+\\)'"' device: /LABEL="\1":/'|
    tr -d '"' |
    grep -v "'' *device:"
)

echo XFS:
echo "$xfslabel"
echo end

for xfs in $(
    grep -v '^#' /etc/fstab|awk '{if ($3 == "xfs") print $2 ":" $1}')
do
  mp=$(cut -d: -f1 <<< "$xfs")
  echo xfs $xfs $mp
  if ! mount | grep -q "on $mp type"
  then
    echo .. $part
    part=$(cut -d: -f2 <<< "$xfs")
    if [ "$(cut -d= -f1 <<< "$part")" = "LABEL" ]; then
      part=$(grep "^$part:" <<< "$xfslabel"|cut -d: -f2)
      echo .... $part
    fi
    xfs_check $part && mount $mp
  fi
done

echo JFS:
echo "$jfslabel"
echo end

for jfs in $(
    grep -v '^#' /etc/fstab|awk '{if ($3 == "jfs") print $2 ":" $1}')
do
  mp=$(cut -d: -f1 <<< "$jfs")
  echo jfs $jfs $mp
  if ! mount | grep -q "on $mp type"
  then
    part=$(cut -d: -f2 <<< "$jfs")
    echo .. $part
    if [ "$(cut -d= -f1 <<< "$part")" = "LABEL" ]; then
      part=$(grep "^$part:" <<< "$jfslabel"|cut -d: -f2)
      echo .... $part
    fi
    jfs_fsck $part && mount $mp
  fi
done


this can be called from /etc/rc.d/rc.local via:
if [ -x /etc/rc.d/rc.fsck2 ]; then
/etc/rc.d/rc.fsck2
fi
Tags: fsck, jfs, rc, slackware, xfs
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments