You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Extendinitrd.pm 1.5KB

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