0

How can I determine within a shell script if the script is running:

  • On a Ubuntu LiveOS (not necessarily version dependant) -- (already answered here)
  • Within a chroot on an Ubuntu LiveOS (already addressed here)
  • On a locally installed system (no LiveOS) -- (already answered here)

As all three points seem to be addressed elsewhere, I'm going to vote to close this question. Pointed out in the only answer here, a combination of tests can be used to determine chroot on LiveOS.

5
  • 1
    Detecting chroots are trickier than detecting live os: unix.stackexchange.com/questions/14345/…
    – muru
    Aug 16, 2018 at 3:38
  • If that question addresses the first and 3rd points, why are they still in this question? There's no need to repeat those again.
    – muru
    Aug 16, 2018 at 5:42
  • Good point. I wanted to specify the three distinct cases for sake of use context. I'll edit the question again to specifically note beside the first and third option where they are already answered.
    – b_laoshi
    Aug 18, 2018 at 12:39
  • 1
    Possible duplicate of Test if operating from live session or not inside a shell script
    – b_laoshi
    Aug 18, 2018 at 12:49
  • @muru, If you'd be so kind, just go ahead and close the question again. All the information to get to the respective existing answers is noted in my question.
    – b_laoshi
    Aug 18, 2018 at 12:51

1 Answer 1

2

Consider combining these checks to determine a live sessions:

Look for live file system being mounted somewhere:

losetup -l | grep /cdrom/casper/filesystem.squashfs

If you find something there is a high chance that it's a live session.

Check root file system:

df /

Or look for existence of special files (ex: ubiquity: Ubuntu installer)

which ubiquity

also check it's shortcut at ~/Desktop

Check currently logged in users: users you should get: ubuntu.

And they can all be set up to look like a live session to trick you ...

For chroot, I'm not sure how it's possible... I'll check it out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .