Pages - Menu

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:
if [ -n "$1" ]; then
    /sbin/ethtool -G $1 rx 4096 tx 4096
    /sbin/ethtool -K $1 tso on gso on
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:
case "$1" in
  /sbin/ethtool -G $1 rx 16384 tx 16384
  /sbin/ethtool -K $1 gso on gro on
  /sbin/ethtool -G $1 rx 64 tx 64
  /sbin/ethtool -K $1 tso on gso on
  /sbin/ip link set $1 txqueuelen 0
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.

Wednesday, June 20, 2012

grub2 usb keyboard not working

I installed the newly released Fedora 17 this week, only to find I could no longer control the GRUB2 screen to get into Windows to play some games. The keyboard and mouse work perfectly in BIOS, and in Linux once USB drivers are loaded, just not at the GRUB2 screen.

Many forum threads exist for this, most pointing towards the "USB Legacy" or similar option in the BIOS. I had this turned on, however turning it off made no difference either.

GRUB2 can load some driver modules, so perhaps it wasn't loading the USB modules. Adding GRUB_PRELOAD_MODULES="usb usb_keyboard ehci ohci uhci" to /etc/default/grub and then rebuilding the config files with grub2-mkconfig -o /boot/grub2/grub.cfg didn't change anything either.

At this point I started coming across articles mentioning UEFI support for GRUB2. UEFI is the "new BIOS" standard coming out on new motherboards. My motherboard is a fairly new model, so it does have EFI firmware.

Turns out the solution is to install a version of GRUB2 with EFI support. This was done with yum install grub2-efi to install the package, then grub2-efi-install /dev/sda to install the EFI-supporting bootloader onto my hard drive. I regenerated a new config with grub2-efi-mkconfig -o /boot/grub2/grub.cfg while I was at it.

Now my USB keyboard works perfectly in GRUB2.

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

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 use_uid user = yourusername

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

auth            sufficient 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.

  • 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'
  • 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.
  • 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)

starting minecraft server on system startup

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

  • 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

Released under GNU GPL v3 -


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

The State of the Linux

It's been a while since I've posted but I'm still around. I started this blog as a sharing of tips and fixes I which used and couldn't find anywhere else. I've easily found most things I've wanted to do in the last few years so I haven't had the need to make much noise.

Today I'm here to write about the state of desktop Linux as I see it, compared to when this blog started in 2008 and I was obviously using Ubuntu.

These days I am a Fedora user. This was mostly brought about by starting to use RHEL at work and the need to become familiar with regular use of the RPM-based distro. I've also changed all my own servers over to CentOS.

Fedora's okay. Some people may deny this, but I think it's obviously a dumping ground for features Red Hat want to try, or to have the Fedora community crowdsource most of the initial testing and bugfixing before doing their own QA for inclusion in RHEL.

Fedora's near-bleeding-edge package cycles, still with a focus on stability, is both its strength and its weakness. It's great having the kernel or Wine updated in-distro within a week of new major upstream releases. It's frustrating having to deal with "latest and greatest" features I dislike such as GNOME 3 and systemd. I generally find Yum/rpm to be greatly messy and inferior compared to apt.

GNOME 3 is probably the largest thing to happen to desktop Linux in the last few years. It was met with such a hugely negative response and such polarising opinions that sites are still running polls about it. I think the developers made a mistake, sticking their head in the sand and telling users that the forced paradigm shift to Gnome Shell was what they wanted, despite the fact many people said they didn't.

Many Linux users appear to be seeking alternatives to Gnome Shell and all the competing Desktop Environments (KDE, XFCE, LXDE) have probably seen an increase in user base. Linux Mint listened to their users and pursued the MATE fork of GNOME 2, then created the Cinnamon Desktop. This fulfilling of majority demand has pushed them to the top of Distrowatch and kept them there. Kudos to the Mint Team for putting their money where their mouth is.

Ubuntu chose Unity over Gnome Shell. I've tried Unity several times and have been disgusted by it. It's so un-useable that I consider it just plain broken. I think it's pushing Ubuntu into irrelevance and their declining rating on Distrowatch tends to agree.

Mint used to be based on Ubuntu and have now started offering a re-base on Debian. CrunchBang also used to be based on Ubuntu and has switched to Debian altogether. Ubuntu's own variants Kubuntu and Xubuntu have fallen from sponsored releases to just "officially recognised" community projects.

I considered Ubuntu to be the king of Linux distros for a long time, but its reign is now well and truly over.

One interesting distro I saw on a magazine is Fuduntu. The name is ridiculous but the product itself is worth a look. It's a fork of Fedora 14 which has gone rolling-release. It still runs GTK2 and SysV Init but incorporates the latest 3.x kernel series. It has a smaller package set than Fedora and runs a Mac-like desktop environment based around a top-of-screen Gnome Panel and Avant Window Navigator.

My own desktop these days is Openbox with tint2 panel, a minimalist throwback from my days as an Arch Linux user.

Arch itself is a good distro with a great community, full of positive helpful people, few (if any) jerks, and little politics. However, I found myself spending around a quarter of my computer time just maintaining my system, rather than using the computer to do other things. Arch is something all Linux enthusiasts should do once for a period of time, the amount of tinkering and low-level micro-management required is educational and improves your Linux skills, but I feel it also is very much "using Linux for the sake of using Linux".

There seems to be a big paradigm shift happening all over desktops these days. Unity and GNOME 3 led for Linux and seem to have failed, Microsoft have shown their Metro interface which must be a bad joke. It's as if the development world has suddenly and unanimously decided the "menu and taskbar" interface which began with Windows 95 is no longer good enough, but nobody's come up with a suitable replacement, except perhaps Cinnamon.

Which desktop eventually wins out is still anyone's guess. Mint has shown that it's not necessarily the big corporate-backed developers who set the trend. Maybe we will never see one true new standard environment and modular personalised DEs will be the order of the day.

Sunday, March 11, 2012

mapping middle-click to a keyboard key under fedora

By far the most popular post on this blog was my old mapping middle-click to a keyboard key trick, which worked well under Ubuntu at the time.

Since then I've switched to Fedora which doesn't package old X11 tools like xkbset. However, this is such a useful thing to have on a laptop I've found a way.

We'll need the xdotool package, so yum install xdotool.

Then under the settings of your Window Manager, simply create a shortcut to xdotool click 2.

Under the default Gnome 3 desktop, this is in the Keyboard page of gnome-control-center.

Under Openbox, we'd add an entry to rc.xml like this
<keybind key="Menu">
  <action name="Execute">
    <command>xdotool click 2</command>
And we're done!

xdotool can actually do a whole heap more than just emulate keyboard and mouse events, check out the author's webpage for more info!