Results 1 to 8 of 8

Thread: Finding out if in chroot

  1. #1
    Join Date
    May 2006
    Location
    Amsterdam
    Beans
    1,731
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Finding out if in chroot

    Hello,

    I've been trying to figure out what I need to do to check whether I'm in a chrooted environment.

    At the moment, my search came up with little results.

    Does anyone have some useful tips for me?

    Preferred method is by simple use of shell commands, since I need it for a shell script
    Upgrade Ubuntu | Upgrade unsupported Ubuntu versions | Always backup | Howto upgrade flash
    Minimal CD install | Remove old kernels | My blog | Linux user #462801 | Conscience doth make cowards of us all. -- Shakespeare

  2. #2
    Join Date
    May 2006
    Beans
    1,790

    Re: Finding out if in chroot

    Quote Originally Posted by slakkie View Post
    Hello,

    I've been trying to figure out what I need to do to check whether I'm in a chrooted environment.

    At the moment, my search came up with little results.

    Does anyone have some useful tips for me?

    Preferred method is by simple use of shell commands, since I need it for a shell script
    You can look at the inode number of root:

    Code:
    ls -id /
    If it isn't 2, then you must be chrooted, I suppose. But the converse doesn't hold, so it's not perfect.

  3. #3
    Join Date
    Jul 2008
    Beans
    1,491

    Re: Finding out if in chroot

    Heuristic I'd use: see if things are missing or different from what you'd expect in a normal root. E.g. boot images, home directory names, missing mounts for things such as /mnt... You can even cat the history file and look for a chroot command...

  4. #4
    Join Date
    May 2006
    Location
    Amsterdam
    Beans
    1,731
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Finding out if in chroot

    Quote Originally Posted by Arndt View Post
    You can look at the inode number of root:

    Code:
    ls -id /
    If it isn't 2, then you must be chrooted, I suppose. But the converse doesn't hold, so it's not perfect.
    That doesn't really work, for example:

    Inside my Ubuntu chroot:

    15:33 pts/9 0 wesleys@eniac:/home/wesleys
    $ ls -id /
    2 /

    My Debian (currently running):
    15:33 pts/8 0 wesleys@eniac:/home/wesleys
    $ ls -id /
    2 /
    Upgrade Ubuntu | Upgrade unsupported Ubuntu versions | Always backup | Howto upgrade flash
    Minimal CD install | Remove old kernels | My blog | Linux user #462801 | Conscience doth make cowards of us all. -- Shakespeare

  5. #5
    Join Date
    May 2006
    Beans
    1,790

    Re: Finding out if in chroot

    Quote Originally Posted by slakkie View Post
    That doesn't really work, for example:

    Inside my Ubuntu chroot:

    15:33 pts/9 0 wesleys@eniac:/home/wesleys
    $ ls -id /
    2 /

    My Debian (currently running):
    15:33 pts/8 0 wesleys@eniac:/home/wesleys
    $ ls -id /
    2 /
    Yes, I did say that the converse doesn't hold.

  6. #6
    Join Date
    Dec 2009
    Location
    germany
    Beans
    1,020
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Finding out if in chroot

    Quote Originally Posted by Arndt View Post
    Yes, I did say that the converse doesn't hold.
    high
    i think your chroot is not the same as the origanal system. why not touch a file in any directory what is not
    included in the chroot environment ?
    if this file is not present - your desicon.
    i know that's not really perferct - may be a hint.

    ciao
    "What is the robbing of a bank compared to the FOUNDING of a bank?" Berthold Brecht

  7. #7
    Join Date
    Nov 2008
    Location
    /dev/null
    Beans
    92

    Re: Finding out if in chroot

    When you're chrooting into your environment, change your PS1 environment variable as well to (chroot) + your current PS1 after you've chrooted:

    Code:
    export PS1="(chroot) $PS1"
    That way when you've accidentally gotten out of your chroot, you'll know thanks to the change in your shell prompt.

  8. #8
    Join Date
    May 2006
    Location
    Amsterdam
    Beans
    1,731
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Finding out if in chroot

    For my own systems it is pretty easy to figure out if I'm in a chroot. But on other systems I cannot assume a file is there or not.
    Upgrade Ubuntu | Upgrade unsupported Ubuntu versions | Always backup | Howto upgrade flash
    Minimal CD install | Remove old kernels | My blog | Linux user #462801 | Conscience doth make cowards of us all. -- Shakespeare

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •