Tuesday, August 8, 2023

Apps terminating in Wayland on Linux with error "Gdk-Message: 07:27:13.932: Error flushing display: Resource temporarily unavailable"

Recently I came across a problem where virt-viewer a program which provides a viewer for virtual machines would suddenly crash.

 I was able to reproduce this a couple of times so I looked into it trying to research the root cause problem. 

 

In the terminal I noticed the below:

(virt-viewer:8795): virt-viewer-WARNING **: 07:26:13.285: (virt-viewer-app.c:840):viewer_window_focus_out_cb: runtime check failed: (self->priv->focused >= 0)

Gdk-Message: 07:27:13.932: Error flushing display: Resource temporarily unavailable

 On further research I noticed that other apps also had the error. It appears that Wayland causes this crash.

Heres a workaround:

run the app in terminal with:

env GDK_BACKEND=x11
  <app-name>

e.g.

 env GDK_BACKEND=x11 virt-viewer 

or 

env GDK_BACKEND=x11 xterm

Sunday, February 26, 2023

Finding processes using a port

On and off you may find that you cannot launch a process which needs a port when another process is using the same port. But it is difficult to identify this conflicting process. Here's a tip you can try: lsof -i: e.g. to see which process is using the port 1040 use lsof -i:1040

Thursday, June 16, 2022

Using UFW to retrict network access to specific IP's/LAN

'ufw' is a firewall usually preinstalled on ubuntu systems but disabled by default.

You will need root access to configure the firewall.

This tutorial assumes that the router and the server are in the same subnet -- here 192.168.1.*. The server on LAN which we want to permit access to is 192.168.1.20

#step 1: make sure ipv6 is enabled too for the firewall

sudo nano /etc/default/ufw

check if "IPV6=yes"

if yes then do no changes

# step 2 (these are defaults but no harm forcing it again)

ufw enable

ufw default deny incoming

ufw default allow outgoing

# step 3 manual rules

ufw allow from 192.168.1.20

ufw allow out to 192.168.1.20

ufw deny out to any

# how it works

-- first manual rule allow incoming traffic from the ip

-- second rule allows outgoing traffic to the server

-- third rule denies any other outgoing connections to any ip on any port.

Thursday, June 29, 2017

How to turn off ubuntu unattended updates and upgrades in Ubutntu



 Since Ubuntu 16.x unattended updates and uprades are enabled by default. These run on a schedule periodically to keep your system up to date. SOmetimes you do not want to let Ubuntu automatically do this. THe below commands can be used to shutdown and disable the unttended updates and upgrades service

In a root shell (sudo -i) typing the three commands below will disable unatended updates and upgrades

systemctl mask apt-daily.service
systemctl disable apt-daily.timer
systemctl disable unattended-upgrades

You can reverse this action by using the following three commands as root:


systemctl unmask apt-daily.service
systemctl enable apt-daily.timer
systemctl enable unattended-upgrades

Note: If you have a doubt as to the difference between masking and disabling. Masking prevents a service from ever running/being started. Disable only prevents a service from being started automatically.

 If you do not want to prevent the service from running but want more fine grained control over unattended upgrades.  You can edit the file located at "/etc/apt/apt.conf.d/20auto-upgrades" on your Ubuntu system.

 APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

By changing the "1" to "0" you can disable a specific feature example you want only unattended updates but no upgrades.




Tuesday, June 6, 2017

Installing fonts on a linux distribution

Have you ever wondered how to install fonts on a Linux distribution.  In this blog post I'll be talking about the general process of installing fonts on Linux and more specifically on Ubuntu.

The process of installing fonts and using them broadly comprises of 2 steps:
1) Placing the font file in the appropriate directory.
2) Rebuilding the font cache so that the system can use the new fonts you installed. This is typically done with the "fc-cache" command.

Fonts can be installed at two different levels:
1) System wide: This makes the font available to all users on your Linux System. This requires root privileges but has the advantage of system wide font availability.
2) Per user: This is by far the easiest safest method. It does not require root privileges but makes the newly installed fonts available only to that specific logged in user.

