summaryrefslogtreecommitdiffstats
path: root/make_boot_img
blob: c6f5431bf2d46a4e04a9c88318f2dbcf8a9d504d (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl

@ARGV >= 2 or die "usage: $0 <image> cdrom|hd|network|network_ks|pcmcia\n";

($img, $type) = @ARGV;

$instdir = "install";
$ks = "kickstart=floppy" if $type =~ s/_ks//;
$mnt = "/mnt/disk";
$mke2fs = "/sbin/mke2fs -q -m 0 -F -s 1";

if ($>) {
    $sudo = "sudo";
    $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}";
}

$install = $ {{
    pcmcia => "full-install",
    network => "install",
    cdrom => "local-install",
    hd => "local-install"
}}{$type} or die;

$img =~ /rdz$/ ? initrd($mnt, $img) : msg_boot_img($mnt, $img);
#boot_img($mnt, $img);

sub __ { print @_, "\n"; system(@_); }
sub _ { __ @_; $? and die; }

sub install_s { _ "strip $_[0]"; _ "$sudo install $_[0] $_[1]" }

sub initrd {
    my ($mnt, $img) = @_;
    my $tmp = "$ENV{HOME}/tmp/initrd";
    my $tar = "$instdir/install1_$type.tar.bz2";
    -e $tar or $tar = "$instdir/install1.tar.bz2";

    __ "$sudo umount $tmp $mnt 2>/dev/null";
    _ "dd if=/dev/zero of=$tmp bs=1k count=2000";
    _ "$mke2fs $tmp";
    _ "$sudo mount -t ext2 $tmp $mnt -o loop";

    _ "$sudo tar xyC $mnt -f $tar";
    install_s("$instdir/installinit/init", "$mnt/sbin");
    install_s("$instdir/$install", "$mnt/sbin/install");

    _ "$sudo cp -f install_${type}_modules/* $mnt/modules/" if -d "install_${type}_modules";
    _ "$sudo cp -f modules/${type}_modules.cgz $mnt/modules/modules.cgz";
    _ "$sudo cp -f modules/modules.dep $mnt/modules/";
    _ "$sudo umount $mnt";

# Workaround for vfat-loop bug (quite touchy)
    _ "gzip -9f $tmp";
    _ "cp -f $tmp.gz $img";
    _ "rm -f $tmp.gz";
#    _ "gzip -9 -c $tmp > $img";
#    _ "rm -f $tmp";
}

sub boot_img {
    my ($mnt, $img) = @_;

    __ "$sudo umount $mnt 2>/dev/null";
    _ "bunzip2 -c $instdir/installinit/emptyboot.img.bz2 > $img";
    _ "$sudo mount -t msdos -o umask=0 $img $mnt -o loop";
    _ "cat vmlinuz > $mnt/vmlinuz";
    -f "$type.rdz" ? _ "cp -f $type.rdz $mnt" : initrd("${mnt}2", "$mnt/$type.rdz");
    
    output("$mnt/syslinux.cfg", "
default linux
prompt 0
label linux
  kernel vmlinuz
  append $ks ramdisk=32000 initrd=$type.rdz mdkinst $type
");
    _ "cp -f $instdir/installinit/ks.cfg $mnt 2>/dev/null" if $ks;
    _ "sync";
    _ "df $mnt";
}

sub msg_boot_img {
    my ($mnt, $img) = @_;

    __ "$sudo umount $mnt 2>/dev/null";
    if ($type eq "hd") {
	_ "bunzip2 -c $instdir/installinit/msgboot.img.bz2 > $img";
    } else {
	_ "bunzip2 -c $instdir/installinit/msgboot-graphicallogo.img.bz2 > $img";
    }
    _ "$sudo mount -t msdos -o umask=0 $img $mnt -o loop";
    _ "cat vmlinuz > $mnt/vmlinuz";
    -f "$type.rdz" ? _ "cp -f $type.rdz $mnt" : initrd("${mnt}2", "$mnt/$type.rdz");
    
    my $timeout = $ks ? 1 : 72;
    my $setmode = !($type eq 'hd') && "mode 0x101\n";
    output("$mnt/syslinux.cfg", "
default linux
prompt 1
timeout $timeout
${setmode}display boot.msg
F1 help.msg
F2 boot.msg
label linux
  kernel vmlinuz
  append $ks ramdisk=32000 initrd=$type.rdz mdkinst $type
label expert
  kernel vmlinuz
  append $ks expert ramdisk=32000 initrd=$type.rdz mdkinst $type
label ks
  kernel vmlinuz
  append ks ramdisk=32000 initrd=$type.rdz mdkinst $type
label rescue
  kernel vmlinuz
  append rescue root=/dev/fd0 load_ramdisk=1 prompt_ramdisk=1
");
    _ "cp -f $instdir/installinit/ks.cfg $mnt 2>/dev/null";
    _ "sync";
    _ "df $mnt";
}



sub output {
    my $f = shift;
    local *F;
    open F, "> $f" or die "error writing to $f";
    print F join '', @_;
}