Build disk image directly

| | Comments (0)

An example to build disk image directly

#!/bin/sh
B=16 # cylinders
P1=100 # cylinders
P2=200 # cylinders
dd bs=1k count=16 if=/dev/zero of=0 # Linux disk first 16k stores MBR and partition table
dd bs=1k count=$((P1*64-$B)) if=/dev/zero of=1
dd bs=1k count=$((P2*64)) if=/dev/zero of=2
printf "nn\np\n1\n\n$P1\na\n1\nn\np\n2\n\n$P2\nw\nq\n" | fdisk -H 4 -S 32 -C $(($P1+$P2)) 0
mke2fs -F 1
mount -o loop 1 /mnt
cp files /mnt # copy your files to partition 1
umount /mnt
mke2fs -jF 2
mount -o loop 2 /mnt
cp files /mnt # copy your files to partition 2
umount /mnt
cat 0 1 2 > image.dd

Load image to disk
# dd if=image.dd of=/dev/sda

# fdisk -l /dev/sda

Disk /dev/sda: 32 MB, 32702976 bytes
4 heads, 32 sectors/track, 499 cylinders
Units = cylinders of 128 * 512 = 65536 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 100 6384 83 Linux
/dev/sda2 101 200 6400 83 Linux

Leave a comment

March 2009

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

About this Entry

This page contains a single entry by Pank published on June 13, 2005 11:25 AM.

macchanger was the previous entry in this blog.

人造太陽 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.