Linux, Unix, and whatever they call that world these days

Dual Boot Clock Shenanigans

Probably the most annoying thing when dual booting Windows and Linux is the clock. For the various reasons, Windows keeps BIOS clock in local time-zone while Linux prefers it as UTC. While this is not a problem in Reykjavík, it surely is everywhere else.

There are ways to make Windows run in UTC but they either don’t work with the latest Windows 10 or they require time synchronization to be turned off. As I value precise time, a solution on Linux side was needed.

Fortunately, Linux does offer setting for just this case. Just run the following command:

sudo timedatectl set-local-rtc 1 --adjust-system-clock

This will tell Linux to keep local clock in RTC. While this is not necessarily fully supported, I found it’s actually the only setting that reliably works when dual booting Windows 10.

PS: You might need a reboot or two before this takes effect.

Avoiding Select Audio Device Prompt on Dell XPS 15 under Ubuntu

Illustration

As a headphone user I find nothing more annoying than computer asking me every single freaking time what exactly did I plug in. While Windows drivers for Dell XPS 15 audio do allow you to select default, one is not so lucky under Linux.

However, Linux being configurable to a fault does offer a workaround.

You can append the following options to the end of /etc/modprobe.d/alsa-base.conf, followed by a reboot:

options snd-hda-intel model=headset-mic

This will lie a bit to sound driver and stop the darn questions.


PS: You can also use this one liner:

echo "options snd-hda-intel model=headset-mic" | sudo tee -a /etc/modprobe.d/alsa-base.conf

Installing DropBox on ZFS

While I already wrote about expanding DropBox’s Ext4 volume on ZFS, I never actually wrote how to create one in the first place. I guess it’s time to fix that injustice.

First you need to create a volume of sufficient size. While you can just make it as big as your Dropbox allowance is, I would advise going with at least double of that. Not only this helps if you are doing ZFS snapshots (remember it’s copy-on-write) but it also helps if you are moving files around as Dropbox fully releases space only once the new files are created.

Whatever you decide, you need to create a volume and format it:

sudo zfs create -V 12G ^^pool^^/dropbox
sudo mkfs.ext4 /dev/zvol/^^pool^^/dropbox

Once volume is created, mounting the newly created volume within our user directory is in order:

mkdir /home/^^user^^/Dropbox
sudo mount /dev/zvol/^^pool^^/dropbox /home/^^user^^/Dropbox
sudo chown -R ^^user^^:^^user^^ Dropbox

Of course, to retain it between reboots one should add it to fstab:

echo "/dev/zvol/^^pool^^/dropbox /home/^^user^^/Dropbox ext4 defaults,_netdev 0 0" | sudo tee -a /etc/fstab

Do note the _netdev part as it ensures dropbox volume is mounted way after ZFS has already done so. Without it you might have a race condition and volume mounting might prevent subpools to be mounted under the same path.

Finally you can install Dropbox as you usually would. While it will complain about directory already being present, you can simply cancel directory selection and it will start syncing regardless.

Congratulations, your Dropbox is now on ZFS.

DaVinci Resolve and MP4 under Linux

If you try to import mp4 file to DaVinci Resolve under Linux, you will be greeted with audio-only experience if you’re lucky or nothing at all if you’re not. Unless you’re paying customer of DaVinci Resolve Studion, MP4 and AAC are not supported at all.

Conversion to an intermediate format is needed and good old ffmpeg can help here:

ffmpeg -i ^^input.mp4^^ \
    -c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p \
    -c:a pcm_s16le \
    -f mov ^^output.mov^^

Here I use DNxHR with HQ settings. Even this will generate file that’s much bigger than source. How much bigger depends on the source, but don’t be surprised to see it grow 16-fold or even higher.

Smaller alternative can be MPEG4 format but with a drop in quality even at its best settings:

ffmpeg -i ^^input.mp4^^ \
    -c:v mpeg4 -qscale:v 1 \
    -c:a pcm_s16le \
    -f mov ^^output.mov^^

These files can now be used as input to Resolve and editing can commence.

Once done with rendering a conversion to MP4 might be in order again. For this I use settings discussed on Video StackExchange. While the original discussion was for YouTube, I find their recommendations quite good as a starting point:

$ ffmpeg -i ^^render.mov^^ \
    -c:v libx264 -pix_fmt yuv420p -crf 16 \
    -force_key_frames 'expr:gte(t,n_forced/2)' -bf 2 \
    -vf yadif -use_editlist 0 \
    -movflags +faststart \
    -c:a aac -q:a 1 \
    -ac 2 -ar 48000 \
    -f mp4 ^^out.mp4^^

Mind you, all my cameras use YUV 4:2:0 and I don’t do any major editing so increasing YUV to 4:2:2 or even 4:4:4 makes no sense nor does increase to 10-bit resolution. Depending on which equipment you have, your mileage may vary.

Installing DaVinci Resolve on Ubuntu Dell XPS

When I first installed DaVinci Resolve on my Dell XPS under Ubuntu 19.04 I was greeted with stuck splash screen. What was I missing?

