Author Topic: Mount Chroot script request  (Read 2800 times)

VastOne

  •      v-ger
  • Posts: 4187
    • View Profile
    • VSIDO Community
Mount Chroot script request
« on: January 22, 2017, 08:31:07 PM »
I'll start this off...

I do this a lot on the build systems

Code: [Select]
sudo mount /dev/sdc8 /mnt

sudo mount --bind /dev /mnt/dev

sudo mount --bind /sys /mnt/sys

sudo mount --bind /proc /mnt/proc

sudo chroot /mnt


What I would like to have is a bash script where all I would need to do is

Code: [Select]
sudo script_name sdxx
Where sdxx is a variable of the partition I want to mount and chroot to...

The chroot line is not mandatory but having something I could run to mount and would be incredibly useful

A second script could be written to handle the umount portion I must do also

Code: [Select]
sudo umount /mnt/dev

sudo umount /mnt/sys

sudo umount /mnt/proc

sudo umount /mnt/

Good luck on your mission...  ;D
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Mount Chroot script request
« Reply #1 on: January 23, 2017, 10:12:59 AM »
Save the following code somewhere in your $PATH with the name "vs-chroot".
Give "vs-chroot" execute permission.
run it with fingers crossed.
Let me know what it breaks  ;)

Code: [Select]
#!/usr/bin/env bash
function mke_chr(){
printf "\033c"
echo -e ""
echo -e "Enter the name of the disk partition to chroot to"
echo -e "For example \"sda1\" \"sda2\" \"sdb1\" \"sdb2\" etc. etc."
echo -e "Don't enter the full device path suchas "/dev/sda1""
echo -e ""
echo -e "Enter disk partition name: "
read -er Name
test -b "/dev/$Name"
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "No partition with the name $Name found!!!"
echo -e ""
exit 1
fi
printf "\033c"
mount "/dev/$Name" /mnt
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
printf "\033c"
echo -e ""
echo -e "Your chroot environment is prepared"
echo -e "You can enter the created chroot by"
echo -e "running \"sudo chroot /mnt\" command."
echo -e ""
read -r -s -p $'Press Any Key To Exit...\n' -n1
printf "\033c"
exit 0
}
function rmv_chr(){
printf "\033c"
test -d "/mnt/dev"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/sys"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/proc"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
umount /mnt/dev
umount /mnt/sys
umount /mnt/proc
umount /mnt/
printf "\033c"
echo -e ""
echo -e "Your chroot environment has been removed"
echo -e ""
exit 0
fi
fi
fi
printf "\033c"
echo -e ""
echo -e "No chroot environment found!!!"
echo -e ""
exit 1
}
function MenU (){
if [ "$EUID" -ne 0 ] ; then
printf "\033c"
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
echo -e '\e[38;5;82m'"You must run \"vs-chroot\" script using \"sudo\"."
echo -e '\e[38;5;82m'"Hint Hint Hint Hint ----> \"sudo ./vs-chroot\"."
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
tput sgr0
exit 1
fi
printf "\033c"
echo -e ""
echo -e "Enter \"C\" to create chroot environment"
echo -e "Enter \"R\" to Remove chroot environment"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"c" | "C")
mke_chr
;;
"r" | "R")
rmv_chr
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From C-R"
echo -e ""
echo -e "To create chroot environment, Enter \"C\""
echo -e "To remove chroot environment, Enter \"R\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
;;
esac
}
while :
do
MenU
done
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 4187
    • View Profile
    • VSIDO Community
Re: Mount Chroot script request
« Reply #2 on: January 23, 2017, 02:58:30 PM »
Beautiful... worked perfectly and now a part of VSIDO as vchroot in /usr/local/bin

Thank you hakerdefo!  I had been thinking about something like this for a while and not found a hint anywhere of a script

@jedi.. you can use this and then install grub or update-grub for just about anything
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Mount Chroot script request
« Reply #3 on: January 24, 2017, 10:11:34 AM »
vchroot V2 is here  8)
Absolutely untested  :o

