====== 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'') | src: http://howtos.linux.com/guides/abs-guide/x6361.shtml ===== 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'', or ''screen -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, or ''screen -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 or/and maybe: xhost local: 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 '' |.tar.gz ; .tgz | |''tar jxvf '' |.bz2 | |''tar yxvf '' |.tar.bz2 | |''unzip '' |.zip | ^ Compress ^^ |''tar cxvf '' | .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 > 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 [[http://blog.racoon97.net/index.php?2006/10/05/51-utiliser-deux-ecrans-en-dual-desktop-avec-une-seule-carte-graphique-nvidia|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 [[howtos-tips#udevd|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''). ====== Configuration ====== ===== Do not wake up on lid open ===== Add to /etc/local.d/misc.start: echo " LID" > /proc/acpi/wakeup Ensure that the file misc.start is executable. ===== Fix laptop wakes up immediately after suspend ===== 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 ===== Keep screen off when lid shut ===== 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 + ;; ===== Lock on wake up ===== == With hibernate-scripts == (hibernate-scripts are probably deprecated) Add to /etc/hibernate/ram.conf: LockGnomeScreenSaver true See "man hibernate.conf" for more options. == With pm-utils == 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]] == With systemd == 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. ===== Hard Drive power management ===== Copy and edit /usr/lib/pm-utils/power.d/harddrive files to /etc/pm/power.d ===== Root mail alias ===== Add to /etc/mail/aliases: root: And execute newaliases ===== hddtemp ===== 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. ===== Gnome Screensaver ===== 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 [[http://www.narf.ssji.net/~shtrom/wiki/projets/gnomescreensavernosession|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') ===== Automatically enable/disable second screen ===== 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