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.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 3 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Mounting of the directories via the bind option should be done AFTER mounting the partition on $d. Otherwise they are made invisible.
Thanks for the heads up!
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