forked from pikhq/sabotage
-
Notifications
You must be signed in to change notification settings - Fork 69
bootstrap to hd image
rofl0r edited this page May 17, 2024
·
14 revisions
note: there's also a script in utils/write-hd-image.sh that tries to automate this task using a prebuilt directory tree.
here's how to do it manually (this approach mounts the target hd image directly, so everything gets built inside, no need to copy)
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
# these are interactive commands for fdisk, check its built-in help
# to understand what they do.
/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
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
in case you're using debian 6, congratulations! you have fdisk 2.17, where you have to do all calculations by hand! read below for how to calculate the cylinder crap.
script by landley which shows how to use cylinders etc
<landley> But remember, everything these days is 63/255/cylinders
<landley> If it complains, feed it -h 255 -s 63
<landley> And then cylinders is $(echo $BYTES/255/63/512 | bc)
<landley> (Legacy partition formats FTW.)
<landley> Note that 255*63*512 is 8255280 so your file length should be a multiple of that to make the partitioning software happy.
<landley> Most physical disks are on general principles. (BOW DOWN BEFORE DOS!)
<landley> And yes, "heads" was an 8 bit value and "sectors" was a 6 bit value, and then cylinders was 16 bits.