Code: [Select]
#!/usr/bin/env bash
function mve_chr(){
printf "\033c"
mount "/dev/$Name" /mnt
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
mount --bind /run /mnt/run
cp /proc/mounts /mnt/etc/mtab
printf "\033c"
echo -e ""
echo -e "Your chroot environment is prepared"
echo -e ""
echo -e "Enter \"E\" to move into chroot environment"
echo -e "Enter \"B\" to move back to the script menu"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"e" | "E")
printf "\033c"
xterm -fa fixed-12 -e "sleep 2; chroot /mnt /bin/bash; /bin/bash"
MenU
;;
"b" | "B")
printf "\033c"
echo -e ""
echo -e "You can enter the created chroot by"
echo -e "running \"sudo chroot /mnt\" command."
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From E-B"
echo -e ""
echo -e "To move into chroot environment, Enter \"E\""
echo -e "To move back to the script menu, Enter \"B\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
mve_chr
;;
esac
}
function mke_chr(){
printf "\033c"
echo -e ""
echo -e "Enter the name of the disk partition to chroot to"
echo -e "For example \"sda1\" \"sda2\" \"sdb1\" \"sdb2\" etc. etc."
echo -e "Don't enter the full device path suchas "/dev/sda1""
echo -e ""
echo -e "Enter disk partition name: "
read -er Name
test -b "/dev/$Name"
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "No partition with the name $Name found!!!"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
test -d "/mnt/$Name"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "$Name is already in use on mount-point \"/mnt\""
echo -e "chroot environment for $Name could be in use"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
mve_chr
}
function rmv_chr(){
printf "\033c"
test -d "/mnt/dev"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/sys"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/proc"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
umount /mnt/dev/pts
umount /mnt/dev
umount /mnt/sys
umount /mnt/proc
umount /mnt/run
rm -f /mnt/etc/mtab
umount /mnt
printf "\033c"
echo -e ""
echo -e "Your chroot environment has been removed"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
fi
fi
printf "\033c"
echo -e ""
echo -e "No chroot environment found!!!"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
}
function MenU (){
if [ "$EUID" -ne 0 ] ; then
printf "\033c"
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
echo -e '\e[38;5;82m'"You must run \"vchroot\" script using \"sudo\"."
echo -e '\e[38;5;82m'"Hint Hint Hint Hint ----> \"sudo ./vchroot\"."
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
tput sgr0
exit 1
fi
printf "\033c"
type xterm >/dev/null 2>&1 || { printf "\033c"; echo -e ""; echo -e '\E[1;32;49m'"A required dependency \"xterm\" is not present."; echo -e '\e[1;32;49m'"\"xterm\" is available for almost all linux distros."; echo -e '\e[1;32;49m'"Please install \"xterm\" using your package manager."; echo -e ""; tput sgr0; exit 1; }
printf "\033c"
echo -e ""
echo -e "Enter \"C\" to create chroot environment"
echo -e "Enter \"R\" to remove chroot environment"
echo -e "Enter \"Q\" to quit the vchroot rightnow"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"c" | "C")
mke_chr
;;
"r" | "R")
rmv_chr
;;
"q" | "Q")
printf "\033c"
exit 0
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From C-R"
echo -e ""
echo -e "To create chroot environment, Enter \"C\""
echo -e "To remove chroot environment, Enter \"R\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
;;
esac
}
while :
do
MenU
done

You Can't Always Git What You Want

hakerdefo

  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Mount Chroot script request
« Reply #4 on: January 24, 2017, 02:37:05 PM »
Tonight it's gonna be a jailbreak, chroot jailbreak  :D
vchroot V3 is in town  8)
Absolutely raw  ;)

