From f0824ee78bae058f0e1090235c0437b1fe996119b05ab54faee98a119b476ebb Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Fri, 4 Aug 2017 02:39:17 +0000 Subject: [PATCH 1/3] Accepting request 514488 from home:frispete:Kernel-base Hi Larry, I finally put some effort in fixing the VM autostart mechanics, that are terminally broken in the current package (due to the way, systemd interacts with Sys-V init scripts, stop operations aren't executed most of the time, because it lost track of the state...). With these changes, I'm able to reliably start/stop all VMs on hosts ranging from 13.2 to 42.2. I'm confident, this will improve for all systemd based systems, i.o.w all those systems we care about.. It resembles pretty much the same scheme, vboxdrv is using already. Give it a try. - reorganize vbox autostart, coping with systemd: - add /usr/lib/virtualbox/vboxes.sh (based on /etc/init.d/vboxes) - add /usr/lib/systemd/system/vboxes.service - remove /etc/init.d/vboxes OBS-URL: https://build.opensuse.org/request/show/514488 OBS-URL: https://build.opensuse.org/package/show/Virtualization/virtualbox?expand=0&rev=357 --- vboxes.service | 19 +++ vboxes.sh | 227 +++++++++++++++++++++++++++++++++ virtualbox-vboxes | 307 --------------------------------------------- virtualbox.changes | 8 ++ virtualbox.spec | 21 ++-- 5 files changed, 268 insertions(+), 314 deletions(-) create mode 100644 vboxes.service create mode 100644 vboxes.sh delete mode 100644 virtualbox-vboxes diff --git a/vboxes.service b/vboxes.service new file mode 100644 index 0000000..47df4be --- /dev/null +++ b/vboxes.service @@ -0,0 +1,19 @@ +# Autostart configured Virtual Box VMs +# configuration: /etc/sysconfig/vbox + +[Unit] +SourcePath=/usr/lib/virtualbox/vboxes.sh +Description=Autostart Headless Virtual Box VMs +Before=multi-user.target graphical.target +After=network-online.target vboxdrv.service +Wants=network-online.target vboxdrv.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/virtualbox/vboxes.sh start +ExecStop=/usr/lib/virtualbox/vboxes.sh stop + +[Install] +WantedBy=multi-user.target + diff --git a/vboxes.sh b/vboxes.sh new file mode 100644 index 0000000..22878d6 --- /dev/null +++ b/vboxes.sh @@ -0,0 +1,227 @@ +#!/bin/sh +# +# description: Starts and stops vbox autostart VMs. +# Based on +# http://www.amiryan.org/2009/11/04/virtualbox-init-d-service-autostart-scriptu +# +# By Richard Bos - May 2010 +# +# Converted to standalone script for systemd environments +# +# By Hans-Peter jansen - July 2017 +# + +PRG=$(basename $0) +SERVICE="Virtualbox machines" + +VBOXMGR_BIN=/usr/lib/virtualbox/VBoxManage +if [[ ! -x $VBOXMGR_BIN ]]; then + echo "$VBOXMGR_BIN does not exist" + if [ "$1" = "stop" ]; then + exit 0 + else + exit 6 + fi +fi + +# read config file +[ -r /etc/sysconfig/vbox ] && . /etc/sysconfig/vbox + +start() { + + N=1 + for VBOX in $VBOX_AUTOSTART; do + + if grep -q \; <<< "$VBOX"; then + VBOX_NAME[$N]=$(cut -d\; -f1 <<< "$VBOX") + VBOX_USER[$N]=$(cut -d\; -f2 <<< "$VBOX") + else + VBOX_NAME[$N]="$VBOX" + VBOX_USER[$N]="" + fi + N=$(($N+1)) + done + + VBOXES=${#VBOX_NAME[*]} + + if [ $VBOXES -eq 0 ]; then + # The virtual machines have to be configured in /etc/sysconfig/vbox + echo "Starting $SERVICE: no virtual machines configured" + else + + N=1 + echo "Starting $SERVICE: " + while [[ $N -le $VBOXES ]]; do + if [[ $N -lt $VBOXES ]]; then + echo -n "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}), " + else + echo "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]})" + fi + N=$(($N+1)) + done + + N=1 + while [[ $N -le $VBOXES ]]; do + + if [[ -n "${VBOX_USER[$N]}" ]]; then + + if getent passwd ${VBOX_USER[$N]} &>/dev/null; then + + # The tag "Name:" occurs in multiple sections. Require at least 7 blanks + # with an additional flexible amount of spaces. At the moment of writing + # 13 spaces are needed. + VBOX_RUNNING=$(su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN list --long runningvms" | + sed -n 's/^Name:[[:blank:]]\{7\} *//p' | grep -w "${VBOX_NAME[$N]}") + + if [[ -z "$VBOX_RUNNING" ]]; then + + VBOX_PRESENT=$(su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN list --long vms" | + sed -n 's/^Name:[[:blank:]]\{7\} *//p' | grep -w "${VBOX_NAME[$N]}") + + if [[ -n "$VBOX_PRESENT" ]]; then + + # start VM with VBoxManage in headless mode + # unlike VBoxHeadless, VBoxManage waits until VM is running + su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN -q startvm "${VBOX_NAME[$N]}" -type headless" &> /tmp/$PRG.$$ + RETVAL=$? + + if [[ $RETVAL != 0 ]]; then + echo "Starting virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}) failed: " + cat /tmp/$PRG.$$ + fi + + rm /tmp/$PRG.$$ + + else + echo "Virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}) does not exist" + fi + + else + echo "Virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}) is already running" + fi + + else + echo "Virtual machine: ${VBOX_NAME[$N]}, VBOX_USER: ${VBOX_USER[$N]} does not exist" + fi + + else + echo "Virtual machine: ${VBOX_NAME[$N]}: VBOX_USER not configured" + fi + + N=$(($N+1)) + done + fi +} + +stop() { + + for VBOX in $VBOX_AUTOSTART; do + + if grep -q \; <<< "$VBOX"; then + VBOX_USER=$(cut -d\; -f2 <<< "$VBOX") + + # Only add the user to the list, if not present yet + if ! grep -qw "$VBOX_USER" <<< "$VBOX_USERS"; then + VBOX_USERS="$VBOX_USERS $VBOX_USER" + fi + fi + done + + N=1 + for VBOX_USER in $VBOX_USERS; do + + VBOX_RUNNING=$(su $VBOX_USER -c "$VBOXMGR_BIN list --long runningvms" | + sed -n 's/^Name:[[:blank:]]\{7\} *//p') + + for VBOX in $VBOX_RUNNING; do + VBOX_NAME[$N]="$VBOX" + VBOX_USER[$N]="$VBOX_USER" + N=$(($N+1)) + done + done + + VBOXES=${#VBOX_NAME[*]} + + if [[ $VBOXES -eq 0 ]]; then + echo "Shutting down $SERVICE: no virtual machines running." + else + + echo "Shutting down $SERVICE: " + N=1 + while [[ $N -le $VBOXES ]]; do + echo -n "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}): " + su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN -q controlvm ${VBOX_NAME[$N]} savestate" + N=$(($N+1)) + done + fi +} + +status() { + + for VBOX in $VBOX_AUTOSTART; do + + if grep -q \; <<< "$VBOX"; then + VBOX_USER=$(cut -d\; -f2 <<< "$VBOX") + + # Only add the user to the list, if not present yet + if ! grep -qw "$VBOX_USER" <<< "$VBOX_USERS"; then + VBOX_USERS="$VBOX_USERS $VBOX_USER" + fi + fi + done + + N=1 + for VBOX_USER in $VBOX_USERS; do + # The tag "Name:" occurs in multiple sections. Require at least 7 blanks + # with an additional flexible amount of spaces. At the moment of writing + # 13 spaces are needed. + VBOX_RUNNING=$(su $VBOX_USER -c "$VBOXMGR_BIN list --long runningvms" | + sed -n 's/^Name:[[:blank:]]\{7\} *//p') + + for VBOX in $VBOX_RUNNING; do + VBOX_NAME[$N]="$VBOX" + VBOX_USER[$N]="$VBOX_USER" + N=$(($N+1)) + done + done + + VBOXES=${#VBOX_NAME[*]} + + if [[ $VBOXES -eq 0 ]]; then + echo "$SERVICE: no virtual machines running." + else + N=1 + while [[ $N -le $VBOXES ]]; do + # The long sed line changes the output from: + # running (since 2010-04-25T14:51:57.373000000) + # to: + # running (since 2010-04-25 14:51:57) + # + STATE=$(su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN showvminfo "${VBOX_NAME[$N]}"" | + sed -n 's/State: *//p' | + sed 's/\([0-9][0-9]\)\.[0-9]\{9\}/\1/;s/\([0-9][0-9]\)T\([0-9][0-9]\)/\1 \2/') + printf "%-56s %s\n" "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}):" "$STATE" + N=$(($N+1)) + done + fi +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|force-reload) + stop + start + ;; + status) + status + ;; + *) + echo "Usage: $PRG {start|stop|restart|force-reload|status}" >&2 + exit 3 + ;; +esac diff --git a/virtualbox-vboxes b/virtualbox-vboxes deleted file mode 100644 index dae6c05..0000000 --- a/virtualbox-vboxes +++ /dev/null @@ -1,307 +0,0 @@ -#!/bin/sh -# -# chkconfig: - 91 35 -# description: Starts and stops vbox autostart VMs. -# Based on -# http://www.amiryan.org/2009/11/04/virtualbox-init-d-service-autostart-scriptu -# -# By Richard Bos - May 2010 - -### BEGIN INIT INFO -# Provides: vboxes -# Required-Start: $network vboxdrv -# Required-Stop: $network $named -# Default-Start: 3 5 -# Default-Stop: 0 1 2 3 4 5 6 -# Short-Description: Autostart Virtual Box VMs -# Description: Autostart Virtual Box VMs that are mentioned in /etc/sysconfig/vbox file -### END INIT INFO - -# Shell functions sourced from /etc/rc.status: -# rc_check check and set local and overall rc status -# rc_status check and set local and overall rc status -# rc_status -v be verbose in local rc status and clear it afterwards -# rc_status -v -r ditto and clear both the local and overall rc status -# rc_status -s display "skipped" and exit with status 3 -# rc_status -u display "unused" and exit with status 3 -# rc_failed set local and overall rc status to failed -# rc_failed set local and overall rc status to -# rc_reset clear both the local and overall rc status -# rc_exit exit appropriate to overall rc status -# rc_active checks whether a service is activated by symlinks -. /etc/rc.status - -# Reset status of this service -rc_reset - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - user had insufficient privileges -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signaling is not supported) are -# considered a success. - -VBOXMGR_BIN=/usr/lib/virtualbox/VBoxManage -if [[ ! -x $VBOXMGR_BIN ]]; then - echo "$VBOXMGR_BIN does not exist" - if [ "$1" = "stop" ]; then - exit 0; - else - exit 6 - fi; -fi - -VBOXHeadLess_BIN=/usr/lib/virtualbox/VBoxHeadless -if [[ ! -x $VBOXHeadLess_BIN ]]; then - echo "$VBOXHeadLess_BIN does not exist" - if [ "$1" = "start" ]; then - exit 6; - else - exit 0 - fi; -fi - -PRG=$(basename $0) -SERVICE="Virtualbox machines" - -[ -r /etc/sysconfig/vbox ] && . /etc/sysconfig/vbox - -start() { - - N=1 - for VBOX in $VBOX_AUTOSTART; do - - if grep -q \; <<< "$VBOX"; then - VBOX_NAME[$N]=$(cut -d\; -f1 <<< "$VBOX") - VBOX_USER[$N]=$(cut -d\; -f2 <<< "$VBOX") - else - VBOX_NAME[$N]="$VBOX" - VBOX_USER[$N]="" - fi - N=$(($N+1)) - done - - VBOXES=${#VBOX_NAME[*]} - - if [ $VBOXES -eq 0 ]; then - # The virtual machines have to be configured in /etc/sysconfig/vbox - echo -n "Starting $SERVICE: no virtual machines configured" - rc_status -u - else - - N=1 - echo -n "Starting $SERVICE: " - while [[ $N -le $VBOXES ]]; do - if [[ $N -lt $VBOXES ]]; then - echo -n "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}), " - else - echo "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]})" - fi - N=$(($N+1)) - done - - N=1 - while [[ $N -le $VBOXES ]]; do - - if [[ -n "${VBOX_USER[$N]}" ]]; then - - if grep --quiet --word-regexp ${VBOX_USER[$N]} /etc/passwd; then - - # The tag "Name:" occurs in multiple sections. Require at least 7 blanks - # with an additional flexible amount of spaces. At the moment of writing - # 13 spaces are needed. - VBOX_RUNNING=$(su ${VBOX_USER[$N]} -c "VBoxManage list --long runningvms" | - sed -n 's/^Name:[[:blank:]]\{7\} *//p' | grep -w "${VBOX_NAME[$N]}") - - if [[ -z "$VBOX_RUNNING" ]]; then - - VBOX_PRESENT=$(su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN list --long vms" | - sed -n 's/^Name:[[:blank:]]\{7\} *//p' | grep -w "${VBOX_NAME[$N]}") - - if [[ -n "$VBOX_PRESENT" ]]; then - - # VBoxManage startvm does not result in a VM with working networking - # su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN -q startvm "${VBOX_NAME[$N]}" -type headless" > /tmp/$PRG.$$ 2>&1 - # Start virtualbox in Headless mode - su ${VBOX_USER[$N]} -c "$VBOXHeadLess_BIN --startvm "${VBOX_NAME[$N]}"" > /tmp/$PRG.$$ 2>&1 & - RETVAL=$? - - if [[ $RETVAL == 0 ]]; then - echo -n " Starting virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]})" - rc_status -v -r - else - echo -n " Starting virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}) failed with the following output: " - rc_failed; rc_status -v -r - # Give the VBOXHeadLess_BIN some time to write the output file - sleep 2 - cat /tmp/$PRG.$$ - fi - - rm /tmp/$PRG.$$ - - else - echo -n " Virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}) does not exist" - rc_status -s -r - fi - - else - echo -n " Virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}) is already running" - rc_status -v -r - fi - - else - echo -n " Virtual machine: ${VBOX_NAME[$N]}, VBOX_USER: ${VBOX_USER[$N]} does not exist" - rc_status -s -r - fi - - else - echo -n " Virtual machine: ${VBOX_NAME[$N]}: VBOX_USER not configured" - rc_status -s -r - fi - - N=$(($N+1)) - done - fi -} - -stop() { - - for VBOX in $VBOX_AUTOSTART; do - - if grep -q \; <<< "$VBOX"; then - VBOX_USER=$(cut -d\; -f2 <<< "$VBOX") - - # Only add the user to the list, if not present yet - if ! grep -qw "$VBOX_USER" <<< "$VBOX_USERS"; then - VBOX_USERS="$VBOX_USERS $VBOX_USER" - fi - fi - done - - N=1 - for VBOX_USER in $VBOX_USERS; do - VBOX_RUNNING=$(su $VBOX_USER -c "$VBOXMGR_BIN list --long runningvms" | - sed -n 's/^Name:[[:blank:]]\{7\} *//p') - for VBOX in $VBOX_RUNNING; do - VBOX_NAME[$N]="$VBOX" - VBOX_USER[$N]="$VBOX_USER" - N=$(($N+1)) - done - done - - VBOXES=${#VBOX_NAME[*]} - - if [[ $VBOXES -eq 0 ]]; then - echo -n "Shutting down $SERVICE: no virtual machines running." - rc_status -s -r - else - - echo -n "Shutting down $SERVICE: " - N=1 - while [[ $N -le $VBOXES ]]; do - if [[ $N -lt $VBOXES ]]; then - echo -n "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}), " - else - echo "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]})" - fi - N=$(($N+1)) - done - - N=1 - while [[ $N -le $VBOXES ]]; do - - echo -n " ${VBOX_NAME[$N]}: " - su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN -q controlvm "${VBOX_NAME[$N]}" savestate" - RETVAL=$? - - echo -n " Shutting down virtual machine: ${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]})" - if [[ $RETVAL == $? ]]; then - rc_status -v -r - else - rc_failed; rc_status -v -r - fi - N=$(($N+1)) - done - fi -} - -status() { - - for VBOX in $VBOX_AUTOSTART; do - - if grep -q \; <<< "$VBOX"; then - VBOX_USER=$(cut -d\; -f2 <<< "$VBOX") - - # Only add the user to the list, if not present yet - if ! grep -qw "$VBOX_USER" <<< "$VBOX_USERS"; then - VBOX_USERS="$VBOX_USERS $VBOX_USER" - fi - fi - done - - N=1 - for VBOX_USER in $VBOX_USERS; do - # The tag "Name:" occurs in multiple sections. Require at least 7 blanks - # with an additional flexible amount of spaces. At the moment of writing - # 13 spaces are needed. - VBOX_RUNNING=$(su $VBOX_USER -c "$VBOXMGR_BIN list --long runningvms" | - sed -n 's/^Name:[[:blank:]]\{7\} *//p') - for VBOX in $VBOX_RUNNING; do - VBOX_NAME[$N]="$VBOX" - VBOX_USER[$N]="$VBOX_USER" - N=$(($N+1)) - done - done - - VBOXES=${#VBOX_NAME[*]} - - if [[ $VBOXES -eq 0 ]]; then - echo -n "$SERVICE: no virtual machines running." - rc_status -s -r - else - N=1 - while [[ $N -le $VBOXES ]]; do - # The long sed line changes the output from: - # running (since 2010-04-25T14:51:57.373000000) - # to: - # running (since 2010-04-25 14:51:57) - # - STATE=$(su ${VBOX_USER[$N]} -c "$VBOXMGR_BIN showvminfo "${VBOX_NAME[$N]}"" | - sed -n 's/State: *//p' | - sed 's/\([0-9][0-9]\)\.[0-9]\{9\}/\1/;s/\([0-9][0-9]\)T\([0-9][0-9]\)/\1 \2/') - printf " %-56s %s" "${VBOX_NAME[$N]} (user: ${VBOX_USER[$N]}):" "$STATE" - rc_status -v - N=$(($N+1)) - done - fi -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|force-reload) - stop - start - ;; - status) - status - ;; - *) - echo "Usage: $PRG {start|stop|restart|force-reload|status}" >&2 - exit 3 - ;; -esac - diff --git a/virtualbox.changes b/virtualbox.changes index 4e8c902..a7636f4 100644 --- a/virtualbox.changes +++ b/virtualbox.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Thu Aug 3 17:37:58 UTC 2017 - hpj@urpla.net + +- reorganize vbox autostart, coping with systemd: + - add /usr/lib/virtualbox/vboxes.sh (based on /etc/init.d/vboxes) + - add /usr/lib/systemd/system/vboxes.service + - remove /etc/init.d/vboxes + ------------------------------------------------------------------- Sat Jul 29 20:55:24 UTC 2017 - Larry.Finger@lwfinger.net diff --git a/virtualbox.spec b/virtualbox.spec index 447894d..2648eb0 100644 --- a/virtualbox.spec +++ b/virtualbox.spec @@ -44,8 +44,6 @@ Source8: %{name}-guest-preamble Source9: %{name}-wrapper.sh Source10: %{name}-LocalConfig.kmk Source11: %{name}-60-vboxdrv.rules -# init script to start virtual boxes during boot, to be configured via /etc/sysconfig/vbox bnc#582398 -Source12: %{name}-vboxes Source13: %{name}-sysconfig.vbox Source14: vboxdrv.service Source15: vboxadd-service.service @@ -53,6 +51,9 @@ Source16: vboxconfig.sh Source17: vboxguestconfig.sh Source18: fix_usb_rules.sh Source19: vboxdrv.sh +# init script to start virtual boxes during boot, to be configured via /etc/sysconfig/vbox bnc#582398 +Source20: vboxes.sh +Source21: vboxes.service Source98: %{name}-rpmlintrc Source99: %{name}-patch-source.sh #rework init scripts to fit suse needs @@ -631,19 +632,23 @@ install -m 644 %{SOURCE9} %{buildroot}%{_bindir}/VirtualBox # modify and install the vboxdrv init script #sed -i "s|%{NOLSB}%|yes|g;s|%{DEBIAN}%||g;s|%{PACKAGE}%|virtualbox|g" \ # src/VBox/Installer/linux/vboxdrv.sh -install -m 0755 %{SOURCE19} %{buildroot}%{_vbox_instdir}/vboxdrv.sh -ln -s %{_vbox_instdir}/vboxdrv.sh %{buildroot}%{_sbindir}/rcvboxdrv + # Service files to load kernel modules on boot install -m 0644 %{SOURCE14} %{buildroot}%{_unitdir}/vboxdrv.service install -m 0644 %{SOURCE15} %{buildroot}%{_unitdir}/vboxadd-service.service install -m 0755 %{SOURCE16} %{buildroot}/sbin/vboxconfig install -m 0755 %{SOURCE17} %{buildroot}/sbin/vboxguestconfig install -m 0755 %{SOURCE18} %{buildroot}/sbin/vbox-fix-usb-rules.sh +install -m 0755 %{SOURCE19} %{buildroot}%{_vbox_instdir}/vboxdrv.sh +install -m 0755 %{SOURCE20} %{buildroot}%{_vbox_instdir}/vboxes.sh +install -m 0644 %{SOURCE21} %{buildroot}%{_unitdir}/vboxes.service +ln -s %{_vbox_instdir}/vboxes.sh %{buildroot}%{_sbindir}/rcvboxes +ln -s %{_vbox_instdir}/vboxdrv.sh %{buildroot}%{_sbindir}/rcvboxdrv + # Init script to start virtual boxes during boot -install -m 755 %{SOURCE12} %{buildroot}%{_sysconfdir}/init.d/vboxes -ln -s %{_sysconfdir}/init.d/vboxes %{buildroot}%{_sbindir}/rcvboxes ln -sf %{_unitdir}/vboxdrv.service %{buildroot}%{_unitdir}/multi-user.target.wants/vboxdrv.service ln -sf %{_unitdir}/vboxadd-service.service %{buildroot}%{_unitdir}/multi-user.target.wants/vboxadd-service.service +ln -sf %{_unitdir}/vboxes.service %{buildroot}%{_unitdir}/multi-user.target.wants/vboxes.service # sysconfig file intended for vboxes script install -d -m 755 %{buildroot}%{_var}/adm/fillup-templates install -m 640 %{SOURCE13} %{buildroot}%{_var}/adm/fillup-templates/sysconfig.vbox @@ -867,11 +872,13 @@ export DISABLE_RESTART_ON_UPDATE=yes %dir %{_unitdir} %dir %{_unitdir}/multi-user.target.wants /usr/lib/virtualbox/vboxdrv.sh +/usr/lib/virtualbox/vboxes.sh %{_unitdir}/vboxdrv.service +%{_unitdir}/vboxes.service %{_unitdir}/multi-user.target.wants/vboxdrv.service +%{_unitdir}/multi-user.target.wants/vboxes.service %dir %{_sysconfdir}/vbox %config %{_sysconfdir}/vbox/vbox.cfg -%{_sysconfdir}/init.d/vboxes %{_var}/adm/fillup-templates/sysconfig.vbox %{_sbindir}/rcvboxes %{_sbindir}/rcvboxdrv From c3af46ed4de87f47c24116175a1a9bfa408137c26c0213e2be82a84fb16dc042 Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Mon, 7 Aug 2017 18:11:53 +0000 Subject: [PATCH 2/3] Accepting request 515041 from home:Andreas_Schwab:Factory - internal-headers.patch: fix invalid use of internal headers, enable POSIX extensions OBS-URL: https://build.opensuse.org/request/show/515041 OBS-URL: https://build.opensuse.org/package/show/Virtualization/virtualbox?expand=0&rev=358 --- internal-headers.patch | 72 ++++++++++++++++++++++++++++++++++++++++++ virtualbox.changes | 6 ++++ virtualbox.spec | 3 ++ 3 files changed, 81 insertions(+) create mode 100644 internal-headers.patch diff --git a/internal-headers.patch b/internal-headers.patch new file mode 100644 index 0000000..7e0a454 --- /dev/null +++ b/internal-headers.patch @@ -0,0 +1,72 @@ +Index: VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/Makefile.kmk +=================================================================== +--- VirtualBox-5.1.26.orig/src/VBox/Additions/x11/vboxvideo/Makefile.kmk ++++ VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/Makefile.kmk +@@ -23,6 +23,9 @@ vboxvideo_70_DEFS := \ + ifeq ($(KBUILD_TARGET),solaris) # don't use .solaris or anything here. + vboxvideo_70_DEFS += __EXTENSIONS__ ## @todo Why this? + endif ++if1of ($(KBUILD_TARGET), linux) ++ vboxvideo_70_DEFS += _POSIX_SOURCE ## X requires POSIX extensions ++endif + vboxvideo_13_DEFS := $(vboxvideo_70_DEFS) VBOXVIDEO_13 + vboxvideo_15_DEFS := \ + $(vboxvideo_13_DEFS) NO_ANSIC PCIACCESS XSERVER_LIBPCIACCESS _XORG_SERVER_H_ _DIX_CONFIG_H_ +Index: VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/edid.c +=================================================================== +--- VirtualBox-5.1.26.orig/src/VBox/Additions/x11/vboxvideo/edid.c ++++ VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/edid.c +@@ -44,10 +44,6 @@ + * Dave Airlie + */ + +-#if XORG_VERSION_CURRENT >= 11900000 +-#include +-typedef __sigset_t sigset_t; +-#endif + #include + #include + #include +Index: VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/pointer.c +=================================================================== +--- VirtualBox-5.1.26.orig/src/VBox/Additions/x11/vboxvideo/pointer.c ++++ VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/pointer.c +@@ -15,10 +15,6 @@ + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +-#if XORG_VERSION_CURRENT >= 11900000 +-#include +-typedef __sigset_t sigset_t; +-#endif + #include + + #ifndef PCIACCESS +Index: VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/vboxvideo.h +=================================================================== +--- VirtualBox-5.1.26.orig/src/VBox/Additions/x11/vboxvideo/vboxvideo.h ++++ VirtualBox-5.1.26/src/VBox/Additions/x11/vboxvideo/vboxvideo.h +@@ -52,10 +52,6 @@ + #ifndef _VBOXVIDEO_H_ + #define _VBOXVIDEO_H_ + +-#if XORG_VERSION_CURRENT >= 11900000 +-#include +-typedef __sigset_t sigset_t; +-#endif + #include + #include + #include "version-generated.h" +Index: VirtualBox-5.1.26/src/VBox/ExtPacks/VBoxDTrace/Makefile.kmk +=================================================================== +--- VirtualBox-5.1.26.orig/src/VBox/ExtPacks/VBoxDTrace/Makefile.kmk ++++ VirtualBox-5.1.26/src/VBox/ExtPacks/VBoxDTrace/Makefile.kmk +@@ -103,7 +103,7 @@ if defined(VBOX_WITH_EXTPACK_VBOXDTRACE) + VBoxDTraceCmd_TEMPLATE = VBoxR3ExtPackDTrace + VBoxDTraceCmd_DEFS = RTMEM_WRAP_TO_EF_APIS VBOX_EXTPACK_VBOXDTRACE_MANGLED_NAME=\"$(VBOX_EXTPACK_VBOXDTRACE_MANGLED_NAME)\" + #VBoxDTraceCmd_DEFS += YYDEBUG +- VBoxDTraceCmd_DEFS.linux = _XOPEN_SOURCE=700 ++ VBoxDTraceCmd_DEFS.linux = _XOPEN_SOURCE=700 _DEFAULT_SOURCE + VBoxDTraceCmd_DEFS.win = YY_USE_PROTOS=1 YYENABLE_NLS=0 YYLTYPE_IS_TRIVIAL=0 + VBoxDTraceCmd_SDKS = VBOX_ZLIB + ifn1of ($(KBUILD_TARGET), win) diff --git a/virtualbox.changes b/virtualbox.changes index a7636f4..028d878 100644 --- a/virtualbox.changes +++ b/virtualbox.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Aug 7 10:24:42 UTC 2017 - schwab@suse.de + +- internal-headers.patch: fix invalid use of internal headers, enable + POSIX extensions + ------------------------------------------------------------------- Thu Aug 3 17:37:58 UTC 2017 - hpj@urpla.net diff --git a/virtualbox.spec b/virtualbox.spec index 2648eb0..808151e 100644 --- a/virtualbox.spec +++ b/virtualbox.spec @@ -105,6 +105,8 @@ Patch115: vbox_fix_for_gcc7.patch Patch116: Fix_for_server_1.19.patch # Fix for missing cleanup in KMS support Patch117: fix_KMS_support.patch +# Fix invalid use of internal headers +Patch118: internal-headers.patch # BuildRequires: LibVNCServer-devel BuildRequires: SDL-devel @@ -386,6 +388,7 @@ as an "extpack" for VirtualBox. The implementation is licensed under GPL. %patch115 -p1 %patch116 -p1 %patch117 -p1 +%patch118 -p1 #copy user manual cp %{SOURCE1} UserManual.pdf From c6ad50c18b092b595a3fc99885c8bc6d4a0f564dc76ef083ba3c1cc856ebe485 Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Mon, 7 Aug 2017 20:33:23 +0000 Subject: [PATCH 3/3] - Update vboxconfig.sh to fix problems noted in bsc#1042726 Disable pae build for 32-bit kernels. Added missing commands to keep mkinitrd from being called twice during installation of host kernel modules. bsc#105248. OBS-URL: https://build.opensuse.org/package/show/Virtualization/virtualbox?expand=0&rev=359 --- vboxconfig.sh | 26 +++++++++++++++++--------- virtualbox.changes | 7 +++++++ virtualbox.spec | 11 +++++++---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/vboxconfig.sh b/vboxconfig.sh index 7ca30d4..a5a7eb8 100644 --- a/vboxconfig.sh +++ b/vboxconfig.sh @@ -12,22 +12,30 @@ INCLUDE="/lib/modules/`uname -r`/build/include" # Test if vboxpci module loaded. If it is, skip everything else loaded=$(lsmod | grep vboxpci) if [ -n "$loaded" ] ; then - echo "Kernel modules available - exiting..." - exit 0 + echo "Kernel modules are loaded, unload them via" + echo "systemctl stop vboxdrv.service if you wish to rebuild them." + echo "Quitting .." + exit 1 fi # -# Force installation of VB host sources. Zypper will install all the prerequisies -echo "Installing all required packages..." -killproc PackageKit -zypper install -y virtualbox-host-source > /dev/null 2>&1 -if [ "$?" -ne 0 ] ; then - echo "Installation of required packages failed." - echo "Use 'sudo zypper install virtualbox-host-source' to see the reason." +# Check if virtualbox-host-source is installed, quit if not +if ! rpm -qf "$SOURCE/Makefile" &>/dev/null ; then + echo "Sources for building host modules are not present," + echo "Use 'sudo zypper install virtualbox-host-source' to install them. Quitting .." + exit 1 +fi +# +# Check if virtualbox-host-source version matches virtualbox version +if [ "$(rpm -q virtualbox virtualbox-host-source --queryformat='%{version}-%{release}\n' 2>/dev/null | sort -u | wc -l)" -ne "1" ] ; then + echo "virtualbox-host-source package version doesn't match" + echo "the version of virtualbox package." + echo "Reinstall virtualbox-host-source package. Quitting .." exit 1 fi # Prerequisites are available, start build pushd $SOURCE > /dev/null 2>&1 echo "Building kernel modules..." +make clean &>/dev/null make > $LOGFILE 2>&1 if [ "$?" -ne 0 ] ; then echo "" diff --git a/virtualbox.changes b/virtualbox.changes index 028d878..9ad6dc9 100644 --- a/virtualbox.changes +++ b/virtualbox.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Mon Aug 7 20:29:05 UTC 2017 - Larry.Finger@lwfinger.net + +- Update vboxconfig.sh to fix problems noted in bsc#1042726 + Disable pae build for 32-bit kernels. + Added missing commands to keep mkinitrd from being called twice during installation of host kernel modules. bsc#105248. + ------------------------------------------------------------------- Mon Aug 7 10:24:42 UTC 2017 - schwab@suse.de diff --git a/virtualbox.spec b/virtualbox.spec index 808151e..32187a1 100644 --- a/virtualbox.spec +++ b/virtualbox.spec @@ -240,7 +240,7 @@ websrv GUI part for %{name}. %package host-KMP Summary: Host kernel module for VirtualBox Group: System/Emulators/PC -%kernel_module_package -t %{_builddir}/virtualbox-kmp-template -p %{SOURCE7} -n %{name}-host -f %{SOURCE5} -x kdump um xen xenpae pv +%kernel_module_package -t %{_builddir}/virtualbox-kmp-template -p %{SOURCE7} -n %{name}-host -f %{SOURCE5} -x kdump um xen pae xenpae pv %description host-KMP This package contains the kernel-module for VirtualBox. @@ -249,7 +249,7 @@ This package contains the kernel-module for VirtualBox. %package guest-KMP Summary: Guest kernel modules for VirtualBox Group: System/Emulators/PC -%kernel_module_package -t %{_builddir}/virtualbox-kmp-template -p %{SOURCE8} -n %{name}-guest -f %{SOURCE6} -x kdump um xen xenpae pv +%kernel_module_package -t %{_builddir}/virtualbox-kmp-template -p %{SOURCE8} -n %{name}-guest -f %{SOURCE6} -x kdump um xen pae xenpae pv %description guest-KMP This package contains the kernel-module for VirtualBox. @@ -532,10 +532,13 @@ echo "entering virtualbox-kmp-guest and virtualbox-kmp-host install section" #################################################################################### export INSTALL_MOD_PATH=%{buildroot} export INSTALL_MOD_DIR=misc -#to install modules we use here similar steps like in build phase, go trought the all modules : +#Keep the install process from calling mkinitrd. The VB kernel modules are not in initrd. bsc#1052428 +export INITRD_IN_POSTTRANS=1 +export KMP_NEEDS_MKINITRD=0 +#to install modules we use here similar steps like in build phase, go through all the modules : for module_name in vbox{drv,netflt,pci,netadp,guest,sf,video} do - #and trought the all flavors + #and through the all flavors for flavor in %{flavors_to_build}; do #to install modules use Makefile from %{_prefix}/src/linux-obj/%_target_cpu/$flavor and builds from $PWD/modules_build_dir/$flavor/$module_name make -C %{_prefix}/src/linux-obj/%{_target_cpu}/$flavor modules_install M=$PWD/modules_build_dir/$flavor/$module_name