Wednesday, October 31, 2012

chroot - access another Linux from your current Linux

If you need to access one Linux distribution from another chroot is an excellent choice. A couple common usage examples are resetting a forgotten password and reinstalling the bootloader.

I have also used a chroot environment in order to install neccesary packages in order to get the operating system where it is X capable, This is very useful in more advanced Linux systems such as Arch Linux or Gentoo where you start in a command line interface, allowing you access to useful graphical tools such as web browsers to look up information while you work on the system.

Here is a bash script that needs to be run as root, administrator or superuser, it tells you what it is doing while it is doing it. Copy and Paste this into a text file and save. Upon saving the file you need to make it executable, run chmod a+x as root. Then to run the script sh ./

#!/bin/bash
#Written by Edge226.

#Mount Guest Linux Partitions
#modify  with the / partition of the guest system. 

echo "Mounting Guest Operating System."
mount  /mnt/chroot 

#Mount the home partition 

echo "Mounting Home Drive."
mount -o bind /home /mnt/chroot/home 

#Mount Operating system devices.

echo "Mounting System Devices." 
mount -o bind /proc /mnt/chroot/proc 
mount -o bind /dev /mnt/chroot/dev 
mount -o bind /sys /mnt/chroot/sys 
mount -t devpts devpts /mnt/chroot/dev/pts

#Enable Network Access. 

echo "Enabling Network Access." 
cp /etc/resolv.conf /mnt/chroot/etc/resolv.conf
  
#Enter the Chroot Environment. 

echo "Entering the chroot environment." 
env NAME=chroot chroot /mnt/chroot /bin/bash

#Clean up after exiting the environment. 
#Unmount devices.

echo "Unmounting System Devices." 
umount /mnt/chroot/dev/pts
umount /mnt/chroot/sys 
umount /mnt/chroot/dev
umount /mnt/chroot/proc
echo "Done."

echo "Unmounting Home drive."
umount /mnt/chroot/home
echo "Done." 

echo "Unmounting Guest Operating System."
umount /mnt/chroot
echo "Returned to Host System Successfully!"

No comments:

http://goo.gl/BGVrJP

MY Motto

My photo
giving amenity to all visitor.

Total Pageviews