### CONSTRUCTION IMAGE GNU/LINUX ### # Création d'une image extensible # ex avec 20 Millions de secteurs de 512 octets = 10GB dd if=/dev/zero of=disk.img bs=512 count=0 seek=20M # Récupération taille en octets ls -l disk.img -rw-r--r-- 1 root root 10737418240 2010-01-29 10:16 disk.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 disk.img Disk disk.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 disk.img1 * 1 1240 9960268+ 83 Linux disk.img2 1241 1305 522112+ 82 Linux swap / Solaris # Création des loops pour l'img et ses partitions losetup /dev/loop0 disk.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 # Montage de la partition virtuelle ext3 mkdir diskdir && mount /dev/mapper/loop0p1 diskdir # Installation d'une base de debian (gnu + dpkg/apt) dans la partition racine debootstrap lenny diskdir # (ou) à partir d'une archive d'une racine de système GNU/Linux tar -zxvf lenny.tgz -C diskdir/ # Config basique via un chroot + config serial port # Installation d'un kernel et du grub si c'est une debian "bootstrappée" mount --bind /dev diskdir/dev chroot diskdir env -i TERM=xterm-color HOME=/root PATH=$PATH LANG=C bash mount -t proc none /proc mount -t sysfs none /sys printf "127.0.0.1 localhost\n127.0.1.1 srv" > /etc/hosts echo "srv" > /etc/hostname printf "/dev/hda1 / ext3 defaults 0 1\n/dev/hda2 none swap\n" > /etc/fstab sed -i 's/^exit 0/rmmod pcspkr 2\>\/dev\/null\nloadkeys fr\nexit 0/' /etc/rc.local echo "nameserver 4.2.2.2" > /etc/resolv.conf echo "deb http://ftp.debian.org/debian lenny main contrib" > /etc/apt/sources.list 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 diskdir/dev # Démontage des loops kpartx -d /dev/loop0 losetup -d /dev/loop0 # Install du grub legacy dans le MBR de l'img grub --device-map=/dev/null device (hd0) disk.img find /boot/grub/stage1 root (hd0,0) setup (hd0) quit # Infos sur l'img créée file disk.img disk.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/Qemu... modprobe kvm kvm_intel kvm -smp 2 -m 512M -hda disk.img -nographic -usb -soundhw ac97 # ...ou préparer un disque physique (SATA, USB...) dd if=disk.img of=/dev/sdb bs=512 conv=noerror,notrunc