Archive for the ‘Linux’ Category

Miscellaneous Linux tips and tricks

Saturday, July 10th, 2010

Gnome Key Bindings and IntelliJ IDEA

IntelliJ IDEA key bindings conflict with Gnome’s window manager. In IDEA, I can type CTRL-B to jump to a symbol definition. Normally, I’d type CTRL-ALT-LEFTARROW to navigate back to where I had come from. Gnome’s MetaCity intercepts that key mapping before IDEA sees it, and tries to move my desktop to the left. There are several other Gnome/Metacity key bindings that conflict with IntelliJ IDEA. Rather than remap the keys in Gnome, I found that on Fedora, I could add the Windows key to the mix, and Gnome would ignore it, and pass it along to IDEA. This means that I can type CTRL-ALT-WINDOWS-LEFTARROW to navigate backward, and so forth.

Unfortunately, this doesn’t work in RHEL 5 and CentOS 5. The solution is to Go to the Gnome menu bar and select System > Preferences > Keyboard (not Keyboard Shortcuts). Then select the “Layout Options” tab, and expand the “Alt/Win key behavior”. Then I select “Super is mapped to the Win-keys”.

Every time I log in after that, Gnome tells me that my X keyboard settings conflict with my Gnome Keyboard settings, and it asks which I want to use. Selecting the Gnome settings is what I want.

Bandwidth limiting downloads with ‘curl’ or ‘wget’

When downloading a large file, it’s nice to be polite to others on the network, so I use the --limit-rate option for curl and wget:

  • curl -O --limit-rate 20k http://server.com/linux.iso
  • wget --limit-rate=20k http://server.com/linux.iso

GDB TUI (text user interface)

After starting gdb, it’s possible to switch to its text user interface with CTRL-X, CTRL-A. Typing it a second time exits TUI mode.

Vim C++ Auto completion with ctags

I appreciate full blown IDEs in Linux, but I like the quick start up time of vim. Until recently though, I didn’t have C++ auto completion (also known as vim omni completion).

This got me up and running, and was a great resource: http://vim.wikia.com/wiki/C%2B%2Bcodecompletion

This would have been useful if I was a new comer to vim and ctags: http://www.justlinux.com/nhf/Programming/IntroductiontoC_Programming.html

xdg-open, gnome-open, start, cygstart

How to easily open files and URLs from the command line http://www.dwheeler.com/essays/open-files-urls.html

  • Linux: xdg-open filename_or_URL
  • Linux: gnome-open filename_or_URL
  • Mac: open filename_or_URL
  • Windows: cmd /c start filename_or_URL
  • Cygwin: cygstart filename_or_URL

Nomachine NX and ALT-TAB

I use the Nomachine NX client from time to time to get a remote-desktop like connection to a remote Linux machine. It’s faster than VNC, but it suffers from not forwarding all of my keyboard shortcuts to the remote end of the connection.

Usually, I start the nxlcient from within a Gnome login session. Gnome happily grabs ALT-TAB before the NX client gets to see it. That’s not what I want. To work around this limitation, I log into a virtual terminal, and start X manually as follows:

Type CTRL-ALT-F2 Login Run: startx -- :1 gnome-terminal

From the gnome-terminal, run: nxclient

And then I connect to the remote machine in full screen mode. There’s no local window manager to interfere with my keyboard shortcuts.

Remote desktop and dual screens

I’ve been using Remote Desktop to connect to Windows XP, Vista and 7 machines. Until Windows 7, there was no way for a local computer having dual monitors to connect and have the remote end display across both monitors.

So I used linux’s ‘rdesktop’ program to do it:

rdesktop -0 -a16 -f -rdisk:CLIENT=/home/jared/Desktop -r sound remote.host.com

I notice that in Windows 7, there are some new options in the Remote Desktop client (mstsc.exe): /multimon and /span. Or run mstsc /? to list all possible options.

Editing windows registry files on Linux

Use Gedit: gedit --encoding=UTF-16LE myfile.reg

Gvim: LANG=UTF-16LE gvim myfile.reg

