Pages

Thursday, October 5, 2017

Encrypted Storage Disk On Ubuntu

I decided to install a USB disk with encryption. There were many tutorials about encrypted partitions. I thought it is neater to simply encrypt the whole disk.

I used an old USB3 HDD which I had laying around. It was actually rather simple. My USB drive appeared as /dev/sdd It is possible to zerofill the drive before doing this. However I did not have sensitive data in the drive previously so I am not worried about people recovering random stuff from there . So I saved some time by skipping that step. You have to run the commands below as root user or use sudo

# apt-get install cryptsetup

The commands below will create an encrypted filesystem using the whole /dev/sdd disk. You won't be able to create partitions in it. But you can use that one encrypted filesystem inside it.

# cryptsetup -v luksFormat /dev/sdd
# cryptsetup luksOpen /dev/sdd usbdrive
# mkfs -t ext4 /dev/mapper/usbdrive

After mounting it to /mnt we can access it like any other disk.

# mount /dev/mapper/usbdrive /mnt

Here is how you close/lock it again. You should umount it first

# umount /mnt
# cryptsetup luksClose usbdrive

Monday, October 2, 2017

LightDM and 4K / HiDPI displays

I have recently acquired a 4K display and the fonts were tiny on it. I did a quick Internet search and found several questions from people having the same problem.

Most suggestions were involving around changing the font DPI. But this has undesirable effects, such as fonts being so much larger than other elements. I opted in to change scaling/resolution. To be honest from few meters away, I can't tell the difference between FullHD and 4K anyway.

The solution was setting the scaling with xrandr. To be able to apply the settings at startup, one should use the greeter-setup-script and session-setup-script options in lightdm. Below is how my /etc/lightdm/lightdm.conf file looks like

[SeatDefaults]
user-session=xfce
greeter-show-manual-login=true
greeter-setup-script=/etc/profile.d/lightdm.sh
session-setup-script=/etc/profile.d/lightdm.sh
 
Inside the /etc/profile.d/lightdm.sh file (this file needs to have executable permissions for lightdm to be able to execute it). You have to change HDMI-0 with the name of your display output. Unfortunately making too large scaling causes jagged edges. I had good quality with 0.5. The alternative line works much better.

#!/bin/sh
if [ ! -z "$DISPLAY" ]; then
  # Scale the display
  #/usr/bin/xrandr --output HDMI-0 --scale 0.5x0.5
  # Alternative method, this may give better results
  /usr/bin/xrandr --output HDMI-0 --scale-from 1920x1080
fi

There was one problem with this. I use KODI and it does not seem to care about the scaling. Therefore it didnt fit to screen. In my system KODI has it's own user. I created a .profile file under this user with the following information to rescale the display when KODI starts.

#!/usr/bin/env bash
/usr/bin/xrandr --output HDMI-0 --scale 1x1

If anything goes wrong. You should check your file permissions.