Code: [Select]
#!/usr/bin/env bash
function mve_chr(){
printf "\033c"
mount "/dev/$Name" "/mnt/vschroot"
test -d "/mnt/vschroot/dev"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/sys"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/proc"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
printf "\033c"
mount --bind "/dev" "/mnt/vschroot/dev"
mount --bind "/dev/pts" "/mnt/vschroot/dev/pts"
mount --bind "/sys" "/mnt/vschroot/sys"
mount --bind "/proc" "/mnt/vschroot/proc"
test -d "/run"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/run"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
mount --bind "/run" "/mnt/vschroot/run"
fi
fi
test -f "/mnt/vschroot/etc/mtab"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/mv "/mnt/vschroot/etc/mtab" "/mnt/vschroot/etc/mtab.bakup"
fi
/bin/cp "/proc/mounts" "/mnt/vschroot/etc/mtab"
test -f "/mnt/vschroot/etc/resolv.conf"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/mv "/mnt/vschroot/etc/resolv.conf" "/mnt/vschroot/etc/resolv.conf.bakup"
fi
/bin/cp "/etc/resolv.conf" "/mnt/vschroot/etc/resolv.conf"
printf "\033c"
echo -e ""
echo -e "Your chroot environment is prepared"
echo -e ""
echo -e "Enter \"E\" to move into chroot environment"
echo -e "Enter \"B\" to move back to the script menu"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"e" | "E")
printf "\033c"
xterm -fa fixed-12 -e "sleep 2; chroot /mnt/vschroot /bin/bash; /bin/bash"
MenU
;;
"b" | "B")
printf "\033c"
echo -e ""
echo -e "You can enter the created chroot environment by"
echo -e "running the \"chroot /mnt/vschroot\" command."
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From E-B"
echo -e ""
echo -e "To move into chroot environment, Enter \"E\""
echo -e "To move back to the script menu, Enter \"B\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
mve_chr
;;
esac
fi
fi
fi
printf "\033c"
sleep 4
umount "/mnt/vschroot"
sleep 4
/bin/rm -rf "/mnt/vschroot"
printf "\033c"
echo -e ""
echo -e "$Name is either corrupt or doesn't contain GNU-Linux system"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
}
function mke_chr(){
printf "\033c"
test -d "/mnt/vschroot" || mkdir -p "/mnt/vschroot"
echo -e ""
echo -e "Enter the name of the disk partition to chroot to"
echo -e "For example \"sda1\" \"sda2\" \"sdb1\" \"sdb2\" etc. etc."
echo -e "Don't enter the full device path suchas "/dev/sda1""
echo -e ""
echo -e "Enter disk partition name: "
read -er Name
test -b "/dev/$Name"
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "No partition with the name $Name found!!!"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
grep -qs "/dev/$Name" "/proc/mounts"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "$Name is already mounted"
echo -e "unmount the $Name please"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
mve_chr
}
function rmv_chr(){
printf "\033c"
test -d "/mnt/vschroot"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/dev"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/dev/pts"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/sys"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/proc"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
umount "/mnt/vschroot/dev/pts"
umount "/mnt/vschroot/dev"
umount "/mnt/vschroot/sys"
umount "/mnt/vschroot/proc"
test -d "/mnt/vschroot/run"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
umount "/mnt/vschroot/run"
fi
test -f "/mnt/vschroot/etc/mtab.bakup"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/rm -f "/mnt/vschroot/etc/mtab"
/bin/mv "/mnt/vschroot/etc/mtab.bakup" "/mnt/vschroot/etc/mtab"
fi
test -f "/mnt/vschroot/etc/resolv.conf.bakup"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/rm -f "/mnt/vschroot/etc/resolv.conf"
/bin/mv "/mnt/vschroot/etc/resolv.conf.bakup" "/mnt/vschroot/etc/resolv.conf"
fi
sleep 4
umount "/mnt/vschroot"
sleep 4
/bin/rm -rf "/mnt/vschroot"
printf "\033c"
echo -e ""
echo -e "Your chroot environment has been removed"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
fi
fi
fi
fi
printf "\033c"
echo -e ""
echo -e "No chroot environment found!!!"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
}
function MenU (){
if [ "$EUID" -ne 0 ] ; then
printf "\033c"
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
echo -e '\e[38;5;82m'"You must run \"vchroot\" script using \"sudo\"."
echo -e '\e[38;5;82m'"Hint Hint Hint Hint ----> \"sudo ./vchroot\"."
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
tput sgr0
exit 1
fi
printf "\033c"
type xterm >/dev/null 2>&1 || { printf "\033c"; echo -e ""; echo -e '\E[1;32;49m'"A required dependency \"xterm\" is not present."; echo -e '\e[1;32;49m'"\"xterm\" is available for almost all linux distros."; echo -e '\e[1;32;49m'"Please install \"xterm\" using your package manager."; echo -e ""; tput sgr0; exit 1; }
printf "\033c"
echo -e ""
echo -e "Enter \"C\" to create chroot environment"
echo -e "Enter \"R\" to remove chroot environment"
echo -e "Enter \"Q\" to quit the vchroot rightnow"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"c" | "C")
mke_chr
;;
"r" | "R")
rmv_chr
;;
"q" | "Q")
printf "\033c"
exit 0
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From C-R"
echo -e ""
echo -e "To create chroot environment, Enter \"C\""
echo -e "To remove chroot environment, Enter \"R\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
;;
esac
}
while :
do
MenU
done
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 4187
    • View Profile
    • VSIDO Community
Re: Mount Chroot script request
« Reply #5 on: January 24, 2017, 06:01:38 PM »
Tonight it's gonna be a jailbreak, chroot jailbreak  :D
vchroot V3 is in town  8)
Absolutely raw  ;)

