Re: Building a Linuxulator userland from source

From: Felix Palmen <zirias_at_freebsd.org>
Date: Mon, 21 Aug 2023 09:30:21 UTC
* Tatsuki Makino <tatsuki_makino@hotmail.com> [20230821 17:40]:
> Felix Palmen wrote on 2023/08/21 16:21:
> > This works perfectly fine when used from within a Linux shell. Example
> > from testing my new userland:
> > 
> > | [00:00:20] Entering interactive test mode. Type 'exit' when done.
> > | root@14a-default:~ # /compat/linux/bin/bash
> > | bash-5.2# ldd /bin/bash
> > |         linux-vdso.so.1 (0x00007fffffffe000)
> > |         libreadline.so.8 => /usr/lib64/libreadline.so.8 (0x0000000801154000)
> > |         libhistory.so.8 => /usr/lib64/libhistory.so.8 (0x00000008011ad000)
> > |         libncursesw.so.6 => /usr/lib64/libncursesw.so.6 (0x00000008011bb000)
> > |         libc.so.6 => /usr/lib64/libc.so.6 (0x0000000801400000)
> > |         /lib64/ld-linux-x86-64.so.2 (0x0000000001021000)
> > | bash-5.2# 
> 
> Oh, I understand.
> If we try to use it directly, the command not found if bash is not installed.

Installing a FreeBSD bash won't help either, this script expects
/bin/bash which will never exist on FreeBSD (it's installed in
/usr/local/bin/bash).

> we want poudriere to mount real devfs to /compat/linux/dev as well,
> since linux binary behaves like chroot to /compat/linux.

Well, first /compat/linux is *not* a chroot or jail, but actually just
some kind of "filesystem overlay", which is the great thing about it. It
means Linux binaries can access *all* files of the FreeBSD system, as
long as they are not "shadowed" by something below /compat/linux.

And indeed, to support building native Linux software using poudriere,
it *should* mount devfs on /compat/linux/dev.

> Alternatively, pkg-plist in emulators/linux_base-c7 is creating dummy
> /compat/linux/dev, and removing it seems to be a workaround.

In a live system, there's no issue. /etc/rc.d/linux will mount all
necessary pseudo filesystems:

| if checkyesno linux_mounts_enable; then
|         linux_mount linprocfs "${_emul_path}/proc" -o nocover
|         linux_mount linsysfs "${_emul_path}/sys" -o nocover
|         linux_mount devfs "${_emul_path}/dev" -o nocover
|         linux_mount fdescfs "${_emul_path}/dev/fd" -o nocover,linrdlnk
|         linux_mount tmpfs "${_emul_path}/dev/shm" -o nocover,mode=1777
| fi

So far, poudriere doesn't mount anything on /compat/linux/dev for its
building jails, although it *does* mount /compat/linux/proc.

For now, I found that a simple symlink to the real /dev also does the
trick, which I can add with some hackery in the port Makefile itself, by
adding some extra prerequisite for "build-depends" when a poudriere
build is detected. In the long run, poudriere should mount a real devfs
though.

Cheers, Felix

-- 
 Felix Palmen <zirias@FreeBSD.org>     {private}   felix@palmen-it.de
 -- ports committer --                     {web}  http://palmen-it.de
 {pgp public key}  http://palmen-it.de/pub.txt
 {pgp fingerprint} 6936 13D5 5BBF 4837 B212  3ACC 54AD E006 9879 F231