Linux Tips and Tricks
This document is an unorganized collection of various Linux tips and tricks, mostly applicable to various flavors of Mandrake. Some of this may apply to other distributions like Red Hat (a mostly Mandrake-compatible distribution).
Set the Hostname
If you can't figure out how to point and click your way to changing the hostname (assuming you can), you can edit it by hand. This is the easiest way; I haven't bothered with any other.
Look for the file /etc/sysconfig/network and add a line
or otherwise modify it to include:
HOSTNAME=myhostname
This probably applies to all distributions that use sysconfig, such as Red Hat and Mandrake.
You should also add an entry in /etc/hosts, as follows:
127.0.0.1 persephone
Running root commands without being root
Some people get tired of having to switch to root to do certain
things, especially laptop users who frequently connect and disconnect
things. The sudo facility allows certain named users to
execute certain privileged commands without having to authenticate.
Edit the file /etc/sudoers. For example, if I (walter)
wanted to be able to issue the ifup and
ifdown commands without being root, I add the following
line:
walter ALL = NOPASSWD: /sbin/ifup, /sbin/ifdown
You can also add aliases for groups of users, or groups of commands, which simplifies things like allowing a user to execute all network-related commands. See the manual for details.
I hate the boot-time splash screen
Yeah, I hear you.
Most current distributions have a graphical bootloader and a pretty
graphical boot screen by default, and they don't make it all that easy
to get rid of. This is handled by the bootsplash
package, and if we want to go back to the tried and true 80x25 text
console, we're going to have to fight it.
First, get rid of the LILO graphical menu. On Mandrake, the
drakboot tool can do this, or you can edit
/etc/lilo.conf yourself, selecting
install=menu or install=text instead of
graphical.
Now change /etc/sysconfig/bootsplash and tell it to take
the stupid graphics elsewhere by changing the lines to include
SPLASH=no LOGO_CONSOLE=no
Now make sure that you pass the splash=0 option to your
bootloader (in LILO, this is the append option), reboot, and enjoy
your glorious text. Don't forget to run LILO first.
The Gnome 2.4 Workspace Switcher doesn't play nice with Sawfish
This is a known issue, with a known fix. The short story is that Gnome 2.4 doesn't support viewports, but the workspace switcher sends viewport messages anyway. Hilarity ensues as windows seem to shift randomly when you click on a workspace. Please see this Bugzilla report for the gory details.
It's usually better to rebuild the SRPM instead of downloading the
sources for everything -- this way you'll know that they will install
to exactly the same place and otherwise be exactly the same. Get the
SRPM for the libwnck package, blow it up somewhere (with rpm
-ivh, edit pager.c as instructed (look for the
wnck_screen_move_viewport calls and remove them, or apply their
patch), put everything back together, and install your custom-tailored
version. I walk you through this example in my RPM tutorial. If you are not familiar with
the RPM build process, I refer you to the Mandriva RPM
HOWTO, which has all sorts of stuff on building your own RPMs.
Hopefully this fix will be integrated into the next version of Gnome.
I dual boot, and the time keeps changing!
Suppose you dual boot, and Windows seems to think the time is five hours ahead of Linux. So you change it, and now Linux is five hours behind. What's going on here?
Windows reads the hardware clock and assumes it is in the local time zone. Linux can read the hardware clock as either local time or GMT, depending on how you've set it up. In the case above, you might have noticed that your GMT offset just happens to be five hours.
The solution is to tell Linux to treat the hardware clock as local
time instead of GMT. The command for this is hwclock,
but this is usually initialized from boot scripts. On systems with
sysconfig, look at /etc/sysconfig/clock and change any
line that reads UTC=true to UTC=false.
Adobe Reader 7 has a stupid ad thingy
Adobe Reader 7 (Acrobat 7) has a highly distracting button-like thing in the upper right. To get rid of it, drag any button on the same toolbar down a bit. This creates a second toolbar just below the current one. Drag the remainder of the buttons down to match. When you drag the last button down, the first toolbar disappears (because it is empty), taking the offending ad thingy with it. To prevent it from appearing again, lock your toolbar in place now.
Alternatively, going to Edit/Preferences and deselecting "Show messages and automatically update" achieves a similar effect.
How to I merge PostScript files?
There is psmerge, but it doesn't always work right. The
following command uses ghostscript and has the same
effect of printing a bunch of files in sequence, except that the
output goes to a file.
ghostscript -dNOPAUSE -sDEVICE=pswrite -dBATCH -sOutputFile=out.ps file1.ps file2.ps ...
This prints file1.ps, file2.ps, etc, to
out.ps. In my experience, this is much more reliable
than psmerge or the CUPS pdfwriter, especially in really
funky cases with non-embedded foreign fonts.
Why is Flash so slow in Mozilla?
There is an interesting interaction between Mozilla (and other Mozilla-based browsers like Fire-whatever and Galeon), Xft, and Flash.
The fix is to export an environmental variable as follows:
export FLASH_GTK_LIBRARY=libgtk-x11-2.0.so.0
You'll probably want to stick this in a script somewhere so that you
don't forget. The libgtk-x11-2.0.so.0 works on my
machine; if it doesn't work for you, you should give it the correct
libgtk-x11 library on your system. It is likely that after Flash 7,
this problem will cease to exist anyway.
CUPS won't print to a remote LPD server
By default, when CUPS connects to a remote LDP server, it does not reserve a privileged port. Some LPD servers may be configured to require an incoming connection to come from a privileged port (per RFC 1179) and will reject print requests originating from non-privileged ports (ostensibly for security, although that is very debatable). You need to change this behavior.
Suppose you wish to print to printhost.cs.utexas.edu,
queue lw42. Add a printer through the CUPS web interface
(http://localhost:631) or by editing files, and for the
Device URI, specify:
lpd://printhost.cs.utexas.edu/lw42?reserve=on
Assuming the lpd backend is installed, the remote print server should now be receiving requests from you from a privileged port. See the CUPS Software Administrator's Manual for more details.
How do I make my Linux DVD player region-free?
You don't. That is, you don't have to - it already is.
For the unfamiliar, virtually every DVD movie in the US (and most of the industrial world) is encrypted with CSS and has a region code. A player made for Region 1 (United States and Canada) will refuse to play a disc marked for Region 2 (Europe and Japan), and vice versa. The goal of this deliberate technical incompatibility is to prevent individuals from traveling to other countries and bringing DVDs home. This strengthens the local distribution monopolies and allows distributors to charge different prices for each region (since this attempts to make importing impossible). Most reasonable individuals feel this is underhanded at best, and possibly an illegal restraint of trade, but nobody has the money or political will to go up against the major studios.
Starting around 2000, all manufacturers of DVD-ROM drives were required to implement RPC-2 region coding in hardware. In principle, this should prevent software-only solutions for playing out-of-region discs. However, clever people have found ways.
Region coding works in conjunction with CSS encryption to provide hardware support for region locking. The player software and the drive do several things before playback of encrypted content can begin:
- The player requests the disc title key from the drive.
- The drive checks the disc's region and its own region.
- If the regions match, the drive returns the title key.
- The player uses the title key to decrypt the movie content and play back the disc.
Note that all the hardware stops you from doing is getting the title key. You can still read all the data on the disc in encrypted format. If there were another way to get the title key, the hardware protection is rendered useless, as we would have both the data and encryption key.
Normally libdvdcss uses the usual means (which they call "key") for playback. However, it falls back to "title" which performs a brute-force cryptographic attack on the key. This process can be rather CPU-intensive, but usually reveals the key and permits region-free playback on unmodified region-locked hardware. You should not have to do anything on a recent build of libdvdcss to enable this behavior. For more details, see the libdvdcss programming documentation.
The DVD FAQ has everything you want to know about DVDs.
Go enjoy your foreign movies!
Disclaimer: I own no foreign-region DVDs, so it's not very easy for me to rigorously test this.
What Nautilus URIs can I use?
This isn't very well documented anywhere, but you can type a number of URIs into the Nautilus address bar and get cool things. Some of the ones I know about are:
- preferences:///
- Gives the Gnome Control Center
- smb:///
- Samba browser -- basically "Network Neighborhood"
- fonts:///
- Font browser. Click on font to see stuff.
- applications:///
- Shows a categorized menu of a bunch of Gnome applications. I think you can change the Gnome menu from here, but Mandrake uses the Debian menu system anyway, so that exercise is pointless.
- burn:///
- Supposedly this gives you something to drag files into in preparation for burning to CD, but my Linux machine doesn't have a CD burner.
- themes:///
- Displays a whole bunch of themes. You can change your theme from here, but the Control Center is probably better. It does offer a great thumbnail view, though.
There are probably a lot more undocumented ones as well.
How do I make a Windows filesystem on Linux?
You got yourself some nice shiny USB external storage device (for example) and you want to create a FAT32 filesystem on it so that Windows and Linux can read it. You've already allocated a partition (Windows FAT32 LBA, type 0C) and figured out that you need to do something involving mkfs to actually create the partition, but get the following error:
[root@persephone root]# mkfs.vfat /dev/sda1 mkfs.vfat 2.9 (15 May 2003) mkfs.vfat: Attempting to create a too large file system
This occurs if the partition is too large for a FAT filesystem. Tell
it to create a FAT32 filesystem instead: mkfs.vfat -F 32
/dev/sda1
Anecdotally, I've seen Windows create a FAT32 partition on a removable storage device that Linux couldn't read (lots of errors about reading beyond the end of the device); the problem went away when I created the partition from Linux. I haven't bothered to investigate further.
Adding Wireless Interfaces By Hand
Sometimes the various point and click tools don't work right, and you need to add a new network interface by hand. As an example, let's add a Netgear MA401 wireless LAN card, which is happily supported out of the box, at least as far as drivers go.
First, we insert the card and hope that the appropriate kernel modules are loaded. I see that they are (the MA401 uses the orinoco driver):
[root@persephone etc]# lsmod Module Size Used by Not tainted orinoco_cs 5652 0 (unused) orinoco 36972 0 [orinoco_cs] hermes 7524 0 [orinoco_cs orinoco] eepro100 21844 1 ...
Now I check that the wireless tools know about it (obviously, if it isn't a wireless card, you won't want to do this):
[root@persephone etc]# iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
eth1 IEEE 802.11-DS ESSID:"" Nickname:"Prism I"
Mode:Managed Frequency:2.422GHz Access Point: 00:00:00:00:00:00
Bit Rate:11Mb/s Tx-Power=15 dBm Sensitivity:1/3
Retry min limit:8 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality:0/92 Signal level:134/153 Noise level:134/153
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
It's there, but it isn't doing anything. Time to fix that. I want
the new network interface on eth1, with certain options. I create a
file at /etc/sysconfig/network-scripts/ifcfg-eth1 with
the following lines:
DEVICE=eth1 BOOTPROTO=dhcp NETMASK=255.255.255.0 ONBOOT=no MII_NOT_SUPPORTED=yes WIRELESS_MODE=Managed WIRELESS_ESSID=tsunami DHCP_HOSTNAME=persephone NEEDHOSTNAME=no
This specifies that device eth1 uses DHCP to get an IP address, that it is not started automatically on boot, it is named persephone (although the DHCP server does not require it), and that the wireless is operating in Managed mode (connect through base station) with ESSID "tsunami" (if the base station is broadcasting the ESSID, you can substitute "any").
Now that it knows the appropriate settings, we can try to bring up the interface:
[root@persephone network-scripts]# ifup eth1
Determining IP information for eth1... done.
[root@persephone network-scripts]# iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
eth1 IEEE 802.11-DS ESSID:"tsunami" Nickname:"persephone"
Mode:Managed Frequency:2.412GHz Access Point: 00:60:1D:21:7D:EF
Bit Rate:11Mb/s Tx-Power=15 dBm Sensitivity:1/3
Retry min limit:8 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality:77/92 Signal level:-25 dBm Noise level:-144 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
[root@persephone network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:03:47:93:1C:1C
inet addr:128.83.158.153 Bcast:128.83.158.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6807 errors:0 dropped:0 overruns:0 frame:0
TX packets:4190 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:4090713 (3.9 Mb) TX bytes:949479 (927.2 Kb)
Interrupt:11 Base address:0x9000
eth1 Link encap:Ethernet HWaddr 00:30:AB:11:F5:62
inet addr:128.62.233.212 Bcast:128.62.233.255 Mask:255.255.254.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:116 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:9819 (9.5 Kb) TX bytes:792 (792.0 b)
Interrupt:3 Base address:0x100
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1436 errors:0 dropped:0 overruns:0 frame:0
TX packets:1436 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:96608 (94.3 Kb) TX bytes:96608 (94.3 Kb)
As you can see, we now have happy wireless on eth1.
Note that if your card uses the wlan-ng package, things will look
slightly different. Also, don't forget to type cardctl eject
0 (or as appropriate) before physically ejecting the card.
Emacs has Strange Colors in KDE
If your Emacs (or other old X11 application) has weird colors under KDE, you should uncheck the "Apply Colors to non-KDE Applications" option, usually somewhere in Look and Feel/Colors.
Why is the text preview in Nautilus not working?
Whether or not Nautilus previews text files in the icon depends on the theme. Some themes (like Industrial) don't; some themes (like Gnome) do.
What do the long font names in X11 mean?
People see something like:
-adobe-helvetica-medium-*-*-*-12-*-75-*-*-*-iso8859-*
instead of "Helvetica 12pt" and get all scared. This is the
old X11 font specifier string; you'll see it occasionally. It
specifies all relevant information for a font in a nice,
programmer-friendly string. I'm not going to explain exactly how it
is formed; the easiest way is to run xfontsel and play
with it (it makes sense, in a strange way). If you do not have
xfontsel installed, it's probably in the X11R6-contrib rpm.
Right, now how do specify nice anti-aliased TrueType fonts?
The old X11 specifier only works well on the X core fonts. Since all of these fonts are ugly, you'll probably want to use your nice TrueType fonts everywhere.
On Linux (and others), this is usually done through the Xft font library, which actually gives pretty fonts. The font specifier is different (and more readable) from the old X11 font string. In general, the font strings look like:
My Font Name-pointsize:property1:property2...
For example, my custom Sawfish theme specifies an Xft font for the
titlebar with (via the get-font-typed call with
"Xft"):
Bitstream Vera Sans-14:bold:italic
This does exactly what you think it does. Naturally, this only works
for applications that can use Xft. See the manpage for
fonts-conf for more information.
My Emacs fonts are tiny on my super high resolution screen
This actually applies to most older X11 applications, not just Emacs.
For Emacs, you can attempt to solve this problem by going into the Faces configuration (from M-x customize), but this doesn't always work depending on your X11 resources and font stuff. KDE (and to a lesser extent, Gnome) may have issues with this on some distributions.
The "nice" way to fix this is to add the appropriate lines
to your ~/.Xresources file. For example, mine contains
the lines
emacs*Background: White emacs*Foreground: Black emacs*font: -*-fixed-*-*-*-*-18-*-*-*-*-*-*-*
This makes the colors more appealing to me, and makes the default font significantly larger for my tired old eyes. Fonts are specified in the old X11 manner.
This trick works in a lot of other older X11 apps as well, if you want bigger fonts in xman...
My pagan sacrifices to the computer don't work!
This is a common error among American English speakers. Ordinarily, when one sacrifices a goat within a circle of candles at the full moon to appease the computer gods, one chants "Elath grash nar maral, noor din Turing-wa ost, grash nar throk" (May our computers work, by the grace of Turing, may they run). While technically correct, it is important that the stress be on the second syllable of "maral" as placing the stress on the first syllable changes the request to "May our computers play, by the grace of Turing..." and as the gods have a strange sense of humor, this particular change frequently results in unfortunate consequences.