<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>linux on Mister Muffin Blog</title>
    <link>http://blog.mister-muffin.de/tags/linux/</link>
    <description>Recent content in linux on Mister Muffin Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 25 Oct 2015 18:44:00 +0000</lastBuildDate><atom:link href="http://blog.mister-muffin.de/tags/linux/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>unshare without superuser privileges</title>
      <link>http://blog.mister-muffin.de/2015/10/25/unshare-without-superuser-privileges/</link>
      <pubDate>Sun, 25 Oct 2015 18:44:00 +0000</pubDate>
      
      <guid>http://blog.mister-muffin.de/2015/10/25/unshare-without-superuser-privileges/</guid>
      <description>&lt;p&gt;TLDR: With the help of Helmut Grohne I finally figured out most of the bits
necessary to unshare everything without becoming root (though one might say
that this is still cheated because the suid root tools &lt;code&gt;newuidmap&lt;/code&gt; and &lt;code&gt;newgidmap&lt;/code&gt;
are used). I wrote a Perl script which documents how this is done in practice.
This script is nearly equivalent to using the existing commands &lt;code&gt;lxc-usernsexec [opts] -- unshare [opts] -- COMMAND&lt;/code&gt; except that these two together cannot be
used to mount a new proc. Apart from this problem, this Perl script might also
be useful by itself because it is architecture independent and easily
inspectable for the curious mind without resorting to sources.debian.net (it is
heavily documented at nearly 2 lines of comments per line of code on average).
It can be retrieved here at
&lt;a href=&#34;https://gitlab.mister-muffin.de/josch/user-unshare/blob/master/user-unshare&#34;&gt;https://gitlab.mister-muffin.de/josch/user-unshare/blob/master/user-unshare&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Long story: Nearly two years after my last &lt;a href=&#34;http://blog.mister-muffin.de/2014/01/11/why-do-i-need-superuser-privileges-when-i-just-want-to-write-to-a-regular-file/&#34;&gt;last rant about everything needing
superuser privileges in
Linux&lt;/a&gt;,
I&amp;rsquo;m still interested in techniques that let me do more things without becoming
root. Helmut Grohne had told me for a while about unshare(), or user namespaces
as the right way to have things like chroot without root. There are also
reports of LXC containers working without root privileges but they are hard to
come by. A couple of days ago I had some time again, so Helmut helped me to get
through the major blockers that were so far stopping me from using unshare in a
meaningful way without executing everything with &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;My main motivation at that point was to let &lt;code&gt;dpkg-buildpackage&lt;/code&gt; when executed
by &lt;code&gt;sbuild&lt;/code&gt; be run with an unshared network namespace and thus without network
access (except for the loopback interface) because like pbuilder I wanted
sbuild to enforce the rule not to access any remote resources during the build.
After several evenings of investigating and doctoring at the Perl script I
mentioned initially, I came to the conclusion that the only place that can
unshare the network namespace without disrupting anything is schroot itself.
This is because unsharing &lt;em&gt;inside&lt;/em&gt; the chroot will fail because
dpkg-buildpackage is run with non-root privileges and thus the user namespace
has to be unshared. But this then will destroy all ownership information. But
even if that wasn&amp;rsquo;t the case, the chroot itself is unlikely to have (and also
should not) tools like &lt;code&gt;ip&lt;/code&gt; or &lt;code&gt;newuidmap&lt;/code&gt; and &lt;code&gt;newgidmap&lt;/code&gt; installed. Unsharing
the schroot call itself also will not work. Again we first need to unshare the
user namespace and then schroot will complain about wrong ownership of its
configuration file &lt;code&gt;/etc/schroot/schroot.conf&lt;/code&gt;. Luckily, when contacting Roger
Leigh about this wishlist feature in
&lt;a href=&#34;http://bugs.debian.org/802849&#34;&gt;bug#802849&lt;/a&gt; I was told that this was already
implemented in its git master \o/. So this particular problem seems to be taken
care of and once the next schroot release happens, sbuild will make use of it
and have &lt;code&gt;unshare --net&lt;/code&gt; capabilities just like &lt;code&gt;pbuilder&lt;/code&gt; already had since
last year.&lt;/p&gt;
&lt;p&gt;With the sbuild case taken care of, the rest of this post will introduce &lt;a href=&#34;https://gitlab.mister-muffin.de/josch/user-unshare/blob/master/user-unshare&#34;&gt;the
Perl script I wrote&lt;/a&gt;.
The name &lt;code&gt;user-unshare&lt;/code&gt; is really arbitrary. I just needed some identifier for
the git repository and a filename.&lt;/p&gt;
&lt;p&gt;The most important discovery I made was, that Debian disables unprivileged user
namespaces by default with the patch
&lt;code&gt;add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by-default.patch&lt;/code&gt; to the
Linux kernel. To enable it, one has to first either do&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;echo 1 | sudo tee /proc/sys/kernel/unprivileged_userns_clone &amp;gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo sysctl -w kernel.unprivileged_userns_clone=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The tool tries to be like unshare(1) but with the power of lxc-usernsexec(1) to
map more than one id into the new user namespace by using the programs
&lt;code&gt;newgidmap&lt;/code&gt; and &lt;code&gt;newuidmap&lt;/code&gt;. Or in other words: This tool tries to be like
lxc-usernsexec(1) but with the power of unshare(1) to unshare more than just
the user and mount namespaces. It is nearly equal to calling:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;lxc-usernsexec [opts] -- unshare [opts] -- COMMAND
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Its main reason of existence are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;as a project for me to learn how unprivileged namespaces work&lt;/li&gt;
&lt;li&gt;written in Perl which means:
&lt;ul&gt;
&lt;li&gt;architecture independent (same executable on any architecture)&lt;/li&gt;
&lt;li&gt;easily inspectable by other curious minds&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;tons of code comments to let others understand how things work&lt;/li&gt;
&lt;li&gt;no need to install the lxc package in a minimal environment (perl itself
might not be called minimal either but is present in every Debian
installation)&lt;/li&gt;
&lt;li&gt;not suffering from being unable to mount proc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I hoped that &lt;code&gt;systemd-nspawn&lt;/code&gt; could do what I wanted but it seems that its
requirement for being run as root will &lt;a href=&#34;http://lists.freedesktop.org/archives/systemd-devel/2015-February/028139.html&#34;&gt;not change any time
soon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Another tool in Debian that offers to do chroot without superuser privileges is
&lt;code&gt;linux-user-chroot&lt;/code&gt; but that one cheats by being suid root.&lt;/p&gt;
&lt;p&gt;Had I found &lt;code&gt;lxc-usernsexec&lt;/code&gt; earlier I would&amp;rsquo;ve probably not written this. But
after I found it I happily used it to get an even better understanding of the
matter and further improve the comments in my code. I started writing my own
tool in Perl because that&amp;rsquo;s the language sbuild was written in and as mentioned
initially, I intended to use this script with sbuild. Now that the sbuild
problem is taken care of, this is not so important anymore but I like if I can
read the code of simple programs I run directly from /usr/bin without having to
retrieve the source code first or use sources.debian.net.&lt;/p&gt;
&lt;p&gt;The only thing I wasn&amp;rsquo;t able to figure out is how to properly mount proc into
my new mount namespace. I found a workaround that works by first mounting a new
proc to &lt;code&gt;/proc&lt;/code&gt; and then bind-mounting &lt;code&gt;/proc&lt;/code&gt; to whatever new location for
proc is requested. I didn&amp;rsquo;t figure out how to do this without mounting to
&lt;code&gt;/proc&lt;/code&gt; first partly also because this doesn&amp;rsquo;t work at all when using
&lt;code&gt;lxc-usernsexec&lt;/code&gt; and &lt;code&gt;unshare&lt;/code&gt; together. In this respect, this perl script is a
bit more powerful than those two tools together. I suppose that the reason is
that &lt;code&gt;unshare&lt;/code&gt; wasn&amp;rsquo;t written with having being called without superuser
privileges in mind. If you have an idea what could be wrong, the code has a big
&lt;code&gt;FIXME&lt;/code&gt; about this issue.&lt;/p&gt;
&lt;p&gt;Finally, here a demonstration of what my script can do. Because of the &lt;code&gt;/proc&lt;/code&gt;
bug, &lt;code&gt;lxc-usernsexec&lt;/code&gt; and &lt;code&gt;unshare&lt;/code&gt; together are not able to do this but it
might also be that I&amp;rsquo;m just not using these tools in the right way. The
following will give you an interactive shell in an environment created from one
of my sbuild chroot tarballs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ mkdir -p /tmp/buildroot/proc
$ ./user-unshare --mount-proc=/tmp/buildroot/proc --ipc --pid --net \
	--uts --mount --fork -- sh -c &#39;ip link set lo up &amp;amp;&amp;amp; ip addr &amp;amp;&amp;amp; \
	hostname hoothoot-chroot &amp;amp;&amp;amp; \
	tar -C /tmp/buildroot -xf /srv/chroot/unstable-amd64.tar.gz; \
	/usr/sbin/chroot /tmp/buildroot /sbin/runuser -s /bin/bash - josch &amp;amp;&amp;amp; \
	umount /tmp/buildroot/proc &amp;amp;&amp;amp; rm -rf /tmp/buildroot&#39;
