Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Bash:Chroot into another system from your ubuntu linux terminal!

That is a simple chroot script,i used this to repair my grub many times on ubuntu!

Here it is:
Code
#!/bin/bash

clear
#Colors
black() { echo "$(tput setaf 0)$*$(tput setaf 9)"; }
red() { echo "$(tput setaf 1)$*$(tput setaf 9)"; }
green() { echo "$(tput setaf 2)$*$(tput setaf 9)"; }
yellow() { echo "$(tput setaf 3)$*$(tput setaf 9)"; }
blue() { echo "$(tput setaf 4)$*$(tput setaf 9)"; }
magenta() { echo "$(tput setaf 5)$*$(tput setaf 9)"; }
cyan() { echo "$(tput setaf 6)$*$(tput setaf 9)"; }
white() { echo "$(tput setaf 7)$*$(tput setaf 9)"; }
#REDbold="\e[1;31m"  #Alter fonts to red bold
#REDN="\e[0;31m"  #Alter fonts to red normal
GRN="\e[1;32m" #Alter fonts to green bold
GRNN="\e[0;32m"  #Alter fonts to green normal
BLU="\e[1;36m"  #Alter fonts to blue bold
BLUN="\e[0;36m"  #Alter fonts to blue normal
YEL="\e[1;33m"   #Alter fonts to yellow bold
YELN="\e[0;33"   #Alter fonts to yellow normal
PUR="\e[1;35m"    #Alter fonts to purple bold
PURN="\e[0;35m"   #Alter fonts to purple normal
CYA="\e[1;36m"    #Alter fonts to cyan normal
CYAN="\e[0;36m"   #Alter fonts to purple bold
dgrey="\033[0;34m"
port="\033[0;33m"
RED="\033[1;31m"
GREEN="\033[2;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
RED="\033[0;31m"
ENDCOLOR="\033[0m"


echo -e $GREEN"Enter the name of the partition that your system is installed to  chroot on it(etc.. /dev/sdb5):"$ENDCOLOR
read name
sleep 0.5
echo -e $RED"removing old chroot environments.."$ENDCOLOR
rm -rf /mnt/ubuntu
sleep 0.5
mkdir /mnt/ubuntu
sleep 0.5
echo -e $RED"mounting $name filesystem"$ENDCOLOR
sudo mount $name  /mnt/ubuntu
sleep 0.5
chroot /mnt/ubuntu apt -y install lvm2
sleep 0.5
mount -o bind /proc /mnt/ubuntu/proc
sleep 0.5
mount -o bind /dev /mnt/ubuntu/dev
sleep 0.5
mount -o bind /dev/pts /mnt/ubuntu/dev/pts
sleep 0.5
mount -o bind /sys /mnt/ubuntu/sys
sleep 0.5
mount --bind /run/udev /mnt/ubuntu/run/udev
sleep 0.5
cp /etc/resolv.conf /mnt/ubuntu/etc/resolv.conf
sleep 0.5
chroot /mnt/ubuntu /bin/bash
wait
echo -e $port"umounting $name filesystem"$ENDCOLOR
sleep 0.5
umount  /mnt/ubuntu/run/udev
sleep 0.5
umount  /mnt/ubuntu/proc
sleep 0.7
sudo umount /mnt/ubuntu/dev
sleep 0.5
umount  /mnt/ubuntu/dev/pts
sleep 0.5
umount  /mnt/ubuntu/sys
sleep 0.5
sudo umount  /mnt/ubuntu
sleep 0.5
echo -e $GREEN"exiting chroot environment"$ENDCOLOR
echo "done" | festival --tts

If anyone has a better one please share,or any recommendations!
[Image: sig.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Leroy Jethro GibbsApr 10, 2017 02:39 AM 6 203 Apr 10, 2017 02:39 AM
Last Post: Leroy Jethro Gibbs
[DBMS] by c00perzzJun 16, 2016 08:13 PM 2 208 Jun 16, 2016 08:13 PM
Last Post: pppickle2
by ΑrtificialAug 7, 2012 05:45 PM 4 113 Aug 7, 2012 05:45 PM
Last Post: Αrtificial