How To: Disable Sleep on Ubuntu Server

Ubuntu 19.10

You may remember that I have a small automation server in my home office that’s running Ubiquiti UniFi Controller software and where I upgraded UniFi Controller on Ubuntu 19.04.

I noticed that this server hasn’t been terribly available since upgrade to Ubuntu 19.04: more than once I went looking for the server and it was offline.

Now that I’m finally progressing with centralized RSyslog setup at home, I noticed that the UniFi controller server was reporting the following in logs recently:

So, it appears the power management has improved enough to start bringing this server to sleep every hour or so.

Since this is a recent enough version of Ubuntu, I figured there should be a way to disable power management using systemctl. Turns out, there is.

Confirm Sleep Status with systemd

IMPORTANT: I didn’t run this command on server, so this is example from another system: I’m running it on my XPS laptop with Ubuntu, just to show you expected output.

As you can see, my laptop rests well and often:

greys@xps:~ $ systemctl status sleep.target
 ● sleep.target - Sleep
    Loaded: loaded (/lib/systemd/system/sleep.target; static; vendor preset: enabled)
    Active: inactive (dead)
      Docs: man:systemd.special(7)
 Feb 24 13:18:08 xps systemd[1]: Reached target Sleep.
 Feb 26 13:29:31 xps systemd[1]: Stopped target Sleep.
 Feb 26 13:29:57 xps systemd[1]: Reached target Sleep.
 Feb 26 13:30:19 xps systemd[1]: Stopped target Sleep.

Disable Sleep in Ubuntu with systemd

This is what I did on my server:

root@server:/ # sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
 Created symlink /etc/systemd/system/sleep.target → /dev/null.
 Created symlink /etc/systemd/system/suspend.target → /dev/null.
 Created symlink /etc/systemd/system/hibernate.target → /dev/null.
 Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
 root@server:/etc/pm/sleep.d#

This is obviously a very simple way of disabling power management, but I like it because it’s standard and logical enough – there’s no need to edit config files or create cronjobs manually controlling sleep functionality.

The service is dead, no power management is happening and most importantly, my server has been up for 12 hours now.

greys@server:~$ systemctl status sleep.target
● sleep.target
   Loaded: masked (Reason: Unit sleep.target is masked.)
   Active: inactive (dead)

(re) Enabling Sleep in Ubuntu with systemctl

When the time comes and I would like to re-enable power management and sleep/hibernation, this will be the command I’ll run:

root@server:/etc/pm/sleep.d# sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

That’s all for now. Have a great day!

See Also




Install Sublime Text 3 in Ubuntu

Editing Markdown file in Sublime Text 3 on Linux

Pretty cool! Didn’t realise this, but Sublime Text 3 is available for Linux as well! Today I took a few minutes to download/install it and to even make it use some of the GUI themes for better coding experience.

All of these steps are taken from the Sublime Text 3 website.

Step 1: Activate Sublime Text 3 repo

First, we install the key to trust Sublime Text 3 repo:

greys@xps:~ $ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
 [sudo] password for greys: 
 OK

Now we ensure apt-get will support https protocol for working with repos:

greys@xps:~ $ sudo apt-get install apt-transport-https

We update apt sources with the repo URL:

greys@xps~ $ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Step 2: Install Sublime Text 3

We refresh apt package info:

$ sudo apt-get update

and install the packages:

greys@xps:~/proj/unixtutorial/examples $ sudo apt-get install sublime-text
 Reading package lists… Done
 Building dependency tree       
 Reading state information… Done
 The following packages were automatically installed and are no longer required:
   dkms libgsoap-2.8.75 libvncserver1
 Use 'sudo apt autoremove' to remove them.
 The following NEW packages will be installed
   sublime-text
 0 to upgrade, 1 to newly install, 0 to remove and 73 not to upgrade.
 Need to get 9,835 kB of archives.
 After this operation, 34.8 MB of additional disk space will be used.
 Get:1 https://download.sublimetext.com apt/stable/ sublime-text 3211 [9,835 kB]
 Fetched 9,835 kB in 8s (1,189 kB/s)                                                                                    
 Selecting previously unselected package sublime-text.
 (Reading database … 271734 files and directories currently installed.)
 Preparing to unpack …/sublime-text_3211_amd64.deb …
 Unpacking sublime-text (3211) …
 Setting up sublime-text (3211) …
 Processing triggers for desktop-file-utils (0.24-1ubuntu1) …
 Processing triggers for mime-support (3.63ubuntu1) …
 Processing triggers for hicolor-icon-theme (0.17-2) …
 Processing triggers for gnome-menus (3.32.0-1ubuntu1) …

