Pages - Menu

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, January 16, 2020

Disable Bluetooth on by default in Ubuntu MATE 18.04

I'd like to have my laptop power up, have the Bluetooth system tray app (blueman) start, but not have the actual Bluetooth powered on by default.

This was an easy change in the terminal:

gsettings set org.blueman.plugins.powermanager auto-power-on false

Thanks to Arch Wiki for this: https://wiki.archlinux.org/index.php/Blueman

Thursday, May 4, 2017

Commandline auto-login in Ubuntu 16.04

This is based on how RetroPie does its autologin and autostart which you can find in scriptmodules/supplementary/autostart.sh in the RetroPie-Setup source.

This works in Ubuntu and Raspbian, it probably works in any systemd distro.

mkdir -p /etc/systemd/system/getty@tty1.service.d/

Create a file at /etc/systemd/system/getty@tty1.service.d/autologin.conf with contents:

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin USERNAME --noclear %I \$TERM


Replace USERNAME with the actual username to login.

You can now reboot and test this.

If you want to start something on startup, then create a file /etc/profile.d/10-runthing.sh with contents like:

if [ "$(tty)" = "/dev/tty1" ]; then
    THING
fi


Replace THING with the command to run. You could run tmux so you never forget. You could compile DOSBox so it runs on the framebuffer and you appear to have a DOS computer, which is why I wanted to do this.

Saturday, March 4, 2017

3D Printing Software on Ubuntu 16.04 (Cura, Slic3r, Pronterface, Repetier Host)

I recently got a cheap 3D printer and wanted to get started printing with Ubuntu. Some of the software is not so obvious to install, so here's how I got these popular applications going:

Cura


Cura is available in the https://launchpad.net/~thopiekar/+archive/ubuntu/cura PPA. To install, just:

sudo add-apt-repository ppa:thopiekar/cura
sudo apt update
sudo apt install cura

Launch with the cura command.

Cura website: https://ultimaker.com/en/products/cura-software

Slic3r (Slicer)


The version in repos is the latest (1.2.9) at the time of writing, however the package is missing some dependencies. This installs all that's required:

sudo apt install slic3r wx-common libopengl-perl libwx-glcanvas-perl

Launch the GUI with the slic3r --gui command

Slic3r website: http://slic3r.org/

Pronterface (aka Printrun)


This requires python-wxgtk2.8 which is removed in Ubuntu Xenial 16.04, and the replacement python-wxgtk3.0 does not work well with Printrun.

There are some instructions around the internet suggesting to install the Wily 15.10 version, but that led to messy dependencies for me.

Luckily, WebUpd8 package python-wxgtk2.8 for 16.04 in their PPA, thanks!

First, install the dependencies Printrun requires with:

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt update
sudo apt install python-serial python-wxgtk2.8 python-pyglet python-numpy cython python-libxml2 python-gobject python-dbus python-psutil python-cairosvg git


Now change to the directory where you want the application to be and fetch the software with:

git clone https://github.com/kliment/Printrun.git

To run, change to the Printrun directory with cd Printrun and run the python pronterface.py command.

Pronterface website: http://www.pronterface.com/

Repetier Host


This uses Mono to run the Windows binary, install requirements with:

sudo apt install monodevelop libmono-system-serviceprocess4.0-cil

Download and uncompress:

tar xf repetierHostLinux_1_6_2.tgz
cd RepetierHost

Run with:

mono RepetierHost.exe

Repetier Host website: https://www.repetier.com/

Monday, December 7, 2015

Disable Promise FastTrack FakeRAID on CentOS 7

I have a system with an onboard Promise FastTrack SATA RAID controller. This isn't a "real" RAID controller, but one which relies on the OS to perform some of the RAID work. This is commonly called "FakeRAID" and is not desirable.

Despite setting the controller into AHCI Mode in the BIOS, I still get a disk called  /dev/mapper/pdc_abcdef or similar and cannot use the disk /dev/sdb directly. I wanted the FakeRAID gone.

The FakeRAID is managed by Device-Mapper RAID called "dmraid".

An old CentOS 5 post suggests removing the dmraid package might work, but this wanted to remove anaconda and many other things, so didn't seem a good option.

There is a kernel boot parameter to disable Device-Mapper RAID so I applied this.

In /etc/default/grub add nodmraid to GRUB_CMDLINE_LINUX_DEFAULT:

GRUB_CMDLINE_LINUX_DEFAULT="quiet rhgb nodmraid"

Then re-create the GRUB2 configuration file:

grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot, and no more FakeRAID drive. Success.

