0% found this document useful (0 votes)
137 views12 pages

Repair Corrupted File System

This document provides instructions for recovering a root or lost password on Linux systems like CentOS, openSUSE, and Red Hat. It describes options like single-user mode, chrooting from a live CD, and directly editing files like /etc/shadow. Key steps include mounting the root file system read-write, chrooting into it, and using passwd to change the password. For CentOS 7, it provides directions to boot into an early systemd target and perform the same recovery steps from the initial RAM disk.

Uploaded by

Amit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views12 pages

Repair Corrupted File System

This document provides instructions for recovering a root or lost password on Linux systems like CentOS, openSUSE, and Red Hat. It describes options like single-user mode, chrooting from a live CD, and directly editing files like /etc/shadow. Key steps include mounting the root file system read-write, chrooting into it, and using passwd to change the password. For CentOS 7, it provides directions to boot into an early systemd target and perform the same recovery steps from the initial RAM disk.

Uploaded by

Amit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Lsblk –f

Mount -n -o remount , rw /

Then edit /etc/fstab

Repair Corrupted File System


The simplest use case of the fsck command is to repair a non-root
corrupted ext3 or ext4 file system.

1. If you don’t know the device name, use fdisk, df , or any other tool to
find it.
2. Unmount the device:

sudo umount /dev/sdc1Copy

3. Run fsck to repair the file system:

sudo fsck -p /dev/sdc1Copy

The -p option tells fsck to automatically repair any problems that can


be safely fixed without user intervention.

4. Once the file system is repaired, mount the partition:

sudo mount /dev/sdc1Copy

Repair Root File System #


fsck cannotcheck the root file system on a running machine because it
cannot be unmounted.

If you want to check or repair the root file system, you have several options
at your disposal. You can set the fsck to run on boot, boot the system in
recovery mode, or use a live CD.

To run fsck in recovery mode:


sudo fsck -y /dev/sdb

It indicates that the data in the partition is corrupted. For recovering,

 Boot the system from the CD/DVD of the same release of the installed system. After
the system boots successfully from the ISO, run this command without quotes. It’ll look
like this:

boot: linux rescue

 When asked, enter all the required information like keyboard layout, language and
pertinent information for the system. When you’ll be asked for network device enabling,
select “No”.
 When you’ll be prompted to allow rescue environment mounting Oracle Linux
installation under “/mnt/sysimage”, directory, select “Skip”.
 Depending on the LVM usage on the system, run the following commands:
If not using LVM,

# e2fsck -f /dev/sda1

e2fsck 1.41.12.14 (17-May-2014)

[…]
If using LVM,

# pvscan

PV /dev/sda1 VG VolGroup00 lvm2 [96.00 MB / 0 free]

Total: 1 [3.34 GB] / in use: 1 [3.34 GB] / in no VG: 0 [0 ]

# vgscan

Reading all physical volumes. This may take a while...

Found volume group "VolGroup00" using metadata type lvm2

# lvscan

INACTIVE '/dev/VolGroup00/LogVol00' [3.34 GB] inherit

# lvdisplay
--- Logical volume ---

LV Name /dev/VolGroup00/LogVol00

VG Name VolGroup00

LV UUID 335qTi-Ossg-32O5-yQC7-xNON-egdI-frj4et

LV Write Access read/write

LV Status NOT available

LV Size 3.34 GB

Current LE 107

Allocation inherit

Read ahead sectors 0

# vgchange -ay

1 logical volume(s) in volume group "VolGroup00" now active

# e2fsck -f -y /dev/VolGroup00/LogVol00

e2fsck 1.41.12.14 (17-May-2014)

[...]
After the process is complete, exit rescue mode, remove the CD/DVD or boot device from
the system and reboot the machine normally.

It should work just fine. If the luck is still not in your favor, you may want to re-install the
system.

Recover Root Password - openSUSE

Set Root Password