Code: [Select]
#!/usr/bin/env bash
function mve_chr(){
printf "\033c"
mount "/dev/$Name" "/mnt/vschroot"
test -d "/mnt/vschroot/dev"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/sys"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/proc"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
printf "\033c"
mount --bind "/dev" "/mnt/vschroot/dev"
mount --bind "/dev/pts" "/mnt/vschroot/dev/pts"
mount --bind "/sys" "/mnt/vschroot/sys"
mount --bind "/proc" "/mnt/vschroot/proc"
test -d "/run"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/run"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
mount --bind "/run" "/mnt/vschroot/run"
fi
fi
test -f "/mnt/vschroot/etc/mtab"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/mv "/mnt/vschroot/etc/mtab" "/mnt/vschroot/etc/mtab.bakup"
fi
/bin/cp "/proc/mounts" "/mnt/vschroot/etc/mtab"
test -f "/mnt/vschroot/etc/resolv.conf"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/mv "/mnt/vschroot/etc/resolv.conf" "/mnt/vschroot/etc/resolv.conf.bakup"
fi
/bin/cp "/etc/resolv.conf" "/mnt/vschroot/etc/resolv.conf"
printf "\033c"
echo -e ""
echo -e "Your chroot environment is prepared"
echo -e ""
echo -e "Enter \"E\" to move into chroot environment"
echo -e "Enter \"B\" to move back to the script menu"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"e" | "E")
printf "\033c"
xterm -fa fixed-12 -e "sleep 2; chroot /mnt/vschroot /bin/bash; /bin/bash"
MenU
;;
"b" | "B")
printf "\033c"
echo -e ""
echo -e "You can enter the created chroot environment by"
echo -e "running the \"chroot /mnt/vschroot\" command."
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From E-B"
echo -e ""
echo -e "To move into chroot environment, Enter \"E\""
echo -e "To move back to the script menu, Enter \"B\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
mve_chr
;;
esac
fi
fi
fi
printf "\033c"
sleep 4
umount "/mnt/vschroot"
sleep 4
/bin/rm -rf "/mnt/vschroot"
printf "\033c"
echo -e ""
echo -e "$Name is either corrupt or doesn't contain GNU-Linux system"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
}
function mke_chr(){
printf "\033c"
test -d "/mnt/vschroot" || mkdir -p "/mnt/vschroot"
echo -e ""
echo -e "Enter the name of the disk partition to chroot to"
echo -e "For example \"sda1\" \"sda2\" \"sdb1\" \"sdb2\" etc. etc."
echo -e "Don't enter the full device path suchas "/dev/sda1""
echo -e ""
echo -e "Enter disk partition name: "
read -er Name
test -b "/dev/$Name"
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "No partition with the name $Name found!!!"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
grep -qs "/dev/$Name" "/proc/mounts"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e "$Name is already mounted"
echo -e "unmount the $Name please"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
mve_chr
}
function rmv_chr(){
printf "\033c"
test -d "/mnt/vschroot"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/dev"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/dev/pts"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/sys"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
test -d "/mnt/vschroot/proc"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
umount "/mnt/vschroot/dev/pts"
umount "/mnt/vschroot/dev"
umount "/mnt/vschroot/sys"
umount "/mnt/vschroot/proc"
test -d "/mnt/vschroot/run"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
umount "/mnt/vschroot/run"
fi
test -f "/mnt/vschroot/etc/mtab.bakup"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/rm -f "/mnt/vschroot/etc/mtab"
/bin/mv "/mnt/vschroot/etc/mtab.bakup" "/mnt/vschroot/etc/mtab"
fi
test -f "/mnt/vschroot/etc/resolv.conf.bakup"
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
/bin/rm -f "/mnt/vschroot/etc/resolv.conf"
/bin/mv "/mnt/vschroot/etc/resolv.conf.bakup" "/mnt/vschroot/etc/resolv.conf"
fi
sleep 4
umount "/mnt/vschroot"
sleep 4
/bin/rm -rf "/mnt/vschroot"
printf "\033c"
echo -e ""
echo -e "Your chroot environment has been removed"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
fi
fi
fi
fi
fi
printf "\033c"
echo -e ""
echo -e "No chroot environment found!!!"
echo -e ""
read -r -s -p $'Press Any Key To Go Back...\n' -n1
MenU
}
function MenU (){
if [ "$EUID" -ne 0 ] ; then
printf "\033c"
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
echo -e '\e[38;5;82m'"You must run \"vchroot\" script using \"sudo\"."
echo -e '\e[38;5;82m'"Hint Hint Hint Hint ----> \"sudo ./vchroot\"."
echo -e ""
{ for i in {16..51} {51..16}; do echo -en "\e[38;5;${i}m#\e[0m"; done; echo; }
echo -e ""
tput sgr0
exit 1
fi
printf "\033c"
type xterm >/dev/null 2>&1 || { printf "\033c"; echo -e ""; echo -e '\E[1;32;49m'"A required dependency \"xterm\" is not present."; echo -e '\e[1;32;49m'"\"xterm\" is available for almost all linux distros."; echo -e '\e[1;32;49m'"Please install \"xterm\" using your package manager."; echo -e ""; tput sgr0; exit 1; }
printf "\033c"
echo -e ""
echo -e "Enter \"C\" to create chroot environment"
echo -e "Enter \"R\" to remove chroot environment"
echo -e "Enter \"Q\" to quit the vchroot rightnow"
echo -e ""
echo -e "Enter your choice: "
read -er Choice
case "$Choice" in
"c" | "C")
mke_chr
;;
"r" | "R")
rmv_chr
;;
"q" | "Q")
printf "\033c"
exit 0
;;
*)
printf "\033c"
echo -e ""
echo -e "\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e "Correct Options To Choose Are From C-R"
echo -e ""
echo -e "To create chroot environment, Enter \"C\""
echo -e "To remove chroot environment, Enter \"R\""
echo -e ""
read -r -s -p $'Press Any Key To Continue...\n' -n1
;;
esac
}
while :
do
MenU
done

