Skip to content

bootstrap to hd image

rofl0r edited this page Mar 20, 2012 · 14 revisions
export IMG_MOUNT=/tmp/mnt-sabotage
export IMG=/tmp/sabotage.img
#vdi image for vbox
export VDI=/tmp/sabotage.vdi

dd if=/dev/zero of=$IMG bs=1 count=1 seek=8589M
/sbin/fdisk $IMG
    c
    n
    p
    1
        <start at default sector 63>
    +100M
    c
    p
    2
        <start at default sector>
        <end at default sector>
    a #set bootable flag
    w

#partition layout

Disk sabotage_x64.img: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe065c58f

                                  Device Boot      Start         End      Blocks   Id  System
sabotage_x64.img1   *          63      204863      102400+  83  Linux
sabotage_x64.img2          204864    16777215     8286176   83  Linux

start offsets

sudo /sbin/losetup /dev/loop1 $IMG
sudo /sbin/losetup -o 32256 --sizelimit 104857600 /dev/loop2 $IMG
sudo /sbin/losetup -o 104890368 /dev/loop3 $IMG
sudo /sbin/mkfs.ext3 /dev/loop2
sudo /sbin/mkfs.ext4 /dev/loop3
sudo mount -t ext4 /dev/loop3 $IMG_MOUNT

set $R in config to $IMG_MOUNT

. config
./build-stage 0
./enter-chroot

#inside chroot

cd src
vi config
. config
#the installation of stage1 has to happen separately. 
#all other packages can be placed in the second invocation
butch install stage1 && butch install nano ...
mv /boot/ /boot-backup
mkdir /boot
mount -t ext3 /dev/loop2
cp /boot-backup/* /boot/
extlinux --install /boot
cat /src/syslinux-4.04/mbr/mbr.bin > /dev/loop1
sed -i 's,sda1,sda2,' /boot/extlinux.conf
cat /etc/fstab 
# 
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
/dev/sda2              /             ext4      acl,user_xattr      1      1
/dev/sda1              /boot         ext3      acl,user_xattr      1      2
proc                   /proc         proc      defaults            0      0
devpts                 /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs     nodev,nosuid        0      0

umount /boot

#tarballs are mounted into the chroot for convenience, we maybe want them to copy them
#for use inside the VM
cp -r /src/tarballs /src/tarballs_copy
# dont forget to adapt /src/config to point to /src/tarballs_copy

^D

#outside chroot

sudo umount $IMG_MOUNT

sudo /sbin/losetup -d /dev/loop1
sudo /sbin/losetup -d /dev/loop2
sudo /sbin/losetup -d /dev/loop3

VBoxManage convertfromraw $IMG $VDI

vbox converfromraw manual