If you've lost your root password, you might be able to recover it using the steps below. However,
some systems are protected with boot loader passwords that will not let you do that without THAT
password. If the boot loader is password protected, you need to boot from other media Like the
OpenSUSE CD/DVD/mini-boot. OpenSUSE install CD is probably the best one to use.
CD/DVD Recovery Mode

If using CD/DVD boot media, You need to choose Rescue System. You enter root and then mount the
disk manually. For example, a Compaq raid controller will probably be /dev/ida/c0d0 or an IDE drive
will be /dev/hda1. Find the partitions by using fdisk /dev/ida/c0d0 or fdisk /dev/hda (just "p" and quit)
and then mount what you need.

mount -o remount,rw /dev/sda2 /mnt

# cd /mnt

# chroot /mnt

# passwd

For 10.3, you need somemore steps:

Start the rescue system. Find the disk root partition, then, assuming its hdxy (or probably sdxy):

mount /dev/hdxy /mnt

mount -o bind /proc /mnt/proc

mount -o bind /sys /mnt/sys

mount -o bind /dev /mnt/dev

chroot /mnt

you are root in the installed sytem, with all at hand: passwd, but also YaST...

"bind" allow using two mount points for system virtual folders.

If all fails, consider that you can pull this drive (or install another drive in this machine) and mount it
from another running Linux. Then recover the root password as explained above.

Single User Mode

The first thing to try is to boot to single user mode. This MIGHT not work for you, because your
system might be configured to still ask for a root password to get to single user mode. If that's the
case, we'll use another trick that replaces init with /bin/bash.

First, try single user. If you don't see either a LILO or GRUB boot screen, try hitting CTRL-X to get
one. If it's LILO, just type "linux single" and that should do it (assuming that "linux" is the lilo label). If
GRUB, hit 'e", then select the "kernel" line, hit "e" again, and add " single" (or just " 1") to the end of
the line. Press ENTER, and then "b" to boot. (Newer version of grub uses "a" to append to the boot
line)

You should get a fairly normal looking boot sequence except that it terminates a little early at a bash
prompt. If you get a "Give root password for system maintenance", this isn't going to work, so see the
"init or /bin/bash" version below.

If you do get the prompt, the / filesystem may not be mounted rw (although "mount" may say it is). Do

mount -o remount,rw /
If that doesn't work (it might not), just type "mount" to find out where "/" is mounted. Let's say it is on
/dev/sda2. You'd then type:

mount -o remount,rw /dev/sda2

If you can do this, just type "passwd" once you are in and change it to whatever you like. Or just
edit /etc/shadow to remove the password field: move to just beyond the first ":" and remove everything
up to the next ":". With vi, that would be "/:" to move to the first ":", space bar once, then "d/:" and
ENTER. You'll get a warning about changing a read-only file; that's normal. Before you do this,
/etc/shadow might look like:

root:$1$8NFmV6tr$rT.INHxDBWn1VvU5gjGzi/:12209:0:99999:7:-1:-
1:1074970543

bin:*:12187:0:99999:7:::

daemon:*:12187:0:99999:7:::

adm:*:12187:0:99999:7:::

and after, the first few lines should be:

root::12209:0:99999:7:-1:-1:1074970543

bin:*:12187:0:99999:7:::

daemon:*:12187:0:99999:7:::

adm:*:12187:0:99999:7:::

You'll need to force the write: with vi, ":wq!". (If that still doesn't work, you needed to do the -o
remount,rw, above).

INIT or /bin/bash Mode

Another trick is to add "init=/bin/bash" (LILO "linux init=/bin/bash" or add it to the Grub "kernel" line).
This will dump you to a bash prompt much earlier than single user mode, and a lot less has been
initialised, mounted, etc. You'll definitely need the "-o remount,rw" here. Also note that other
filesystems aren't mounted at all, so you may need to mount them manually if you need them. Look
in /etc/fstab for the device names.

Keep this in mind if you have a Linux machine in a publically accessible place : without more
protection, it's not usually hard to recover a lost root password, which means it's just as easy for
someone to CHANGE it, or access root without your knowledge.

