Howto Debian Rootfs
Howto Debian Rootfs
txt
=======================================
How to Set Up a Debian RootFS for PRoot
=======================================
:Abstract:
In this article and the following one, I will show that using
PRoot_, such testing is quite handy and can be done by any users.
.. _PRoot: https://proot-me.github.io
In order to test PRoot, you can download the latest version on the
`official website`_ and compile it. You can also grab a package for
your distribution on the `Open Build Service`_.
#!/bin/sh
git clone https://github.com/proot-me/proot.git
cd proot/src
make
[...]
./proot
Grabbing a RootFS
=================
The first and easy way to have a working root file system is to
download it from `OpenVZ repository`_ or `OpenVZ contribs`_.
.. _OpenVZ repository: http://download.openvz.org/template/precreated/
.. _OpenVZ contribs: http://download.openvz.org/template/precreated/contrib/
It's also possible, under Debian and Ubuntu, to create a root file
system using debootstrap, but let's take the easy way for today::
#!/bin/sh
% mkdir debian-6.0-x86_64
% cd debian-6.0-x86_64
% wget http://download.openvz.org/template/precreated/debian-6.0-x86_64.tar.gz
[...]
% tar xf debian-6.0-x86_64.tar.gz
% cd ..
As we will see later, you can safely ignore the warnings printed by
tar when extracting the file system. Let us note that everything is
run as a normal user.
Now you can "jump" into this new root file system using PRoot::
#!/bin/sh
% cat /etc/debian_version
wheezy/sid
% proot debian-6.0-x86_64
~ cat /etc/debian_version
6.0.4
For now on, the root file system is the one you just downloaded. For
instance::
#!/bin/sh
~ gcc --version
gcc (Debian 4.4.5-8) 4.4.5
~ logout
% gcc --version
gcc (Debian 4.6.3-1) 4.6.3
As you may have noticed, I used ``%`` for the host file system shell
prompt (a Debian Sid) and ``~`` for the PRooted one (a Debian
Squeeze).
We now have a basic and working root file systems but some
configuration has to be done before any real usages:
Normally, all this tasks can only be done by root as they will
modifies files owned by root. As we extracted the archive as a normal
user, the current user can modify any files in the root file system
though making root privileges pointless.
In order to keep the same user inside the PRooted file system, you
just have to copy the right lines from ``/etc/passwd`` to the
corresponding file in the PRooted file system. You can do the same
thing for groups in ``/etc/group``.
Just copy ``/etc/resolv.conf`` from the host root file system to the
PRooted one. This way the same mechanism will be used in the host
system and in the PRooted one.
#!/bin/sh
% proot debian-6.0-x86_66
~ cat /etc/resolv.conf
cat: /etc/resolv.conf: No such file or directory
~ logout
% proot -b /etc/resolv.conf debian-6.0-x86_64
~ cat /etc/resolv.conf
[...]same file as /etc/resolv.conf on the host[...]
We should bind the real /dev and /proc in the new root file
system. Adding ``-b /dev -b /proc`` to the PRoot command line will
solve this issue.
We already noticed that the current user can modify any file on the
PRooted file system because it was extracted by this user.
However most tools like dpkg required the current user id to be root
in order to work. For this reason, PRoot can be launched with the
``-0`` (zero) option which fake some syscalls and makes the programs
think the current user is root::
#!/bin/sh
% proot -b /etc/resolv.conf -0 debian-6.0-x86_64
~ id -a
uid=0(root) gid=0(root) groupes=0(root)
~ cat /etc/apt/source.list
deb http://ftp.debian.org/debian squeeze main contrib non-free
deb http://security.debian.org squeeze/updates main contrib non-free
~ apt-get update
Hit http://ftp.debian.org squeeze Release.gpg
Ign http://ftp.debian.org/debian/ squeeze/contrib Translation-en
[...]
Reading package lists... Done
~ apt-get upgrade
[...]
You can manage this root file system like a classical one. Pay
attention that some services that really required root privileges to
work (like apache or some daemons) could not run correctly under PRoot
as we only fake root privileges.
Future work
===========
We saw a simple way to get a working Debian root file systems that we
can manage without real root privileges. This work will be useful for
the next article which will cover the compilation and testing of VLC
media player in this new root file system.