That’s it! Sublime Text 3 is now installed and can be started using the subl command:

Sublime Text 3

My primary environment is macOS, but it’s comforting to know that I can fall back on Dell XPS laptop with Ubuntu to edit some Ansible playbooks in a similar way.

See Also




Show Files Installed by a Debian/Ubuntu Package

List files in a Debian/Ubuntu package with dpkg-query

Sometimes it’s not enough to know that a certain package is installed on your Linux system. You want to know the full list of files installed by the package, with exact locations of such files. This is when dpkg-query command may help.



Get List of Files Installed by a Package in Ubuntu

I mentioned xz-utils package for XZ archives yesterday, so let’s look at the xz-utils package. This is how I can get the full list of files installed by it:

greys@xps:~ $ dpkg-query -L xz-utils                                                                             [15/15]
 /.                                                                                                                      
 /usr                                                                                                                    
 /usr/bin                                                                                                                
 /usr/bin/lzmainfo                                                                                                       
 /usr/bin/xz                                                                                                             
 /usr/bin/xzdiff                                                                                                         
 /usr/bin/xzgrep                                                                                                         
 /usr/bin/xzless                                                                                                         
 /usr/bin/xzmore                                                                                                         
 /usr/share                                                                                                              
 /usr/share/doc                                                                                                          
 /usr/share/doc/xz-utils                                                                                                 
 /usr/share/doc/xz-utils/README.Debian                                                                                   
 /usr/share/doc/xz-utils/README.gz                                                                                       
 /usr/share/doc/xz-utils/copyright                                                                                       
 /usr/share/doc/xz-utils/extra
 /usr/share/doc/xz-utils/extra/7z2lzma
 /usr/share/doc/xz-utils/extra/7z2lzma/7z2lzma.bash
 /usr/share/doc/xz-utils/extra/scanlzma
 /usr/share/doc/xz-utils/extra/scanlzma/scanlzma.c
 /usr/share/doc/xz-utils/faq.txt.gz
 /usr/share/doc/xz-utils/history.txt.gz
 /usr/share/man
 /usr/share/man/man1
 /usr/share/man/man1/lzmainfo.1.gz
 /usr/share/man/man1/xz.1.gz
 /usr/share/man/man1/xzdiff.1.gz
 /usr/share/man/man1/xzgrep.1.gz
 /usr/share/man/man1/xzless.1.gz
 /usr/share/man/man1/xzmore.1.gz
 /usr/bin/unxz
 /usr/bin/xzcat
 /usr/bin/xzcmp
 /usr/bin/xzegrep
 /usr/bin/xzfgrep
 /usr/share/doc/xz-utils/AUTHORS
 /usr/share/doc/xz-utils/NEWS.gz
 /usr/share/doc/xz-utils/THANKS 
 /usr/share/doc/xz-utils/changelog.Debian.gz
 /usr/share/man/man1/unxz.1.gz
 /usr/share/man/man1/xzcat.1.gz 
 /usr/share/man/man1/xzcmp.1.gz 
 /usr/share/man/man1/xzegrep.1.gz
 /usr/share/man/man1/xzfgrep.1.gz

Find Binaries Installed by a Package

Simple grep will make the previous example even more useful. Let’s say we just want to know if a package installs any binaries, here’s how we can do it:

greys@xps:~ $ dpkg-query -L xz-utils | grep bin
 /usr/bin
 /usr/bin/lzmainfo
 /usr/bin/xz
 /usr/bin/xzdiff
 /usr/bin/xzgrep
 /usr/bin/xzless
 /usr/bin/xzmore
 /usr/bin/unxz
 /usr/bin/xzcat
 /usr/bin/xzcmp
 /usr/bin/xzegrep
 /usr/bin/xzfgrep

That’s it for today. Have fun!

See Also




Ubuntu – Static IP

I’m finishing up the VM based Ubuntu 19.10 setup and decided to make a few screenshots to test new workflow. Instead of random topic, I documented the task of configuring Ubuntu to use static IP address.

Why use Static IP?

Desktops don’t benefit from this much, but servers benefit from having static (fixed) IP addresses because you configure DNS once and then use server hostname and same fixed IP address for using any services.

Even if all you need is connect to server via SSH, static IP address will make things much easier – plus it usually comes as default for most dedicated hosting plans.

In my home lab I prefer to configure most virtual machines with static IP addresses because this allows me to easily access them remotely (working from one of the laptops).

Things to Know Before Configuring Static IP

Assuming you’re going to assisg a static IP from your local network (LAN), you need to have the following information confirmed:

  • what’s the local network addressing in use? It most likely starts with 192.168 or 10.0, but you need to know for sure. You need the full network – so something like 192.168.0.x or 192.168.1.x
  • static IP address you plan to use (from the same network)
    • make sure this IP is available – currently not in use (and at least does not answer to ping)
  • default route (sometimes called gateway) address – this is usually the IP address of your broadband modem. In my case it’s 192.168.1.1
  • DNS server IP address – usually the same as your gateway IP
    • you can also easily use external DNS server like 1.1.1.1 (CloudFlare) or 8.8.8.8 (Google)

Configure Ubuntu 19.10 for Static IP

Here are the screenshots walking you through the static IP configuration:

Go to app listing:

… choose Settings:

and select Network:

Inspect current settings (they would be automatic IP address and DNS details via DHCP):

…and now go to IPv4 settings:

Now, select Manual option for IPv4 method:

…and provide new values:

Now click Apply (top right) and in the next screen turn the Wired network off:

Now turn it back on and you can review the result:

That’s it – it’s a rather simple procedure but I still find it more comfortable (and easier to manage) when I update configuration directly or via Ansible.

See Also




Ubuntu 19.10

Ubuntu 19.10
Ubuntu 19.10 Desktop Wallpaper

Ubuntu 19.10 was released on October 17th, which means it’s time to upgrade Ubuntu on my Dell XPS laptop. Please note this is NOT a long-term support (LTS) release, so 19.10 will only be supported until July 2020.



Ubuntu 19.10 – Eoan Ermine

Seems like a pretty solid upgrade:

  • WPA3 support for improved wireless security – need to check if I can upgrade my Ubiquiti equipment to support it
  • Linux Kernel upgraded to 5.3 – this is where I expect majority of improvements for my laptop
  • Dark Theme – in a very short space of just a few months I’m now using dark themes on my iPhone, desktop and laptop, plus in as many apps as support it properly
  • Ubuntu 19.10 is available for Raspberry Pi 4
  • lots of visual improvements in each of the Ubuntu editions – Xubuntu, Kubuntu, Ubuntu MATE

Download Ubuntu 19.10

As always, the best place to start with Ubuntu download is http://releases.ubuntu.com/19.10/

Upgrading to Ubuntu 19.10

I did the usual sequence to get my laptop upgraded. Except the last step which needed the -d option to recognise that Ubuntu 19.10 is available. All of these commands were run through sudo.

  • apt update
  • apt upgrade
  • apt dist-upgrade
  • do-release-upgrade -d

Do you use Ubuntu? When are you planning to upgrade?

See Also




ZFS on root in Ubuntu 19.10

Ubuntu 19.10

Just read about ZFS making it into Ubuntu 19.10 installer as an experimental feature here, sounds pretty cool!

What is ZFS?

