Difference between revisions of "fakeroot"

From Noah.org
Jump to navigationJump to search
m (Created page with 'Category:Engineering The Debian `fakeroot` tool is useful for building filesystem trees and packages where files must have ownership or 'root' or other privileged users. Wit…')
 
 
Line 40: Line 40:
 
</pre>
 
</pre>
  
== ownership does not persist outside of fakeroot ==
+
== ownership environment does not persist outside of fakeroot ==
  
Notice that `fakeroot` lets you change ownership of files to other users. You can mix different users in the same session. In reality all files that you create are owned by you. While you are in a session `fakeroot` will keep track of the different fake UIDs and GIDs that you use. These ownership maps are lost when you exit the fakeroot session. Outside of fakeroot all files are owned by you. Notice the `ls -lAR` command in the previous example. Files appear to be owned by root and mysql. Run the same `ls -lAR` command outside of the fakeroot session. Everything has the same owner now.
+
Notice that `fakeroot` lets you mix different users in the same session. In reality all files that you created are owned by you, but while you are in a session `fakeroot` will keep track of the different fake UIDs and GIDs that are used. The ownership maps are lost when you exit the fakeroot session. Notice the `ls -lAR` command in the previous example. Files appear to be owned by root or mysql. Run the same `ls -lAR` command outside of the fakeroot session. Everything has one owner now.
  
 
<pre>
 
<pre>

Latest revision as of 16:31, 28 September 2010


The Debian `fakeroot` tool is useful for building filesystem trees and packages where files must have ownership or 'root' or other privileged users. With `fakeroot` you can do this without `sudo` even if you have limited user privileges.

# fakeroot /bin/bash
# id -un
root
# id -u
0
# mkdir my_package
# cd my_package
# mkdir -p var/lib/mysql
# chown mysql:mysql var/lib/mysql
# ls -lAR
.:
total 4
drwxr-xr-x 3 root root 4096 2010-09-28T16:02:26-07 var

./var:
total 4
drwxr-xr-x 3 root root 4096 2010-09-28T16:02:26-07 lib

./var/lib:
total 4
drwxr-xr-x 2 mysql mysql 4096 2010-09-28T16:02:26-07 mysql

./var/lib/mysql:
total 0
# cd ..
# tar -cz -f my_package.tar.gz my_package
# exit
$ id -un
noah
$ tar -tz -v -f my_package.tar.gz 
drwxr-xr-x root/root         0 2010-09-28 16:02 my_package/
drwxr-xr-x root/root         0 2010-09-28 16:02 my_package/var/
drwxr-xr-x root/root         0 2010-09-28 16:02 my_package/var/lib/
drwxr-xr-x mysql/mysql       0 2010-09-28 16:02 my_package/var/lib/mysql/

ownership environment does not persist outside of fakeroot

Notice that `fakeroot` lets you mix different users in the same session. In reality all files that you created are owned by you, but while you are in a session `fakeroot` will keep track of the different fake UIDs and GIDs that are used. The ownership maps are lost when you exit the fakeroot session. Notice the `ls -lAR` command in the previous example. Files appear to be owned by root or mysql. Run the same `ls -lAR` command outside of the fakeroot session. Everything has one owner now.

$ ls -lAR
.:
total 4
drwxr-xr-x 3 noah noah 4096 2010-09-28T16:02:26-07 var

./var:
total 4
drwxr-xr-x 3 noah noah 4096 2010-09-28T16:02:26-07 lib

./var/lib:
total 4
drwxr-xr-x 2 noah noah 4096 2010-09-28T16:02:26-07 mysql

./var/lib/mysql:
total 0

Unfortunately, if you start a new fakeroot session the ownerships you had previously set will not be restored. All files will appear to be owned by root. You can preserve the environment between fakeroot sessions by using the -s and -i options to save and restore the fake ownership environment.