#*** CREATION D'UNE IMAGE SYSTEME BRUTE ET GENERIQUE *** (réutilisables pour QEMU/KVM, Xen, VMware, VirtualBox, disques SATA ou USB) I. DISQUE DUR Au choix... * disque dur virtuel "extensible" (ici 10G) # dd if=/dev/zero of=disk.img bs=512 count=0 seek=20M * disque dur virtuel (ici 4M de blocks de 512 bytes -> 2G) # dd if=/dev/zero of=disk.img bs=512 count=4M II. PARTIONNEMENT * Utilisation du disque non extensible, de 2147483648 bytes. Géométrie du disque : on choisit 255 heads, 63 sectors/track (convention : 512 bytes/sector), d'où 2147483648 / (255 * 63 * 512) = 261 cylindres. # fdisk -C261 -H255 -S63 disk.img * On créé 3 partitions primaires : - une pour la racine / (type: 83, taille: ~700M, fanion d'amorce) - une pour de la swap (type: 82, taille: ~256M) - une pour le /home (type: 83, taille: restante ~1G) * Ce qui peut se faire de façon scriptée : # printf "n\np\n1\n2\n+690M\nn\np\n2\n91\n+256M\nn\np\n3\n125\n\nt\n2\n82\na\n1\nw\n" | fdisk -C261 -H255 -S63 disk.img * Visualisation des partitions créées (unité: sector) # fdisk -C261 -H255 -S63 -lu disk.img >> Vérif (part1 commence au secteur 16065, part2 -> 1445850, part3 -> 1992060) # file disk.img disk.img: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 16065, 1429785 sectors; partition 2: ID=0x82, starthead 0, startsector 1445850, 546210 sectors; partition 3: ID=0x83, starthead 0, startsector 1992060, 2200905 sectors, code offset 0x0 III. CREATION DES FILESYSTEMS * Swap de 256M # dd if=/dev/zero of=swap.img bs=512 count=500k # mkswap swap.img # file swap.img swap.img: Linux/i386 swap file (new style), version 1 (4K pages), size 63999 pages, no label, UUID=a3936d9b-739d-4399-b40b-b781f19ec6f3 * Partitions ext3 (650M et 1G) # dd if=/dev/zero of=debian.img bs=512 count=1300k # dd if=/dev/zero of=home.img bs=512 count=2M # mkfs.ext3 -F debian.img # mkfs.ext3 -F home.img # file *.img debian.img: Linux rev 1.0 ext3 filesystem data, UUID=9baec4e1-7560-4579-84b9-e1f4a3c80a53 (large files) home.img: Linux rev 1.0 ext3 filesystem data, UUID=7fd59083-3893-4b66-b5bb-b2da5d02c4b5 (large files) IV. DEBIAN/GNU BOOTSTRAP * Création d'un système racine "lenny" (au choix) dans le répertoire "bootstrap" # debootstrap lenny bootstrap * Installation d'un kernel et du GRUB, + config fichier de base # mkdir bootstrap/boot/grub # cp -R /usr/lib/grub/x86_64-pc/stage{1,2} bootstrap/boot/grub/ # mount --bind /dev bootstrap/dev # chroot bootstrap env -i TERM=xterm-color LANG=C PATH=$PATH bash # mount -t proc none /proc # mount -t sysfs none /sys # apt-get update && apt-get install linux-image-2.6.26-2-amd64 grub locales console-data # echo "timeout 3\ntitle Debian\nroot (hd0,0)\n" > /boot/grub/menu.lst # echo "kernel /vmlinuz root=/dev/hda1 rw\ninitrd /initrd.img\nboot\n" >> /boot/grub/menu.lst # echo "127.0.0.1 debian" > /etc/hosts # echo "debian" > /etc/hostname # echo "/dev/hda1 / ext3 rw,errors=remount-ro 0 0" > /etc/fstab # echo "/dev/hda2 none swap sw 0 0" >> /etc/fstab # echo "/dev/hda3 /home ext3 defaults 0 ww0" >> /etc/fstab # echo # umount /sys # umount /proc # exit * Copie de cette racine dans l'image ext3 # losetup /dev/loop0 debian.img # cp -rfp bootstrap/* /mnt && sync # losetup -d /dev/loop0 V. INSTALL DU BOOT LOADER & CONCATENATION DES FILESYSTEMS # losetup /dev/loop0 disk.img * Install du MBR - images stage1 et stage2 du GRUB dans /usr/lib/grub - conservation de la table des partitions de disk.img (octets 446->512) # dd if=grub/stage1 of=/dev/loop0 bs=446 count=1 # dd if=grub/stage2 of=/dev/loop0 bs=512 seek=1 * Copie des partitions (à partir de leur point d'entrée correspondant au num de secteur) # dd if=debian.img of=/dev/loop0 bs=512 seek=16065 # dd if=swap.img of=/dev/loop0 bs=512 seek=1445850 # dd if=home.img of=/dev/loop0 bs=512 seek=1992060 # losetup -d /dev/loop0 # file disk.img disk.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3; partition 1: ID=0x83, active, starthead 0, startsector 16065, 1429785 sectors; partition 2: ID=0x82, starthead 0, startsector 1445850, 546210 sectors; partition 3: ID=0x83, starthead 0, startsector 1992060, 2200905 sectors, code offset 0x48 VI. UTILISATION DES IMAGES SYSTEMES BRUTES * Utilisation directe dans QEMU/KVM # kvm -m 256M -hda disk.img * Conversion vers VirtualBox (VDI) (ou même: VHD le format M$, VMDK le format VMWARE) # VBoxManage convertfromraw disk.img disk.vdi --format VDI * Conversion vers VMWare à l'aide des outils QEMU (taille d'origine divisée par 4) # qemu-img convert -f raw -O vmdk disk.img disk.vmdk * Installation sur disque SATA 2, ou sur une clé USB (/dev/sdb...) # cat disk.img > /dev/sdb