Another way to do this is to remove the password from /etc/shadow. Just in case you screw up, I'd
copy it somewhere safe first. You want to end up with the root line looking something like this:

Original line:

root:$1$EYBTVZHP$QtjkCG768giXzPvW4HqB5/:12832:0:99999:7:::

After editing:
root::12832:0:99999:7:::

If you are having trouble with editing (you really do have to learn vi one of these days), you could just
(after making a copy, of course) just

echo "root::12832:0:::::" > /mnt/etc/shadow

or, if you were in single user mode

echo "root::12832:0:::::" > /etc/shadow

and then fix things up when rebooted.

RESET A FORGOTTEN ROOT PASSWORD

FOR CENTOS 6
Option A
1. Boot Computer & Interrupt (Press space).

2. Type ‘a’ for kernel argument.

3. Append 1 at the end of “rhgbquiet” and press ‘Enter’ key to boot in Single mode.

4. Type “runlevel” to know runlevel.

5. Type “passwd” and change the password.

Option B
1. Bootsystem and list avaiable kernel version. (Press any key to enter the menu)

2. Press ‘e’.

3. Highlight the list item with vmlinuz & press ‘e’.

4. Type single or init 1 at end of the line.

5. Press enter and ‘b’ to boot with new argument.

6. Type password.

FOR CENTOS 7
1. Reboot your system, and interrupt the countdown in the boot loader menu.

a. Send a Ctrl+Alt+Del to your system using the relevant button or menu entry.
b. When the boot loader menu appers, press any key to interrupt the countdown.
2. Edit the default boot loader entry (in memory) to abort the boot process just after
all file systems have been mounted, but before control is handed over to systemd,
then boot.
a. Use the cursor keys to highlight the default boot loader entry.

b. Press ‘e’ to edit the current entry.


c. Using the cursor keys, navigate to the line that starts with linux16.
d. Press End to move the cursor to the end of the line.
e. Append rd.break to the end of the line.
f. Press Ctrl +x to boot using the modified config.
3. At the switch_root prompt, remount the /sysroot file systemd read-write, then use
chroot to go into a chroot jail at /sysroot.

switch_root:/# mount -oremount,rw /sysroot


switch_root:/# chroot /sysroot
4. Change the root password as you desire.

sh-4.2# echo redhat | passwd --stdin root


5. Configure the system to automatically perform a full SELinux relabel after boot.
This is necessary since the passwd tool re-created the /etc/shadow file without an
SELinux context.

sh-4.2# touch /.autorelabel


6. Type exit twice to continue booting your system as normal. The system will run an
SELinux relabel, then reboot again by itself.

https://www.unixarena.com/2013/09/redhat-linux-how-to-fix-read-only-root.html/

Redhat Linux How to Fix Read only root Filesystem Issue

SEPTEMBER 16, 2013 BY LINGESWARAN R 1 COMMENT

One of the most common problem in Redhat Linux is “read only root filesystem”
when there is issue with hardware or SAN sub-systems .To fix the “read only
filesystem” issue ,you need to reboot the server.But while rebooting the server,
you will definitely  encounter many issues and that requires a manual intervention
by logging in with the root. Unfortunately you may not logging as root if root
filesystem is corrupted and it will not accept the root password. In this case, you
need to boot the system in rescue mode using Redhat Linux DVD.

Here is the steps which you need to try before rebooting the system
in rescue mode using Redhat Linux DVD.

1.Reboot the system and see whether system is automatically booting in normal


mode with root filesystem in read/write.While booting automatically, it will check
the root filesystem filesystem integrity using fsck.

2.Some times system will go in to maintenance mode after after rebooting.In this


case, system will prompt for root password. Try to Login and run fsck on root
filesystem to fix the issue.

3.If there is any problem with /etc/rc.sysinit(/etc/rc.d/rc.sysinit) , system will