ZFS (originally called Zettabyte File System) is a revolutionary filesystem introduced by Sun Microsystems in 2005. ZFS took a few years to crystallise and was eventually shipped with Solaris 10 in 2009. It brought a number of fresh ideas to the world of enterprise storage and ZFS management of filesystems:

  • new parity checking modes, even more reliable than RAID5/RAID6
  • storage pool that can consist of different sized disks (typically you expect all disks to be of the same size and model)
  • self-healing
  • extra focus on the data consistency on disk – meaning ZFS caters for typical software and hardware errors
  • smart implementation and use of filesystem journaling
  • snapshots
  • data deduplication

ZFS in Ubuntu 19.10

To be clear, this is big deal not because ZFS is finally available in Ubuntu – it’s been around for quite some time thanks to the ZFS on Linux project. But this is the first time native support will be available in Ubuntu installer and also allow you to not just ZFS enable data disks but use it for root partition.

See Also




Assign Keyboard Shortcut to Screenshot in Ubuntu

I’m finding myself working on Linux laptop with Ubuntu 19.04 more often than I expected – sometimes I spend most of my day research and preparing Unix Tutorial posts in Linux instead of macOS. Today I got an opportunity to improve my screenshotting productivity a bit more.



How To Take Screenshots in Ubuntu

I tried a few screenshot apps in Ubuntu but eventually settled on the default one that comes pre-installed – it’s called Screenshot. The main reason for this choice wasn’t for its functionality (and certainly not for its performance, it’s rather slow) but because most of other options don’t support the HiDPI resolutions properly – so a quick task of screenshotting something becomes a tedious chore that defeats the purpose.

So I settled on using Screenshot app. I usually press the Start (Windows?) key on my keyboard and this brings a view of all the windows and gives me the app search window at the top of the screen:

I can then type Screenshot there and press Enter to run the app:

And then select the type of screenshot action I want to progress:

Adding Keyboard Shortcut to Screenshot

I decided to improve the things by skipping the whole “search for an app named Screenshot” part of the process and started looking into Keyboard Shortcuts settings.

Turns out, there is an even better option: I can select a shortcut to not just start Screenshot but to also select the action (screenshot current window) and save the file into Pictures directory:

The default shortcut Alt+Print is more than adequate, but on my multimedia keyboard from Logitech I don’t have Print button and must press Fn for invoke it. So I decided to change the default shortcut to Alt+S:

That’s it, I now can simply press Alt+S and get the window I’m working with automatically screenshotted (is this a word?) and placed into Pictures:

Hope you like this tip, have a great day!

See Also




Create swap from File on BTRFS Filesystem

mkswap-swapon

I didn’t create any swap during initial Ubuntu 19.04 install on Dell XPS laptop, so had to improvise when compiling a massive opensource project recently. This post shows you how to temporarily add swap memory using a regular file.

Create swap Using Regular File

The usual approach is fairly simple:

  • you create a large enough file (the desired size of your swap memory) – 1GB or 4GB or something like that
  • you initialise it as swap
  • you activated it as swap

Swap Files Support in BTRFS

Since I’ve used BTRFS filesystem for root in my Ubuntu setup, I discovered that there are additional steps needed: BTRFS filesystem creates and writes files in a way that’s been mostly incompatible with swap usage.

But as luck would have it, BTRFS supports swap files with Linux Kernel 5.0.x, so you just need to create file with specific attribute.

Swap Space Using File Procedure

Step 1: Create new empty file

We need to create a file with NOCOW (NO Copy-On-Write) property (no harm anywhere but is a requirement for BTRFS):

root@xps:/ # touch /swapfile
root@xps:/ # chattr +C /swapfile

Step 2: Allocate required amount of space to the file

root@xps:/ # fallocate -l 8G /swapfile

This file is 8GB now:

root@xps:/ # ls -ald /swapfile 
-rw------- 1 root root 8589934592 Jul 17 19:55 /swapfile

Step 3: Update permissions

root@xps:/ # chmod 0600 /swapfile 

Step 4: Initialise /swapfile as swap storage

root@xps:/ # mkswap /swapfile 
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=16d35c04-78de-4dd3-aeb0-e2228bb7ce36

Step 5: Activate swap space from /swapfile

