# BAREMETAL DEBIAN SYSTEM IMAGE # WARNING: NO WARRANTY OF ANY KIND, USE IT AT YOUR OWN RISK. # License: GNU GPL v.2+ && GNU LGPL v.2.1+ # Requires: util-linux, debootstrap, grub # Recommends: kvm # # Create a disk of 10G (extensible) # dd if=/dev/zero of=vm1.img count=0 bs=512 seek=20M losetup /dev/loop0 vm1.img # # Create an ext3 root filesystem of 1G # dd if=/dev/zero of=debian.img count=2M bs=512 mkfs.ext3 -F debian.img tune2fs -c 50 debian.img losetup /dev/loop1 debian.img # # Create a debian core # mkdir rootfs mount /dev/loop1 rootfs debootstrap lenny rootfs # # Install a kernel and grub, then customize the debian core system. # Variants for a x86_64 system are commented. # ROOTFS_UUID=`file debian.img | awk -F"UUID=" '{print $2}' | cut -d" " -f1` mount --bind /dev rootfs/dev chroot rootfs env -i TERM=xterm-color LANG=C PATH=$PATH bash mount -t proc none /proc mount -t sysfs none /sys echo "deb http://ftp.debian.org/debian/ lenny main contrib" > /etc/apt/sources.list echo "deb-src http://ftp.debian.org/debian/ lenny main contrib" >> /etc/apt/sources.list apt-get update apt-get --yes install linux-image # apt-get --yes install linux-image-amd64 apt-get install locales console-data less pv htop vim-nox apt-get --yes install grub mkdir /boot/grub cp /usr/lib/grub/i386-pc/* /boot/grub # cp /usr/lib/grub/x86_64-pc/* /boot/grub/ # # (Setup your locales if needed) # dpkg-reconfigure console-data # loadkeys fr # # Then exit from the chroot # umount /sys # umount /proc # exit # # Configure the grub boot loader echo "(hd0) debian.img" >> device.map grub --device-map=device.map root (hd0,0) setup (hd0) quit echo "(hd0) UUID=$ROOTFS_UUID" >> rootfs/boot/grub/device.map chroot rootfs env -i ROOTFS_UUID=$ROOTFS_UUID TERM=xterm-color LANG=C PATH=$PATH bash update-grub # Then replace "root=/dev/mapper/loop0p1" by "root=UUID=$ROOTFS_UUID", # and add groot=(hd0,0) in /boot/grub/menu.lst # # Format with fdisk (n, p, 1, \n, $PART_SIZE, a, 1, w) # Number of cylinders = IMG_SIZE / (Heads * Sectors * Block size) # PART_SIZE=`ls -l debian.img | cut -d" " -f5` DISK_SIZE=`ls -l vm1.img | cut -d" " -f5` let CYL="$DISK_SIZE/(255*63*512)" fdisk -C$CYL -H255 -S63 vm1.img # # Insert the root filesystem image inside the disk image # dd if=/dev/loop1 of=/dev/loop0 bs=512 seek=1 # TODO kpartx -a /dev/loop0 mke2fs -j /dev/mapper/loop0p1 #vol_id --uuid /dev/mapper/loop0p1 > target.uuid #blkid /dev/mapper/loop0p1 mount /dev/mapper/loop0p1 /mnt/target # # Free the loop devices # losetup -d /dev/loop0 losetup -d /dev/loop1