- Run a process detached to the current terminal:
nohup my_command &
- Get the exit code of the latest runned command:
echo $?
- Run the last command as
root(source):sudo !!
- Show the user under which I’m currently logged in:
whoami
- If you have the following error:
-bash: ./myscript.sh: /bin/bash^M: bad interpreter: No such file or directory
Then the fix consist of removing the bad characters:
sed -i 's/\r//' ./myscript.sh
- Free up some memory by clearing RAM caches (source):
sync ; echo 3 > /proc/sys/vm/drop_caches
- Display which distro is running the system (source):
lsb_release -a
or
cat /etc/lsb-release
- List of most used commands:
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head - Disable a service on Debian/Ubuntu, then re-enable it:
update-rc.d my-service-name remove update-rc.d my-service-name defaults
- Same thing as above but on a RedHat-like system:
chkconfig sshd --del chkconfig sshd --add
Tag Archives: kernel
Hardware commands
- Change the keyboard layout in Debian (don’t forget to logoff and logon to activate the new setting):
dpkg-reconfigure keyboard-configuration
- Low-level format of the
hdadevice:dd if=/dev/zero of=/dev/hda
- Same as above but for paranoïd, as random bits will be written 3 times before performing the “low-level format” (i.e. writting zeros):
shred --verbose --force --iterations=3 --zero /dev/hda
- Remove the MBR:
dd if=/dev/null of=/dev/hda bs=446 count=1
- Restore the original Windows MBR:
apt-get install mbr install-mbr -i n -p D -t 0 /dev/hda
- To add touchpad kernel support, add the following option to kernel at boot time:
psmouse.proto=imps
- Sometimes, depending of the laptop I use, the mouse pointer disappear from the screen when I plug a VGA cable to a projector. In this case, I do a
CTRL + ALT + F1, then I login as a normal user and finally I start a new X session:startx -- :1
Easy Mirroring Without RAID: the Poor Man’s Disk Array
This howto explain how to use rsync to build a data mirroring mechanism on a local machine, with two hard drives, ala RAID 1, but without RAID 1 (!).
I had the project to setup a RAID 5 array using 3*120 Gb hard drives in USB enclosures. Unfortunately my project stalled due to instability in early 2.6.x kernels (I heard that 2.6.12 and upper are now useable for “RAID over USB”).
Because of the urgency of reliable storage (and because I don’t want to waste time compiling and fine-tuning kernels), I decided to do it using traditionnal IDE host. So I plugged two 120Gb HDD on my machine as master device, one on each IDE channel.
Then I made a big XFS partition on each, and update my /etc/fstab:
/dev/sda1 / auto noatime 1 1 /dev/hda1 /mnt/hd1 xfs defaults 1 2 /dev/hdc1 /mnt/hd1_mirror xfs defaults 1 2
At that moment I have to explain you that my machine is an OpenBrick NG, with a USB 2.0 512 Mb thumb drive (/dev/sda1 in the fstab) on which all my linux system is installed. That explain why my two IDE channels are free for use.
The idea is now to use /mnt/hd1 to store and manipulate my datas, then rsync that drive with his alter-ego (/mnt/hd1_mirror) every night. To do that, I’ve just added the following command in a cron entry:
rsync -a --delete --delete-excluded --delete-after /mnt/hd1/ /mnt/hd1_mirror/
And voilà !
As you guess, this solution is far from perfect, and has major inconvenients regarding RAID 1:
- No immediate backup : the backuped datas are 1-day old;
- Seek time is not reduce by half;
- Transfer rate is not doubled.
Oh, and by the way, be careful to not write files on /mnt/hd1_mirror/ because they will be deleted each night during the mirroring process.
