• I still don't understand sudo properly

    From rsutton@rsutton43@comcast.net to alt.os.linux.ubuntu on Tue Jul 8 10:31:28 2025
    From Newsgroup: alt.os.linux.ubuntu

    Hi all,
    I've been using linux (Ubuntu/Mint mainly) for 20 years and I still find things that I don't understand. I need some help!

    I have a need to run the following code after generating a virtual
    machine in LXD. The following code runs fine in the VM from the terminal:
    sudo su -
    mount -t 9p config /mnt
    cd /mnt
    ./install.sh
    exit

    However, when I converted the commands to my bash script and try to run
    this code , it fails:
    cd /mnt
    sudo mount -t 9p config /mnt
    sudo /mnt/install.sh
    .
    .

    The error it gives me is:
    "This script must be run from within the 9p mount"

    Can someone explain how I can accomplish the intent of this code?
    Richard


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Dan Purgert@dan@djph.net to alt.os.linux.ubuntu on Tue Jul 8 15:15:25 2025
    From Newsgroup: alt.os.linux.ubuntu

    On 2025-07-08, rsutton wrote:
    Hi all,
    The following code runs fine in the VM from the terminal:
    sudo su -
    mount -t 9p config /mnt
    cd /mnt
    ./install.sh
    exit

    However, when I converted the commands to my bash script and try to run
    this code , it fails:
    cd /mnt
    sudo mount -t 9p config /mnt
    sudo /mnt/install.sh

    The error it gives me is:
    "This script must be run from within the 9p mount"

    Can someone explain how I can accomplish the intent of this code?

    Well, in the working code, your current working directory is the one
    that contains the install script; whereas the non-working code, you are
    calling the explicit path (which sort of implies you are "somewhere
    else").

    Chances are the script does a bunch of things relative to the current
    working directory, and it performs a check to ensure that its execution
    path is also the current working directory.
    --
    |_|O|_|
    |_|_|O| Github: https://github.com/dpurgert
    |O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1 E067 6D65 70E5 4CE7 2860
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Richard Kettlewell@invalid@invalid.invalid to alt.os.linux.ubuntu on Tue Jul 8 18:15:34 2025
    From Newsgroup: alt.os.linux.ubuntu

    rsutton <rsutton43@comcast.net> writes:
    Hi all,
    I've been using linux (Ubuntu/Mint mainly) for 20 years and I still
    find things that I don't understand. I need some help!

    I have a need to run the following code after generating a virtual
    machine in LXD. The following code runs fine in the VM from the
    terminal:
    sudo su -
    mount -t 9p config /mnt
    cd /mnt
    ./install.sh
    exit

    However, when I converted the commands to my bash script and try to
    run this code , it fails:
    cd /mnt

    After this your current working directory is the /mnt directory in the
    root filesystem.

    sudo mount -t 9p config /mnt

    After the mount command, the path /mnt refers to the root of the 9p
    filesystem (whatever that is). But your current working directory
    remains the (now hidden) /mnt directory of the root filesystem.

    So the answer is to move the ‘cd’ command in your script one line down.

    sudo /mnt/install.sh
    .
    .

    The error it gives me is:
    "This script must be run from within the 9p mount"
    --
    https://www.greenend.org.uk/rjk/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Jonathan N. Little@lws4art@gmail.com to alt.os.linux.ubuntu on Tue Jul 8 21:49:05 2025
    From Newsgroup: alt.os.linux.ubuntu

    Richard Kettlewell wrote:
    rsutton <rsutton43@comcast.net> writes:
    Hi all,
    I've been using linux (Ubuntu/Mint mainly) for 20 years and I still
    find things that I don't understand. I need some help!

    I have a need to run the following code after generating a virtual
    machine in LXD. The following code runs fine in the VM from the
    terminal:
    sudo su -
    mount -t 9p config /mnt
    cd /mnt
    ./install.sh
    exit

    However, when I converted the commands to my bash script and try to
    run this code , it fails:
    cd /mnt

    After this your current working directory is the /mnt directory in the
    root filesystem.

    sudo mount -t 9p config /mnt

    After the mount command, the path /mnt refers to the root of the 9p filesystem (whatever that is). But your current working directory
    remains the (now hidden) /mnt directory of the root filesystem.

    So the answer is to move the ‘cd’ command in your script one line down.

    sudo /mnt/install.sh
    .
    .

    The error it gives me is:
    "This script must be run from within the 9p mount"


    To further expand on what Richard here said, the hint was in the
    differences in OP's original post. When he did it step by step by
    command line he cd into mounted dir before running install.sh whereas hi
    script did not.

    The install.sh script must reference assets within the same directory as
    the script AND the script assumes the pwd is that directory.

    If you are the author of install.sh, what I do to prevent this problem
    in my scripts:

    SCRIPT_PATH="$(dirname "$(realpath "$0")")"
    # reference some asset located with this script
    source "$SCRIPT_PATH/some_asset"
    # or alternatively cd to script directory first
    cd $SCRIPT_PATH"
    source ./some_other_asset
    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    --- Synchronet 3.21a-Linux NewsLink 1.2