If already in gvim: :e! ++enc=utf-16le or :e ++enc=utf-16le myfile.reg

Convert, edit, convert:

iconv -f UTF-16LE -t utf-8 myfile.reg > myfile.reg.utf8

Edit myfile.reg.utf8, then convert it back

iconv -f utf-8 -t UTF-16LE myfile.reg.utf8 > myfile.reg

How Firefox opens files and mime types

I needed to give Firefox some extra help knowing how to open a custom file type with a custom application. Here’s some helpful information.

https://developer.mozilla.org/en/HowMozilladeterminesMIMETypes

Firefox uses mime.types on Linux, as well as other things. I helped Firefox by the mime type to the link in the generated HTML file. Either one of the following seems to work:

  • <a href=”file:subdir/file1.cst” type=”application/octet-stream”> open file </a>
  • <a href=”file:subdir/file1.cst” type=”application/x-extension-cst”> open file </a>

Worth the money: Automated, online backup

Friday, March 12th, 2010

10 February 2010

Yesterday, I found out I’d lost over three thousand calendar entries, and I had lost them five months ago. Fortunately, I had been using an automated, online backup service and was able to restore the missing data.

I found out about my loss when I searched for a phone number on my Palm TX that should have been in my calendar, but was missing. I wondered what was up, and started going through my calendar a month at a time. I noticed that calendar entries after Sept 7, 2009 were present, but nearly everything before that was missing.

My Palm TX is synchronized frequently with Windows, and infrequently with Linux. My Linux copy of the calendar wasn’t going to help me, because it was missing the calendar entries as well. The same was true for the Windows copy.

The Palm-to-SD-card backup that happened every night wasn’t going to help, because it deletes any backups older than seven days old to make room for the new backups. I needed something that stretched back five months or more.

The backup of my Linux computer wasn’t going to help me, because I overwrite my old backups with new copies of the same files, using ‘rsync’.

I thought my Mozy backups worked the same way. Fortunately, I was partially wrong. Mozy keeps point-in-time backups of some files. I don’t know how they determine which files to do it for, but they did it for my Palm Pilot calendar database file. I was able to restore my missing calendar entries, which was a huge relief.

I heartily recommend automated online backups. Manual backups aren’t done by most people and if they are done, they’re sporadic and incomplete. My intermittent manual, replace-the-old-files style of backup to USB hard drive wouldn’t have allowed me to restore the calendar entries. The $5/month that I spend for online backup was very worthwhile, and easy to justify considering that it’s less than the cost of eating out for lunch. It’s less expensive than a cell phone or monthly internet service.

If you aren’t already doing automated backups, I recommend that you sign up with an online backup service today. Here are some recommendations:

  1. Dropbox is the most popular. Works on Windows, Mac, Linux, iPhone.
  2. Spideroak is the second most popular. Works on Windows, Mac, Linux.
  3. Alternatives to these, including Mozy, which is what I use for Windows: http://alternativeto.net/desktop/dropbox/.

A word of caution: backups can’t work miracles. If a file was corrupted BEFORE it was backed up, no backup solution is going to be able to solve the problem. This is why I make two copies of all photos from my digital camera BEFORE deleting them from the camera. Still, if the memory card in the camera contained corrupted images, even this wouldn’t be good enough.


The missing calendar entries were, in fact, not missing. They were corrupted. I found this out by running jpilot-dump -D | sort -r on my linux computer. I had 3462 blank entries listed on 12/31/1969. The first time I restored my Windows datebook.dat, and hot-synced, all of the restored records were again “deleted” because my Palm though it had the more current copy of those records in 1969. I had to purge the records from my Palm before hot-syncing with the restored datebook.dat file.


Techrepublic has a Review of 10 outstanding Linux backup utilities, many of which work on other platforms as well.

Personal solutions (not hosted):

  • Simple Backup Suite for Ubuntu and Fedora, which does full and incremental backups, on a schedule or manually. Install it on Fedora by running “yum install sbackup“. Configure and run by running “/usr/bin/simple-backup-config
  • fwbackups, of which Techrepublic says, “This is, by far, the easiest of all the Linux backup solutions.”
  • Rsnapshot
  • Duplicity which is a command line utility, and is recommended by http://rsync.net

