Could not initialize SDL(x11 not available) error while I'm trying to start automatically a bash script which configures a qemu virtual machine

ziomario

New Member
Credits
100
Hello.

I would like to run a shell script automatically every time my ubuntu 18.04 installation has landed and I see the desktop manager fully loaded. The script should be executed regarless of the desktop manager that I'm using. To do this I created these scripts :

Created executable file /opt/rasp/setup-rasp.sh:

#!/bin/bash
echo "Setting up rasp ...mounting I9"
touch /tmp/rasp-activated
echo mounting I9...wait 20s
sleep 20s

sudo mount -t nfs -o nolock,local_lock=all 192.168.1.6:/home/ziomario/Scrivania/Dati/Data/Nano/I9 /home/zi/Desktop/Work/I9

sleep 20s

qemu-system-aarch64 -M virt -m 2048 -smp 2 -cpu host,aarch64=off -enable-kvm \
-kernel /home/zi/Desktop/Work/I9/arm32/debian11-bullseye/vmlinuz-5.10.0-5-armmp-lpae \
-initrd /home/zi/Desktop/Work/I9/arm32/debian11-bullseye/initrd.img-5.10.0-5-armmp-lpae \
-append 'root=/dev/vda2' \
-device usb-ehci -device usb-kbd -device usb-mouse -usb -serial stdio \
-device virtio-gpu-pci,virgl=on,xres=1920,yres=1080 -display sdl,gl=on \
-drive if=none,file=/home/zi/Desktop/Work/I9/arm32/hda-bullseye2.qcow2,format=qcow2,id=hd \
-device virtio-blk-device,drive=hd -netdev user,id=mynet \
-device virtio-net-device,netdev=mynet \
-bios edk2-arm-code.fd \
-no-reboot


Created executable file /opt/rasp/teardown-rasp.sh:

#!/bin/bash
echo "Tearing down rasp ..."
if [ -f /tmp/rasp-activated ]; then
rm /tmp/rasp-activated
else
echo "Doesn't seem to be up: Skipping ..."
fi


Created systemd unit file : /etc/systemd/system/rasp.service

[Unit]
Description=Setup rasp
#After=network.target

[Service]
Type=oneshot
ExecStart=/opt/rasp/setup-rasp.sh
RemainAfterExit=true
ExecStop=/opt/foo/teardown-rasp.sh
StandardOutput=journal

[Install]
WantedBy=multi-user.target


and I have activated the service with :

sudo systemctl enable rasp.service


I have rebooted ubuntu and I saw that the nfs folder I9 has been mounted,but the raspberry qemu-system-aarch64 virtual machine didn't start because this error :

[email protected]:~$ sudo systemctl status raspberry.service

raspberry.service - Setup rasp
Loaded: loaded (/etc/systemd/system/raspberry.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-04-16 12:19:30 CEST; 524ms ago
Process: 4060 ExecStart=/opt/rasp/setup-rasp.sh (code=exited, status=1/FAILURE)
Main PID: 4060 (code=exited, status=1/FAILURE)
apr 16 12:18:39 zi-desktop setup-rasp.sh[4060]: Setting up rasp ...mounting I9
apr 16 12:18:39 zi-desktop setup-rasp.sh[4060]: mounting I9...wait 20s
apr 16 12:19:00 zi-desktop sudo[7326]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/mount -t nfs -o nolock,local_lock=all 192.168.1.6:/home/zioma
apr 16 12:19:00 zi-desktop sudo[7326]: pam_unix(sudo:session): session opened for user root by (uid=0)
apr 16 12:19:00 zi-desktop sudo[7326]: pam_unix(sudo:session): session closed for user root
apr 16 12:19:00 zi-desktop setup-rasp.sh[4060]: Running raspbian. Wait 30s...
apr 16 12:19:30 zi-desktop setup-rasp.sh[4060]: Could not initialize SDL(x11 not available) - exiting
apr 16 12:19:30 zi-desktop systemd[1]: raspberry.service: Main process exited, code=exited, status=1/FAILURE
apr 16 12:19:30 zi-desktop systemd[1]: raspberry.service: Failed with result 'exit-code'.
apr 16 12:19:30 zi-desktop systemd[1]: Failed to start Setup rasp.


the vm starts correctly when I open a terminal and I run the qemu vm from there.

I have also tried this script : /opt/rasp/setup-rasp.sh:

#!/bin/bash
gnome-terminal

this time error is :

Unable to init server: could not connect : connection refused failed to parse arguments: cannot open display:
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Staff online

Members online


Latest posts

Top