Well, the first issue was missing OpenCL. Fortunately that was easy to solve:

sudo apt install ocl-icd-opencl-dev

Other issue was missing nVidia driver. For some reason Resolve really dislikes nouveau driver. Therefore we have to upgrade driver a bit. I found that auto-install works perfectly for me:

sudo ubuntu-drivers autoinstall

Those who like to be more precise can always check which drivers are available and install only those:

ubuntu-drivers devices
 == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
 modalias : pci:v000010DEd00001C8Dsv00001028sd000007BEbc03sc02i00
 vendor   : NVIDIA Corporation
 model    : GP107M [GeForce GTX 1050 Mobile]
 driver   : nvidia-driver-390 - distro non-free
 driver   : nvidia-driver-418 - distro non-free recommended
 driver   : xserver-xorg-video-nouveau - distro free builtin

sudo apt install nvidia-driver-418

With these two changes my DaVince Resolve can finally start properly.


PS: Interestingly, installing non-free nVidia driver solved Ubuntu getting stuck booting after incorrect password got entered.

Switching to Linux Desktop?

I’ve been playing with Linux/Unix servers for a long time now - both at work and home. I even switched almost completely to Linux at work - Outlook and Excel being the only reason why I still have Windows VM. However, at home I still used Windows 10 as my main OS. With Linux Desktop getting better and better while Windows 10 is getting more and more annoying, I figured I need to revisit installing Linux at home too.

And no, I didn’t go full-in. However, for the first time in the last 10 years I am dual booting again.

Ubuntu with ZFS was Linux of my choice primarily because of the ZFS support. Running ZFS on my NAS has been a pure joy (as much as any file system can be) and that’s what moved needle from Linux Mint toward Ubuntu. Other benefits include a huge install base and prepackaged software support.

While Linux is rather enjoyable, I don’t see Windows going away from my computer for a while. And the major reason is Visual Studio - there is simply nothing equivalent for C# development. Visual Studio Code does try but that’s like saying butcher is an equivalent of a surgeon. It’s simply a difference between IDE and really good text editor.

While running under Wine is an option, DipTrace still works better under Windows. And this goes for the whole “electronics tools” category. Whether it’s MPLAB (which actually has a Linux version), PicoScope (Linux version in beta), or just some stupid utility, making it work under Windows is simply easier with less issues present.