(unstable-amd64-sbuild)josch@hoothoot-chroot:/$ whoami
josch
(unstable-amd64-sbuild)josch@hoothoot-chroot:/$ hostname
hoothoot-chroot
(unstable-amd64-sbuild)josch@hoothoot-chroot:/$ ls -lha /proc | head
total 0
dr-xr-xr-x 218 nobody nogroup    0 Oct 25 19:06 .
drwxr-xr-x  22 root   root     440 Oct  1 08:42 ..
dr-xr-xr-x   9 root   root       0 Oct 25 19:06 1
dr-xr-xr-x   9 josch  josch      0 Oct 25 19:06 15
dr-xr-xr-x   9 josch  josch      0 Oct 25 19:06 16
dr-xr-xr-x   9 root   root       0 Oct 25 19:06 7
dr-xr-xr-x   9 josch  josch      0 Oct 25 19:06 8
dr-xr-xr-x   4 nobody nogroup    0 Oct 25 19:06 acpi
dr-xr-xr-x   6 nobody nogroup    0 Oct 25 19:06 asound
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course instead of running this long command we can also instead write a
small shell script and execute that instead. The following does the same things
as the long command above but adds some comments for further explanation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/sh
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;set -exu
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# I&amp;#39;m using /tmp because I have it mounted as a tmpfs&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;rootdir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/tmp/buildroot&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# bring the loopback interface up&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ip link set lo up
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# show that the loopback interface is really up&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ip addr
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# make use of the UTS namespace being unshared&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;hostname hoothoot-chroot
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# extract the chroot tarball. This must be done inside the user namespace for&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# the file permissions to be correct.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# tar will fail to call mknod and to change the permissions of /proc but we are&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ignoring that&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;tar -C &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$rootdir&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; -xf /srv/chroot/unstable-amd64.tar.gz &lt;span style=&#34;color:#f92672&#34;&gt;||&lt;/span&gt; true
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# run chroot and inside, immediately drop permissions to the user &amp;#34;josch&amp;#34; and&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# start an interactive shell&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/usr/sbin/chroot &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$rootdir&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; /sbin/runuser -s /bin/bash - josch
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# unmount /proc and remove the temporary directory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;umount &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$rootdir&lt;span style=&#34;color:#e6db74&#34;&gt;/proc&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;rm -rf &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$rootdir&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and then:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ mkdir -p /tmp/buildroot/proc
$ ./user-unshare --mount-proc=/tmp/buildroot/proc --ipc --pid --net --uts --mount --fork -- ./chroot.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As mentioned in the beginning, the tool is nearly equivalent to calling
&lt;code&gt;lxc-usernsexec [opts] -- unshare [opts] -- COMMAND&lt;/code&gt; but because of the problem
with mounting proc (mentioned earlier), &lt;code&gt;lxc-usernsexec&lt;/code&gt; and &lt;code&gt;unshare&lt;/code&gt; cannot
be used with above example. If one tries anyways one will only get:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ lxc-usernsexec -m b:0:1000:1 -m b:1:558752:1 -- unshare --mount-proc=/tmp/buildroot/proc --ipc --pid --net --uts --mount --fork -- ./chroot.sh
unshare: mount /tmp/buildroot/proc failed: Invalid argument
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;rsquo;d be interested in finding out why that is and how to fix it.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Why do I need superuser privileges when I just want to write to a regular file</title>
      <link>http://blog.mister-muffin.de/2014/01/11/why-do-i-need-superuser-privileges-when-i-just-want-to-write-to-a-regular-file/</link>
      <pubDate>Sat, 11 Jan 2014 01:21:00 +0000</pubDate>
      
      <guid>http://blog.mister-muffin.de/2014/01/11/why-do-i-need-superuser-privileges-when-i-just-want-to-write-to-a-regular-file/</guid>
      <description>&lt;p&gt;I have written a number of scripts to create Debian foreign architecture
