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 hda device:
    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
    

Samsung Q35 XIC-5500 : Tiny Review of a Strong Compact Laptop.

samsung-q35-xic-5500 I’m the happy owner of a brand new Samsung Q35 XIC-5500 laptop. Here is a review of the machine hardware, not the software.

The hard disk of the machine is supposed to be a 120 GB one, and as usual a hidden partition is reserved for windows backups. I deleted this one and reformatted the whole disk. After this operation, fdisk (fdisk -l /dev/hda) report me a total usable space of 112.4 GiB. Not bad.

Now I’ll tell you what I noticed about the aesthetic and the usability of the machine itself.

samsung-q35-touchpad The touchpad has a good soft touch, but is located so close of the keyboard that I inadvertently activate it while typing. This is quite bad, especially when you write long texts. I think with some practice I’ll be able to move my fingers to avoid this unintended behavior.

I feared having a glossy screen but I’m finally happy. This one is not as reflexive as I thought, and bright colors are welcomed for watching movies. I still hadn’t the opportunity to test it in a sunny environment. October is not the sunniest month in the north of France ! ;)

samsung-q35-strange-keys To keep the machine as compact as possible, some keys of the keyboard were located in unusual places. Page Up / Page Down keys are for example on the right and on the left of the Upper key. Home and End need the function (Fn) key to work. This slow me down because I use them a lot when programming or editing blog posts.

The fan is located on the right side of the machine. I’m right handed so it’s not cool (pun intended). In reality it’s not a problem at all since the fan is not often activated during “normal” use (Internet surfing, mails, etc…).

I don’t like having sounds connectors in front of the machine.

The battery is unpleasant because half of it appear outside the laptop case. But having twice the capacity (6 cells instead of 3) is welcomed.

Finally the laptop is not ultra-mobile. It’s a very compact laptop (only 1.9 Kg), but not “ultra”: it has big margins around the keyboard and the screen, and is as large as usual 14” laptops. It is also as thick as others, because of the optical drive.

My Conclusion: If you need an ultra light laptop or if you are a gamer, this is not a machine for you. But if you need a light-weight notebook with everything heavy laptops have (including the optical drive), it’s a very good deal. I paid mine 1160 € on a French online store. This laptop is not an object of design. But for 100 € more than a 13” MacBook, you have a compact machine with superior hardware: Core 2 Duo, 1GB of RAM, 120GB HDD, 7 hours of max autonomy and 1280×800 screen. This is why I choose this machine, and I’m very happy with it ! :)

CD Burning commands

  • List all CD devices:
    cdrdao scanbus
    
  • Blank a CD-RW:
    cdrdao blank --device ATA:0,1,0 --driver generic-mmc
    
  • Burn an ISO:
    cdrecord -v speed=8 dev=ATA:0,1,0 ./geexbox-0.98-fr.iso
    
  • Generate an ISO image of a CD-ROM:
    dd if=/dev/cdrom of=/tmp/cdrom-image.iso
    
  • Create an ISO from a local directory:
    mkisofs -R -r -l -J -V volid -o /tmp/cdrom-image.iso src
    

    volid is the volume ID to be written into the master block;
    /tmp/cdrom-image.iso is the destination filename of the newly created ISO image;
    src is the temporary ISO directory containing the files and file structure you wish to have included in the ISO image.

  • Mount a local ISO image as if it’s a physical CD-Rom:
    mount -t iso9660 -o loop /tmp/cdrom-image.iso /media/cd-image/
    
  • Mount an UDF file system image:
    fuseiso -p dvd.img /media/dvd-image/
    
  • Convert a Nero’s proprietary .nrg CD image to standard ISO file:
    nrg2iso dvd-image.nrg dvd-image.iso
    

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.

Open Brick NG and RAID-1-like setup

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.

How-To Mount a File System Binary Image

Obtain a binary image

We have a USB key with a file system on it, and we want to save its content. We do a binary image using:

dd if=/dev/sda1 of=/home/kevin/usb_key.img

Mount the image file

Get informations about the file system of the image file using:

fdisk -l -u /home/kevin/usb_key.img

This show you something like that:

Disque usb_key.img: 0 Mo, 0 octets
9 têtes, 56 secteurs/piste, 0 cylindres, total 0 sectors
Unités = secteurs de 1 * 512 = 512 octets

Périphérique Boot   Start   End      Blocks   Id   System
usb_key.img1        56      511559   255752   83   Linux

Get the sector number where the partition start (56) and the size of sectors (512). Multiply the two values:

