Skip to content

Commit 0aa15d1

Browse files
Merge pull request #29 from balena-io-examples/alanb128-remove-balenalib_sq
Re-work examples to drop balenalib usage
2 parents beac847 + cf81089 commit 0aa15d1

File tree

12 files changed

+610
-113
lines changed

12 files changed

+610
-113
lines changed

jetson-agx-orin-devkit/Dockerfile

Lines changed: 0 additions & 91 deletions
This file was deleted.

jetson-nano/Dockerfile

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1-
FROM balenalib/jetson-nano-ubuntu:bionic
1+
FROM ubuntu:bionic-20230530
22

33
# Prevent apt-get prompting for input
44
ENV DEBIAN_FRONTEND noninteractive
55

6+
# From balenalib base:
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
less \
9+
kmod \
10+
nano \
11+
net-tools \
12+
sudo \
13+
ca-certificates \
14+
gnupg \
15+
dirmngr \
16+
inetutils-ping \
17+
netbase \
18+
curl \
19+
udev \
20+
ifupdown \
21+
i2c-tools \
22+
usbutils \
23+
$( \
24+
if apt-cache show 'iproute' 2>/dev/null | grep -q '^Version:'; then \
25+
echo 'iproute'; \
26+
else \
27+
echo 'iproute2'; \
28+
fi \
29+
) \
30+
&& rm -rf /var/lib/apt/lists/* \
31+
&& c_rehash
32+
633
# Update to 32.7 repository in case the base image is using 32.6
734
RUN sed -i 's/r32.6 main/r32.7 main/g' /etc/apt/sources.list.d/nvidia.list
835

@@ -55,5 +82,7 @@ RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
5582
## GPU Device 0: "Maxwell" with compute capability 5.3
5683
## Average clocks/block = 3294.203125
5784

58-
# Start XFCE desktop
59-
CMD ["startx"]
85+
COPY entry.sh /usr/bin/entry.sh
86+
87+
# Start entry script
88+
CMD ["bash", "/usr/bin/entry.sh"]

jetson-nano/entry.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# This command only works in privileged container
4+
tmp_mount='/tmp/_balena'
5+
mkdir -p "$tmp_mount"
6+
if mount -t devtmpfs none "$tmp_mount" &> /dev/null; then
7+
PRIVILEGED=true
8+
umount "$tmp_mount"
9+
else
10+
PRIVILEGED=false
11+
fi
12+
rm -rf "$tmp_mount"
13+
14+
function mount_dev()
15+
{
16+
tmp_dir='/tmp/tmpmount'
17+
mkdir -p "$tmp_dir"
18+
mount -t devtmpfs none "$tmp_dir"
19+
mkdir -p "$tmp_dir/shm"
20+
mount --move /dev/shm "$tmp_dir/shm"
21+
mkdir -p "$tmp_dir/mqueue"
22+
mount --move /dev/mqueue "$tmp_dir/mqueue"
23+
mkdir -p "$tmp_dir/pts"
24+
mount --move /dev/pts "$tmp_dir/pts"
25+
touch "$tmp_dir/console"
26+
mount --move /dev/console "$tmp_dir/console"
27+
umount /dev || true
28+
mount --move "$tmp_dir" /dev
29+
30+
# Since the devpts is mounted with -o newinstance by Docker, we need to make
31+
# /dev/ptmx point to its ptmx.
32+
# ref: https://www.kernel.org/doc/Documentation/filesystems/devpts.txt
33+
ln -sf /dev/pts/ptmx /dev/ptmx
34+
35+
# When using io.balena.features.sysfs the mount point will already exist
36+
# we need to check the mountpoint first.
37+
sysfs_dir='/sys/kernel/debug'
38+
39+
if ! mountpoint -q "$sysfs_dir"; then
40+
mount -t debugfs nodev "$sysfs_dir"
41+
fi
42+
43+
}
44+
45+
function start_udev()
46+
{
47+
if [ "$UDEV" == "on" ]; then
48+
if $PRIVILEGED; then
49+
mount_dev
50+
if command -v udevd &>/dev/null; then
51+
unshare --net udevd --daemon &> /dev/null
52+
else
53+
unshare --net /lib/systemd/systemd-udevd --daemon &> /dev/null
54+
fi
55+
udevadm trigger &> /dev/null
56+
else
57+
echo "Unable to start udev, container must be run in privileged mode to start udev!"
58+
fi
59+
fi
60+
}
61+
62+
function init()
63+
{
64+
# echo error message, when executable file is passed but doesn't exist.
65+
if [ -n "$1" ]; then
66+
if CMD=$(command -v "$1" 2>/dev/null); then
67+
shift
68+
exec "$CMD" "$@"
69+
else
70+
echo "Command not found: $1"
71+
exit 1
72+
fi
73+
fi
74+
}
75+
76+
UDEV=$(echo "$UDEV" | awk '{print tolower($0)}')
77+
78+
case "$UDEV" in
79+
'1' | 'true')
80+
UDEV='on'
81+
;;
82+
esac
83+
84+
start_udev
85+
init "$@"
86+
sleep 8
87+
startx

jetson-orin/Dockerfile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# AGX Orin, Orin NX and Orin Nano use the same T234 platform, therefore base images can be used
22
# interchangeably as long as nvidia.list contains the right apt repositoy
3-
FROM balenalib/jetson-orin-nano-devkit-nvme-ubuntu:jammy-20240401
3+
FROM ubuntu:jammy-20250404
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
sudo \
7+
ca-certificates \
8+
findutils \
9+
gnupg \
10+
dirmngr \
11+
inetutils-ping \
12+
netbase \
13+
curl \
14+
udev \
15+
kmod \
16+
nano
417

518
# Prevent apt-get prompting for input
619
ENV DEBIAN_FRONTEND noninteractive
@@ -46,13 +59,13 @@ RUN \
4659
xterm
4760

4861
ENV LD_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/tegra
49-
ENV UDEV=1
5062

5163
# Prevent screen from turning off
5264
RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
5365
&& echo "" >> /etc/X11/xinit/xserverrc \
54-
&& echo 'exec /usr/bin/X -s 0 dpms' >> /etc/X11/xinit/xserverrc && \
55-
echo 'modules=("tegra_drm" "nvidia_drm" "nvidia_modeset"); for module in "${modules[@]}"; do if lsmod | grep -q ${module} ; then echo "Found $module"; rmmod $module; fi; done; startxfce4 & sleep 5; modprobe tegra_drm; modprobe nvidia_drm; while [ 1 ]; do sleep 10; done; ' > /opt/startxfce.sh
66+
&& echo 'exec /usr/bin/X -s 0 dpms' >> /etc/X11/xinit/xserverrc
67+
68+
5669

5770
## If any apt packages install mesa-egl, it will overwrite the tegra-egl
5871
## symlink and ld path, so the following command will ensure tegra-egl remains
@@ -110,5 +123,9 @@ RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
110123
## deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.6, CUDA Runtime Version = 12.6, NumDevs = 1
111124
## Result = PASS
112125

113-
CMD ["/bin/bash", "/opt/startxfce.sh"]
126+
COPY startxfce.sh /opt/startxfce.sh
127+
RUN chmod +x /opt/startxfce.sh
128+
COPY entry.sh /usr/bin/entry.sh
129+
RUN chmod +x /usr/bin/entry.sh
114130

131+
CMD ["/bin/bash", "/usr/bin/entry.sh"]

jetson-orin/entry.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
echo "Starting entry script."
4+
5+
# This command only works in privileged container
6+
tmp_mount='/tmp/_balena'
7+
mkdir -p "$tmp_mount"
8+
if mount -t devtmpfs none "$tmp_mount" &> /dev/null; then
9+
PRIVILEGED=true
10+
umount "$tmp_mount"
11+
else
12+
PRIVILEGED=false
13+
fi
14+
rm -rf "$tmp_mount"
15+
16+
function mount_dev()
17+
{
18+
tmp_dir='/tmp/tmpmount'
19+
mkdir -p "$tmp_dir"
20+
mount -t devtmpfs none "$tmp_dir"
21+
mkdir -p "$tmp_dir/shm"
22+
mount --move /dev/shm "$tmp_dir/shm"
23+
mkdir -p "$tmp_dir/mqueue"
24+
mount --move /dev/mqueue "$tmp_dir/mqueue"
25+
mkdir -p "$tmp_dir/pts"
26+
mount --move /dev/pts "$tmp_dir/pts"
27+
touch "$tmp_dir/console"
28+
mount --move /dev/console "$tmp_dir/console"
29+
umount /dev || true
30+
mount --move "$tmp_dir" /dev
31+
32+
# Since the devpts is mounted with -o newinstance by Docker, we need to make
33+
# /dev/ptmx point to its ptmx.
34+
# ref: https://www.kernel.org/doc/Documentation/filesystems/devpts.txt
35+
ln -sf /dev/pts/ptmx /dev/ptmx
36+
37+
# When using io.balena.features.sysfs the mount point will already exist
38+
# we need to check the mountpoint first.
39+
sysfs_dir='/sys/kernel/debug'
40+
41+
if ! mountpoint -q "$sysfs_dir"; then
42+
mount -t debugfs nodev "$sysfs_dir"
43+
fi
44+
45+
}
46+
47+
function start_udev()
48+
{
49+
if [ "$UDEV" == "on" ]; then
50+
if $PRIVILEGED; then
51+
mount_dev
52+
if command -v udevd &>/dev/null; then
53+
unshare --net udevd --daemon &> /dev/null
54+
else
55+
unshare --net /lib/systemd/systemd-udevd --daemon &> /dev/null
56+
fi
57+
udevadm trigger &> /dev/null
58+
else
59+
echo "Unable to start udev, container must be run in privileged mode to start udev!"
60+
fi
61+
fi
62+
}
63+
64+
UDEV='on'
65+
66+
echo "Starting UDEV..."
67+
start_udev
68+
69+
echo "Starting xfce script."
70+
exec /opt/startxfce.sh

jetson-orin/startxfce.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Ensure plymouth exited so that it won't hold /dev/fb0 open and tegra_drm can be unloaded
4+
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
5+
dbus-send \
6+
--system \
7+
--print-reply \
8+
--dest=org.freedesktop.systemd1 \
9+
/org/freedesktop/systemd1 \
10+
org.freedesktop.systemd1.Manager.StopUnit \
11+
string:plymouth-quit.service string:replace
12+
13+
# Prevent "Server is already active for display 0" error,
14+
# in case X was forcedly closed before
15+
rm -rf /tmp/.X0-lock* || true
16+
17+
# Prevent black screen with cursor only
18+
rm -rf /root/.config/ || true
19+
20+
modules=("tegra_drm" "nvidia_drm" "nvidia_modeset"); for module in "${modules[@]}";
21+
do
22+
if lsmod | grep -q ${module} ; then
23+
echo "Found $module"; rmmod $module;
24+
fi;
25+
done;
26+
27+
startxfce4 & sleep 5;
28+
29+
modprobe tegra_drm;
30+
modprobe nvidia_drm;
31+
while [ 1 ]; do
32+
sleep 10;
33+
done;

0 commit comments

Comments
 (0)