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.
setxkbmap -layout us setxkbmap -layout fr
or even :
loadkeys fr
/etc/init.d/gpm start
/etc/init.d/xdm stop
To restart X, /etc/init.d/xdm restart
or of course the well-known ctrl-alt-backspace.
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 ) |
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.
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.
screen
, or screen -S sessionname
to give a name to the sessionscreen -list
if there are several running screensscreen -r
to recall the last screen, or screen -r sessionname
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) |
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
or/and maybe:
xhost local:
Then you can do as root for example :
scite /etc/fstab &
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
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)
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 |
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
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 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
There are several ways to do dual screen with Linux :
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;
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.
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
.
You should not exclude /dev, see udevd error.
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.
grub grub> root (hd0,0) grub> setup (hd0) grub> quit
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.
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
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 .*
.
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
Check that PS/2 mouse is enabled in the kernel in Device drivers / Input device support / Mouse / PS/2 mouse
.
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).
If your speakers keep playing sound even if headphones are plugged, check with alsamixer
that “Headphone Jack Sense” is not muted…
Check you compiled mplayer with the xv
use flag.
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
).
Add to /etc/local.d/misc.start:
echo " LID" > /proc/acpi/wakeup
Ensure that the file misc.start is executable.
May be due to some USB devices, even if not plugged. Look if some USB* or EHC* or XHC* are enabled in /proc/acpi/wakeup
, and disable them:
echo EHC1 > /proc/acpi/wakeup
You can run it in a script at boot time right before suspending:
for usb in "EHC1" "EHC2" "XHC"; do state=`cat /proc/acpi/wakeup | grep $usb | cut -f3 | cut -d' ' -f1 | tr -d '*'` echo "device = $usb, state = $state" if [ "$state" == "enabled" ]; then echo $usb > /proc/acpi/wakeup; fi done
If your laptop don't physically switch off your screen when the lid is closed, it sends an ACPI event. Your system will probably switch off the screen by software (if it does not uncomment the “xset” line in the script), but even if it does when you will move your mouse it will switch back on, even if the lid is still closed. One solution is to use “vbetool”, but when I use it a few seconds later I cannot interact with the computer anymore. So instead I disable the mouse, with “xinput” you can selectively disable input devices, such as a mouse, the touchpad, the keyboard, the webcam… (use xinput –list to find ids).
Create /etc/acpi/actions/lid.sh with execution permissions:
#!/bin/sh case `cat /proc/acpi/button/lid/LID/state | awk '{print $2}'` in open) #vbetool dpms on DISPLAY=:0.0 XAUTHORITY="/home/cyril/.Xauthority" xinput set-int-prop 12 "Device Enabled" 8 1 ;; closed) #xset dpms force off #vbetool dpms off DISPLAY=:0.0 XAUTHORITY="/home/cyril/.Xauthority" xinput set-int-prop 12 "Device Enabled" 8 0 ;; esac
Edit /etc/acpi/default.sh to add:
case "$group" in button) case "$action" in + lid) + /etc/acpi/actions/lid.sh + ;;
(hibernate-scripts are probably deprecated)
Add to /etc/hibernate/ram.conf:
LockGnomeScreenSaver true
See “man hibernate.conf” for more options.
When using the button or when it is automatic apparently gnome-power-manager and gnome-screensaver deals correctly with it if you configure it to lock when lid closed. But it doesn't work when you manually call “pm-suspend” for instance.
So you can add this script /etc/pm/sleep.d/lock:
. "${PM_FUNCTIONS}" suspend_nm() { } resume_nm() { DISPLAY=:0.0 XAUTHORITY="/home/cyril/.Xauthority" su cyril -c "(gnome-screensaver-command --lock)" } case "$1" in hibernate|suspend) suspend_nm ;; thaw|resume) resume_nm ;; *) exit $NA ;; esac
A more complete one to automatically detect the user name is available here: https://wiki.archlinux.org/index.php/Pm-utils#Locking_the_screen_saver_on_hibernate_or_suspend
Create service /usr/lib/systemd/system/slimlock.service
:
[Unit] Description=Lock X session using slimlock [Service] User=cyril ExecStart=/usr/bin/slimlock [Install] WantedBy=sleep.target
Ensure right permissions and enable it:
chmod a+r /usr/lib/systemd/system/slimlock.service systemctl enable slimlock
Now when you suspend the system with systemctl suspend
the screen will be locked.
Copy and edit /usr/lib/pm-utils/power.d/harddrive files to /etc/pm/power.d
Add to /etc/mail/aliases:
root: <your-real-email-address>
And execute
newaliases
Edit the file /usr/share/hddtemp/hddtemp.db, find the line with the hard drive model that is the closest to yours, duplicate it and modify the model into yours.
If you don't have gnome-session, it will lock correctly the session but won't monitor idle time to start automatically. You can start the script available here instead of gnome-session. I had to make the following change to correctly detect the configured idle delay:
-gvalue = gclient.get('/apps/gnome-screensaver/idle_delay') +gvalue = gclient.get('/desktop/gnome/session/idle_delay')
disper -s disper -e
autodisper
for completely automatic with dock: http://askubuntu.com/questions/42741/how-to-automatically-switch-monitors-with-my-laptop-dock/48627#48627