This is an old revision of the document!
Table of Contents
Howtos, tips and errors
These howtos and tips are normally appropriate for all linux distributions, but when there are packages to install I take the example of gentoo with emerge
. But you can probably do the same with apt-get
or yum
or whatever.
Tips are things that maybe you don't know they exist.
Howtos are things that maybe you don't know how to do it.
Errors are things that maybe you don't understand at all why they occur.
Tips
Change quickly your keyboard layout
setxkbmap -layout us setxkbmap -layout fr
or even :
loadkeys fr
Mouse without X
/etc/init.d/gpm start
Stop properly X
/etc/init.d/xdm stop
To restart X, /etc/init.d/xdm restart
or of course the well-known ctrl-alt-backspace.
Suspend a program
ctrl-s | suspend (freeze) a running console process |
ctrl-q | unfreeze a suspended process |
ctrl-z | interrupt a running console process (sigsusp), it gives you back the prompt |
fg | uninterrupt and run in foreground the latest interrupted process |
bg | uninterrupt and run in background the latest interrupted process |
jobs | display all processes attached to the current session |
fg %n | bring back to foreground the process with job id n (1,2,3… : given by jobs ) |
bg %n | send to background the process with job id n (1,2,3… : given by jobs ) |
Identify your usb storage devices by label or id
With Linux, when you plug several mass storage peripherals (external hard drive, usb key, digital camera, mp3 player etc), they are seen as scsi drives and are given the names sda,sdb… according to the order in which they are connected. This is very annoying when you want to always mount your external hard drive partitions in the same folders, and your usb key in another one, particularly if you set it up in your fstab.
But if you have udev
installed, it create symlinks based on labels or ids in /dev/disk/…
, and you can use it in your fstab.
One other solution with udev could be to write rules in /etc/udev/rules.d
, so that you can change the sd*
name, but it is much more complicated.
Let running a program after ssh disconnection with screen
When you connect to a machine with ssh and launch a program, if you disconnect before the program has finished running it will be killed. To avoid that you can use the screen
program.
- Connect with ssh to the machine
- Enter in the screen by typing
screen
, orscreen -S sessionname
to give a name to the session - Launch your program
- Press ctrl-a and then d, it will detach the screen
- Close the ssh connection
- Reconnect with ssh to the machine
- Optionally, type
screen -list
if there are several running screens - Type
screen -r
to recall the last screen, orscreen -r sessionname
- Your program is still running in this window, or if it has stopped you can see its std out
Monitor your resources
top → htop | show processes with cpu and mem usage, kill them |
netstat → nettop → jnettop | show current tcp and udp connections |
iostat → dstat | show disk usage (io) |
Run X applications in your normal user session as root
Normally you can't run X applications from a root shell. This can be annoying when you want to open a document with root credentials.
As root :
export DISPLAY=:0.0
As user :
xhost +localhost
Then you can do as root for example :
scite /etc/fstab &
Change separators in your shell
For example to handle filenames with spaces.
# default value : trigger on spaces, tabs and new line IFS=$' \t\n' # example to not trigger on spaces : IFS=$'\t\n' # now this is working with filenames with spaces : for i in `cat bestof.m3u`; do cp $i /mnt/mp3; done
Howtos
Recompile your kernel
Almost all operations must be done in root or with sudo.
First, download your kernel http://www.kernel.org, and uncompress it :
cp linux-2.6.xx.tar.gz /usr/src cd /usr/src tar xvzf linux-2.6.xx.tar.gz
Or for Gentoo :
emerge gentoo-sources # sources patched with gentoo patches emerge suspend2-sources # OR sources patched with both gentoo patche and suspend2 patches for laptops
Then compile and install it :
rm linux ln -s linux-2.6.xx linux cd /usr/src/linux cp /boot/config . # get back your old config file (if exists) make menuconfig # to change configuration of your kernel make gconfig # OR with the GTK GUI make xconfig # OR with the X GUI make && make modules && make install && make modules_install
And that's finished, the make install
command did automatically something like :
cd /boot rm vmlinuz.old ln vmlinuz vmlinuz.old # save your old kernel which works ;-) cp linux/arch/x86_64/boot/bzImage /boot/vmlinuz-2.6.xx # or arch/i386/ if it is your case of course cp linux/System.map /boot/System.map-2.6.xx cd /boot ln -s System.map-2.6.xx System.map ln -s vmlinuz-2.6.xx vmlinuz
in order to install the new kernel, and let you access to older kernels in your boot manager (grub or lilo). It is up to you to remove useless versions from time to time.
The associated grub menu.lst
with a boot partition is :
title= Linux root (hd0,2) kernel /vmlinuz root=/dev/hda4 title= Linux Old Kernel root (hd0,2) kernel /vmlinuz.old root=/dev/hda4
With this method, you always have the old kernel in case you have a problem with the new one, and you don't have to modify your grub config file when you change kernel.
But if you do another way, you can use :
update-grub -v
to generate it automatically (but it will probably remove your Windows entry)
Tar/Unzip
Command | Archive type |
---|---|
Uncompress | |
tar zxvf <archive-name> | .tar.gz ; .tgz |
tar jxvf <archive-name> | .bz2 |
tar yxvf <archive-name> | .tar.bz2 |
unzip <archive-name> | .zip |
Compress | |
tar cxvf <archive-name> <files-names> | .tar.gz |
Detail of some options :
tar | |
---|---|
x | extract |
v | verbose |
c | compress |
Line for Windows in Grub
Grub is a boot manager, to choose at boot which OS you want to launch. Sometime with automatics installations it removes the line which permits to boot Windows.
You have to add in grub/menu.lst
:
------------------------ title Windows XP root (hd0,0) makeactive chainloader +1
Modify your path variable
echo $PATH export PATH="$PATH:/sbin"
But if you want the modification to be definitive (still valable after reboot), you have to modify it in the config files of your shell (.bashrc
, .zshrc
).
Create/Use a patch
Create a patch :
diff -ur <orig-folder> <modified-folder> > name.patch
Use the patch, if you are in the root folder of those you used above :
patch -p1 < name.patch
Dual Display
There are several ways to do dual screen with Linux :
- Xinerama : equivalent of windows dual screen (?)
- TwinView : the same as xinerama but with nvidia drivers
- Dual Desktop : two separate desktops (which can even be different window managers), you can move the cursor between them but not apps link [FR]
Chronic
Chronic is a task scheduler, which unlike crons use constraints and not only time to schedule tasks. This permits to schedule tasks when you are not using your computer (updatedb
, emerge –sync
, etc). Constraints can be Inactivity (based on load average, disk use, screensaver), ping etc.
Download the tar.gz archive here : http://sourceforge.net/projects/chronic/
Then install it :
tar zxvf Chronic-v.vv.tar.gz cd Chronic-v.vv perl Makefile.PL make make test su make install
You can then edit the /etc/chrontab
file. Format is well described in the man page (http://search.cpan.org/~vipul/Chronic-0.30/docs/chronicd.pod).
Here is as an example my chrontab file :
command = "updatedb"; \ constraint = Freq, 70000; \ constraint = Inactivity, 1200; \ constraint = Xscreensaver, 600; command = "eix-sync"; \ constraint = Freq, 70000; \ constraint = Inactivity, 1300; \ constraint = Xscreensaver, 700; \ constraint = Ping, 209.85.129.99; \ constraint = Concurrent, updatedb, 1;
Moving your linux system to another disk
If you don't want to reinstall linux, you can just move it to your new hard drive or partition.
Let's start from a disk with partitions and file systems created.
Copy the system
mkdir /mnt/boot mount -t reiserfs /dev/sda2 /mnt/boot rsync -irua /boot /mnt/gentoo umount /boot mkdir /mnt/linux mount -t reiserfs /dev/sda5 /mnt/linux rsync -irua /* /mnt/gentoo --exclude /proc --exclude /sys --exclude /mnt/gentoo --exclude /tmp --exclude /mnt/data mkdir /mnt/gentoo/proc mkdir /mnt/gentoo/sys
If you do not have a special boot partition, ignore all the parts related to boot
.
Note:
You should not exclude /dev, see udevd error.
Update some config files
If you changed the partition plan of your new drive, you have to update grub.conf and
/etc/fstab to match the new plan, and only automount necessary partitions at first.
Install Grub in the MBR
grub grub> root (hd0,0) grub> setup (hd0) grub> quit
Other method
Actually it is easier to copy a “dead” partition. So boot first on a liveced, and then mount and copy your system and boot partitions, without any precaution.
But you still have to update your fstab and grub.conf, and to reinstall grub if the disk changed.
Errors and problems
Shell errors with ZSH
Sometimes ZSH refuses some commands that are accepted by Bash. For example if you try :
emerge =package-4.3.2 echo mem > /sys/power/state
It won't work. In this case, and more generally when you have strange errors, just type bash
and tries with bash.
For the emerge thing, this is because =
is a particular character for zsh. You can either type :
emerge '=package-4.3.2' # or emerge \=package-4.3.2
or add an option in your .zshrc
file :
unsetopt equals
Command behave differently in script and prompt
Sometimes a command can work when you type it in your shell, and doesn't when you put it in a script. This is probably juste because your shell is different from the one you specified for the script, as most often scripts have the header #!/bin/sh
, but you use another shell.
For instance, zsh doesn't deal with . (current folder) and .. (parent folder) in the same manner that sh and bash :
tar -zcf /home/user/.*
will pack all your home with sh/bash, because .
is part of .*
, but with zsh it will only pack your config files, because .
and ..
are not in ls .*
.
udevd
During boot :
udevd[509]: get_ctrl_msg: unable to receive user udevd message: Socket operation on non-socket udevd[509]: get_netlink_msg: unable to receive kernel netlink message: Socket operation on non-socket
Some critical files are missing in /dev. I don't know exactly which ones, it happened to me when I tried to move my linux system to another disk.
Emerging baselayout
install some of them, but it doesn't seem to be enough, I had to copy all my original /dev to the new partition. You can use a live CD :
cp -rp /dev/* /mnt/gentoo/dev
Touchpad doesn't work
Check that PS/2 mouse is enabled in the kernel in Device drivers / Input device support / Mouse / PS/2 mouse
.
No sound in headphones
If sound works with the speakers, but not with the headphones, check with alsamixer
that the headphones output is not muted (M
key), and that the volume not at the minimum (up/down keys) (you can change output with left/right keys).
Speakers are not disabled when plugging headphones
If your speakers keep playing sound even if headphones are plugged, check with alsamixer
that “Headphone Jack Sense” is not muted…
Full screen doesn't stretch image in MPlayer
Check you compiled mplayer with the xv
use flag.
updatedb freezes with rlocate
rlocate
is an implementation of locate
that updates in-line the database by using a kernel module that detects all file creations. Then updatedb
just merges the main database with the in-line database.
But sometimes updatedb
freezes and doesn't do anything. It seems that this occurs when you restarted X, and then several instances of rlocated
(the rlocate daemon) are running.
To fix this, kill all rlocated
instances and restart the rlocate service (/etc/init.d/rlocate restart
).