Saturday, November 7, 2015

Unknown symbol __dynamic_pr_debug

I was working with the default x86_64 + kvm kernel config and a kernel module which uses the pr_debug() printk logging method.

On load, modprobe prints:

FATAL: Error inserting modulename: Unknown symbol in module, or unknown parameter (see dmesg)

And dmesg contains:

Unknown symbol __dynamic_pr_debug

I do have the CONFIG_DYNAMIC_DEBUG=y parameter set in my .config.

I found reference to this upstream at: https://lkml.org/lkml/2012/8/30/378 where Jim Crombie said "Ok, transient error, went away with a clean build".

I'd done a make; make modules_install; make install and reboot but that didn't work for me.

Like Jim found, a make clean then recompile worked for me.

You need to mount debugfs to use pr_debug(), see dynamic-debug-howto.txt in the kernel Documentation directory.

Wednesday, November 13, 2013

how does mke2fs decide automatic check mount count?

Whenever you create an ext3 or ext4 filesystem with mkfs or mke2fs, a message is printed saying "This filesystem will be automatically checked every X mounts or Y days, whichever comes first".

However, the number seems to vary depending on the filesystem. How is this value calculated? I used the source of e2fsprogs-1.42.8 and the cscope source code tool to find this out.

Thursday, August 29, 2013

finding the netdev_priv struct

In addition to the net_device struct within the kernel, network drivers also have their own private or device-specific struct which stores stats unique to the individual hardware.

The name of the struct varies for each device type, however the location remains the same, right after net_device:

linux-2.6.32-358.14.1.el6.x86_64/include/linux/netdevice.h
/**
 *      netdev_priv - access network device private data
 *      @dev: network device
 *
 * Get network device private data
 */
static inline void *netdev_priv(const struct net_device *dev)
{
        return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
}
A search in cscope for netdev_priv will show you many functions within drivers which update the priv structure via pointers, for example this one in e1000_main.c:
struct e1000_adapter *adapter = netdev_priv(netdev);
So, given that we know what the device-specific struct is called, and where the device-specific private struct is, how do you find it and read it?

We'll need the ability to read kernel memory using crash, either run on a live system, or in a vmcore captured with kdump:
crash /usr/lib/debug/lib/modules/2.6.32-358.14.1.el6.x86_64/vmlinux /var/crash/2013-08-26/vmcore
We'll also need the debugging symbols for the driver in question:
crash> mod -s e1000 /usr/lib/debug/lib/modules/2.6.32-358.14.1.el6.x86_64/kernel/drivers/net/e1000/e1000.ko.debug
     MODULE       NAME                 SIZE  OBJECT FILE
ffffffffa01550e0  e1000              170678  /usr/lib/debug/lib/modules/2.6.32-358.14.1.el6.x86_64/kernel/drivers/net/e1000/e1000.ko.debug 
The net command will show you the network devices in the system:
crash> net
   NET_DEVICE     NAME   IP ADDRESS(ES)