As an example I will demonstrate installing of fonts on Ubuntu 16.04 (this should work on older ubuntu systems too it was tested on Ubuntu 14).
 
1) Installing fonts on Ubuntu system wide:
 -> Login to a root shell

 -> Create a sub folder in directory '/usr/share/<font-type>/'.

     Ubuntu splits different font types into their own individual directories (so for instance if a font is a truetype font it would go into '/usr/share/truetype/'.

    Assuming our font is a truetype font we create a sub folder called 'customFonts' inside '/usr/share/truetype/' and save your font there.

 -> Update the font cache. Run 'fc-cache'.

 -> your done

2) Installing fonts on an Ubuntu system per user:
 -> Open a regular shell as a logged in user.

 -> check if a folder "~/.fonts" exists otherwise make it. Note: here "~" is a shortcut for you homedirectory. If you username is 'foo' then "~" typically expands to '/home/foo'.

 -> install your font there (you can create a sub folder and organize your fonts however you like)

 -> Update the font cache. Run 'fc-cache'.

 -> your done

Now just reopen any program where you wish to use the font and try looking for your font. You should see the font in the list of available fonts.

Saturday, November 8, 2014

Adding rules for MTP and getting your device to work on OpenSUSE

MTP is the Media transfer protocol. It allows files to be transferred to and from media devices. MTP does not allow operations such as editting and modifying the file. MTP  is different from USB mass storage. With MTP the device still has full control over the file system.

Of late Android devices only allow you to transfer data to/from them via MTP/PTP. New devices may or may not be detected.

In order to ensure that a device is detected on openSuse you will need to learn to add and manage udev rules.

We will take the example of a pretty new budget android phone called the Xaomi RedMi 1s. 
When we plug it into Suse and enable MTP nothing appears to happen. Though we expect to be able to access the internal storage and SD Card via MTP.

This is because there are no rules on how to handle the MTP device.

I found that guides are very sparse online when it comes to MTP. So I decided to make a small write up to guide people.  

First we will install a package called "mtp-tools" this provides a number of command line tools for MTP.

zypper in mtp-tools

Once installed we make sure our device has MTP enabled and then we type "mtp-detect" command as root.

Sample output is shown below.
>mtp-detect
Unable to open ~/.mtpz-data for reading, MTPZ disabled.libmtp version: 1.1.6

Listing raw device(s)
Device 0 (VID=2717 and PID=1260) is UNKNOWN.
Please report this VID/PID and the device model to the libmtp development team
   Found 1 device(s):
   2717:1260 @ bus 2, dev 52
Attempting to connect device(s)
ignoring libusb_claim_interface() = -6PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
Android device detected, assigning default bug flags

<----- Output Clipped ----->

What is most important here is the VID and the PID with this information rules can be formulated.

By adding an MTP rule we can get KDE to pickup the device.

MTP rules as of libMTP version 0.9 onward are stored in /usr/lib/udev/rules.d/69-libmtp.rules

The udev rules for MTP devices follow the below syntax typically.

ATTR{idVendor}=="<VID here>", ATTR{idProduct}=="<PID here>", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

So in our case assuming VID of 27217 and PID of 1260 the udev rule becomes:

ATTR{idVendor}=="2717", ATTR{idProduct}=="1260", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

There are more options which can be added here such as "mode" and "group" but these are rarely required. In most cases setting ENV{ID_MTP_DEVICE} and ENV{ID_MEDIA_PLAYER} to "1" should suffice.

After the rule line has been added along with the existing rule lines in /usr/lib/udev/rules.d/69-libmtp.rules you are almost set.

Now all that is left is to apply the new rules and restart the udev service with the below 2 commands.

udevadm control --reload-rules
service udev restart

These two commands are used to reload rules and restart the udev process with the new rules. Now disabling and enabling MTP on the device should allow you to connect to the device via MTP from OpenSuse.

Hope this short guide helps.

Troubleshooting:
Q 1) I have followed allt he above rules, the MTP device(s) do not show up on KDE still. What do I do ?
1) Test if mtp works from terminal.
 as user type the command mtp-filetree wait for the command to complete initially you will only see few string containing device info. Once the command finishes (may take a minute or more even) you should see a list of files on your device. If you do then that means MTP is working properly.