56 * 512 = 28672

Then setup a loopback block device based on the image:

losetup -o 28672 /dev/loop0 /home/kevin/usb_key.img

Now you can mount your USB key:

mount /dev/loop0 /mnt/usb_key/

Créer un Espace de Stockage Fiable avec RAID 5 et LVM sous Linux

Cet article explique comment créer un espace de stockage redondant et fiable en utilisant du matériel grand public et bon marché. Cela est possible par la combinaison de Linux, des mécanismes RAID logiciel et du gestionnaire de volumes logiques LVM.

Mise à jour: Le but initial était d’utiliser des boîtiers externes USB pour construire une matrice RAID. En réalité je n’ai jamais pu obtenir de résultats convaincants car les disques USB ne sont pas aussi fiables que des disques dur IDE classique. Je m’explique: une partie seulement des instructions IDE trouvent leurs équivalents dans le protocole USB, limitant ainsi l’accès bas niveau aux disques durs externes par le kernel linux. Voila pourquoi cet article reste inachevé et que certaines parties ci-dessous peuvent paraître décousues.

Pour commencer une explication de la technologie RAID et de ses intérêts n’est pas superflu.

Je dispose de 2 disques durs de 120 Go, que je met chacun dans un boîtier externe USB 2. Je les branche ensuite sur mon OpenBrick NG qui possède sur son port IDE0 un disque dur de 160 Go qui héberge l’OS. L’OS en question est une Mandrakelinux 10.0 installée sur les 40 premiers gigas du disque IDE, dans des partitions classiques qui ne seront pas protégées par le RAID. J’ai choisi une Mandrakelinux 10.0 car à l’époque la Mandriva 2005 n’était pas encore disponible et la Mandrake 10.1 à un udev buggé qui ne créée pas les devices RAID (donc impossibilité d’activer automatiquement le RAID au démarrage).

Supposons à partir de maintenant que l’OS est installé, pour nous concentrer uniquement sur la configuration et la mise en route du RAID.

Étape 1: Formater les partitions

J’ai donc les devices suivants:

  • /dev/hda -> DD de 160 Go (40 Go pour l’OS et 120 Go de libre)
  • /dev/sda -> DD externe de 120 Go n°1
  • /dev/sdb -> DD externe de 120 Go n°2

Nous voulons créer une matrice RAID 5 à partir de 3 x 120 Go. Plutôt que de faire une seule grosse partition de 120 Go par disque, nous allons créer dans chacun des disques trois partitions de 40 Go (3 x 3 x 40 Go = 3 x 120 Go). Nous construirons ensuite 3 unités RAID 5 de 3 x 40 Go puis nous les assemblerons via LVM. L’intérêt de diviser nos grosses partitions en plus petites est de réduire considérablement (par un facteur 3 dans notre cas) le temps de régénération de nos unités RAID en cas de corruption d’une partition.

Les partitions à créer sont de type Linux RAID. On pourra éventuellement faire cela avec drakconf.

Étape 2: Configuration de la matrice RAID

Nous utiliserons mdadm pour la gestion de notre RAID.

Note: A partir de la 10.1, la version de webmin fournie avec la Mandrake supporte mdadm. Pour arriver à nos fins par ce moyen, on pourras s’inspirer d’un article sur la mise en place d’un RAID via webmin.

Installation de mdadm:

urpmi mdadm

Création des matrices:

mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/hda2 /dev/sda2 /dev/sdb2
mdadm --create --verbose /dev/md1 --level=5 --raid-devices=3 /dev/hda3 /dev/sda1 /dev/sdb1
mdadm --create --verbose /dev/md2 --level=5 --raid-devices=3 /dev/hda4 /dev/sda3 /dev/sdb3

Lors de la création, les paramètres par défaut sont suffisants. Pour information, les paramètres optimaux sont:

  • Parity: left symetric
  • Persistent super block
  • Chunk size: 32kb ou 64kb (pour nos partitions de 40 Go)

Éditons le fichier de configuration /etc/mdadm.conf:

DEVICE          /dev/sda*
DEVICE          /dev/sdb*
DEVICE          /dev/hda2
DEVICE          /dev/hda3
DEVICE          /dev/hda4
ARRAY           /dev/md0 devices=/dev/hda2,/dev/sda2,/dev/sdb2
ARRAY           /dev/md1 devices=/dev/hda3,/dev/sda1,/dev/sdb1
ARRAY           /dev/md2 devices=/dev/hda4,/dev/sda3,/dev/sdb3

