Hints and tips on linux

These are some helpful hints on various topics.


Copy Volume serial number of a disk

When you make a copy of a disk using Copy Disk you get identical clone, except for a small detail: Volume serial number.

Volume serial number

There are some anti-copy protections based on this. Here is how to change this number under Linux:

Using mdir tool from package mtools you can see the serial number of the original disk, for example 173c-10db
Put the copied disk into the flopy device and save its volume serial number to the file  floppy.vsn using this command:
    dd if=/dev/floppy bs=1 count=4 skip=39  > floppy.vsn
Edit this file with some hex editor for example hexedit, and put the original number in it. You should be careful - bytes are copied backwards. So if you want to write number 173c-10db, you should type db 10 3c 17 into this file.
Save the number back to the copy:
    dd of=/dev/floppy bs=1 count=4 skip=39  < floppy.vsn

Starting additional X servers

To start additional X server use this command:
 startx -- :1
where :1 should be unique for every new server, meaning the second one will be :2 and so on. To switch between servers use Ctrl + Alt + F7, F8 and so on.

Creating files with fixed length and random content

Handy command to create file with fixed length and random content is  dd. Some examples:

File test1.bin, 10k size, containing only zero bytes:
 dd bs=1024 count=10 if=/dev/zero of=test1.bin

File test2.bin, 100k size and random content:
 dd bs=1024 count=100 if=/dev/random of=test2.bin

Above example is rather slow, especially for large files, so here's another way to generate pseudo-random file:
 dd bs=1024 count=100 if=/dev/hda of=test2.bin skip=1000
This will copy 100k from the hard drive 1М after the beginning.

Rsync over ssh with non-default port

If you use rsync over ssh to a server running on port different from 22, for example 555, use the following format:

rsync -a -e "ssh -p 555" rsyncuser@remoteserver:/data/to/sync /archive/

More on rsync

Mounting Windows shared folder in Linux

We have Windows resource under \\otherhost\share which we want to to see on the Linux machine as /mnt/winshare. Windows credentials are user/pass. So we use:

mkdir /mnt/winshare

mount -t smbfs -o username=user,password="pass" //otherhost/share /hmnt/winshare


mount -t cifs -o username=user,password="pass" //otherhost/share /hmnt/winshare

Add easily "sleep" functionality to your Linux box with installing zero new packages

If you want to be able to turn of your computer after a number of minutes you have a plenty of programs to choose from. Here's an easy way to do this with just using bash and at. Add the following to your .bashrc:
sleeper() {
    echo 'init 0' | sudo at now + $1 minutes

The just use it - set you desktop to poweroff in 50 minutes:
> sleeper 50

Use pm-suspend or pm-hibernate instead of init 0 to suspend or hibernate.