Sunday, March 26, 2017

RHEL7 - Restore system from bad (corrupted) /etc/fstab file


Resque messed root fs
1. Original /etc/fstab was 300MB so we have to null it down.
- we look into similar server and found the following entry

UUID=ba44543c-834d-4847-b00d-548bc8404e64 /                       xfs     defaults        0 0
UUID=d3301139-be26-491e-ab11-67ea1548dad4 /boot                   xfs     defaults        0 0
UUID=a41490aa-246a-41b0-a973-7b2d4fffba25 swap                    swap    defaults        0 0

- fdisk lists

/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux


2. rebooted the system and on splash menu, where timer runs, highlight the default kernel line
- press e to edit
- go to line linux16
- go to end of the line (either type CTRL+E, to use left arrow key to move to the end of the line)
- type rd.break to go to rescue/emergency mode
- type mount and remount
  # mount -o remount,rw /
  # chroot /sysroot
  # cp -p /etc/fstab /etc/fstab.today
  # cat > /etc/fstab
/dev/sda3 /                       xfs     defaults        0 0
/dev/sda1   /boot                   xfs     defaults        0 0
/dev/sda2 swap                    swap    defaults        0 0

Note: Based on output, we changed UUID of related disk to /dev/sdaX. and rebooted the system and it came fine.

3. Type crtl+d and reboot the system.

Note: If you are changing root password, type touch /.autorelabel before reboot and reboot the system.


No comments:

Post a Comment