Sample output below:

Device 0 (VID=2717 and PID=1260) is UNKNOWN.
Please report this VID/PID and the device model to the libmtp development team
Attempting to connect device(s)
Android device detected, assigning default bug flags
Device: (NULL)
Storage: Internal storage
1 FolderFoo
  2 .data
    478 b697b2b6ae559e26f3fc90abb449faa2
    480 7c7320086a99708c28138fd086553e33
    481 eb0d265b69315673573eb5a47d4b8df4
    8534 58074bc9565a44d9c57b11394be867e0
    8535 230d3b2452c6b7e32b74b2beae943a49
    13204 ed38625755998a993a67dd1e93a5fac6
    13205 02fd4baa976f28991a35bfd05a5fa269

Here you can see a folder called  "FolderFoo" and the contents of another sub-folder folder inside "FolderFoo" called  ".data" and its contents. If you see this kind of output that means MTP protocol level communication between your system and your device and your linux PC is working fine.

This indicates the problem is most likely a DE problem. For KDE you need to install a package called "kio_mtp" by using the code below.

zypper in kio_mtp

Note: the package may be called by a slightly different name if so just run

zypper se mtp

and look for a package with the 'kio' words in it and install.

Monday, August 4, 2014

Mounting disks as non root from the shell

The most popular method for mounting disks and the most traditional method is the "mount" command.

In most cases (with the exception of specifying before hand that unprivileged users can mount specific disk in /etc/fstab) the "mount" command requires root privileges.

Now often the question becomes "How come I can use a file manager to mount regular disks E.g. USB's, external HDD's without root and the mount command requires root ?"

The answer to this is to use the more traditional "Udisks1" or the newer "Udisks2" there has been a debate on why Udisks is better than Udisks2 but keeping the debate and arguments aside both tools serve the purpose.

For Udisk1 (the original) the command line  utility is "udisks". For Udisks2 (the rewrite) the command line utility is "udiskctl" both can coexist and normally do coexist on most linux distributions but are different. Both however are used for managing storage devices.

The original Udisks mounted all partitions in "/media/<partition-name> " E.g. /media/linux_data (Where linux_data is the partition name)

The new Udisks2 mounts storage devices  in /run/media/<username>/<partition-name> E.g. /run/media/lin-user/linux_data (WHere username is lin-user and partition is linux_data).

Note: /var/run is a symbolic link to /run so Udisks normally states that it has mountded the disks to
 /var/run/media/<username>/<partition-name> E.g. var/run/media/lin-user/linux_data (you can reference the same storage device as a directory using /run/media/ or /var/run/media/ it does not matter)

Now armed with basic info on the tools we will be using lets go ahead and try to use the tools mentioned above to mount and unmount storage devices.

Typical steps involved:

1) Plug in the storage device (if its an internal HDD and just an unmounted drive you can skip this step.)
2) type "lsblk" and look at the output to determine which drive/block-device you are interested in mounting E.g. /dev/sdb1 or /dev/sdc3 or /dev/sda2 etc.
3) Use Udisks or Udisks2 syntax to mount the specific drive automatically.

Udisks and Udisk2 syntax

Udisks syntax:

a) mounting a drive
udisks --mount /dev/sdX
E.g. udisks --mount /dev/sdb2

b) unmounting a drive
udisks --unmount /dev/sdX
E.g. udisks --unmount /dev/sdb2

The syntax is very clean and easy to use for udisks


Udisks2 syntax:
The syntax is for udisk2 is different.

a) mounting a drive
udisksctl mount -b /dev/sdX
E.g. udisksctl mount -b /dev/sdb2

b) unmounting a drive
udisksctl unmount -b /dev/sdX
E.g. udisksctl unmount -b /dev/sdb2

Note: there are no double dashes before the word "mount" and "unmount" also -b is a must so that udisks2 knows that you are giving it a block device to mount.

The advantage of udisks /udisks2 over the mount command is that you do not need to specify a mount location or create a special folder. Udisks/Udisks2 automatically exposes the device as a folder for you in the paths mentioned earlier on in the article.