Tuesday, November 2, 2021

[SOLVED] My Bash script ends after entering chroot environment

Issue

My question:

After the following lines in my script, the script ends unexpectedly. I am trying to enter chroot inside of a bash script. How can I make this work

I am writing a script that installs Gentoo

echo " Entering the new environment"


chroot /mnt/gentoo /bin/bash 

source /etc/profile 

export PS1="(chroot) ${PS1}"

Solution

chroot command will start new child bash process, so rest of your script will not be executed until you quit from child bash process. So instead of /bin/bash just run your script in chroot:

chroot /mnt/gentoo myscript.sh

myscript.sh:

#!/bin/bash
echo " Entering the new environment"

source /etc/profile 
export PS1="(chroot) ${PS1}"


Answered By - Saboteur