Another stumbling point was Vegas Movie Studio in particular and media editing in general. These applications are few and far between. I did find DaVinci Resolve to be actually extremely powerful and free alternative. It definitely has a steeper learning curve and does require a bit of getting used to. However, at this moment it actually doesn’t support H.264 and MP4 file format under Linux. :(

I am still looking for a good alternative to Paint.NET as Gimp doesn’t really work for me. It’s excellent software if you need to do a major work, but it’s really annoying when it comes to simple operations. As Windows 10 image viewer is pure shit, I didn’t need to search long to find a substitute.

WinRAR was another stupidly simple utility that doesn’t really work properly under Linux. Yes, you can get other archivers but there is nothing that really offers the same features; archive locking and preview without extracting to temporary directory being my favorites.

And lastly, there is nothing as good on Linux as Explorer. Yes, Nautilus does come close when it comes to pure file browsing but just trying to do something in Open and Save dialog brings tears to my eyes. No, there is no rename, full right-click menu, or even pasting file there. Nope, you can just open and save files. As I often remember things I want to adjust only when saving other file, this seems overly restricting.

End result is that for Visual Studio, electronics, and gaming I still use Windows. For all other purposes I simply switch to Linux as my preferred environment. It’s something I wouldn’t believe just a few years ago - oh, how times change.


PS: If you’re curious as to what I find annoying in Windows 10, here are the first couple of things coming to mind without any specific order: Windows update reboots my computer overnight time and time again, every major update randomly resets my settings, local account requires THREE damn password reminders, it keeps forgetting my damn network credentials (despite checking the “remember” checkbox), Start menu cannot find applications that are freshly installed, damn settings are distributed between multiple apps and programs with each holding some settings, it uses every opportunity to shove Edge and Skype app down my throat, and the list goes on.

Configuring HTTP/2 for WordPress on Ubuntu

I moved my website to Ubuntu just recently and big part of that was due to desire for HTTP/2. However, if you have a legacy site configuration, things might not be as straightforward as one would hope.

The first step, of course, is enabling HTTP/2 module:

a2enmod http2

Second step is adding HTTP/2 protocol definition to /etc/apache2/apache2.conf:

Protocols h2 h2c http/1.1
H2Direct on
H2ModernTLSOnly on

Followed by Apache’s restart:

systemctl restart apache2

In ideal world this would be it. But, despite Apache starting without error, a check via Developer Tools in browser showed I was still stuck with HTTP 1.1. Yep, as many other sites, mine used mpm_prefork module. Unfortunately, prefork is not compatible with HTTP/2 and PHP 7.2 (needed for WordPress) is not compatible with anything else.

The only additional package we need is PHP with FastCGI support:

apt-get install php7.2-fpm

Furthermore, we need some modules enabled and disabled:

a2dismod php7.2
a2dismod mpm_prefork
a2enmod mpm_event
a2enmod proxy_fcgi
a2enconf php7.2-fpm

Of course, addition to /etc/apache2/apache2.conf is needed too:

<Files "*.php">
   SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
</Files>

If you configured prefork same as me, you also need to remove it’s configuration. In my case StartServers, MinSpareServers, MaxSpareServers, MaxClients, and MaxRequestsPerChild settings had to go.

Of course, another Apache restart is upon us:

systemctl restart apache2

Congratulations! HTTP/2 should be working now.

Moving Blog from CentOS 7 to Ubuntu 19.04

With WordPress 5.2 I decided to leave my CentOS 7 installation as it required PHP 5.6.20 or higher and my CentOS only had 5.4.16. Yes, I could have manually upgraded PHP from alternative CentOS repositories but I decided not to. While CentOS has been stable for me and I had pretty much no issues with it, that stability came at the cost of slow or non-existent new features. Biggest example being stuck in pre-HTTP2 times.

It took me a while to decide which distribution to use as a replacement, the final candidates being Debian and Ubuntu. While I was really tempted to go with Debian due to its reputation, I decided to go with Ubuntu at the end. It was due to frequency of updates more than anything else. After sticking with CentOS for so long, I wanted something more dynamic.

Most of my setup scripts needed just a simple replacement of yum with apt-get, the only major hurdle presented switching from CentOS Apache (httpd) to Ubuntu’s Apache (apache2). Despite both being 2.4, differences were significant enough that I couldn’t just move my config files. So I went with true and tested way of gradually modifying my config file until I could actually start Apache.

The first hurdle was how to install it. My CentOS installation used httpd mod_ssl php php-mysql, and php-gd packages. The equivalent Ubuntu setup consisted of apache2 php php-mysql php-gd. Essentially only the SSL package was missing from list and only because Apache2 already contained it.

The first error appeared with User and Group setting. While CentOS uses apache, the Ubuntu needs www-data. Remember that you need to change this not only in config file but that a chown or two might be needed.

The biggest issue were includes. On CentOS I used the following collections:

Include conf.modules.d/00-base.conf
Include conf.modules.d/00-mpm.conf
Include conf.modules.d/00-ssl.conf
Include conf.modules.d/00-systemd.conf
Include conf.modules.d/10-php.conf

On Ubuntu there is no equivalent. One has to either use wildcards to load all or list each include separately. Since list of enabled modules is rather conservative, I decided to use wildcards:

Include mods-enabled/*.load
Include mods-enabled/*.conf
Include conf-enabled/*.conf

Due to aforementioned conservative list of enabled modules, I had to enable a few more:

a2enmod autoindex
a2enmod expires
a2enmod headers
a2enmod rewrite
a2enmod ssl
a2enmod socache_shmcb
a2enmod php7.2

And yes, this is not strictly speaking equivalent of CentOS configuration but it’s close enough for my WordPress installation. Depending on your exact setup, you might need to enable a few more (or choose to skip some).

The last change I had to do was for firewall. As Ubuntu uses ufw, the following commands were needed to allow traffic through:

ufw allow 'Apache'
ufw allow 'Apache Secure'
sudo ufw reload

And now my WordPress runs on Ubuntu. :)

Remembering the Last Grub OS

If you are dual booting Linux and Windows, you might want to have Grub automatically select the last booted OS instead of just going with the default. The whole trick rests on adding just two lines to /etc/default/grub:

GRUB\_DEFAULT=saved GRUB\_SAVEDEFAULT=true

Of course that has to be followed by update-grub:

sudo update-grub

Now Grub will track which OS you booted last and preselect that menu entry.

PS: If you have custom menu entries, do not forget that you need to have savedefault option present.

Adding UEFI Windows 10 Menu Entry to Grub

If you install Ubuntu first and Windows later, you’ll notice that it’s not possible to boot into Linux anymore. As Windows boot loader doesn’t really handle Linux, you’ll need to tell Windows to use Grub.

Once you’re in command prompt with administrative privileges, you can execute:

BCDEDIT /set {bootmgr} path \EFI\Ubuntu\grubx64.efi

After reboot Grub will show it’s ugly face and you’ll have another problem - there are no Windows entries.

To get them into Grub menu, one can simply update grub:

sudo update-grub

On most Linux distributions this will trigger OS Prober and Windows Boot Manager entry will magically appear. However, if you have OS Prober disabled or you want to disable it in future for some reason, you can add manual entry too:

cat << EOF | sudo tee /etc/grub.d/25_windows
#!/bin/sh
exec tail -n +3 \$0
menuentry 'Windows 10' {
  savedefault
  search --no-floppy --set=root --file /EFI/Microsoft/Boot/bootmgfw.efi
  chainloader (\${root})/EFI/Microsoft/Boot/bootmgfw.efi
}
EOF

sudo chmod +x /etc/grub.d/25_windows

sudo update-grub

In either case, boot menu should now offer you option to get into Windows.