TFTP default blocksize fix from Vampyre
[gpxe.git] / contrib / mkffwnb / Extendinitrd.pm
blob3b919ad13102e2d3e37e7872d827480db6fc54fb
1 #!/usr/bin/perl -w
3 sub status_system ($$) {
4 my ($command, $message) = @_;
6 $status = system($command);
7 $status <<= 8;
8 if ($status < 0) {
9 print STDERR "$!\n";
11 if ($status != 0) {
12 print STDERR "$message\n";
16 sub extendinitrd ($$) {
17 my ($initrd, $nblocks) = @_;
19 if ($nblocks <= 1440) {
20 print STDERR "nblocks must be >= 1440\n";
21 return (1);
23 (undef, $type, undef, $fnlen, undef) = split(' ', `file $initrd`, 5);
24 print "$type $fnlen\n";
25 if ($type ne 'Minix' || $fnlen != 30) {
26 die "Can only handle Minix initrds with 30 char filenames\n";
27 return (1);
29 status_system("dd if=/dev/zero of=newinitrd bs=1k count=$nblocks", "Cannot create new initrd\n");
30 status_system("mkfs.minix -n 30 newinitrd $nblocks", "Cannot mkfs.minix new initrd\n");
31 mkdir("initrd.from") || print STDERR "Cannot make temp mount point initrd.from\n";
32 mkdir("initrd.to") || print STDERR "Cannot make temp mount point initrd.to\n";
33 status_system("mount -o ro,loop $initrd initrd.from", "Cannot mount $initrd on initrd.from");
34 status_system("mount -o loop newinitrd initrd.to", "Cannot mount newinitrd on initrd.to");
35 status_system("cp -a initrd.from/* initrd.to/", "Cannot copy initrd to newinitrd");
36 status_system("umount initrd.from", "Cannot umount initrd.from");
37 status_system("umount initrd.to", "Cannot umount initrd.to");
38 rmdir("initrd.from") || print STDERR "Cannot remove temp mount point initrd.from\n";
39 rmdir("initrd.to") || print STDERR "Cannot remove temp mount point initrd.to\n";
40 return (0);