Berkus: Five Steps to PostgreSQL Performance

Friday, March 12th, 2010

Five Steps to PostgreSQL Performance by Josh Berkus October 2009

I found this to be informative, and much of the advice applies to databases besides PostgreSQL.

f-spot and sqlite

Friday, January 1st, 2010

I recently tried using Linux f-spot, with the intent to make it easier to browse, manipulate, manage and publish my photos. I wanted f-spot to manage my photo screen saver as well. f-spot seems to be good at importing photos, but getting photos removed is a bit more difficult.

I organize my photos by date an a directory structure such as “2010/2010.01.01 New Years Day”. The “2010″ directory contains several sub directories. Each sub directory consists of a date and a description. If, for some reason, I import photos into f-spot that I don’t want in its database, I know what directory the photos pertain to. Unfortunately, F-spot doesn’t allow me to remove photos from its catalog by filename or file path. That’s okay though, because it stores its database using sqlite.

I figured this out by running lsof -p pid-of-f-spot, and noticed a file descriptor opened to “/home/jared/.config/f-spot/photos.db”. Then I ran file ~/.config/f-spot/photos.db and it helpfully told me that it is a “SQLite 3.x database”.

After a bit of google research, I figured out I could install a SQLite manager on my Fedora system: yum install -y sqliteman, followed by running sqliteman ~/.config/f-spot/photos.db. I was expecting to see a command-line client, but to my surprise, I found a pleasant graphical interface. It was simple to browse the table schema and to run queries to update and morph the f-spot photo database. Note: I’d recommend making a backup copy of the database before altering it.

F-spot may not be everything I want it to be, but I managed to work past its limitations due to the fact that it used a well known, open data storage format.

Minimizing tracing/instrumentation overhead, injectso

Monday, December 21st, 2009

Reading these articles from lwn.net: Minimizing instrumentation impacts and Debugging the Kernel using Ftrace, reminded me of Microsoft detours and Linux injectso (updated to work with current glibc, kernels).

Using rsync with SELinux

Friday, September 18th, 2009

Last week, I needed to move /home from one Fedora computer to another, and I used rsync over ssh move the data.

On the new system, I noticed that procmail didn’t seem to be working, and neither did Dovecot. Nor could apache serve up my files. This had all been working on my previous Fedora system, which was running SELinux, as was my new system. What had happened?

I hadn’t told rsync to bring across the SELinux file contexts, which are stored in extended attributes. Here is the rsync option I should have used:

-X, --xattrs

I could have used ‘tar’ to move my home directory as well. In that case, I would have needed one of the following options: --selinux or --xattrs

I resolved my SELinux issues using the excellent SETroubleShoot, which explained what commands to run to restore the proper SELinux contexts on various files.

SELinux requires time to tune, and I use it because it enhances the security of my linux system, which serves up content over HTTP (Apache), IMAP (dovecot) and CIFS (Samba).

Fedora 11 and Virtualization (KVM)

Monday, July 27th, 2009

I’ve recently upgraded another computer from Fedora 9 to Fedora 11, and I’ve decided to try the built-in KVM (i.e. Applications -> System Tools -> Virtual Machine Manager). I wanted a virtual machine that had bridged mode networking, but it wasn’t available by default. To get it as an option, I disabled SELinux (not sure if it was necessary), followed some special instructions to setup a bridged interface, and restarted my network and libvirtd.

Now I’ve got a working guest OS inside of KVM, and I like it. The guest OS feels snappy and responsive.

Update: KVM and the accompanying tools aren’t as mature as VirtualBox or VMWare. E.g. I didn’t see how to get my USB flash drive to be recognized by a KVM guest OS. At one point, I tried to use VirtualBox at the same time as KVM. VirtualBox told me I needed to disable the KVM kernel module before using VirtualBox.

Switched from digitalspace to justhost

Friday, July 10th, 2009

