CentOS / Redhat: Chroot And Mount Raid Or Actual Hard Disk From Rescue Kernel / CD

by on June 23, 2010 · 3 comments· LAST UPDATED June 24, 2010

in

Something is wrong with my RHEL networking configuration so I booted using my ISPs remote rescue kernel mode to fix my system. How do I mount and chroot into actual installation to fix the problem? How do I boot from any Live Linux CD and chroot into /dev/sda1 or /dev/md0 to fix the problem or recover the data?

Once booted into rescue kernel or using Live Linux CD you need to verify that your disks are detected. Type the following command to verify the same:
# fdisk -l
Next, create a directory to chroot and mount existing partitions:
# mkdir /chroot
# d=/chroot

Mount actual partition:
# mount /dev/sda1 $d
Mount /proc and other file system inside $d, enter:
# mount -o bind /dev $d/dev
# mount -o bind /sys $d/sys
# mount -o bind /dev/shm $d/dev/shm
# mount -o bind /proc $d/proc

Chroot and access your data:
# chroot $d
# df
# ls
# vi /etc/somefile

Exit and reboot the system:
# exit
# umount $d/proc
# umount $d/sys
# umount $d/dev/shm
# umount $d/dev
# umount /dev/sda1

A Note About Multiple /boot, /home, /tmp Partitions

Cosinder the following parition layout for /dev/sda

  • / - /dev/sda1
  • /boot - /dev/sda2
  • /home - /dev/sda3
  • /tmp - /dev/sda4

To mount all at /chroot, enter:
# d=/chroot
# mkdir $d
# mount /dev/sda1 $d
# mount -o bind /dev $d/dev
# mount -o bind /sys $d/sys
# mount -o bind /dev/shm $d/dev/shm
# mount -o bind /proc $d/proc
# mount /dev/sda2 $d/boot
# mount /dev/sda3 $d/home
# mount /dev/sda4 $d/tmp
# chroot $d

A Note About /dev/md0 (Software RAID)

Type the following command to mount /dev/md0 at /chroot/data (/dev/sda1 at /chroot):
# d=/chroot
# mkdir $d
# mount /dev/sda1 $d
# mount -o bind /dev $d/dev
# mount -o bind /sys $d/sys
# mount -o bind /dev/shm $d/dev/shm
# mount -o bind /proc $d/proc
# mount /dev/md0 $d/data
# chroot $d
# ls
# df

Now you can access software RAID too.

How Do I Recover Data?

Once /dev/md0 or /dev/sda1 mounted simply copy data using scp / rsync or external usb pen / hard disks.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 Thomas June 24, 2010 at 10:47 am

Mounting of the directories via the bind option should be done AFTER mounting the partition on $d. Otherwise they are made invisible.

Reply

2 nixCraft June 24, 2010 at 10:55 am

Thanks for the heads up!

Reply

3 Ram March 5, 2012 at 6:59 am

Thank you so much for your help. This is one of the many times your web site has saved me hours of headaches! So thanks

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: