]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/init.d/checkfstab
Add emergency shell if filesystem check fail.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / checkfstab
CommitLineData
ba3e5905
AF
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
18case "${1}" in
19 start)
3b50eb81
AF
20 #Skip if root is set by UUID
21 if (grep "root=UUID=" /proc/cmdline); then
22 exit 0;
23 fi
27159f53 24 boot_mesg "Checking fstab bootdevice ..."
03f0aa26 25 read CMDLINE < /proc/cmdline
a7748862
AF
26 ROOTPOS=`expr index "$CMDLINE" root=`
27 NEWROOT=`echo ${CMDLINE:$ROOTPOS} | cut -d"=" -f2 | cut -d" " -f1`;
94f6d10b 28 OLDBOOT=`cat /etc/fstab | grep -m1 " / " | cut -d" " -f1 | cut -f1`;
27159f53 29 OLDDRV=${OLDBOOT::`expr length $OLDBOOT`-1}
ba3e5905 30 NEWDRV=${NEWROOT::`expr length $NEWROOT`-1}
27159f53 31 if [ "$OLDDRV" == "$NEWDRV" ]; then
ba3e5905
AF
32 echo_ok;
33 exit 0;
34 fi
35 echo_failure;
27159f53 36 boot_mesg "Warning! Bootdrive not match with fstab!"
ba3e5905 37 boot_mesg
27159f53
AF
38 boot_mesg "Bootdrive: $NEWDRV"
39 boot_mesg "fstab-entry: $OLDDRV"
ba3e5905 40 boot_mesg
94f6d10b
AF
41 if [ "${OLDDRV:0:4}" == "UUID" ]; then
42 #Short sleep because the kernel has not finished hardware detections
43 #and made many messages here and the password question is not readable
44 sleep 3
45 boot_mesg "${FAILURE}Error OLD Bootdrive is already a UUID. Can't fix."
46 boot_mesg "${NORMAL}"
47 sulogin
48 reboot -f
49 fi
ba3e5905
AF
50 boot_mesg "Attempt to repair it ..."
51 mount -o remount,rw /
52 sed -i -e "s|$OLDDRV|$NEWDRV|g" /etc/fstab
53 mount /boot
54 sed -i -e "s|$OLDDRV|$NEWDRV|g" /boot/grub/grub.conf
55 umount /boot
56 echo_ok;
57 exit 0;
58 ;;
59 *)
60 echo "Usage: ${0} {start}"
61 exit 1
62 ;;
63esac
64
65# End $rc_base/init.d/checkfstab