I have written a BASH script that would prepare and install everything during ArchLinux initial installation. The script would work fine and execute everything successfully until it reaches the arch-chroot command then it would stop.

Also, the solutions I found online (like the EOF trick) wouldn't pass functions or variables after chroot.

Here is a demo:



pause ()
if [ $pause_var -eq 1 ]
    read -n 1 -s -r -p "Press any key to continue"

arch-chroot /mnt #the script stops after executing this line!!

# some commands after chroot
useradd -m $username

echo $username:123 | chpasswd

# ... more commands below

I googled for a solution but none of the solutions that I found have worked for me. I'm a Linux noob.

Thank you.


From man arch-chroot

arch-chroot [options] chroot-dir [command]

So you can simply do this arch-chroot /mnt /bin/bash /file/in/chroot/script.sh

If it doesn't accept additional arguments you could try arch-chroot /mnt /file/in/chroot/script.sh

  • Thank you for your reply. I'll try it out and give you a feedback. Thank you again. – CodingNoob Jun 12 at 9:37
  • 1
    Well, I tried many times. Until I realized I needed a "script" to be copied inside the chroot path BEFORE the chroot command. But that made the script start itself from the beginning and I had to adjust the script so that it doesn't repeat itself. Something like if pwd = "/" then don't repeat. It was a lot of work but I least I got it functioning like I wanted. THANK YOU, BRO!! – CodingNoob Jun 12 at 12:01
  • You're welcome! – Artem S. Tashkinov Jun 12 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.