Run linux on freebsd

Install Ubuntu base system into FreeBSD’s Linux Binary Compatibility.

Procedure for installing the Ubuntu base system into FreeBSD’s built-in Linux Binary Compatibility, so Ubuntu and Debian based desktop applications, such as Signal, Spotify and Netflix, can run directly on FreeBSD. Tested with Ubuntu 20.04 on FreeBSD 13.0 for 64-bit amd64 architecture.

What is FreeBSD’s Linux Binary Compatibility?

FreeBSD’s built-in Linux Binary Compatibility makes it possible for FreeBSD users, that are running the 32-bit i386, 64-bit amd64 or 64-bit arm64 architecture, to install and run 32-bit and 64-bit Linux binaries directly from the command line. This is done through a system call table, which means, that Linux applications can run without emulation nor virtualization. FreeBSD’s built-in Linux Binary Compatibility was introduced in the 90’s.

In the following example, Spotify desktop client for Linux is launched from the command line in FreeBSD.

$ /compat/ubuntu/usr/bin/spotify

Screenshot of Spotify desktop client, that is running in GNOME on FreeBSD 13.0.

Enable FreeBSD’s built-in Linux Binary Compatibility.

FreeBSD has built-in binary compatibility with Linux. This makes it possible to run Ubuntu and Linux binaries. It is enabled by loading the Linux kernel modules.

# kldload linux # kldload linux64 # kldload fdescfs # kldload linprocfs # kldload tmpfs # kldload linsysfs

To make this permanent, so it also works after reboot, configure the FreeBSD system bootstrap configuration information in loader.conf.

# nano /boot/loader.conf linux_load="YES" linux64_load="YES" fdescfs_load="YES" linprocfs_load="YES" tmpfs_load="YES" linsysfs_load="YES"

Prepare command script for Ubuntu base system.

Prepare a command script, that will be used to start and stop the Ubuntu base system.

# touch /usr/local/etc/rc.d/ubuntu # chmod +x /usr/local/etc/rc.d/ubuntu # nano /usr/local/etc/rc.d/ubuntu

Insert the following lines of shell script code into the command script.

#!/bin/sh # # PROVIDE: ubuntu # REQUIRE: archdep mountlate # KEYWORD: nojail # . /etc/rc.subr name="ubuntu" desc="Ubuntu for FreeBSD Linux Binary Compatibility" rcvar="ubuntu_enable" start_cmd="$_start" stop_cmd=":" unmounted() < [ `stat -f "%d" "$1"` == `stat -f "%d" "$1/.."` -a `stat -f "%i" "$1"` != `stat -f "%i" "$1/.."` ] >ubuntu_start() < local _tmpdir load_kld -e 'linux(aout|elf)' linux case `sysctl -n hw.machine_arch` in amd64) load_kld -e 'linux64elf' linux64 ;; esac if [ -x "/compat/ubuntu/sbin/ldconfigDisabled" ]; then _tmpdir=`mktemp -d -t linux-ldconfig` /compat/ubuntu/sbin/ldconfig -C $/ld.so.cache if ! cmp -s "$/ld.so.cache" "/compat/ubuntu/etc/ld.so.cache"; then cat "$/ld.so.cache" > "/compat/ubuntu/etc/ld.so.cache" fi rm -rf $ fi load_kld pty if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then sysctl kern.elf64.fallback_brand=3 > /dev/null fi if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then sysctl kern.elf32.fallback_brand=3 > /dev/null fi sysctl compat.linux.emul_path="/compat/ubuntu" unmounted "/compat/ubuntu/dev" && (mount -o nocover -t devfs devfs "/compat/ubuntu/dev" || exit 1) unmounted "/compat/ubuntu/dev/fd" && (mount -o nocover,linrdlnk -t fdescfs fdescfs "/compat/ubuntu/dev/fd" || exit 1) unmounted "/compat/ubuntu/dev/shm" && (mount -o nocover,mode=1777 -t tmpfs tmpfs "/compat/ubuntu/dev/shm" || exit 1) unmounted "/compat/ubuntu/home" && (mount -t nullfs /home "/compat/ubuntu/home" || exit 1) unmounted "/compat/ubuntu/proc" && (mount -o nocover -t linprocfs linprocfs "/compat/ubuntu/proc" || exit 1) unmounted "/compat/ubuntu/sys" && (mount -o nocover -t linsysfs linsysfs "/compat/ubuntu/sys" || exit 1) unmounted "/compat/ubuntu/tmp" && (mount -t nullfs /tmp "/compat/ubuntu/tmp" || exit 1) unmounted /dev/fd && (mount -o nocover -t fdescfs fdescfs /dev/fd || exit 1) unmounted /proc && (mount -o nocover -t procfs procfs /proc || exit 1) true > load_rc_config $name run_rc_command "$1"

