Friday, February 25, 2005

Wonders of 'dd' and 'netcat': Cloning OS harddrives

The other day, I needed to clone a Linux system again. I had done cloning before, to an identical drive in the same computer. The dd command makes that boringly easy:

dd if=/dev/sda of=/dev/sdb

Wait a while, and your second SCSI disk (/dev/sdb) is an exact copy of the first (/dev/sda): boot record, partitions, everything. And by the way, the system on /dev/sda need not be Linux. If it is Windows or whatever else, just reboot to some Live Linux CD to make the copy.

But this time, the problem was a little different: I wanted the copy to go to an identical disk, but on another (also identical) computer. Not only did I not want to stop the system during the copy, but I didn't even have the cable to attach my disk to the "master" computer. Well it turned out to be almost as boringly easy than the previous example.

This page (from which this blog entry got it's title) goes into a lot of details, but to sum it up for the impatient, my simple problem was solved like this:

  • Boot the machine (which we will call Slave) with some Linux media like a Knoppix live CD. My DHCP server assigned it the IP address

  • On Slave, run
    nc -l -p 9000 | dd of=/dev/sda
    (note that it is important to start with Slave)

  • On Master, run
    dd if=/dev/sda | nc 9000

  • Go have a drink

That was it. If you enjoy drinks and want to also take a nap or something, replace your Gigabit switch with an old 10-Base-T hub between the 2 machines.

Don't forget to disconnect the network cable before rebooting Slave into it's brand new system, or you will have an IP address conflict if Master uses fixed IP addresses. And find more interesting names for the poor machines before the PC police gets you.

Update: now that I have used this method several times, I would like to do it with multicast to several machines at once. If you know how to do that, please leave a comment...

Thursday, February 24, 2005

The Braindead "Browse For Folder" dialog

[Update: Just found out that I'm not the only one who hates this stupid dialog]

I'm getting really mad at that braindead "Browse For Folder" dialog box which many applications seem to like using. I guess the dialog is really a Microsoft invention supposed to make life easier for braindead users. Maybe it does for them, but I doubt it. Anyway, for any normal person, it only makes it extremely difficult to create a new folder. What is particularly disheartening is that it seems to be mainly the open source apps which use it.

This example shows the dialog when installing Firefox. But I have had to endure it with many other apps.

So, let's say I would like firefox installed in D:\firefox instead of C:\Program Files\Firefox. I click on "Browse..." and what I expect is having a choice of browsing to there, or just typing or pasting into an edit box, which is usually much faster and easier.

When I click "Browse...", I see something like this (well, not really; but you don't need to see my Program Files folder):

So instead of painfully clicking my way through the maze of disks and folders while trying to avoid the traps of all the stupid virtual folders which Windows helpfully scattered around, I just type ahead into the edit box ...

... and press enter.

Well, guess where Firefox is about to install itself:

Was this supposed to be "user-friendly" and "intuitive"? I have only one explanation: the developers expect me to be too stupid to use my keyboard, and think it's better if they ignore the random characters I could accidentally have typed when putting my beer on the keyboard (what is a keyboard anyway? some legacy device from before Apple invented mice?) ...

Tuesday, February 22, 2005

Ping pour les nuls

Quand quelque chose ne fonctionne pas sur le réseau, on me téléphone et il n'est pas toujours facile de faire faire des ping à l'utilisateur pour localiser la panne.

Désormais, j'installe ce petit batch primitif mais efficace pour accélérer le processus. La partie la plus difficile est maintenant d'expliquer à l'utilisateur comment ouvrir une "invite de commandes". Une fois que c'est fait, il n'a plus qu'à taper netcheck:
Checking network connectivity

* OK 1: ping gateway at
* OK 2: ping external IP address (
* OK 3: ping external host name (

*** Everything looks OK

Si le gateway n'est pas, on peut en donner un autre en argument:

Voilà netcheck.bat:
@echo off
set gateway=
set externalip=

echo Checking network connectivity

if not "%1" == "" set gateway=%1
echo Gateway: %gateway%

ping -n 2 -w 500 %gateway% >nul:
if "%errorlevel%" == "1" goto nogateway
echo * OK 1: ping gateway at %gateway%

ping -n 2 -w 500 %externalip% >nul:
if "%errorlevel%" == "1" goto nointernet
echo * OK 2: ping external IP address %externalip% (%externalhost%)

ping -n 2 -w 500 %externalhost% >nul:
if "%errorlevel%" == "1" goto nodns
echo * OK 3: ping external host name %externalhost% (%externalip%)

echo *** Everything looks OK

goto end

echo * Failed 1: Cannot reach gateway at %gateway%. Check cables, hub, gateway (router).
goto end

echo * Failed 2: Cannot reach external IP address %externalip% ( Check router and connection between router and Internet; call ISP.
goto end

echo * Failed 3: Cannot find IP address of host %externalhost%. Check DNS settings.


Restaurer les barres par défaut d'Eudora

La gestion des différentes barres d'Eudora est parfois étrange. Si elles disparaissent ou ont des réglages bizarres, la simple ligne de Perl ci-dessous, certes un peu brutale, permet de supprimer tous les réglages qui s'y rapportent et de récupérer les réglages par défaut.

L'intérêt est qu'on ne perd pas ses autres réglages Eudora comme les comptes email, signatures, etc.

Après avoir fermé Eudora:

perl -i.bak -ne "if(/^\[.*Bar/){$inbar=1} elsif (/^\[/){$inbar=0}; print unless (/Bar/ or $inbar)" eudora.ini