]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/initscripts/init.d/checkfstab
Merge branch 'master' into next
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / checkfstab
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/checkfstab
4 #
5 # Description : Check and repair fstab if the drivename has changed
6 #
7 # Authors : Arne Fitzenreiter - arne_f@ipfire.org
8 #
9 # Version : 00.00
10 #
11 # Notes :
12 #
13 ########################################################################
14
15 . /etc/sysconfig/rc
16 . ${rc_functions}
17
18 case "${1}" in
19 start)
20 #Skip if root is set by UUID
21 if (grep "root=UUID=" /proc/cmdline); then
22 exit 0;
23 fi
24 boot_mesg "Checking fstab bootdevice ..."
25 read CMDLINE < /proc/cmdline
26 ROOTPOS=`expr index "$CMDLINE" root=`
27 NEWROOT=`echo ${CMDLINE:$ROOTPOS} | cut -d"=" -f2 | cut -d" " -f1`;
28 OLDBOOT=`cat /etc/fstab | grep -m1 "/boot" | cut -d" " -f1 | cut -f1`;
29 OLDDRV=${OLDBOOT::`expr length $OLDBOOT`-1}
30 NEWDRV=${NEWROOT::`expr length $NEWROOT`-1}
31 if [ "$OLDDRV" == "$NEWDRV" ]; then
32 echo_ok;
33 exit 0;
34 fi
35 echo_failure;
36 boot_mesg "Warning! Bootdrive not match with fstab!"
37 boot_mesg
38 boot_mesg "Bootdrive: $NEWDRV"
39 boot_mesg "fstab-entry: $OLDDRV"
40 boot_mesg
41 boot_mesg "Attempt to repair it ..."
42 mount -o remount,rw /
43 sed -i -e "s|$OLDDRV|$NEWDRV|g" /etc/fstab
44 mount /boot
45 sed -i -e "s|$OLDDRV|$NEWDRV|g" /boot/grub/grub.conf
46 umount /boot
47 echo_ok;
48 exit 0;
49 ;;
50 *)
51 echo "Usage: ${0} {start}"
52 exit 1
53 ;;
54 esac
55
56 # End $rc_base/init.d/checkfstab