I’ve been running my website on digitalspace.net hosting for years. Then they sold out to jumpline, and my ability to push changes to my website via ‘rsync‘ disappeared, and was never restored. Although I still had ssh shell access, the account was seriously limited. It was probably a good security decision on their part, but I missed having wget, tar, gunzip, chmod, and other essential utilities that I used when upgrading my blogging software. It became tedious, at best, to maintain my website.

I’ve finally switched to hosting through http://www.justhost.com and the transition has taken more time than I wanted. As a father of four dear children, I feel the time pinch. Migrating wordpress has been more tedious than expected. And then there’s email — that was a pain to switch as well. At one point, I even considered abandoning my website and switching my blog to a site like blogger.com. But I stuck with it.

Jumpline support has been good to work with, and I’m pleased with my ssh shell access. I get the power of a typical linux shell with my favorite utilities: rsync, tar, etc.

My impressions of Fedora 11

Wednesday, June 17th, 2009

Here's my take on installing Fedora 11, which was released June 9, 2009. I chose not to do an upgrade as I often do. Instead, I did backup, followed by a fresh install, preserving my /home partition, but wiping out the other partitions. Then I used meld to restore my configuration files in /etc -- such as ssh server keys, printer settings and file system mounts. I found that I had to use the kernel boot option nomodeset in order to avoid system lockups. Overall, I've been pleased with my Fedora 11 experience, despite the bumps.

Fedora 11 useful resources:

Pre-install:

  • cp -a /etc /home/backup/etc
  • cp -a /root /home/backup/etc
  • backup /home
  • booted the LiveCD to make sure it would detect my hardware and run

Install

  • I decided to preserve my partition layout, which isn't the default option upon fresh install
  • Didn't delete my /home partition.
  • Reformatted all other partitions, with "/" as ext4

Post-install:

  • Had to enable eth0 in NetworkManager, and make "enabled" the default.
  • yum install -y meld nautilus-actions nautilus-open-terminal vim-X11 zsh screen mc rdesktop
  • meld /home/backup/etc /etc
    • Restored /etc/ssh settings
    • Restored /etc/cups printer settings
    • Checked /etc/fstab differences
  • Installed NX Server

Pleasurable:

  • Bootup is very pleasant, and seems faster. 30 seconds boot. 17 seconds login. 14 second shutdown. This is on an AMD Athlon 2400 Mhz Sempron with an ATI video card.
  • Artwork is top notch (backgrounds on login screen and default wallpaper)

Pain points:

  • Unavailable extensions for Thunderbird 3.0 -- Enigmail
  • Unavailable extensions for Firefox 3.5 -- Aardvark -- QuickProxy
  • Computer locked up every few hours until I added nomodeset to my kernel settings in /etc/grub.conf.

Gnome Slideshow Screensaver Sanity, Take 2

Wednesday, June 17th, 2009

Last year, I wrote about how to achieve Gnome Slideshow Screensaver Sanity. I've recently upgraded to Fedora 11, and I noticed that GLSlideshow isn't installed by default (maybe it never was), and I wondered if I could alter the settings for gnome slideshow. By default, it uses pictures out of the $HOME/Pictures folder, and there's no way in the user interface to change that location, which can be frustrating. Here's how I worked around it. Note the use of the --location option, and that I changed my Name= setting.

  • cp /usr/share/applications/screensavers/personal-slideshow.desktop ~/.local/share/applications/my-slideshow.desktop
  • gedit ~/.local/share/applications/my-slideshow.desktop

[Desktop Entry]
Encoding=UTF-8
Name=Custom Photos
Exec=/usr/libexec/gnome-screensaver/slideshow --location=/home/images/Photos
TryExec=/usr/libexec/gnome-screensaver/slideshow
StartupNotify=false
Terminal=false
Type=Application
Categories=GNOME;Screensaver;
OnlyShowIn=GNOME;

Go into the screensaver preferences (System -> Preferences -> Screensaver), and select "Custom Photos". There's no way to customize the duration to display each photo, but at least I don't have to settle for Gnome's default location.