Author Archives: Tom

Mounting Android phone over USB on Debian

Debian Stretch

Using the following steps an Android phone can be mounted over USB by a Debian Linux system.

  • apt-get install jmtpfs
  • connect phone and select data transfer over USB
  • jmtpfs /mnt/phone

At this point, my phone prompts me whether or not to allow this connection. I select allow, but it is too late for the computer and any attempts to browse the directory /mnt/phone result in i/o errors. Unmounting and remounting without changing anything on the phone and leaving it connected, is a work-around for this issue.

  • umount /mnt/phone
  • jmtpfs /mnt/phone

Do work.

  • umount /mnt/phone

Vim – disable mouse mode

Newer versions of vi/vim included with Debian Stretch and later have the mouse mode enabled, which prevents traditional copy and paste from being used – the ability to highlight text and then middle-click to paste.

To re-enable this behaviour so that the middle-click can be used, enter the following line into your ~/.vimrc file:

set mouse=r

Iperf – multicast IPv4

Using Iperf version 2.0.9 on Debian (Stretch) it’s possible to test networks using a multicast connection.

On the receiving end execute the command:
iperf -s -u -B 239.1.1.10 -i 1

On the sending end execute the command:
iperf -c 239.1.1.10 -u -T 3 -t 10 -i 1 -b 100M

This will run a bandwidth test using UDP traffic at 100Mbps.

Note, if your system is multi-homed you must make sure your multicast traffic is routed out of the correct interface. For example:
ip route add 224.0.0.0/4 dev eth0

Bash – Internal Field Separator (IFS)

By default in Bash, the Internal Field Separator (IFS) is a ‘ ‘ character.

This is used to determine how bash splits text input into different fields. For example:

for file in *.jpg; do echo $file; done

will output each jpg filename on a separate line, unless there are spaces used in the filename.

For a more complete solution, change the IFS to the new line character and list each filename on a new line:

IFS=$'\n'
for file in `ls -1 *.jpg;` do echo "$file"; done

Of course the above doesn’t really achieve much, but it might be used as part of a simple script to resize images:

IFS=$'\n'
for file in `ls -1 *.jpg`; do convert "$file" -resize 200 "thumb-$file"; done

Debian 9 (Stretch) – Systemd network interface names

One of the effects of introducing Systemd into Debian is that the traditional naming convention for network interfaces has changed. No more is your Ethernet interface called eth0, instead it has a name based on its MAC address.

It’s still possible to use the old naming convention by creating a Systemd configuration file for each interface under /etc/systemd/network/. Each filename should start with a number lower than 99. The default configuration file starts with ’99’, the new config should run before that one.

The system config files can be found in /lib/systemd/network/, and are overlaid on top of the files in /etc/systemd/network/

For example, create the file: /etc/systemd/network/10-eth0.link which contains:
[Match]
MACAddress=01:02:03:04:05:06

[Link]
Name=eth0

For more info about the options available for the Match and Link sections, see the man page.

Update your initramfs which is used during boot-up to configure your system.
update-initramfs -u

After the next reboot, the Ethernet interface with MAC address 01:02:03:04:05:06 will be called eth0.

USB Ethernet devices

Annoyingly the configuration of USB Ethernet devices is interfered with by udev, so that the above Systemd config file will not have any effect. To prevent this, either delete or comment out the contents of the file /lib/udev/rules.d/73-usb-net-by-mac.rules and restart udev.

The USB Ethernet device will now be named based on the Systemd configuration file above.

WiFi Cards

I had some difficulty using the MACAddress Match option with my WiFi card, so I instead matched on the basis of card type:
$ cat /etc/systemd/network/10-wlan0.link
[Match]
Type=wlan

[Link]
Name=wlan0