Create ZFS dataset for Linux compatibility directory.

If the benefits of ZFS dataset is of interest, then create a ZFS dataset. This will also make it possible to use snapshots, safely delete files without crossing mountpoints and safely delete the entire volume, if necessary.

# zfs create -o compression=on -o mountpoint=/compat zroot/compat

The snapshot feature of ZFS can be used as a kind of quick backup before changes.

# zfs snapshot -r zroot/compat@2022-04-22

Create directories for the Ubuntu base system.

Prepare directories for Ubuntu.

Читайте также:  Размер окна приложения linux

Start Ubuntu base system.

Enable Ubuntu chroot jail and make it automatically enabled at boot time.

Start Ubuntu base system in its chroot jail.

# service ubuntu start compat.linux.emul_path: /compat/linux -> /compat/ubuntu

Install Ubuntu base system into the Linux compatibility directory.

Install Debootstrap. This will be used to download and install Ubuntu base systems by specifying the Ubuntu target, such as focal for Focal Fossa, which is version 20.04 LTS of Ubuntu. The different targets and releases of Ubuntu are listed at List of releases at Ubuntu Wiki.

Download and install Ubuntu base system into Linux compatibility directory.

# debootstrap --arch=amd64 --no-check-gpg focal /compat/ubuntu I: Base system installed successfully.

Restart Ubuntu chroot jail.

# service ubuntu restart compat.linux.emul_path: /compat/ubuntu -> /compat/ubuntu

Fix the dynamic linker (ELF interpreter) with a symbolic link.

# cd /compat/ubuntu/lib64/ # rm ./ld-linux-x86-64.so.2 # ln -s ../lib/x86_64-linux-gnu/ld-2.31.so ld-linux-x86-64.so.2

Configure Ubuntu.

Enter the chroot jail, which will restrict the following processes to the Ubuntu base filesystem. If Ubuntu shows a message about a missing group ID, this can just be ignored. You will see, that the prompt changes.

# chroot /compat/ubuntu /bin/bash
/# printf "%b\n" "0.0 0 0.0\n0\nUTC" > /etc/adjtime /# dpkg-reconfigure tzdata
/# printf "APT::Cache-Start 251658240;" > /etc/apt/apt.conf.d/00aptitude

Add repositories. In this example, the target focal is used. Change as necessary.

/# printf "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list

Install and run Ubuntu and Debian based application and binaries.

You have now enabled the Linux Binary Compatibility in FreeBSD and installed the Ubuntu base system into it. You can install Ubuntu and Debian based application and binaries by entering the Ubuntu chroot jail and using Ubuntu’s package manager apt.

If you would like to install the Signal desktop application on FreeBSD, then see my guide in Install and run Signal desktop application on FreeBSD.

Update Ubuntu and Debian based applications.

# chroot /compat/ubuntu /bin/bash /# apt update /# apt list --upgradable /# apt upgrade /# apt autoremove /# apt clean

Safely deleting the Ubuntu base system and Linux Binary Compatibility in FreeBSD.

If necessary, the Ubuntu base system in FreeBSDs Linux Binary Compatibility can be safely deleted by first disabling the automatic start of Ubuntu base system, then rebooting FreeBSD and then deleting the Ubuntu base system directory or destroying the ZFS volume. I recommend deleting without crossing mountpoints for extra safety measure. If the Ubuntu base system is running, while attempting to delete it, FreeBSD will crash and FreeBSD disk related services will core dump.

# nano /etc/rc.conf # reboot # cd /compat # rm -rxv ubuntu

More about Linux Binary Compatibility in FreeBSD.

Would you like to treat me a cup of coffee?

If you would like to treat me a cup of coffee, then please consider making a small donation to My Bitcoin (BTC) Address. It would be greatly appreciated.

Читайте также:  Альт линукс установка deb пакетов

This page was last updated 2022-10-09.

Published by Micski

Micski lives in Copenhagen, which is the capitol city of Denmark, where he’s a system administrator of information technology and a semi-professional poker player. View all posts by Micski

Categories

  • Adventure (44)
  • Ancestry (1)
  • Cerwin-Vega (1)
  • Chess (11)
  • Death (3)
  • FreeBSD (37)
  • Fun (4)
  • General (3)
  • Photography (9)
  • Poker (19)
  • System Administration (54)

Источник

run Linux applications on FreeBSD

is it possible at to run Linux applications on a FreeBSD machine? How can I do it? Thank in advance !

As always, most FreeBSD questions are answered in The Handbook as linked to by @Bob . In most cases, there is a port/pkg of the same application from Linux available on FreeBSD.

FreeBSD has a Linux subsystem which does run Linux applications natively w/o a need to recompile. Read up on that on freebsd.org where there are plenty of resources.