ffff88007e76b820  lo     127.0.0.1
ffff8800372c0020  eth0   192.168.1.126
We can then cast net_device against this to see the in-kernel device struct:
crash> net_device 0xffff8800372c0020
struct net_device {
  name = "eth0\000\000\060:03.0\000\000\000",
...
But we want to get after this struct and cast it against the struct in the driver.

We need to know how big net_device is:
crash> struct -o net_device
struct net_device {
...
}
SIZE: 1728
We then find the net address plus the size of net_device:
crash> px 0xffff8800372c0020+1728
$1 = 0xffff8800372c06e0
We can now cast the device-specific private struct against this new address:
crash> e1000_adapter 0xffff8800372c06e0
struct e1000_adapter {
  vlgrp = 0x0,
  mng_vlan_id = 65535,
  bd_number = 0,
  rx_buffer_len = 1522,
...
and we're done!

Tuesday, July 9, 2013

akg perception 120 usb mic works on linux

I recently bought an AKG Perception 120 USB microphone to do some voiceover work with.

I couldn't find any reliable source which confirmed whether this works on Linux or not, so hopefully this post will help someone out.

This microphone works great on Linux.

Not only that, it works great full stop. I was using a cheap headset before, and the difference in sound quality is incredible. I'm not any sort of audio expert or audiophile, though I can tell you the constant "hiss" that my old headset produced is eliminated with this new microphone.

I tested using Fedora 18 with kernel 3.9.6-200 which worked fine.
I also tried Ubuntu 13.04 with kernel 3.8.0-19 and that worked too.
However, Ubuntu 12.04.3 with kernel 3.8.0-29 didn't work. It recognised the device but would not pick up sound.

If you wonder about any specific distro, preferably one with a LiveCD, just leave a comment and I'll give it a try if I can.

Here is the output of lsusb on F18 with the device connected:

Bus 001 Device 027: ID 074d:3556 Micronas GmbH Composite USB-Device

Here is the output of dmesg on F18 as the device is connected:

usb 1-1.2: new full-speed USB device number 27 using ehci-pci
usb 1-1.2: New USB device found, idVendor=074d, idProduct=3556
usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1.2: Product: AKG Perception 120 USB
usb 1-1.2: Manufacturer: AKG Acoustics
ALSA sound/usb/clock.c:243 current rate 0 is different from the runtime rate 48000
ALSA sound/usb/clock.c:243 current rate 0 is different from the runtime rate 48000
usbcore: registered new interface driver snd-usb-audio
ALSA sound/usb/clock.c:243 current rate 48000 is different from the runtime rate 44100
ALSA sound/usb/clock.c:243 current rate 48000 is different from the runtime rate 44100

Tuesday, July 2, 2013

how to display tcp rto

Calculating the TCP Retransmission Timeout always makes my head explode, yet it can be useful when troubleshooting TCP algorithms like FRTO or TIME_WAIT timeout when TCP Timestamps are in use.

This excellent post by sgros gives a very thorough overview of the RTO algorithms in the kernel and how RTO is actually calculated:
However, I don't want to do that, and I certainly don't want to do it for every socket in realtime. Is there an easy way to display the RTO for every socket?

There sure is:
ss -i
The -i option of ss is the flag to "Show internal TCP information", check man ss for more options.

Here's an example of a socket on my system including its RTO:

State   Recv-Q   Send-Q    Local Address:Port      Peer Address:Port
ESTAB   0        0           10.99.0.123:51308   192.168.34.111:http
cubic wscale:6,7 rto:660 rtt:396/38.75 ato:40 cwnd:10 send 272.3Kbps rcv_space:14600
                 ^^RTO^^
ss is one of the "next generation" iproute2 commands to replace the older netstat. Much like ip addr has replaced ifconfig, ip route has replaced route, and ip neigh has replaced arp.

Sunday, August 5, 2012

how to persist ethtool settings across reboot

You can use the ethtool command to read and change information about your network interfaces.

For example, ethtool -g ethX reads the size of the ring buffer on the NIC, and ethtool -G ethx rx A tx B changes it. Use man ethtool to discover more settings.

But these options don't persist across reboot, so how do you make sure your settings are kept permanent?

You can enter the ethtool commands in /etc/rc.local (or your distribution's equivalent) where commands are run after the current runlevel completes, but this isn't ideal. Network services may have started during the runlevel and ethtool commands tend to interrupt network traffic. It would be more preferable to have the commands applied as the interface is brought up.

The network service in CentOS has the ability to do this. The script /etc/sysconfig/network-scripts/ifup-post checks for the existence of /sbin/ifup-local, and if it exists, runs it with the interface name as a parameter (eg: /sbin/ifup-local eth0)

We can create this file with touch /sbin/ifup-local make it executable with chmod +x /sbin/ifup-local set its SELinux context with chcon --reference /sbin/ifup /sbin/ifup-local and then open it in an editor.

A simple script to apply the same settings to all interfaces would be something like:
#!/bin/bash
if [ -n "$1" ]; then
    /sbin/ethtool -G $1 rx 4096 tx 4096
    /sbin/ethtool -K $1 tso on gso on
fi
Keep in mind this will attempt to apply settings to ALL interfaces, even the loopback.

If we have different interfaces we want to apply different settings to, or want to skip the loopback, we can make a case statement:
#!/bin/bash
case "$1" in
 eth0)
  /sbin/ethtool -G $1 rx 16384 tx 16384
  /sbin/ethtool -K $1 gso on gro on
  ;;
 eth1)
  /sbin/ethtool -G $1 rx 64 tx 64
  /sbin/ethtool -K $1 tso on gso on
  /sbin/ip link set $1 txqueuelen 0
  ;;
esac
exit 0
Now ethtool settings are applied to interfaces as they start, all potential interruptions to network communication are done as the interface is brought up, and your server can continue to boot with full network capabilities.

Saturday, August 4, 2012

kvm virtual machine won't start

Recently I brought my KVM host down for an upgrade. I shut down the guests within their OSes, confirmed they were powered off with a virsh list --all, and everything went well with the upgrade.

However, upon returning the guests to service, one of them would not start up. Typing virsh start I got the helpful error message

Error restoring domain: cannot send monitor command
Connection reset by peer

Why was this one VM broken but the others were fine?

I played around with virsh autostart and virsh autostart --disable but that had no effect, nor did a reboot of the hypervisor.

After some searching around, it turns out libvirt has the capability to keep "managed save states" of guests, kinda like a sleep mode or snapshot, to save you fully powering a guest OS off.

For some reason, a managed save for this one guest had been created, perhaps it had not shut down properly, or perhaps there's an errorr in libvirt. I could view the saved state with

# virsh list --all --managed-save
 Id Name                 State
----------------------------------
  - guest1               shut off
  - guest2               saved


Now a virsh managedsave-remove guest2 returned it to the "shut off" state, and I could start it properly with virsh start as per usual.

Thursday, April 26, 2012

su to root without a password

I'm sick of typing the root password every time I want to su - on Fedora to become the root user. I know how to allow sudo access without a password, but I don't want to use sudo, I want to be able to just type su - and become root.

I couldn't find a good answer for this on Google, so I read the man pages of pam (Pluggable Authentication Modules) until I figured it out.

In the file /etc/pam.d/su put this as the second line:

auth            sufficient      pam_permit.so

This is incredibly insecure as it lets literally anyone at all with a login become root.

To restrict this just to your username, use this line instead, replace the yourusername with your actual username:

auth            sufficient      pam_succeed_if.so use_uid user = yourusername

You can also restrict this to a group, here the group allowedpeople can su without a password:

auth            sufficient      pam_succeed_if.so use_uid user ingroup allowedpeople

Saturday, April 21, 2012

starting rtorrent on system startup

rTorrent is a curses-based bittorrent client for Linux.

It's very light on system resources but has great features such as monitoring of a directory for .torrent files, auto-move based on status (incoming, seeding, complete, etc), categories, magnet link handling and RSS capabilities.

I have a headless system where I seed some (legal) torrents and wanted rTorrent to start up when the system did. There are some examples of init scripts on the rTorrent site but I didn't like how these ran, specifically the su constantly needing a password and the odd way it started GNU Screen.

Download
Installation
  • Put it at /etc/init.d/bittorrent and make it executable
    chmod +x /etc/init.d/bittorrent
  • Add to chkconfig
    chkconfig --add bittorrent
  • Set to start on system startup
    chkconfig bittorrent on
  • If you want non-root users to be able to control it, put this in your visudo, replace "username" with your non-priveledged username
    username localhost=NOPASSWD:/etc/init.d/bittorrent*
  • Setup an alias to the script in the user's ~/.bashrc
    alias bittorrent='/etc/init.d/bittorrent'
    alias bt='bittorrent'
Requirements
  • CentOS 6 or Fedora 12-14. Probably also works on CentOS 5.
  • screen and rtorrent
  • A non-priveledged user to run rtorrent, this can either be a new user just to run torrents, or an existing user
  • Absolute session path in the .rtorrent.rc file
    session = /home/rtorrent/.session  ## this is good
    session = ~/.session               ## this will break
    session = .session                 ## so will this
  • Paths for other actions such as monitoring directories for .torrent files and auto-moving complete downloads don't have to be absolute.
Usage
  • Control the daemon withbittorrent start, bittorent stop, bittorrent restart
  • Get information about the daemon with
    bittorrent status, bittorrent info
  • Connect to the screen session with
    bittorrent connect
    (press ctrl+a then d to disconnect)
Licensing

starting minecraft server on system startup

This is an initscript to run a Minecraft or CraftBukkit server on CentOS, Fedora, and Ubuntu.

Features
  • Start, stop, restart CraftBukkit as a system service
  • Automatic (via cron) and manual logfile rotation
  • Automatic (via cron) and manual backups
  • Backup compression and rotation (keeps 7 days worth of backups)
  • Check latest Recommended Build and update to it if required
  • Information display including Java path, current memory usage, current TCP connections
  • Able to run multiple separate instances of the server at once
Supported Distributions
  • CentOS 6, CentOS 5, Fedora 14
    (probably works on Fedora Core 6 and later, untested)
  • Ubuntu Server 12.04 LTS
Other distros which use SysV Init or Upstart (Debian, Mint) will probably work.
Distros using systemd (Fedora 15+, Arch Linux, etc) will not work.

Get the script, view Requirements, Installation, Backups, Multiple Instances, and Usage
License

Released under GNU GPL v3 - http://www.gnu.org/licenses/

Credits

Thanks to these people whose work I have used in the making of this