LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-24-2018, 03:38 AM   #1
cdgoldin
LQ Newbie
 
Registered: Aug 2018
Posts: 19

Rep: Reputation: Disabled
chroot from bash script not working


I have a bash script as follows:

for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt/root$i; done
cat << EOF | sudo chroot /mnt/root
update-initramfs -u
grub-install --recheck /dev/sda
grub-install --recheck /dev/sdb
update-grub
EOF

The commands work if entered manually in a terminal, but when the bash script runs, I get the following error message: "unable to execute /usr/sbin/chroot: input output error"

Why?
 
Old 08-24-2018, 03:58 AM   #2
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 871

Rep: Reputation: 287Reputation: 287Reputation: 287
Quote:
Originally Posted by cdgoldin View Post
cat << EOF | sudo chroot /mnt/root
update-initramfs -u
grub-install --recheck /dev/sda
grub-install --recheck /dev/sdb
update-grub
EOF
What are you trying to attempt with those commands? What's their purpose?
Are you aware that
Code:
update-initramfs -u
grub-install --recheck /dev/sda
grub-install --recheck /dev/sdb
update-grub
won't execute but will only appear as text on your terminal? So I don't understand the meaning of piping the text output to chroot...
 
Old 08-24-2018, 05:40 AM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,248

Rep: Reputation: 573Reputation: 573Reputation: 573Reputation: 573Reputation: 573Reputation: 573
Perhaps you want to pass the commands to a chroot'ed shell?
Code:
sudo chroot /mnt/root /bin/sh << EOF
update-initramfs -u
grub-install --recheck /dev/sda
grub-install --recheck /dev/sdb
update-grub
EOF

Last edited by MadeInGermany; 08-24-2018 at 05:41 AM.
 
1 members found this post helpful.
Old 08-24-2018, 08:02 AM   #4
cdgoldin
LQ Newbie
 
Registered: Aug 2018
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by l0f4r0 View Post
What are you trying to attempt with those commands? What's their purpose?
Are you aware that
Code:
update-initramfs -u
grub-install --recheck /dev/sda
grub-install --recheck /dev/sdb
update-grub
won't execute but will only appear as text on your terminal? So I don't understand the meaning of piping the text output to chroot...
1) These commands (from "Sudo chroot ... update-grub") are the final part of a system restore-from-backup routine that is run from Live CD. They install grub (and the grub menu) on the two physical disks (sda and sdb). If I don't enter these commands, the restored system will be unbootable, and I would have to install them with "Boot Repair". If I enter the commands manually from the terminal after the restore, they work as desired. But I want to automate the routine.

2) No, I was NOT aware that the commands following the "chroot" command won't execute but will only appear as text. Apparently I misunderstand what the "cat << EOF |" command does. I'm not trying to pipe the text output to chroot. I'm trying to pipe the command input to chroot. (This is what happens when I try to learn bash from forum examples).

3) I tried what "MadeinGermany" has suggested, and it worked.

4) Thank both of you for your help.

Last edited by cdgoldin; 08-24-2018 at 08:49 AM.
 
Old 08-28-2018, 09:36 AM   #5
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 871

Rep: Reputation: 287Reputation: 287Reputation: 287
Quote:
Originally Posted by cdgoldin View Post
3) I tried what "MadeinGermany" has suggested, and it worked.
4) Thank both of you for your help.
Great, you're welcome. Can you mark your thread as "SOLVED" then?

Last edited by l0f4r0; 08-28-2018 at 09:37 AM.
 
Old 08-28-2018, 09:45 AM   #6
cdgoldin
LQ Newbie
 
Registered: Aug 2018
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by l0f4r0 View Post
Great, you're welcome. Can you mark your thread as "SOLVED" then?
Sorry. I didn't know how to mark it as solved yesterday. I finally found it under "thread tools" today.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash script to chroot and umount local partition Hungry ghost Programming 4 10-06-2014 04:09 PM
bash script to chroot j1alu Programming 10 08-13-2010 08:38 PM
Bash script and chroot with a pipe Luminoth Programming 6 09-19-2007 02:01 PM
Working Script chroot rssh tested on FC5 ~=gr3p=~ LinuxQuestions.org Member Success Stories 0 10-01-2006 01:52 PM
Now Bash isnt working within the chroot enviroment matthewa Linux From Scratch 2 06-02-2005 07:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration