Solved why can't I start ubuntu service?

Trying to install Ubuntu 22.04 Jammy following the instructions at https://wiki.freebsd.org/LinuxJails and https://www.micski.dk/2021/12/21/install-ubuntu-base-system-into-freebsds-linux-binary-compatibility/.
I have these lines in /boot/loader.conf:
Code:
linux_load=”YES”
linux64_load=”YES”
fdescfs_load="YES"
linprocfs_load="YES"
tmpfs_load="YES"
linsysfs_load="YES"
This line in /etc/rc.conf:
Code:
ubuntu_enable=”YES”
Note, I don't have linux_enable="YES" in /etc/rc.conf because it would cause ampgpu not load.
There are these lines in /etc/fstab:
Code:
devfs           /compat/ubuntu/dev      devfs       rw,late                                     0       0
linprocfs       /compat/ubuntu/proc     linprocfs   rw,late                                        0       0
linsysfs        /compat/ubuntu/sys      linsysfs    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
/tmp            /compat/ubuntu/tmp      nullfs      rw,late                                     0       0
/home           /compat/ubuntu/home     nullfs      rw,late                                     0       0
I have /usr/local/etc/rc.d/ubuntu, access mode 755:
Code:
#!/bin/sh
#
# PROVIDE: ubuntu
# REQUIRE: archdep mountlate
# KEYWORD: nojail
#
# This file is a modified version of /etc/rc.d/linux
# Based on the script by mrclksr:
# https://github.com/mrclksr/linux-browser-installer/blob/main/rc.d/ubuntu.in
#
. /etc/rc.subr

name="ubuntu"
desc="Enable Ubuntu chroot, and Linux ABI"
rcvar="ubuntu_enable"
start_cmd="${name}_start"
stop_cmd=":"

unmounted()
{
    [ `stat -f "%d" "$1"` == `stat -f "%d" "$1/.."` -a \
      `stat -f "%i" "$1"` != `stat -f "%i" "$1/.."` ]
}

