Random general-use UNIX how-to's

This page is a simple compendium of how-to snippets, mostly pertaining to life with GNU/Linux. If you hit this from a search, then I hope you find what you are looking for here.


Disable Ctrl-Q quit in Mozilla/Seamonkey

Had it up to here with hitting Ctrl-Q by accident instead of Ctrl-W? Turn that trash off, Firefox-style, with this little hack. (And complain to the Mozilla crew while you're at it; they disabled it in Firefox, why the hell is it still there in Mozilla?) This hack should work for Mozilla v1.3 - 1.8 or so, who knows what changed outside of those versions.


Change fonts in xterm


If you are an avid user of classic X Window System desktops, you are probably using xterm (or its similar-but-not-quite-similar-enough translucent-capable counterpart, aterm) for just about every fuction that a simple window manager like fluxbox doesn't provide. If this is the case, you probably already know that pressing Shift-KPplus or Shift-KPminus keys changes the font size of these applications. (With xterm, you can also achieve the same using the Ctrl-RightClick menu, but sadly aterm provides no such feature.)

But have you ever wanted to change the actual font that xterm uses? Or worse, are you confused when you run xterm -fn courier, and then hit Shift-KPplus, only to find that a larger size of the fixed font greets your eyes? Lucky you: despite ZERO hits on google on this topic, the topic of changing xterm fonts in Linux or other UNIX-like X-Windows based operating systems, I found the answer for you.

Here's the general idea:


CIFS home directories: a configuration primer

Years and years and years after my first adventures in the realm of NFS, there are still unsolvable problems behind the scenes with this protocol that every UNIX admin loves to hate. The good news: there is an alternative you might never have thought about: CIFS (the Common Internet File System, an obnoxious name that only Microsoft could have conjured up). The bad news: there isn't a drop of documentation on configuring Samba in CIFS mode.

So the bottom line is, you want to replace NFS. You want to mount a CIFS share read-write, as root, with no password, on /home, with no security flaws. Impossible, right? Wrong! I have basically recreated the general features of NFS in a Samba server, thanks to the CIFS features available. So here is the scoop: This configuration seems to be working for me, at the time of this writing. I should point out, though, that performance appears to be somewhat poorer than with NFS. (Did you expect anything different? But actually, it seems even more laggy than regular old Samba!) Definitely contact me if you use this or a similar setup yourself, I'd really like to know just how well it works.


Running MySQL server unprivileged

Suppose you need to setup a MySQL database, and you don't have access to the system-wide MySQL environment. Not an unreasonable circumstance, really, but let us also suppose you asked the sysadmin for a table or something, and didn't get the answer yes. The solution? Run your own database install!

Naturally, MySQLd runs unprivileged. (All the good daemons do.) So there is nothing to stop you. But manual configuration looks brutal, doesn't it? Thankfully, it is incredibly easy -- mysql ships with some internal scripts which setup a server environment from scratch. It is as simple as running these commands: Naturally, you should substitute your own user id from the above examples, and the appropriate paths therein. Note, however, that the ~ home alias will produce errors in the above commands -- you will need to use the full path to your home directory. Other than that, you are good to go with your new, home-brewed MySQL server.


Debian fake-a-package trick

If you're like me, and build bizarre systems with qmail manually installed for the MTA, you know that hassles lie ahead. (If brief: qmail provides exemplary functionality as a Mail Transfer Agent (or MTA), but, being manually installed, it does not provide the package dependency. Thus, numerous packages will hassle you to choose and install another MTA. And you do not want this, now do you? I was under the impression there was an even easier way to do this, by flagging some entry in the APT database, but I was unable to confirm this at the time of writing (which is also the time that I needed a solution!) If you happen to know anything on this subject, please do not hesitate to contact me.

Meanwhile, the "less easy" way is to use the tool equivs. It will build a dummy package, containing nothing but the dependency information. The transaction is about as straightforward as this:
apt-get install equivs

cd /tmp
cp /usr/share/doc/equivs/examples/mail-transport-agent.ctl .
equivs-build mail-transport-agent.ctl

dpkg -i /tmp/mta-local_1.0_all.deb
You can hand-build a similar meta-package for any sort of similar dependency gap-filling. One caveat of the Debian equivs package though, is that it depends (ironically) on something that pulls in quite a large list of extras; I felt it wasn't worth installing on the server I needed it for, in the end I used a workstation. If you're in the same boat, save yourself those steps, and just download the file I compiled instead.

Credit to billslinuxqmail.sourceforge.net for this one.

On the topic of dpkg trickery, another one I needed recently was getting a list of packages manually selected for installation; in other words, a list of installed packages, excluding dependencies. (This is useful, for example, when cloning a server, which I do all the bloody time!)

I was sure I had come across a nice clean command for this, but in my most recent search, the best I could find was this chunk of obfuscation:
comm -23 <(dpkg --get-selections | sed -n 's/\t\+install$//p') \
   <(</var/lib/apt/extended_states \
   awk -v RS= '/\nAuto-Installed: *1/{print$2}' |sort)
Note, the resulting list will include "base system" packages, so if you install the list on a pristine new system, you will still get a raft of "package already installed" errors. Fortunately, APT is not that picky ...

I also need to find that aptitude one-liner for installing "The Base System". Very handy for bootstrapping VMs, chroot's, etc (which I also do all the damn time!) Any insight here would be appreciated!


Hot-add / remove SATA devices

This one is somewhat minor, as Linux systems will mostly do this automatically for you. But I've needed it a few times, so that's good enough to add here. You can force the "SCSI" bus (specifically in this case, the SATA bus) to reset, thereby re-reading the connected device.
echo x > /sys/bus/scsi/devices/n:0:0:0/delete
This command will disconnect the drive on ata bus number "n" (replace with the number for the bus you wish to interact with; typically bus "0" is the first, etc). A disconnected device should spin down, power off, and otherwise no longer be accessible to the system. Ready for hot-removal!
echo "0 0 0" >/sys/class/scsi_host/hostn/scan



Boot a PowerPC Macintosh from USB device

This guide is stolen verbatim from lifedigital2010.wordpress.com/2011/04/03/how-to-install-mac-osx-from-usb-on-powerbook-g4, though I made a few formatting changes for my own clarity.

Here is the rundown on how to manually boot a Mac that doesn't natively boot from USB. (This will also work on newer Macs, but it wouldn't be necessary; on the other hand, some other fancy new boot method might come along, and then those systems might be booted from the same way!)
  1. Using Disk Utility, prepare a USB disk by deleting everything on it and create an “Apple Partition Map”
  2. Restore the MacOSX image onto the USB thumbdrive
  3. Using Disk Utility, find out the partition on the USB key that holds the OS you want to restore (in my case : it was called disk1s3, the last figure holds the partition number thus : 3 )
  4. Then you boot in the PowerBook OpenFirmware (the bootstrap that loads before MacOSX) by pressing the “Apple / Alt / O / F” keys at the same time right after you switch on the machine (before the chime sound)
  5. Type dev / ls and try to find something like /disk@1 next to an entry named USB (in my case usb@1b,1, the dev entry seems to correspond to the positional location of the USB port, e.g. "port 2" = usb2)
  6. Type devalias in the command prompt and locate the short name of the USB entry you just found using dev / ls (in my case usb2)
  7. Make sure your USB key holds a file called “BootX” with the tbxi attribute by listing the directory. In the following command, disk@1 should be replaced by what you found in Step 5, also every character is important (this includes colon, forward slash, etc.). Type dir shortname_found_in_step_6/disk@1:partition_number_found_in_step_3,\System\Library\CoreServices (in my case dir usb2/disk@1:3,\System\Library\CoreServices)
  8. If BootX is found with an attribute called tbxi then you’re all set and you can instruct OpenFirmware to boot from the USB drive : boot usb2/disk@1:3,\System\Library\CoreServices\BootX
  9. Hit enter and you should be booting from the USB drive. You can then install MacOSX as you would with a DVD.
Other (possibly useful) tidbits
  1. The DEVALIAS command lists aliases to otherwise complicated paths to hardware (harddisk, USB, Soundcard, etc.) or software places (bootstrap). It is the equivalent of the Environmental Variables in Windows
  2. tbxi is an alias to the binary boot loader. This very interesting article is a good primer on the Open Firmware : www.netneurotic.de/mac/openfirmware.html
  3. The default keyboard in Open Firmware is US so if using a swiss-french keyboard, remember that @ is shift-2, \ is the $ sign, / is the – key next to right shift, : is the é key (etc).




Feel free to email me regarding any of these topics. I am quite interested to hear about other people's exploits.



Copyright © 2006 UltrX corp. All rights reserved.