(mostly armel and armhf) rootfs images for SD cards or NAND flashing. I started
with putting Debian on my &lt;a href=&#34;http://wiki.openmoko.org/wiki/Manual_Debian&#34;&gt;Openmoko gta01 and gta02&lt;/a&gt; and continued with
devices like the qi nanonote, a &lt;a href=&#34;https://blog.mister-muffin.de/2011/06/06/new-toy/&#34;&gt;marvel kirkwood based device&lt;/a&gt;, the Always
Innovating Touchbook (close to the Beagleboard), the &lt;a href=&#34;https://blog.mister-muffin.de/2011/05/01/putting-debian-on-the-notion-ink-adam/&#34;&gt;Notion Ink Adam&lt;/a&gt; and
most recently the &lt;a href=&#34;http://lists.goldelico.com/pipermail/gta04-owner/2011-October/000517.html&#34;&gt;Golden Delicious gta04&lt;/a&gt;. Once it has been manufactured, I
will surely also get my hands dirty with the &lt;a href=&#34;http://neo900.org/&#34;&gt;Neo900&lt;/a&gt; whose creators are
currently &lt;a href=&#34;https://shop.goldelico.com/wiki.php?page=Neo900&#34;&gt;looking for potential donors/customers&lt;/a&gt; to increase the size of
the first batch and get the price per unit further down.&lt;/p&gt;
&lt;p&gt;Creating a Debian rootfs disk image for all these devices basically follows the
same steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;create an disk image file, partition it, format the partitions and mount the &lt;code&gt;/&lt;/code&gt; partition into a directory&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;debootstrap&lt;/code&gt; or &lt;code&gt;multistrap&lt;/code&gt; to extract a selection of armel or armhf packages into the directory&lt;/li&gt;
&lt;li&gt;copy over &lt;code&gt;/usr/bin/qemu-arm-static&lt;/code&gt; for qemu user mode emulation&lt;/li&gt;
&lt;li&gt;chroot into the directory to execute package maintainer scripts with &lt;code&gt;dpkg --configure -a&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;copy the disk image onto the sd card&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It was not long until I started wondering why I had to run all of the above
steps with superuser privileges even though everything except the final step
(which I will not cover here) was in principle nothing else than writing some
magic bytes to files I had write access to (the disk image file) in some more
or less fancy ways.&lt;/p&gt;
&lt;p&gt;So I tried using &lt;code&gt;fakeroot&lt;/code&gt;+&lt;code&gt;fakechroot&lt;/code&gt; and after some &lt;a href=&#34;https://lists.debian.org/debian-embedded/2011/01/msg00005.html&#34;&gt;initial troubles&lt;/a&gt; I
managed to build a foreign architecture rootfs &lt;a href=&#34;https://lists.debian.org/debian-embedded/2011/06/msg00022.html&#34;&gt;without needing root
priviliges&lt;/a&gt; for steps two, three and four. I wrote about my solution which
still included some workarounds in &lt;a href=&#34;https://blog.mister-muffin.de/2011/04/02/foreign-debian-bootstrapping-without-root-priviliges-with-fakeroot%2c-fakechroot-and-qemu-user-emulation/&#34;&gt;another article here&lt;/a&gt;. &lt;a href=&#34;https://lists.debian.org/debian-embedded/2011/07/msg00014.html&#34;&gt;These
workarounds&lt;/a&gt; were soon not needed anymore as upstream fixed the outstanding
issues. As a result I wrote the &lt;a href=&#34;http://anonscm.debian.org/gitweb/?p=emdebian/polystrap.git&#34;&gt;&lt;code&gt;polystrap&lt;/code&gt; tool&lt;/a&gt; which combines
&lt;code&gt;multistrap&lt;/code&gt;, &lt;code&gt;fakeroot&lt;/code&gt;, &lt;code&gt;fakechroot&lt;/code&gt; and qemu user mode emulation.  Recently
I managed to integrate &lt;a href=&#34;http://proot.me/&#34;&gt;&lt;code&gt;proot&lt;/code&gt;&lt;/a&gt; support &lt;a href=&#34;http://anonscm.debian.org/gitweb/?p=emdebian/polystrap.git;a=commit;h=e7190f0276039e66c2710a9161c8a44d940927fd&#34;&gt;in a separate branch&lt;/a&gt; of
&lt;code&gt;polystrap&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Last year I got the LEGO ev3 robot for christmas and since it runs Linux I also
wanted to put Debian on it by following the instructions given by the &lt;a href=&#34;https://github.com/mindboards/ev3dev&#34;&gt;ev3dev
project&lt;/a&gt;. Even though ev3dev calls itself a &amp;ldquo;distribution&amp;rdquo; it only deviates
from pure Debian by its kernel, some configuration options and its initial
package selection. Otherwise it&amp;rsquo;s vanilla Debian. The project also supplies
some &lt;a href=&#34;https://github.com/mindboards/ev3dev-rootfs&#34;&gt;&lt;code&gt;multistrap&lt;/code&gt; based scripts&lt;/a&gt; which create the rootfs and then
partition and populate an SD card. All of this is of course done as the
superuser.&lt;/p&gt;
&lt;p&gt;While the creation of the file/directory structure of the foreign Debian armel
rootfs can by now easily be done without superuser priviliges by running
multistrap under &lt;code&gt;fakeroot&lt;/code&gt;/&lt;code&gt;fakechroot&lt;/code&gt;/&lt;code&gt;proot&lt;/code&gt;, creating the SD card image
still seems to be a bit more tricky. While it is no problem to write a
partition table to a regular file, it turned out to be tricky to mount these
partition because tools like &lt;code&gt;kpartx&lt;/code&gt; and &lt;code&gt;losetup&lt;/code&gt; require superuser
permissions. Tools like &lt;code&gt;mkfs.ext3&lt;/code&gt; and &lt;code&gt;fuse-ext2&lt;/code&gt; which otherwise would be
able to work on a regular file without superuser privileges do not seem to
allow to specify the required offsets that the partitions have within the disk
image. With &lt;a href=&#34;https://github.com/jmattsson/fuseloop&#34;&gt;&lt;code&gt;fuseloop&lt;/code&gt;&lt;/a&gt; there exists a tool which allows to &amp;ldquo;loop-mount&amp;rdquo;
parts of a file in userspace to a new file and thus allows tools like
&lt;code&gt;mkfs.ext3&lt;/code&gt; and &lt;code&gt;fuse-ext2&lt;/code&gt; to work as they normally do.  But &lt;code&gt;fuseloop&lt;/code&gt; is not
packaged for Debian yet and thus also not in the current Debian stable. An
obvious workaround would be to create and fill each partition in a separate
file and concatenate them together. But why do I have to write my data twice
just because I do not want to become the superuser? Even worse: because
&lt;code&gt;parted&lt;/code&gt; refuses to write a partition table to a file which is too small to
hold the specified partitions, one spends twice the disk space of the final
image: the image with the partition table plus the image with the main
partition&amp;rsquo;s content.&lt;/p&gt;
&lt;p&gt;So lets summarize: a bootable foreign architecture SD card disk image is
nothing else than a regular file representing the contents of the SD card as a
block device. This disk image is created in my home directory and given enough
free disk space there is nothing stopping me from writing any possible
permutation of bits to that file. Obviously I&amp;rsquo;m interested in a permutation
representing a valid partition table and file systems with sensible content.
Why do I need superuser privileges to generate such a sensible permutation of
bits?&lt;/p&gt;
&lt;p&gt;Gladly it seems that the (at least in my opinion) hardest part of faking chroot
and executing foreign architecture package maintainer scripts is already
possible without superuser privileges by using &lt;code&gt;fakeroot&lt;/code&gt; and &lt;code&gt;fakechroot&lt;/code&gt; or
&lt;code&gt;proot&lt;/code&gt; together with qemu user mode emulation. But then there is still the
blocker of creating the disk image itself through some user mode loop mounting
of a filesystem occupying a virtual &amp;ldquo;partition&amp;rdquo; in the disk image.&lt;/p&gt;
&lt;p&gt;Why has all this only become available so very recently and still requires a
number of workarounds to fully work in userspace? There exists a surprising
amount of scripts which wrap &lt;code&gt;debootstrap&lt;/code&gt;/&lt;code&gt;multistrap&lt;/code&gt;. Most of them require
superuser privileges. Does everybody just accept that they have to put a &lt;code&gt;sudo&lt;/code&gt;
in front of every invocation and hope for the best? While this might be okay
for well tested code like &lt;code&gt;debootstrap&lt;/code&gt; and &lt;code&gt;multistrap&lt;/code&gt; the countless wrapper
scripts might accidentally (be it a bug in the code or a typo in the given
command line arguments) write to your primary hard disk instead of your SD
card. Such behavior can easily be mitigated by not executing any such script
with superuser privileges in the first place.&lt;/p&gt;
&lt;p&gt;Operations like loop mounting affect the whole system. Why do I have to touch
anything outside of my home directory (&lt;code&gt;/dev/loop&lt;/code&gt; in this case) to populate a
file in it with some meaningful bits? Virtualization is no option because every
virtualization solution again requires root privileges.&lt;/p&gt;
&lt;p&gt;One might argue that a number of solutions just require some initial setup by
root to then later be used by a regular user (for example &lt;code&gt;/etc/fstab&lt;/code&gt;
configuration or the &lt;code&gt;schroot&lt;/code&gt; approach). But then again: why do I have to
write anything outside of my home directory (even if it is only once) to be
able to write something meaningful to a file in it?&lt;/p&gt;
&lt;p&gt;The latter approach also does not work if one cannot become root in the first
place or is limited by a virtualized environment. Imagine you are trying to
build a Debian rootfs on a machine where you just have a regular user account.
Or a situation I was recently in: I had a virtual server which denied me
operations like loop mounting.&lt;/p&gt;
&lt;p&gt;Given all these downsides, why is it still so common to just assume that one is
able and willing to use &lt;code&gt;sudo&lt;/code&gt; and be done with it in most cases?&lt;/p&gt;
&lt;p&gt;I really wonder why technologies like &lt;code&gt;fakeroot&lt;/code&gt; and &lt;code&gt;fakechroot&lt;/code&gt; have only
been developed this late. Has this problem not been around since the earliest
days of Linux/Unix?&lt;/p&gt;
&lt;p&gt;Am I missing something and rambling around for nothing? Is this idea a lost
cause or something that is worth spending time and energy on to extend and fix
the required tools?&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