ubuntu_start()
{
    local _emul_path _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 ${_tmpdir}/ld.so.cache
        if ! cmp -s ${_tmpdir}/ld.so.cache /compat/ubuntu/etc/ld.so.cache; then
            cat ${_tmpdir}/ld.so.cache > /compat/ubuntu/etc/ld.so.cache
        fi
        rm -rf ${_tmpdir}
    fi

    # Linux uses the pre-pts(4) tty naming scheme.
    load_kld pty

    # Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
    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

    _emul_path="/compat/ubuntu"
    unmounted "${_emul_path}/dev" && (mount -o nocover -t devfs devfs "${_emul_path}/dev" || exit 1)
    unmounted "${_emul_path}/dev/fd" && (mount -o nocover,linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd" || exit 1)
    unmounted "${_emul_path}/dev/shm" && (mount -o nocover,mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm" || exit 1)
    unmounted "${_emul_path}/home" && (mount -t nullfs /home "${_emul_path}/home" || exit 1)
    unmounted "${_emul_path}/proc" && (mount -o nocover -t linprocfs linprocfs "${_emul_path}/proc" || exit 1)
    unmounted "${_emul_path}/sys" && (mount -o nocover -t linsysfs linsysfs "${_emul_path}/sys" || exit 1)
    unmounted "${_emul_path}/tmp" && (mount -t nullfs /tmp "${_emul_path}/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"

When I try to run # service ubuntu start
Code:
# service ubuntu start
env: /usr/local/etc/rc.d/ubuntu: No such file or directory
Reboot the system doesn't help anything.

I go ahead continue the steps
Code:
# pkg install debootstrap
# debootstrap --arch=amd64 --no-check-gpg jammy /compat/ubuntu

# 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

It was successful. But the ubuntu is not usable because the service doesn't start.
 
This is abit old. There is something wrong with the ubutuntu rc script.
You just need to enable linux and change emul_path. You can remove the lines you added in /boot/loader.conf, /etc/fstab and /etc/rc.conf

Code:
sysctl compat.linux.emul_path=/compat/ubuntu
echo "compat.linux.emul_path=/compat/ubuntu" >> /etc/sysctl.conf
sysrc linux_enable="YES"
 
Changing emul_path to /compat/ubuntu doesn't help start ubuntu service.
Code:
env: /usr/local/etc/rc.d/ubuntu: No such file or directory
It is hard to understand this message. The script file IS there. If script file is not properly written, it should give different message.
 
Hi.
My suggestion: inspect all the programs that get started from the script (see here: https://gitlab.com/tgasiba/trace_exec/).
Also, try to run the script "by hand" and try to figure out where it breaks:
Code:
sh -x /usr/local/etc/rc.d/ubuntu onestart
How to use this script?
Code:
# ./exec.d /usr/local/etc/rc.d/ubuntu 
dtrace: failed to initialize dtrace: DTrace device not available on system

# dtrace -n 'dtrace:::BEGIN { printf("Hello FreeBSD!\n"); }'
dtrace: failed to initialize dtrace: DTrace device not available on system

# kldload dtraceall
kldload: can't load dtraceall: Operation not permitted

# dtrace -l | head
dtrace: failed to initialize dtrace: DTrace device not available on system
 
How to use this script?
Code:
# ./exec.d /usr/local/etc/rc.d/ubuntu
dtrace: failed to initialize dtrace: DTrace device not available on system

# dtrace -n 'dtrace:::BEGIN { printf("Hello FreeBSD!\n"); }'
dtrace: failed to initialize dtrace: DTrace device not available on system

# kldload dtraceall
kldload: can't load dtraceall: Operation not permitted

# dtrace -l | head
dtrace: failed to initialize dtrace: DTrace device not available on system
As root:
Code:
dtrace -s ./exec.d
 
This is the output:
Code:
# sh -x /usr/local/etc/rc.d/ubuntu onestart
+ . $'/etc/rc.subr\r'
: No such file or directory
I think that you might have a problem with file format: notice the "\r" after the rc_subr
This probably means that you copy-pasted the file with DOS format (CRLF) and you should be using Unix format (LF).
Try converting the file with your editor of choice to Unix format, or use dos2unix (from the unix2dos package):
Code:
pkg install unix2dos
dos2unix /usr/local/etc/rc.d/ubuntu
 
You are right. Many thanks. Don't know why the file has dos format.

Now I delete those Dos end-of-line symbols, and can start ubuntu service. Another issue appears:
Code:
# service ubuntu start
kldload: can't load pty: Operation not permitted
/usr/local/etc/rc.d/ubuntu: WARNING: Unable to load kernel module pty
compat.linux.emul_path: /compat/linux -> /compat/ubuntu            '

Is this warning important that I need to get rid of? How?

I think that you might have a problem with file format: notice the "\r" after the rc_subr
This probably means that you copy-pasted the file with DOS format (CRLF) and you should be using Unix format (LF).
Try converting the file with your editor of choice to Unix format, or use dos2unix (from the unix2dos package):
Code:
pkg install unix2dos
dos2unix /usr/local/etc/rc.d/ubuntu
 
Hi.

Not sure what is the problem there...
Can you check the file /etc/rc.d/linux? It should be almost the same as the one you have...
From what I can gather, the pty kernel module is necessary for Linux emulation...
What kind of system are you using? dtrace is usually always available, but you also got an "DTrace device not available on system" error message before...

I guess that in your first post, you mean amdgpu, instead of ampgpu?
Why do you write that enabling linux in rc.conf causes amdgpu not to load?
 
From what I can gather, the pty kernel module is necessary for Linux emulation...
What kind of system are you using? dtrace is usually always available, but you also got an "DTrace device not available on system" error message before...
It's 13.2-release I'm using.

Code:
Why do you write that enabling linux in rc.conf causes amdgpu not to load?
Because this is what happened. Originally I had linux_enable="YES" in rc.conf and I could not load amdgpu. Then I moved it to /boot/loader.conf and amdgpu is loaded.

The WARNING: Unable to load kernel module pty message doesn't show when I reboot the system.
 
Probably the message does not appear because the pty module is not loaded.
Both the linux service and the ubuntu service, as you defined above, require the pty module.
This indicates that there might be some incompatibility with loading the amdgpu and pty module together.
Unfortunately, I am not sure if I can help you further here, as I cannot replicate the problem due to missing hardware.
Maybe you can try to see which modules are loaded with kldstat.
I would guess that if you try to load the pty module by hand ( kldload pty), it will not be possible also, as with the service above...

Maybe you can try some experiments with kldstat, kldload, and kldunload to see if you can load amdgpu and tty at the same time?
 
Back
Top