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

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

ADVERTISEMENTS

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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • Thomas Jun 24, 2010 @ 10:47

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

  • Ram Mar 5, 2012 @ 6:59

    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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.