WORKS!

PERFECTLY!

I was going to ask for these changes... exactly what I wanted

The only issue I have is a personal one... I do not particularly like xterm but will live with it

Thanks mate!
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 2221
    • View Profile
    • PackRat configs on github
Re: Mount Chroot script request
« Reply #6 on: January 24, 2017, 10:36:27 PM »
Quote
The only issue I have is a personal one... I do not particularly like xterm but will live with it

You should be able to change that to the terminal of choice. Looks like just two lines #53 and #202. Just a quick read through though - don't do a search and replace.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

  •      v-ger
  • Posts: 4187
    • View Profile
    • VSIDO Community
Re: Mount Chroot script request
« Reply #7 on: January 25, 2017, 07:22:50 PM »
^ that's true... but I let xterm stay and actually kind of like it now and see it as a good security reason to have it as a different one than what you start with.. meaning it is very obvious what you are running chroot in with xterm and I kind of like that now
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Mount Chroot script request
« Reply #8 on: January 25, 2017, 07:52:31 PM »
^That was the reason xterm was used. Just a something different to remind you where you are.
BTW V4 is coming, may be on sunday. Some more safety measures and an option to automagically install-reinstall GRUB in either UEFI or BIOS mode. The script will (hopefully) select the appropriate mode automagically so user doesn't have to worry too much.
Cheers!!!
You Can't Always Git What You Want

jedi

  • DEFCON 1
  • Posts: 1633
  • Not all those who wander are lost.
    • View Profile
    • NixNut.com
Re: Mount Chroot script request
« Reply #9 on: January 25, 2017, 08:24:30 PM »
^That was the reason xterm was used. Just a something different to remind you where you are.
BTW V4 is coming, may be on sunday. Some more safety measures and an option to automagically install-reinstall GRUB in either UEFI or BIOS mode. The script will (hopefully) select the appropriate mode automagically so user doesn't have to worry too much.
Cheers!!!

 ???  Are you God?  ???

That will be the most perfect script of all time! Your a mind reader if your not God.
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

VastOne

  •      v-ger
  • Posts: 4187
    • View Profile
    • VSIDO Community
Re: Mount Chroot script request
« Reply #10 on: January 26, 2017, 01:21:21 AM »
Heads up ... I was doing some work with the script and there was a hang on unmounting the drive I was working with .. I have seen these errors in the past using chroot, where it will not umount /sys claiming it is busy

the only option I had was to exit

When I rebooted, the only files on that partition was a blank folder named sys...

I have never seen this before to wipe an entire drive... luckily this was a drive specific for testing things just like this and I was restored in 2 minutes
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
Re: Mount Chroot script request
« Reply #11 on: January 26, 2017, 06:34:37 PM »
Hopefully the device busy will be a thing of the past with the new version.
What would you guys like to see in the grub part of the script? Ideas-Suggestions?
You Can't Always Git What You Want