Avant d’aller plus loin, il faut attendre que les matrices soient construites:

watch -n1 'cat /proc/mdstat'

Dans mon cas, cela à nécessité entre deux et trois heures pour chaque unité RAID.

Note: avec la Mandrake 10.1, lors de la création des matrices RAID, on aurait eu des problèmes du type raidstart failed : /dev/md1: No such file or directory, qui peuvent être résolus en créant les device manuellement:

mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
mknod /dev/md2 b 9 2

Ces commandes créent les unités RAID dont nous avons besoin. Malheureusement elles ne sont pas autodetectées au démarrage donc, dans le cas d’une mdk 10.1, il aurait fallu faire cette manip à chaque démarrage de la machine. Voila une bonne raison pour ne pas utiliser la version 10.1.

Étape 3: Agréger les matrices RAID via LVM

J’ai choisi LVM pour agréger les unités RAID, pour bénéficier d’un redimensionnement flexible de mon espace disque, avant de parer à tous les scénarios possibles auxquels je serais confronté dans le futur. Il est tout à fait possible de faire la même chose avec du RAID linéaire (voir l’étape “3-bis” ci-après), mais dans ce cas on perd la une certaine souplesse au niveau des partitions.

Installation de LVM:

urpmi lvm2

On peut consulter la liste des disques parents sur le système avec lvmdiskscan.

Ensuite il faut créer un volume physique (PV = Physical Volume) pour chaque unité RAID:

pvcreate /dev/md0
pvcreate /dev/md1
pvcreate /dev/md2

Créons maintenant un groupe de volumes contenant nos trois partitions :

vgcreate vg01 /dev/md0 /dev/md1 /dev/md2

(marche pas ???)

Étape 3-bis: Agréger les matrices avec du RAID linéaire au lieu d’utiliser LVM

Si vous voulez utiliser du RAID linéaire plutôt que LVM, il faut créer une nouvelle unité RAID sur la base des trois premières:

mdadm --create --verbose /dev/md3 --level=linear --raid-devices=3 /dev/md0 /dev/md1 /dev/md2

Puis penser à mettre à jour /etc/mdadm.conf:

DEVICE          /dev/sda*
DEVICE          /dev/sdb*
DEVICE          /dev/hda2
DEVICE          /dev/hda3
DEVICE          /dev/hda4
DEVICE          /dev/md0
DEVICE          /dev/md1
DEVICE          /dev/md2
ARRAY           /dev/md0 devices=/dev/hda2,/dev/sda2,/dev/sdb2
ARRAY           /dev/md1 devices=/dev/hda3,/dev/sda1,/dev/sdb1
ARRAY           /dev/md2 devices=/dev/hda4,/dev/sda3,/dev/sdb3
ARRAY           /dev/md3 devices=/dev/md0,/dev/md1,/dev/md2

Étape 4: Créer le système de fichier

Formater en xfs:

mkfs.xfs -f /dev/md3

J’ai choisi xfs comme filesystem car il peut être agrandit à chaud, lorsque la partition est montée.

Pour monter le tout:

mkdir -p /mnt/data
mount /dev/md3 /mnt/data

Et enfin, pour le montage automatique au démarrage de notre serveur, il faut ajouter la ligne suivante à notre fichier /etc/fstab:

/dev/md3 /mnt/data xfs defaults 0 0

Maintenance du système

  • Réintégrer une partition dans la matrice.

    Si une partition est éjectée d’une unité raid (par exemple sda1 sur md1), il faut faire:

    cat /proc/mdstat
    mdadm --examine /dev/sda1
    mdadm /dev/md1 -a /dev/sda1
    cat /proc/mdstat
    

    La première commande montre que le RAID est dégradé. La seconde commande examine le status du disque qui à été éjecté de la matrice. La troisième ligne permet de réintégrer à chaud la partition dans la matrice. Et enfin la dernière commande nous montre l’avancement de la reconstruction de la matrice (ce qui peut prendre pas mal de temps).

  • Ré-assembler une matrice.

    La commande est du type:

    mdadm --stop /dev/md0
    mdadm --assemble /dev/md0
    

    Attention --assemble se base sur le fichier /etc/mdadm.conf.

  • Créer une unité RAID dégradée.

    La commande suivante créée une unité RAID 5 sur 3 disques durs, en indiquant que le premier est absent via le mot clé missing:

    mdadm --create /dev/md0 --level=5 --raid-devices=3 missing /dev/hda1 /dev/sda1
    

De la lecture complémentaire sur RAID 5 et LVM