LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 04-16-2021, 09:53 AM   #1
marietto
Member
 
Registered: Aug 2010
Posts: 96

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


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:

Code:
#!/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:

Code:
#!/bin/bash
echo "Tearing down rasp ..."
if [ -f /tmp/rasp-activated ]; then
    rm /tmp/rasp-activated
else
    echo "Doesnt seem to be up: Skipping ..."
fi
Created systemd unit file : /etc/systemd/system/rasp.service

Code:
[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 :

Code:
zi@zi-desktop:~$ 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:

Code:
#!/bin/bash
gnome-terminal
this time error is :

Unable to init server: could not connect : connection refused failed to parse arguments: cannot open display:
 
Old 04-18-2021, 02:58 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
yes, that is definitely the usual issue: you cannot access the X server from "outside".
A user starts an X session and will have a DISPLAY. By default no one else can access it (including root and your bash script).
 
Old 04-18-2021, 05:09 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ that said, it is possible to run gui applications from systemd services by setting a few environment variables.
 
  


Reply

Tags
bash script, display, gnome, systemd, xorg



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
arch/arm/mach-*/mach-*.c What do you call it? TeaYoung Linux - Kernel 1 02-07-2016 08:04 AM
Could not initialize SDL No available video device Julandit Linux - Newbie 0 05-16-2014 02:45 PM
Could not initialize SDL - No available video device sumeet inani Linux - Newbie 4 12-14-2009 02:23 AM
could not initialize SDL: No available video device greenkernel Linux - Games 1 10-15-2008 03:47 PM
clamd upgradation in remote mach through local mac by script to be run on local mach Narayandutt Programming 3 11-29-2006 10:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 11:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration