Waiting for VirtualBox guests to close before reboot or shutdown

See this and this. Basically:

vim /etc/init.d/virtualbox
chmod +x /etc/init.d/virtualbox
update-rc.d virtualbox defaults

The /etc/init.d/virtualbox script should look like this:

#!/bin/sh

# 2017-08-07 jj5 - SEE: How make Debian wait for all VirtualBox guests to
# stop during shutdown/reboot?: https://superuser.com/a/929292/615689

### BEGIN INIT INFO
# Provides:          virtualbox_start_and_stop
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: 
# Description:       Start virtualbox on boot, and shutdown safely on shutdown/reboot.
### END INIT INFO

case "$1" in
  start)
    echo "Starting Virtualbox "

    # Do whatever to start or resume your virtualbox instances.
    # Perhaps look for a txt file someplace with VMs that need to be
    # restarted or resumed... then start 'em.
    ;;
  stop)
    echo "Stopping Virtualbox"

    # Do something to either shutdown or savestate your virtualbox instances.
    # maybe also save the instances that should be resumed into a txt file
    # someplace for the start method above.

    # 2017-08-07 jj5 - SEE:
    # https://askubuntu.com/a/457564

    # 2017-08-07 jj5 - NOTE: You should make sure that ACPI Shutdown actually
    # shuts down the guest...
    # 2017-08-07 jj5 - SEE: Force Ubuntu Desktop to shutdown on power button:
    # https://www.progclub.org/blog/2017/08/07/force-ubuntu-desktop-to-shutdown-on-power-button-keypress-acpi-shutdown/

    while [ -n "$( sudo -u jj5 VBoxManage list runningvms )" ]; do

      sudo -u jj5 VBoxManage list runningvms \
        | sed -r 's/.*\{(.*)\}/\1/' \
        | xargs -L1 -I {} sudo -u jj5 VBoxManage controlvm {} acpipowerbutton;

      sleep 1;

    done;

    ;;
  *)
    echo "Usage: /etc/init.d/virtualbox {start|stop}"
    exit 1
    ;;
esac

exit 0

You may also need to Force Ubuntu Desktop to shutdown on power button keypress

VirtualBox VBoxManage for autostart

I have a script tact:/etc/vbox/register-autostart.sh which will register a VirtualBox VM for auto-start. It required other config in /etc/vbox the details of which I don’t remember, but I think it’s done now anyway… there’s more information in Starting virtual machines during system boot.

  online "$machine" && {

    report "halting machine '$machine'...";

    ssh "$machine" sudo poweroff;

    report "waiting a moment...";

    sleep 8;

  };

  run VBoxManage modifyvm "$machine" --autostart-enabled on;

  run sudo service vboxautostart-service restart;

Adding weekday to Date column in Dolphin in KDE on Debian GNU/Linux

cd /usr/share/i18n/locales
cp en_AU en_JJ
vim en_JJ

Change metadata:

title      "English locale for John Elliot V"
language   "John's English"

And prefix d_fmt with:

d_fmt "<U0025><U0061><U0020>

Then:

sudo localedef -f UTF-8 -i en_JJ en_JJ.UTF-8

Then:

vim /etc/environment

add add:

LC_TIME="en_JJ.UTF-8"

rsync: unexpected remote arg

So I was getting a baffling “unexpected remote arg” error from rsync today. Eventually I figured out the problem was that my argument “–executability” had become “– executablility”, I think due to a copy and paste problem where I copied some shell script code from Vim in a Konsole terminal into another Vim in another Konsole terminal. Traps for young players! If you get baffled by this error try putting an ‘echo’ in front of the command and then resize your terminal window to see if that affects things…

Enabling TRIM in Debian fstab for ext4 file-system on Samsung SSD 960 EVO NVMe M.2

So I was trying to find why in my Debian 9 system my SATA drives are called SCSI devices, and I was reading Why my SATA drive is identified as a SCSI device in Device Manager where I read:

The Intel Rapid Storage driver version 12.6 (Released in March 2013) and newer versions classify all drives as SCSI devices for uniformity. This (and later) versions of the driver also allow for TRIM support (Allows for management of data blocks no longer in use) in SSD drives in RAID 0 arrays and other flexibility in operation of storage devices.

So I’d never heard of “TRIM” so I searched for that and found the Wikipedia Trim (computing) article, but Why SSD TRIM Support is So Important and How to Enable It caught my eye, because, “important” you say?

So that article about the importance of TRIM was for Windows, so I searched again and found How to properly activate TRIM for your SSD on Linux: fstrim, lvm and dm-crypt which suggested things were a bit complicated for LVM (and MD RAID?).

I ended up reading How to set up SSD raid and TRIM support? which sent me to Re: Best way (only?) to setup SSD’s for using TRIM which argued that perhaps TRIM configuration wasn’t necessary at all.

It was then I realised that I probably don’t care about TRIM on my MD RAID SSD drives, but I probably do on my M.2 SSD, which isn’t using MD RAID, but which gets massive tgz files written to it and deleted from it every day. So some more searching and I found Samsung SSD 960 EVO NVMe M.2 Review: Ultra Fast, Affordable Storage which said TRIM was supported:

Supporting features: TRIM (Required OS support), Garbage Collection, S.M.A.R.T

So then I found Enable TRIM On SSD (Solid-State Drives) In Ubuntu For Better Performance which showed me how to enable TRIM in /etc/fstab. So the relevant fstab line was:

# /data/fast was on /dev/nvme0n1p1 during configuration
UUID=87bcc5fa-9261-404b-8bc7-a214f4651b49 /data/fast      ext4    noatime,discard 0       2

Note the ‘discard’ option, that’s where the magic happens.

So I unmounted and remounted the partition,

root@tact:/home/jj5# umount /data/fast
root@tact:/home/jj5# mount /data/fast

And dmesg indicated the discard option had been applied:

[34783.251592] EXT4-fs (nvme0n1p1): mounted filesystem with ordered data mode. Opts: discard

Now I guess we wait and see if my performance issues improve…

Configuring Akonadi for Thunderbird Maildir access

I read this and this.

Then I installed the Akonadi console:

root@tact:/home/jj5# apt-get install akonadiconsole

I opened it from K -> Applications -> Development -> Akonadi Management and Debugging Console.

Then in it I selected Agents -> Local Folders.

Then I changed: /home/jj5/.local/share/akonadi_maildir_resource_0 to my ‘important’ Thunderbird ImapMail directory.