root@xps:/ # swapon /swapfile

Step 6: Confirm newly activated swap space

root@xps:/ # free -h
total used free shared buff/cache available
Mem: 15Gi 6.1Gi 1.7Gi 3.1Gi 7.5Gi 5.8Gi
Swap: 8.0Gi 0B 8.0Gi

That’s it for today!

See Also




How To: Upgrade Packages That Were Kept Back

ubuntu-linux-logo

Now and then you may notice that apt-get upgrade command keeps a few packages back, meaning they don’t get upgraded. This quick post shows what you can do about it and how to get all the packages upgraded.

How apt-get Keeps Packages Back

This is how keeping packages back will look like:

greys@xps:~ $ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
linux-generic linux-headers-generic linux-image-generic
0 to upgrade, 0 to newly install, 0 to remove and 3 not to upgrade.

Why Packages Are Kept Back by apt-get

Most likely reason for keeping packages back is that upgrading them means installing new packages or removing existing ones. apt-get upgrade strictly upgrades existing packages, without removing or installing anything.

Since the command you’re giving to apt-get is upgrade and not to install new packages, packages that require some old packages removed or new packages installed are kept back.

How To Upgrade Packages That Were Kept Back

Simply use the dist-upgrade option of apt-get, which will resolve dependencies and install/remove dependent package as needed:

greys@xps:~ $ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed
linux-headers-5.0.0-20 linux-headers-5.0.0-20-generic linux-image-5.0.0-20-generic linux-modules-5.0.0-20-generic
linux-modules-extra-5.0.0-20-generic
The following packages will be upgraded:
linux-generic linux-headers-generic linux-image-generic
3 to upgrade, 5 to newly install, 0 to remove and 0 not to upgrade.
Need to get 67.0 MB of archives.
After this operation, 334 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

That’s it for todat, enjoy!

See Also




Card Reader Issues in Ubuntu 19.04 on Dell XPS 13 9380

unix-tutorial

It appears there’s a long-standing malfunction of various microSD card readers running Linux. In my particular case, the issue happens on XPS 13 9380 laptop running latest Ubuntu 19.04 with all the updates as of early July 2019. I’ll update this post once I confirm the fix.

Card Reader Device on Dell XPS 13 9380

I believe this is the device I have have:

root@xps:~ #  lspci | grep -i reader
01:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS525A PCI Express Card Reader (rev 01)

mmc0: error -110 whilest initialising SD card

The error message is a bit strange: I’m not trying to initialise my SD card, but instead want to read it. It’s a pretty standard 128GB microSD by SanDisk, but I think part of the problem is that it’s a high-speed SDXC card and the issue is that card reader can’t support the card because it’s running on slower speeds by default.

Here’s how the error looks:

Jul 2 14:02:43 xps kernel: [18743.768947] mmc0: error -110 whilst initialising SD card
Jul 2 14:02:44 xps kernel: [18745.108865] mmc0: error -110 whilst initialising SD card
Jul 2 14:02:46 xps kernel: [18746.452902] mmc0: error -110 whilst initialising SD card

Reloading SDHCI Kernel Module with debug_quirks

One of the common fixes for the problem is to reload kernel module sdhci with debug parameters that assist with improved voltage required for higher speeds.

Unfortunately, this fix didn’t work for me:

$ sudo modprobe sdhci debug_quirks2="0x80000000"

Syslog reports that module has been reloaded:

Jul 06 12:22:01 xps kernel: sdhci: Secure Digital Host Controller Interface driver 
Jul 06 12:22:01 xps kernel: sdhci: Copyright(c) Pierre Ossman

… but when I insert the code I still get the same error:

Jul 06 12:24:43 xps kernel: mmc0: error -110 whilst initialising SD card
Jul 06 12:24:45 xps kernel: mmc0: error -110 whilst initialising SD card
Jul 06 12:24:46 xps kernel: mmc0: error -110 whilst initialising SD card

I’m glad I also have an external card reader with USB-C interface, it works just fine with perfect access to the same microSD card. But ideally I want to fix this issue for the build-in card reader.

See Also