You are not logged in.

#1 2017-06-09 12:28:49

loadlover
Member
Registered: 2017-05-10
Posts: 103

exit, umount -R /mnt, reboot <--- From within install script?

Hi all,

I'm running a number of test installs from the bootable .iso copied onto a USB flash drive.

Instead of entering every command manually I've made a basic install script (well, series of scripts) to do the hard work for me.

At the end of the process, one of the scripts has the following commands in it:

exit
umount -R /mnt
reboot

The problem is this just exits the script. So what do I do once this has happened to achieve the desired reboot automatically?

Thanks,

Loady

Last edited by loadlover (2017-06-09 13:27:19)

Offline

#2 2017-06-09 12:55:39

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: exit, umount -R /mnt, reboot <--- From within install script?

Who put "exit" there? That becomes the *final* command.

Offline

#3 2017-06-09 13:13:37

loadlover
Member
Registered: 2017-05-10
Posts: 103

Re: exit, umount -R /mnt, reboot <--- From within install script?

I have to exit. To get back to the virtual install console. I then need to exit THAT, then reboot - all in an automated way. See?

Like waking up from a dream, only to realize you were dreaming in your dream, and are therefore still asleep. How to solve?

Last edited by loadlover (2017-06-09 13:17:51)

Offline

#4 2017-06-09 14:26:09

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: exit, umount -R /mnt, reboot <--- From within install script?

Run the script using the source command, then there is no need to exit.

Offline

#5 2017-06-09 15:42:50

loadlover
Member
Registered: 2017-05-10
Posts: 103

Re: exit, umount -R /mnt, reboot <--- From within install script?

Superb.

Thanks breb.

Loady

Offline

#6 2017-06-09 18:06:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,545
Website

Re: exit, umount -R /mnt, reboot <--- From within install script?

From the context I gather you were intending to exit from a chroot.  You do need to exit a chroot, and I don't see how sourcing a script will help avoid that.  However, this can't be done with a single script, you need at least two: one to do the work outside the chroot and one inside.  You can have these in the same file with a here document.  But the key is that the "inner" script will exit, then the outscript unmounts and reboots:

fdisk ...
mkfs ...
mount ...

pacstrap ...
genfstab ...

cat <<EOF >/mnt/root/setup
ln -sf /usr/share/zoneinfo/...
sed -i '...' /etc/locale.conf
locale-gen
...
exit
EOF

chmod 0755 /mnt/root/setup
arch-chroot /mnt /root/setup

umnt -R /mnt
reboot

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2017-06-10 12:38:57

loadlover
Member
Registered: 2017-05-10
Posts: 103

Re: exit, umount -R /mnt, reboot <--- From within install script?

Took me a little while to digest but yes I understand now: 'setup' is the inner script.

Many thanks,

Loady

Offline

#8 2017-06-11 14:56:59

vegangaro
Member
Registered: 2017-06-07
Posts: 8

Re: exit, umount -R /mnt, reboot <--- From within install script?

..

Last edited by vegangaro (2017-06-11 15:27:23)


C++ and KDE = PRAISE THE SUN!

Offline

#9 2017-06-11 14:59:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,545
Website

Re: exit, umount -R /mnt, reboot <--- From within install script?

How what is done vegangaro?  Installation of arch linux is done acording to the wiki.  The only step that isn't in the installation guide on the wiki that would be needed for a script is coordinating the inner/outer scripts as I described above.  A here-documented (as demonstrated above) is one simple way of doing this.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2017-06-11 16:18:01

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: exit, umount -R /mnt, reboot <--- From within install script?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#11 2017-07-10 07:56:15

loadlover
Member
Registered: 2017-05-10
Posts: 103

Re: exit, umount -R /mnt, reboot <--- From within install script?

Trilby wrote:

From the context I gather you were intending to exit from a chroot.  You do need to exit a chroot, and I don't see how sourcing a script will help avoid that.  However, this can't be done with a single script, you need at least two: one to do the work outside the chroot and one inside.  You can have these in the same file with a here document.  But the key is that the "inner" script will exit, then the outscript unmounts and reboots:

fdisk ...
mkfs ...
mount ...

pacstrap ...
genfstab ...

cat <<EOF >/mnt/root/setup
ln -sf /usr/share/zoneinfo/...
sed -i '...' /etc/locale.conf
locale-gen
...
exit
EOF

chmod 0755 /mnt/root/setup
arch-chroot /mnt /root/setup

umnt -R /mnt
reboot

I got this working just fine a while ago. Thanks again Trilby. Recently, however, I was messing around and did this:

cat <<EOF >/mnt/root/setup
...
pacman -S --noconfirm $(< /stuff/payload/pac2)
...
EOF

When cat has done its magic, the setup script file created contains the pacman line, but truncated to:

pacman -S --noconfirm 

If you know the answer as to why, PLEASE don't tell me, but could you give me a hint? This is a consequence of how cat works, right?

Thanks,

Loady

EDIT: SOLVED. Forget it;)

Last edited by loadlover (2017-07-10 10:18:41)

Offline

#12 2017-07-10 12:10:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,545
Website

Re: exit, umount -R /mnt, reboot <--- From within install script?

Please share your solution for others.  I'm pretty sure I know: it'd not be due to how cat works, but rather how here documents work.  They can be started with the initial EOF indicator "plain" or quoted ( <<EOF vs <<'EOF' ) and those behave differently.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#13 2017-07-10 17:28:38

loadlover
Member
Registered: 2017-05-10
Posts: 103

Re: exit, umount -R /mnt, reboot <--- From within install script?

My mistake was far more prosaic (and embarrassing) than the interesting difference between the two here document invocations. It arose because of the scope in which the original script was executed - *before* the change of root. So I should have used /mnt/stuff/payload/pac2 and not /stuff/payload/pac2.

In other words, the file doesn't actually exist, and the whole "$(< /stuff/payload/pac2)" part amounts to precisely nothing.

sad

Oh well.

Offline

Board footer

Powered by FluxBB