2 Answers 2

  • Ports/packages There are tens of thousands of softwares in the ports/packages collection, installable and built from source on one’s system in /usr/ports/ (with options that one can configure to one’s local system) or available as pre-built binaries from the FreeBSD package repositories. It’s quite likely that whatever you want to run has already been included.
  • Binary compatibility There’s a subsystem in the FreeBSD kernel that can emulate many Linux system calls and the Linux /compat/linux/proc/ filesystem, although it deliberately does not provide some architecture-specific Linuxisms, for running Linux binaries. In contrast, note, ports/packages are native FreeBSD programs, compiled tailored to FreeBSD and its libraries.

This is all documented in the FreeBSD Handbook.

OpenBSD and NetBSD have ports/packages systems, too. NetBSD refers to it as just the packages collection, because in NetBSD jargon «ports» are ports of the operating system to different platforms and architectures. NetBSD has a similar binary compatibility layer, likewise documented in the NetBSD Guide.

Источник

Run linux on freebsd

This page describes the steps required to configure Ubuntu-based Linux jail or chroot — a complete Linux userspace environment running on top of Linuxulator.

  1. Run FreeBSD 14-CURRENT or 13.0-RELEASE on amd64, or 14-CURRENT on arm64
  2. Have linux(4) compatibility enabled, as documented in the man page; this boils down to having linux_enable=YES in /etc/rc.conf; run service linux start, as root, after adding it there. This is to load the neccessary kernel modules and set some sysctls.
  3. Install sysutils/debootstrap; pkg install debootstrap.
  4. Run debootstrap bionic /compat/ubuntu. This will install Ubuntu Bionic into /compat/ubuntu. While it is technically possible to install into /compat/linux instead, it’s discouraged due to possible clash with CentOS-based ports and packages (linux_base-c7 et al). You might see some errors during configuration phase — they are generally harmless; as long as the log ends with «Base system installed successfully», everything is fine.
  5. Set up mounts in /etc/fstab, as described in linux(4) man page. Remember to actually mount them (mount -al if you use the example below) afterwards. If you want to share home directory contents, and be able to run X11 apps, you will also need null mounts for /home and /tmp. For example:
# Device Mountpoint FStype Options Dump Pass# devfs /compat/ubuntu/dev devfs rw,late 0 0 tmpfs /compat/ubuntu/dev/shm tmpfs rw,late,size=1g,mode=1777 0 0 fdescfs /compat/ubuntu/dev/fd fdescfs rw,late,linrdlnk 0 0 linprocfs /compat/ubuntu/proc linprocfs rw,late 0 0 linsysfs /compat/ubuntu/sys linsysfs rw,late 0 0 /tmp /compat/ubuntu/tmp nullfs rw,late 0 0 /home /compat/ubuntu/home nullfs rw,late 0 0

That’s it! You should now be able to run chroot /compat/ubuntu /bin/bash and use apt like you would on a typical Ubuntu instance. You will probably want to add users and groups with UIDs/GIDs matching the ones on the host system. While systemd doesn’t work, the service command works as usual. Some things that would probably get set up by the installer require manual tweaking: if you get warnings about LC_ALL you’ll want to install appropriate locales (apt search language-pack). There’s a configuration problem with the rsyslog package; use apt remove rsyslog to make apt stop whining. To get your environment variables set up in the typical Ubuntu way you might want to start sshd(8) (service ssh start) and log in this way; you can add chroot /compat/ubuntu /usr/sbin/service ssh start to /etc/rc.local to make it run at boot. As with any other Ubuntu, you will probably want to add the package repositories missing from defaults; for amd64 (x86_64) version of Bionic make your /compat/ubuntu/etc/apt/sources.list look like this:

deb http://archive.ubuntu.com/ubuntu bionic main universe restricted multiverse deb http://security.ubuntu.com/ubuntu/ bionic-security universe multiverse restricted main deb http://archive.ubuntu.com/ubuntu bionic-backports universe multiverse restricted main deb http://archive.ubuntu.com/ubuntu bionic-updates universe multiverse restricted main

For arm64, it should look like this:

deb http://ports.ubuntu.com/ubuntu-ports bionic main universe restricted multiverse

Note that the instructions above apply to both jails and chroots — it makes no difference from Linuxulator point of view; the part that matters is changing the filesystem root directory, which is common to both. Also note that the instructions don’t describe how to manage the jail; take a look at this article for instructions on how to manage your Ubuntu jail using iocage, or this one for Bastille.

Читайте также:  Запуск процесса в фоне линукс

You can find the list of tested apps at LinuxApps. Feel free to add new entries.

LinuxJails (last edited 2023-03-15T16:47:58+0000 by EdwardTomaszNapierala )

Источник

Оцените статью
Adblock
detector