always boot and make the root filesystem in read-only mode.In this case, you need
restore the file from backup or copy the file from other similar redhat server.

4.If the system is booted in maintenance mode and not accpeting the root
password, then you need to boot the system in rescue mode using redhat Linux
DVD.

Rescue mode system recovery:

1.Insert the redhat DVD and boot the system in rescue mode.

2.Select the language as “English” and continue.


3.Select “No” to skip the networking.

4.Select “skip” to run fsck on root filesystem.


 

5.If you are not using “LVM” for root filesystem,execute fsck on the device which
contains the root filesystem
UnixArena# e2fsck -f /dev/sda1
e2fsck 1.51.12 (17-May-2013)
[...]

6.If you are using LVM for root filesystem, You need to activate the logical volumes
using below method.

# lvm pvscan
PV /dev/sda1 VG VolGroup00 lvm2 [996.00 MB / 0 free]
Total: 1 [8.48 GB] / in use: 1 [8.48 GB] / in no VG: 0 [0 ]
# lvm vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2
# lvm lvscan
INACTIVE '/dev/VolGroup00/LogVol00' [8.48 GB] inherit

# lvm vgchange -ay


1 logical volume(s) in volume group "VolGroup00" now active

7.Run fsck on the root filesystem logical volume to check the integrity.

# e2fsck -f /dev/mapper/VolGroup00/LogVol00
e2fsck 1.51.12 (17-May-2013)
[...]
8.Exit the rescue mode and boot the system normally.

Hope this will fix the issue. 

I have seen many times , redhat Linux which is running on VMWARE ESX may face
this issue.In these cases , you need to follow the below steps.
1. Update VMware tools .
2. Migrate the affected virtual machine to other datastore and monitors the virtual
machine. If issue doesn’t reappears, It could be problem with the storage. Engage
the storage vendor.
2. Even after the storage migration, if issue reoccurs .Update the Linux kernel to
the latest version.
3. Increase the SCSI timeout of each disk presented from VMWare as per
the Redhat Linux article.

To troubleshoot further on VMWARE ESX for this issue, Please follow this article.
Thanks to www.vmwarearena.com

Thank you for visiting UnixArena. Please leave a comment if you have any doubt.

Assigning blade slot iDRAC addresses


Move to a laptop and open a browser that has connectivity to the network
where the CMC IP address resides.
Point the browser to the IP address you assigned to the CMC.
Use the username root and the password calvin to access the CMC.
This enables you to quickly assign consecutive IP addresses for the
iDRACs for all 16 blade servers. You will also change the CMC password.
1
. Select Server Overview at the left and choose the Setup tab.
2
. Ensure that the QuickDeploy...checkbox is enabled.
Set Starting iDRAC IPv4 Address (Slot 1) from your chosen IP
3 address range for slot iDRACs. (Check the Netmask and Gateway shown
. on screen, and change if needed.)
4
. Click Save QuickDeploy Settings.
5 Scroll down, to locate the button labeled Auto-Populate Using
. QuickDeploy Settings. Click it.
Note: Contiguous IP addresses are assigned consecutively to all 16
individual slots for iDRACs.
6
. Click Apply iDRAC Network Settings at the bottom of the screen
7 In the left navigation, select User Authentication > Chassis
. Overview.
8
. Select User ID 1.
9
. Change the password for the CMC and click Apply.

https://forums.centos.org/viewtopic.php?t=2040&p=11497

Re: Error on Start-up


 Quote

Post by bubber14 » 2013/11/17 00:56:56

TrevorH wrote:Did you add it to /etc/fstab? If you did then it'll be


trying to mount it even if it's not present (or if you have a typo in
the device name like /dev/sbg instead of sdg - you misspelled it in
your first post). In single user mode, you can
CODE: SELECT ALL
mount -n -o remount,rw /
then edit /etc/fstab and correct the problem and reboot.
mount -o remount,rw /

in maitenace mode

mount -o remount,rw /

then use fstab to edit

You might also like