Re: fakechroot + qemu user emulation (it works now)

"Johannes Schauer" <[email protected]>
Newsgroups gmane.linux.debian.devel.embedded
Message-ID <795777009.309109.1301699509491.JavaMail.fmail@mwmweb070>
Just as a followup on the question i posted back in january...

On Tue, Jan 18, 2011 at 10:29:56PM +0100, Marcus Osdoba wrote
>Am 09.01.2011 15:26, schrieb Johannes Schauer:
>> hi,
>>
>> my goal is to build an armel rootfs without the need of super user
>> privileges.
>>
>Hi, I have the same requirement and want to avoid superuser rights for
>launching multistrap and chroot'ing into generated rootfs.
>
>If you somehow found a solution for this, I am also interested in.

I solved it! :D

If you just put qemu-arm-static into the chroot and then execute:

$ fakeroot fakechroot chroot $ROOTDIR /bin/true

it would return: "Unable to load interpreter". But it will work whithout
fakeroot/fakechroot using the normal chroot(8). The solution is to help it
finding the shared armel libraries correctly.

With qemu-arm-static the solution is to append -L. For example this would
not work:

$ qemu-arm-static $ROOTDIR/bin/true
Unable to load interpreter

but this will work:

$ qemu-arm-static -L $ROOTDIR $ROOTDIR/bin/true

Since it is troublesome to pass over the ELF interpreter prefix when letting
qemu-arm-static being run automatically by the kernel's binfmt support the
solution is to put the shared libraries (armel in my case) into the default
directory for qemu-arm-static. The man page says /usr/gnemul/qemu-arm but
this is wrong and indeed is /etc/qemu-binfmt/arm/. It is sufficient to only
put the $ROOTDIR/lib directory there. Indeed it is sufficient to only put armel
versions of ld-2.11.2.so, ld-linux.so.3, libc-2.11.2.so and libc.so.6 into
/etc/qemu-binfmt/arm/lib/. Every armel binary on the system can now be
executed right away just as if it were a native one. This is damn cool!

$ $ROOTDIR/bin/true <= this works just like that!! :D

The next errors will be:

$ fakeroot fakechroot chroot $ROOTDIR /bin/true
ERROR: ld.so: object 'libfakechroot.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded: ignored.

To fix those, just put armel versions of libfakechroot.so and libfakeroot-sysv.so
into /usr/lib/arm-linux-gnueabi/.

It's done!! you can now create a full foreign debian rootfs without having to
use any root priviliges!

I have a small script that i use for this - it is not complete but does the most basic
things and outputs a tarball with the proper permissions:

http://mister-muffin.de/p/rzM8

The whole thing is of course run within a fakeroot call.
One interesting bit in this script is to temporary replace /sbin/ldconfig since
fakechroot can't handle it. It's switched back to the original one in the end.

I put the armel binary into the correct place by using these commands:

wget http://ftp.debian.org/debian/pool/main/f/fakechroot/fakechroot_2.14-1_armel.deb
wget http://ftp.debian.org/debian/pool/main/f/fakeroot/fakeroot_1.14.5-1_armel.deb
wget http://ftp.debian.org/debian/pool/main/e/eglibc/libc6_2.11.2-11_armel.deb
sudo mkdir -p /etc/qemu-binfmt/arm/
sudo mkdir -p /usr/lib/arm-linux-gnueabi/
sudo dpkg -x libc6_2.11.2-11_armel.deb /etc/qemu-binfmt/arm/
dpkg-deb --fsys-tarfile fakeroot_1.14.5-1_armel.deb | sudo tar -xf - --strip-components=4 -C /usr/lib/arm-linux-gnueabi/ ./usr/lib/libfakeroot/libfakeroot-sysv.so
dpkg-deb --fsys-tarfile fakechroot_2.14-1_armel.deb | sudo tar -xf - --strip-components=4 -C /usr/lib/arm-linux-gnueabi/ ./usr/lib/fakechroot/libfakechroot.so
rm fakechroot_2.14-1_armel.deb fakeroot_1.14.5-1_armel.deb libc6_2.11.2-11_armel.deb

I hope this is useful for somebody.

have a nice day,
josch
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.