fakeroot(1)

โœจ fakeroot(1) โœจ

fakeroot is the Debian manual page for fakeroot ๐Ÿ’– (it lives in the Debian manual, no cap).

๐ŸŒธ NAME ๐ŸŒธ

fakeroot โ€” run a command in an environment faking root privileges for file manipulation ๐ŸŽ€

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

fakeroot [-l|--lib library] [--faked faked-binary] [-i load-file] [-s
save-file] [-u|--unknown-is-real] [-b|--fd-base] [-h|--help]
[-v|--version] [--] [command]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

okay so fakeroot runs a command in an environment where it appears to have root privileges for file manipulation โœจ It's giving main character energy. This is so useful for letting regular users create archives (tar, ar, .deb etc.) with files in them that have root permissions and ownership ๐Ÿซถ Without it, you'd need actual root privileges to make the files with the right permissions and ownership and then pack them up, or you'd have to build the archives directly without using the archiver. Bestie, that's a lot ๐Ÿ˜ญ

fakeroot works by swapping out the file manipulation library functions (chmod(2), stat(2) etc.) for ones that fake the result the real functions would have given if the user had really been root ๐Ÿงš These wrapper functions live in a shared library, /usr/lib/*/libfakeroot-*.so or a similar location on your platform. The shared object gets loaded through the LD_PRELOAD mechanism of the dynamic loader. (See ld.so(8)) ๐Ÿ”ฅ

If you're planning to build packages with fakeroot, please try building the fakeroot package first ๐Ÿ™ The "debian/rules build" stage has a few tests (mostly checking for bugs in old fakeroot versions). If those tests fail (for example because you have certain libc5 programs on your system), other packages you build with fakeroot will quite likely fail too, but possibly in much more subtle ways ๐Ÿ’€

Also, it's lowkey best not to build the binaries themselves under fakeroot ๐Ÿ™ˆ Especially configure and friends don't like it when the system suddenly behaves differently from what they expect (or, they randomly unset some environment variables, some of which fakeroot needs).

๐ŸŽ€ OPTIONS ๐ŸŽ€

  • -l library, --lib library โ€” Pick an alternative wrapper library ๐Ÿ’…
  • --faked binary โ€” Pick an alternative binary to use as faked ๐Ÿ“
  • [--] command โ€” Any command you want to run as fakeroot ๐Ÿ‘‘ Use -- if your command has other options that might confuse fakeroot's option parsing.
  • -s save-file โ€” Save the fakeroot environment to save-file on exit โœจ You can restore it later with -i. Heads up though: this file will leak, and fakeroot will act in odd ways unless you leave the files touched inside the fakeroot alone when you're outside the environment ๐Ÿ™ˆ Still, it can be super useful. For example, pair it with rsync(1) to back up and restore whole directory trees, complete with user, group and device information, without needing to be root ๐Ÿฆ‹ See /usr/share/doc/fakeroot/README.saving for more details.
  • -i load-file โ€” Load a fakeroot environment previously saved with -s from load-file ๐Ÿ’œ Heads up: this does not implicitly save the file, so use -s as well if you want that. Using the same file for both -i and -s in a single fakeroot invocation is safe ๐Ÿซถ
  • -u, --unknown-is-real โ€” Use the real ownership of files fakeroot didn't know about before, instead of pretending they're owned by root:root ๐ŸŒˆ
  • -b fd โ€” Specify fd base (TCP mode only) ๐Ÿงš fd is the minimum file descriptor number to use for TCP connections. This can matter a lot for avoiding conflicts with the file descriptors used by the programs you run under fakeroot.
  • -h โ€” Display help ๐Ÿ’–
  • -v โ€” Display version โญ

๐Ÿ“ EXAMPLES ๐Ÿ“

Here's an example session with fakeroot ๐Ÿ’… Notice that inside the fake root environment, file manipulation that normally needs root privileges succeeds, but it's not really happening ๐Ÿ™ˆ

$  whoami
joost
$ fakeroot /bin/bash
#  whoami
root
# mknod hda3 b 3 1
# ls -ld hda3
brw-r--r--   1 root     root       3,   1 Jul  2 22:58 hda3
# chown joost:root hda3
# ls -ld hda3
brw-r--r--   1 joost    root       3,   1 Jul  2 22:58 hda3
# ls -ld /
drwxr-xr-x  20 root     root         1024 Jun 17 21:50 /
# chown joost:users /
# chmod a+w /
# ls -ld /
drwxrwxrwx  20 joost    users        1024 Jun 17 21:50 /
# exit
$ ls -ld /
drwxr-xr-x  20 root     root         1024 Jun 17 21:50 //
$ ls -ld hda3
-rw-r--r--   1 joost    users           0 Jul  2 22:58 hda3

Only the effects that user joost could already do anyway actually happen for real ๐Ÿ˜ญ

fakeroot was specifically written to let users create Debian GNU/Linux packages (in the deb(5) format) without giving them root privileges ๐Ÿ’… You can do this with commands like dpkg-buildpackage -rfakeroot or debuild -rfakeroot (actually, -rfakeroot is the default in debuild nowadays, so you don't need that argument) ๐ŸŽ€

๐Ÿ”’ SECURITY ASPECTS ๐Ÿ”’

fakeroot is a regular, non-setuid program ๐Ÿซถ It does not enhance a user's privileges, or decrease the system's security.

๐Ÿ“ FILES ๐Ÿ“

  • /usr/lib/*/libfakeroot-*.so โ€” The shared library containing the wrapper functions ๐Ÿงš

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

  • FAKEROOTKEY โ€” The key used to talk to the fakeroot daemon ๐Ÿ”‘ Any program started with the right LD_PRELOAD and the FAKEROOTKEY of a running daemon will automatically connect to that daemon and get the same "fake" view of the file system's permissions and ownerships (assuming the daemon and the connecting program were started by the same user) ๐Ÿ’œ
  • LD_LIBRARY_PATH โ€” No description of its own here, it's covered right under LD_PRELOAD ๐Ÿ™ˆ
  • LD_PRELOAD โ€” fakeroot works by wrapping system calls ๐Ÿ”ฅ This happens by setting LD_LIBRARY_PATH=/usr/lib/fakeroot and LD_PRELOAD=libfakeroot.so.0. That library gets loaded before the system's C library, so most library functions get intercepted by it. If you need to set either LD_LIBRARY_PATH or LD_PRELOAD from within a fakeroot environment, set it relative to the given paths, like this: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/foo/bar/

