Some tech documentation and snippets, finally organized.
Posts tagged as linux

Stop Chromium from listening on UDP Port 5353

Setting chrome://flags/#device-discovery-notifications to "disabled" as well as the configuration line export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --media-router=0" in a file under /etc/chromium.d/ do not prevent the Chromium browser from listening on UDP port 5353 any longer. Instead, a policy has to be defined under /etc/chromium/policies/managed/:

$ mkdir -p /etc/chromium/policies/managed
$ echo '{ "EnableMediaRouter": false }' > /etc/chromium/policies/managed/disable_mediarouter.json

For Google Chrome, this policy has to reside under /etc/opt/chrome/policies/managed/.

Mount an USB connected Android based smartphone into Linux

​User-mountable and world-readable, using fuse and jmtpfs:

Install required software:

$ apt-get install fuse jmtpfs usbutils

Connect the smartphone with an USB data cable and read out required information:

$ lsusb

The command returns a list of all connected USB devices; the line for my Moto G4 play looks like this:

Bus 001 Device 003: ID 22b8:2e82 Motorola PCS

Now use the printed Vendor and Product ID (before resp. after the colon) to create the according udev rule:

$ echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="2e82", SYMLINK+="libmtp-%k", MODE="660", GROUP="audio", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"' >> /etc/udev/rules.d/55-android.rules

Create mountpoint, make sure that you are in the audio group and test setup:

$ mkdir /media/motomobil
$ chmod a+rwx /media/motomobil/
$ jmtpfs -o allow_other /media/motomobil/
$ fusermount -u /media/motomobil/

jmtpfs will grab the first available device. Allternatively, the device can be specified with the -device=<busLocation>,<devNum> switch, to dump the parameters, run jmtpfs --listDevices.

Add fstab entry:

$ echo "jmtpfs       /media/motomobil       fuse       noauto,nodev,allow_others,rw,user,noatime       0       0" >> /etc/fstab

Burning a mixed-mode CD-R

It is possible to "enhance" an audio CD with arbitrary files as a bonus track. The following post shows how to create such a mixed-mode CD or enhanced CD on the command line.

Create suitable wav files with libav-tools

$ for i in $(ls); do avconv -i $i /path/to/outdir/$i.wav; done

Note: ffmpeg will work as well, with the same syntax and options: just /avconv/ffmpeg/.

Burn the audio-tracks

$ cd $WAVDIR
$ wodim -v dev=/dev/sr0 speed=4 -multi -audio *.wav

The -multi switch (for multi session) is necessary to prevent wodim from closing the disk after burning. Additionally, I use the slow speed=4 option to burn sharper delimited dots and thus enhance the disk's readability in older (or dusty) audio players.

Analyze the audio-session and prepare the "bonus track"

$ TRACKINFO=`cdrecord -msinfo dev=1,0,0`

In this case, the first session started at sector 0 and the following will start at sector 105248. This information can now be passed to mkisofs or the newer xorrisofs:

$ xorrisofs -J -r -C $TRACKINFO -V $16_CHAR_DISKLABEL -o /path/to/data.iso /path/to/data

Append the iso to the disk

$ wodim -v dev=/dev/sr0 -data /path/to/data.iso

The resulting CD will serve the first session to all common audio CD players, while the second (data) session can be accessed with a CD-ROM drive.

Note: Not all CD-ROM drives support mixed-mode media - some may fail to access the audio tracks from the first session.

CLI Wifi setup with iw

This is a quick overview of the necessary commands and configuration to connect to wireless networks from the command line with iw and wpa_supplicant.


Identify available Wifi adapters:

$ iw dev

Check the device status (from now on using device wlan0):

$ ip link show wlan0

Bring up the interface and scan for available networks:

$ ip link set wlan0 up
$ iw wlan0 scan

Now there are several possibilities to actually connect to the targeted wireless network:

Solution 1 - manually with wpa_supplicant and dhclient

Generate the wpa_supplicant configuration file (replace $SSID with the network's SSID, hit return and enter the passphrase):

$ wpa_passphrase $SSID >> /etc/wpa_supplicant.conf

Note: You might want to remove the (commented out) clear text passphrase from the resulting wpa_supplicant.conf file.

Connect to the wireless network and obtain an IP address:

$ wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
$ dhclient wlan0

Solution 2 - using wpa_supplicant with ifup/down

Add the Wifi configuration to your /etc/network/interfaces (of course $SSID and $PASSPHRASE have to be replaced by the actual values):

### File: /etc/network/interfaces

auto wlan0
iface wlan0 inet dhcp 
    wpa-ssid $SSID
    wpa-psk  $PASSPHRASE

To avoid the clear text passphrase in your interfaces file, you can run

$ wpa_passphrase $SSID

As before, you'll have to replace $SSID with the network's real SSID, hit return and enter the passphrase. When done, replace the $PASSPHRASE in the above /etc/network/interfaces file with the resulting 256bit value of psk.

Now bring up the interface, connect to the wireless network and obtain an IP address as usual with

$ ifup wlan0

Note: This solution will (try to) automatically connect to the configured wireless network when the system boots.

Checking the link

Finally, use ip or ifconfig to check the link status and ping a known host to verify connectivity:

$ ip addr show wlan0
$ ifconfig wlan0
$ ping -c 2