ShutDown Vbox before Shutting down Linux [solved] :-)
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
ShutDown Vbox before Shutting down Linux [solved] :-)
I have Windows 7 running as a virtual machine in seamless mode via Oracle VirtualBox with raw disk access.
Tis working so well that I may abandon VMware WorkStation.
I have one little nitpicking problem left:
When I shutdown Linux Mint, I need it to shutdown the Vbox Windows 7 virtual machine first.
Is there somewhere I can stuff a command in Linux Mint's Shutdown process ?
Linux Mint 19 Tara 64-bit, Kernel Linux 4.15.0-39-generic x86_64, MATE 1.20.1
Tis working so well that I may abandon VMware WorkStation.
I have one little nitpicking problem left:
When I shutdown Linux Mint, I need it to shutdown the Vbox Windows 7 virtual machine first.
Is there somewhere I can stuff a command in Linux Mint's Shutdown process ?
Linux Mint 19 Tara 64-bit, Kernel Linux 4.15.0-39-generic x86_64, MATE 1.20.1
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
- AZgl1800
- Level 20
- Posts: 11178
- Joined: Thu Dec 31, 2015 3:20 am
- Location: Oklahoma where the wind comes Sweeping down the Plains
- Contact:
Re: ShutDown Vbox before Shutting down Linux
I find it far safer to shutdown VB first, and then tell Linux to shutdown.
but, you could write a bash script to do the job, but I don't know how.
but, you could write a bash script to do the job, but I don't know how.
Re: ShutDown Vbox before Shutting down Linux
I think that I can write the script to shutdown windows and the virtual box ....
I just need to know where to put it so that it gets executed when Mint starts to shut down.
You Tube video demo: https://youtu.be/Obqn7ZjFN0g
This is a short demo of a multi-boot system with Windows 7, Linux Mint 19 Tara and Ubuntu Mate 18.10. The unique feature is that the Windows 7 OS can be booted on native hardware or run as a virtual Machine under the Linux Mint OS. Ubuntu Mate is only used for doing image backups of the other two operating system disk partitions. It is still a work in progress.
I just need to know where to put it so that it gets executed when Mint starts to shut down.
You Tube video demo: https://youtu.be/Obqn7ZjFN0g
This is a short demo of a multi-boot system with Windows 7, Linux Mint 19 Tara and Ubuntu Mate 18.10. The unique feature is that the Windows 7 OS can be booted on native hardware or run as a virtual Machine under the Linux Mint OS. Ubuntu Mate is only used for doing image backups of the other two operating system disk partitions. It is still a work in progress.
Last edited by lewtwo on Sun Nov 18, 2018 3:23 am, edited 1 time in total.
- AZgl1800
- Level 20
- Posts: 11178
- Joined: Thu Dec 31, 2015 3:20 am
- Location: Oklahoma where the wind comes Sweeping down the Plains
- Contact:
Re: ShutDown Vbox before Shutting down Linux
Use a keyboard custom shortcut to run your script.
Have the final line of your script execute a terminal command
I have control-alt-o setup now to do a shutdown
Have the final line of your script execute a terminal command
shutdown now
I have control-alt-o setup now to do a shutdown
Re: ShutDown Vbox before Shutting down Linux
I am building the system for another user.
It needs to use the standard UI.
This is the command to shut it down (gracefully):
It needs to use the standard UI.
This is the command to shut it down (gracefully):
virtualbox controlvm Windows7 acpipowerbutton
Re: ShutDown Vbox before Shutting down Linux
Or add a launcher to the desktop or panel or menu.Use a keyboard custom shortcut to run your script
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Re: ShutDown Vbox before Shutting down Linux
The concept here is:
If the user tells Linux mint to shutdown without shutting down VBox first then do a proper shutdown anyway.
There is a option of start up programs. Why not an equivalent option for shutdown ... it is much more critical than start up.
If the user tells Linux mint to shutdown without shutting down VBox first then do a proper shutdown anyway.
There is a option of start up programs. Why not an equivalent option for shutdown ... it is much more critical than start up.
Re: ShutDown Vbox before Shutting down Linux
I'm used an init sys v system and not this systemd related stuff, but you could try putting a script in /etc/rc0.d and /etc/rc6.d for shutting down the vm's. VirtualBox has a script in both directories already called K01virtualbox. Just makes sure it has a name that is before that one, like K01ShutdownVMs or something that gets executed before K01virtualbox.
Re: ShutDown Vbox before Shutting down Linux
Yes you can, but it means messing around with systemd, and from memory, I don't think you can control the order that processes shut down, so for example, your partitions may get unmounted before your script executes to shut down Vbox. For this reason, when I had a similar requirement, I wrote a script that did what I wanted and then shut the system down.There is a option of start up programs. Why not an equivalent option for shutdown ... it is much more critical than start up.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Re: ShutDown Vbox before Shutting down Linux
That was what I was looking for. By the way this systems does not have anything for virtualbox in rc0.d or rc6.d.bassplayer wrote: ⤴Sun Nov 18, 2018 8:16 am I'm used an init sys v system and not this systemd related stuff, but you could try putting a script in /etc/rc0.d and /etc/rc6.d for shutting down the vm's. VirtualBox has a script in both directories already called K01virtualbox. Just makes sure it has a name that is before that one, like K01ShutdownVMs or something that gets executed before K01virtualbox.
Anyway that is the easy part.
As I am running the Windows 7 VM with raw disk access I first need to go mess with "sudoers ".
Both the VM startup and VM shutdown require root authority.
Re: ShutDown Vbox before Shutting down Linux
This is what I have in /etc/rc0.dlewtwo wrote: ⤴Sun Nov 18, 2018 9:42 amThat was what I was looking for. By the way this systems does not have anything for virtualbox in rc0.d or rc6.d.bassplayer wrote: ⤴Sun Nov 18, 2018 8:16 am I'm used an init sys v system and not this systemd related stuff, but you could try putting a script in /etc/rc0.d and /etc/rc6.d for shutting down the vm's. VirtualBox has a script in both directories already called K01virtualbox. Just makes sure it has a name that is before that one, like K01ShutdownVMs or something that gets executed before K01virtualbox.
Anyway that is the easy part.
As I am running the Windows 7 VM with raw disk access I first need to go mess with "sudoers ".
Both the VM startup and VM shutdown require root authority.
Code: Select all
...
lrwxrwxrwx 1 root root 17 Sep 27 13:40 K01openvpn -> ../init.d/openvpn
lrwxrwxrwx 1 root root 18 Sep 27 13:40 K01plymouth -> ../init.d/plymouth
lrwxrwxrwx 1 root root 17 Sep 27 13:40 K01rsyslog -> ../init.d/rsyslog
lrwxrwxrwx 1 root root 15 Sep 27 13:40 K01saned -> ../init.d/saned
lrwxrwxrwx 1 root root 27 Sep 27 13:40 K01speech-dispatcher -> ../init.d/speech-dispatcher
lrwxrwxrwx 1 root root 15 Sep 27 13:40 K01uuidd -> ../init.d/uuidd
lrwxrwxrwx 1 root root 20 Sep 27 14:43 K01virtualbox -> ../init.d/virtualbox
bassplayer@Gonzo:/etc/rc0.d$
Re: ShutDown Vbox before Shutting down Linux
Always had a habit of shutting down all running programs before shutting down the OS. Probably from my Windoz years
Re: ShutDown Vbox before Shutting down Linux
That would be a negatory.bassplayer wrote: ⤴Sun Nov 18, 2018 11:38 am Do you have the file /etc/init.d/virtualbox ?? As it seems like they are all links to the /etc/init.d folder.
Re: ShutDown Vbox before Shutting down Linux
At one point when I was in IT we had a check list posted on the wall of the server room.
It listed the shutdown order of all applications, servers, network switches, routers, UPSs, etc.
That was back when that required physically switching the power off some of those.
There was another for start up.
Also when I was in IT I learned to expect the operator to never do as they were instructed.
Hope for the best but plan for the worst.
Re: ShutDown Vbox before Shutting down Linux
The script turned out to be a tad bit more complicated.
So for posterity's sake:
So for posterity's sake:
Code: Select all
#!/bin/bash
# file ~/bin/Wind7ShutDown
# create a 'pause' function, used in debugging
function pause () {
read -p "$*"
}
#
# This takes advantage of a line added to the file /etc/sudoers
# username ALL = NOPASSWD: /usr/bin/VirtualBox, /usr/bin/virtualbox, /usr/bin/vboxmanage
# This also assumes only ONE running VM
#
# sudo vboxmanage list runningvms
# "Windows7" {82dc1d4c-e680-4dd6-a2cd-d345bdf2d91d}
#
VM=$(sudo -u root vboxmanage list runningvms)
# test if we have a string that is not empty
if [[ $VM = *[!\ ]* ]]; then
# extract the part of the string after '{'
VM=${VM#*'{'}
# Strip off the last characte '}'
VM=${VM:0:$((${#VM} - 1))}
# shut down the virtual machine via the UUID
sudo -u root vboxmanage controlvm $VM acpipowerbutton
# wait for it ...
sleep 3s
VM=$(sudo -u root vboxmanage list runningvms)
while [[ $VM = *[!\ ]* ]]; do
# echo $VM
sleep 3s
VM=$(sudo -u root vboxmanage list runningvms)
done
fi
Re: ShutDown Vbox before Shutting down Linux
All I can say is ... AMENlewtwo wrote: ⤴Sun Nov 18, 2018 1:11 pmAt one point when I was in IT we had a check list posted on the wall of the server room.
It listed the shutdown order of all applications, servers, network switches, routers, UPSs, etc.
That was back when that required physically switching the power off some of those.
There was another for start up.
Also when I was in IT I learned to expect the operator to never do as they were instructed.
Hope for the best but plan for the worst.