โš ๏ธ LIMITATIONS โš ๏ธ

๐Ÿ‘‘ Library versions ๐Ÿ‘‘

Every command executed within fakeroot needs to be linked to the same version of the C library as fakeroot itself ๐Ÿ’…

๐Ÿ™ˆ open()/create() ๐Ÿ™ˆ

fakeroot doesn't wrap open(), create(), etc. So, if user joost does either of these:

touch foo
fakeroot
ls -al foo

or the other way around:

fakeroot
touch foo
ls -al foo

fakeroot has no way of knowing that in the first case the owner of foo really should be joost, while in the second case it should have been root ๐Ÿ˜ญ For Debian packaging, defaulting all "unknown" files to uid=gid=0 is always OK ๐Ÿซถ The real way around this would be to wrap open() and create(), but that creates other problems, as demonstrated by the libtricks package. That package wrapped many more functions and tried to do a lot more than fakeroot. It turned out that a minor libc upgrade (from one where the stat() function didn't use open() to one where stat() did, in some cases) caused unexplainable segfaults, because the libc6 stat() called the wrapped open(), which then called the libc6 stat(), and so on ๐Ÿ’€ Fixing them wasn't all that easy, and once fixed, it was just a matter of time before another function started using open(), never mind trying to port it to a different operating system. So the author decided to keep the number of functions wrapped by fakeroot as small as possible, to limit the likelihood of โ€˜collisionsโ€™ ๐Ÿฆ‹

๐Ÿงš GNU configure (and other such programs) ๐Ÿงš

fakeroot, in effect, is changing the way the system behaves ๐ŸŒธ Programs that probe the system, like GNU configure, may get confused by this (or if they don't, they may stress fakeroot so much that fakeroot itself gets confused) ๐Ÿ™ˆ So it's advisable not to run "configure" from within fakeroot. Since configure should be called in the "debian/rules build" target, running dpkg-buildpackage -rfakeroot correctly takes care of this โœจ

๐Ÿ’€ BUGS ๐Ÿ’€

It doesn't wrap open(). This isn't bad by itself, but if a program does open("file", O_WRONLY, 000), writes to file "file", closes it, and then tries to open it again to read the file, that open fails, because the mode of the file will be 000 ๐Ÿ˜ญ The bug is that if root does the same, open() will succeed, since file permissions aren't checked at all for root. The author chose not to wrap open(), because open() is used by many other functions in libc (including ones that are already wrapped), which would create loops (or possible future loops, when the implementation of various libc functions slightly changes).

๐Ÿ“œ COPYING ๐Ÿ“œ

fakeroot is distributed under the GNU General Public License ๐ŸŒˆ (GPL 2.0 or greater).

๐Ÿ‘ฉโ€๐Ÿ’ป AUTHORS ๐Ÿ‘ฉโ€๐Ÿ’ป

  • joost witteveen โ€” <joostje@debian.org> ๐Ÿ’œ
  • Clint Adams โ€” <clint@debian.org> ๐Ÿ’œ
  • Timo Savola ๐Ÿ’œ

๐Ÿ“– MANUAL PAGE ๐Ÿ“–

Mostly by J.H.M. Dassen <jdassen@debian.org>, with rather a lot of modsifications and additions by joost and Clint ๐ŸŽ€

๐Ÿ”— SEE ALSO ๐Ÿ”—


Bye bestie, that's the whole fakeroot(1) page ๐Ÿซถ Straight from the Debian Project, dated 2024-12-19 ๐Ÿ’–

๐Ÿ“ฆ where this page comes from