Timeline for How do I tell I'm running in a chroot?
Current License: CC BY-SA 3.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 24, 2024 at 12:39 | comment | added | Gabor Garami | On Arch linux, even in chrooted environment I get 2 for this command. | |
| May 23, 2017 at 12:39 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
| Apr 13, 2017 at 12:36 | history | edited | CommunityBot |
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
|
|
| Sep 16, 2016 at 3:11 | comment | added | Dmitri DB | @AdamKatz Apparently not. Tested in openbsd 6.0-stable, the inode number is still 2 for the actual root path while it's a random number for the chroot. | |
| Jan 14, 2016 at 2:58 | comment | added | Adam D. |
This works well for me, detects perfectly for Crouton running Ubuntu over Chromeos without any need for superuser privileges. alias ischroot='(($(ls -di / | cut -d" " -f1)==2)) && echo "No chroot detected." || echo "Yes, we are chrooted!"'
|
|
| Jan 16, 2015 at 8:29 | history | edited | l0b0 | CC BY-SA 3.0 |
added 193 characters in body
|
| Jan 16, 2015 at 6:03 | comment | added | Adam Katz | I noted that OpenBSD has random PIDs in a comment to Gilles's answer. Similarly, OpenBSD has random inode numbers (same link), which defeats this technique. The more I learn about OpenBSD, the more I like it... | |
| May 29, 2012 at 17:33 | comment | added | Gilles 'SO- stop being evil' | @rozcietrzewiacz Thanks. I had psusi's concern too: the use case that led me to ask this question was a Linux installation that is designed to work both standalone and as a chroot, so it's on its own partition. The inode heuristic wouldn't work there, but it's a useful one in some controlled environements. | |
| May 29, 2012 at 13:14 | comment | added | rozcietrzewiacz |
@Gilles I just wanted to bring your attention to psusi's point (since you were not notified) - the inode number of each separate, "real" filesystem will be 2. (Exceptions include, for instance, tmpfs. I haven't investigated much further.)
|
|
| Nov 9, 2011 at 19:26 | comment | added | psusi |
This is true for ext[234], but not of all filesystems. It also only tests that your root is the root of the filesystem, which may not be mounted as the real root. In other words, if you mount another partition in /jail and chroot /jail, then it will look like the real root to this test.
|
|
| Nov 9, 2011 at 19:15 | comment | added | Gilles 'SO- stop being evil' | So I was fooling around, and I think I've found a more reliable method that doesn't require root permissions (Linux only). I'm still open to counter-examples or more portable methods. | |
| Nov 9, 2011 at 11:52 | comment | added | l0b0 | Tested on ext3 and hfs. | |
| Nov 9, 2011 at 11:37 | history | edited | Gilles 'SO- stop being evil' | CC BY-SA 3.0 |
note that this has an important class of false negatives (chroots rooted at a mount point)
|
| Nov 9, 2011 at 11:36 | comment | added | Gilles 'SO- stop being evil' | On what filesystems does this heuristic work? | |
| Nov 9, 2011 at 8:24 | history | answered | l0b0 | CC BY-SA 3.0 |