# 20M de secteurs de 512 bytes = 10GB (ici img extensible) dd if=/dev/zero of=node4.img bs=512 count=0 seek=20M # Récupération taille en bytes ls -l node4.img -rw-r--r-- 1 root root 10737418240 2010-01-28 10:16 node4.img # Calcul du nombre de cylindres (C=1305) bc 10737418240 / (255*63*512) 1305 # Partionnement fdisk (n p 1 \n 1240 n p 2 \n \n t 2 82 a 1 w) fdisk -C1305 -H255 -S63 node4.img Disk node4.img: 0 MB, 0 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xcce5bc97 Device Boot Start End Blocks Id System node4.img1 * 1 1240 9960268+ 83 Linux node4.img2 1241 1305 522112+ 82 Linux swap / Solaris # Création des loops pour l'img et ses parts losetup /dev/loop0 node4.img kpartx -a /dev/loop0 # Formatage ext3 (fsck tous les 50mt, label /) + de la swap mkfs.ext3 -F /dev/mapper/loop0p1 tune2fs -c 50 /dev/mapper/loop0p1 e2label /dev/mapper/loop0p1 / mkswap /dev/mapper/loop0p2 mkdir n4dir mount /dev/mapper/loop0p1 n4dir # Install d'une racine GNU/Linux (ici un debootstrap lenny) tar -zxvf lenny.tgz -C n4dir/ # Config basique + install pkg kernel & grub + serial port (via un chroot) mount --bind /dev n4dir/dev chroot n4dir env -i TERM=xterm-color HOME=/root PATH=$PATH LANG=C bash mount -t proc none mount -t sysfs none /sys /proc printf "127.0.0.1 localhost\n127.0.1.1 debian" > /etc/hosts echo "debian" > /etc/hostname printf "/dev/hda1 / ext3 defaults 0 1\n/dev/hda2 none swap\n" > /etc/fstab echo "nameserver 4.2.2.2" > /etc/resolv.conf echo "deb http://ftp.debian.org/debian lenny main contrib" > /etc/apt/sources.list sed -i 's/^exit 0/rmmod pcspkr 2\>\/dev\/null\nloadkeys fr\nexit 0/' /etc/rc.local apt-get update && apt-get upgrade apt-get install linux-image-amd64 grub console-data locales less htop ftp file vim-nox apt-get clean sed -i 's/^#T0:/T0:/' /etc/inittab cp -rf /usr/lib/grub/x86_64-pc /boot/grub cat << EOF > /boot/grub/menu.lst serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1 terminal serial title Debian root (hd0,0) kernel /vmlinuz root=/dev/hda1 ro console=ttyS0,9600n8 initrd /initrd.img EOF umount /proc umount /sys exit umount n4dir/dev # Install du grub dans le MBR de l'img grub --device-map=/dev/null device (hd0) node4.img find /boot/grub/stage1 root (hd0,0) setup (hd0) quit # Infos sur l'img créée file node4.img node4.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0x83, active, starthead 1, startsector 63, 19920537 sectors; partition 2: ID=0x83, starthead 254, startsector 19920600, 1044225 sectors, code offset 0x48 # Lancer avec KVM... kvm -smp 2 -m 512M -hda node4.img -nographic -usb -soundhw ac97 # ...ou préparer un disque physique (SATA, USB...) cat node4.img > /dev/sdb