finally move buildroot-ng to trunk
[openwrt.git] / target / image / x86 / gen_image.sh
1 #!/usr/bin/env bash
2 # Copyright (C) 2006 OpenWrt.org
3
4 [ $# == 5 ] || {
5 echo "SYNTAX: $0 <file> <kernel size> <kernel directory> <rootfs size> <rootfs image>"
6 exit 1
7 }
8
9 file="$1"
10 part1s="$2"
11 part1d="$3"
12 part2s="$4"
13 part2f="$5"
14
15 head=16
16 sect=63
17 cyl=$(( ($part1s + $part2s) * 1024 * 1024 / ($head * $sect * 512)))
18
19 dd if=/dev/zero of="$file" bs=1M count=$(($part1s + $part2s)) 2>/dev/null || exit
20 fdisk -u -C $cyl -H $head -S $sect "$file" > /dev/null 2>/dev/null <<EOF
21 n
22 p
23 1
24
25 +${part1s}M
26 n
27 p
28 2
29
30 +${part2s}M
31 w
32 q
33 EOF
34
35 block() {
36 echo -e 'p\nq' | fdisk -u -C $cyl -H $head -S $sect "$file" | awk -v file="$file$1" -v n="$(($2 + 2))" '
37 $1 == file {
38 print $n * 512
39 }'
40 }
41
42 start="$(block 1 0)"
43 end="$(block 1 1)"
44 blocks="$(( ($end - $start) / 1024 ))"
45
46 genext2fs -d "$part1d" -b "$blocks" "$file.kernel"
47 dd if="$file.kernel" of="$file" bs=512 seek="$(($start / 512))" conv=notrunc
48 rm -f "$file.kernel"
49
50 start="$(block 2 0)"
51 dd if="$part2f" of="$file" bs=512 seek="$(($start / 512))" conv=notrunc
52
53 which chpax >/dev/null && chpax -zp $(which grub)
54 grub --device-map=/dev/null <<EOF
55 device (hd0) $file
56 geometry (hd0) $cyl $head $sect
57 root (hd0,0)
58 setup (hd0)
59 EOF
60
This page took 0.054225 seconds and 5 git commands to generate.