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…

Airgap file-system

So I needed to create a file-system to house a handful of archive/backup tarballs (around 40 of them). I created an ext4 file-system with 100 inodes, like this:

# mkfs.ext4 -b 4096 -L airgap -m 0 -N 100 -v /dev/sdc1

Note: 100 inodes isn’t very many! Only supports up to 100 files/folders. Also note that 0% space is reserved for root. If you’re copying the above command make sure you replace /dev/sdc1 with an appropriate partition device.

Registering a systemd Service

So today I read How To Set Up VNC Server on Debian 8 which had a section on creating and registering the requisite scripts:

/usr/local/bin/myvncserver (make sure it’s executable with +x):

#!/bin/bash
PATH="$PATH:/usr/bin/"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
case "$1" in
start)
/usr/bin/vncserver ${OPTIONS}
;;
stop)
/usr/bin/vncserver -kill :${DISPLAY}
;;
restart)
$0 stop
$0 start
;;
esac
exit 0

/lib/systemd/system/myvncserver.service:

[Unit]
Description=VNC Server example

[Service]
Type=forking
ExecStart=/usr/local/bin/myvncserver start
ExecStop=/usr/local/bin/myvncserver stop
ExecReload=/usr/local/bin/myvncserver restart
User=vnc

[Install]
WantedBy=multi-user.target

Then to register and start:

systemctl daemon-reload
systemctl enable myvncserver.service
systemctl start myvncserver.service

fs.inotify.max_user_watches

I had an error tailing my web logs, like this:

==> test.jj5.net-error.log <==
tail: inotify resources exhausted
tail: inotify cannot be used, reverting to polling

I found tail: “inotify resources exhausted” and/or “inotify cannot be used, reverting to polling: Too many open files” which said to edit /etc/sysctl.conf with:

#
# 2017-05-03 jj5 - SEE: tail inotify resources exhausted:
# https://nefaria.com/2014/08/tail-inotify-resources-exhausted/
#
fs.inotify.max_user_watches=1048576

Then to apply the new settings:

# sysctl -p

Disable middle mouse button (paste) on Debian KDE

Every now and again I will accidentally click the middle mouse button when I go to grab my mouse, and KDE will dump my clipboard buffer into a BASH shell. Not good. Could run something damaging if I’m unlucky. So see here for the solution. Basically run this to get the mouse device ID:

xinput list | grep 'id='

Then to edit e.g. device 10 to disable middle mouse button:

xinput set-button-map 10 1 0 3

To persist the changes add the set-button-map command to e.g. ~/.xstartup.

Or you can add a pointer configuration to ~/.Xmodmap like this:

pointer = 1 0 3 4 5 6 7 8 9 10

And make sure xmodmap is applied at start-up with an autostart file like e.g. ~/.config/autostart/mouse-config.desktop:

[Desktop Entry]
Type=Application
Name=mouse-config
Comment=Disables middle mouse button.
Exec=xmodmap /home/jj5/.Xmodmap

Disabling F6 ‘Run Main Project’ hot key in NetBeans because of G15 keyboard

I have a G15 keyboard, and I love it (but not as much as the old model!), but it occasionally causes a problem for me when I’m programming in NetBeans on Debian GNU/Linux.

The issue is that on a newer G15 the G6 key is right near the Ctrl key, and from time to time my pinky hits the G6 key which seems to be by default programmed to be the F6 key.

By default in NetBeans the F6 key is the ‘Run Main Project’ hot key, so when I accidentally press it, it fires up a Firefox window and tries to run my web app! I never configure my web apps in NetBeans, but even if I did, I don’t want to accidentally run anything due to an accidental key press.

So my solution was to disable F6 in NetBeans, and for that:

Tools -> Options -> Keymap -> Click ‘Search in Shortcuts’ -> Press F6 -> Click on the ‘…’ in the Shortcut cell for ‘Run Main Project’ (should be F6) -> Clear -> Apply -> And you’re done!

Everything is easy when you know how!

Installing latest version of Scala on Debian

So this is basically a combination of this and this:

sudo apt-get purge scala
sudo apt-get autoremove

cd ~/desktop/scala
wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.tgz
tar xzf scala-2.11.8.tgz
sudo mv scala-2.11.8 /usr/share/scala

sudo ln -s /usr/share/scala/bin/scala /usr/bin/scala
sudo ln -s /usr/share/scala/bin/scalac /usr/bin/scalac
sudo ln -s /usr/share/scala/bin/fsc /usr/bin/fsc
sudo ln -s /usr/share/scala/bin/sbaz /usr/bin/sbaz
sudo ln -s /usr/share/scala/bin/sbaz-setup /usr/bin/sbaz-setup
sudo ln -s /usr/share/scala/bin/scaladoc /usr/bin/scaladoc
sudo ln -s /usr/share/scala/bin/scalap /usr/bin/scalap

Everything is easy when you know how!