makeext2initrd 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. PWD="`pwd`"
  3. SOURCE_TREE="$PWD/initrd-tree"
  4. OUTPUT_IMAGE="$PWD/initrd.gz"
  5. KERNEL_VERSION="$(uname -r)"
  6. PUPPYVERSION="`cat $SOURCE_TREE/PUPPYVERSION`"
  7. # Calculate size needed for initrd:
  8. SIZE=`du -s -k $SOURCE_TREE | tr "\t" " " | cut -f 1 -d ' '`
  9. # Add a bit of padding:
  10. PAD=900 #600 #600 #160 #98 THIS IS WEIRD HAD TO INCREASE THIS FROM 160 TO 600 v2.12!!!
  11. TRIMOFF=800
  12. if [ -f $SOURCE_TREE/pup_$PUPPYVERSION.sfs ];then #v2.16rc
  13. #humongous, padding needs to be adjusted...
  14. PAD=3100 #1800
  15. TRIMOFF=0
  16. fi
  17. SIZE=`expr $SIZE + $PAD`
  18. TMPSIZE=`expr $SIZE \* 3`
  19. #TMPSIZE=`expr $TMPSIZE + 500`
  20. mkdir /tmp/tmpfs
  21. mount tmpfs /tmp/tmpfs -t tmpfs -o size=${TMPSIZE}k
  22. mkdir /tmp/tmpfs/mntpt
  23. echo "Size of ext2 filesystem is ${SIZE}KB"
  24. # Make an empty file of the proper size:
  25. dd if=/dev/zero of=/tmp/tmpfs/initrd-tmp bs=1k count=$SIZE #2> /dev/null
  26. sync
  27. # Create a filesystem on it:
  28. mke2fs -m 0 -F /tmp/tmpfs/initrd-tmp #1> /dev/null 2> /dev/null
  29. sync
  30. # Fix broken ext2fs defaults:
  31. tune2fs -c 0 -i 0 -m 0 /tmp/tmpfs/initrd-tmp #1> /dev/null 2> /dev/null
  32. sync
  33. # Mount the initrd-to-be:
  34. losetup /dev/loop2 /tmp/tmpfs/initrd-tmp
  35. mount -t ext2 /dev/loop2 /tmp/tmpfs/mntpt
  36. # Populate the initrd image:
  37. ( cd $SOURCE_TREE
  38. cp -a * /tmp/tmpfs/mntpt
  39. )
  40. #v2.16rc...
  41. rm -f /tmp/tmpfs/mntpt/init
  42. ln -s sbin/init /tmp/tmpfs/mntpt/linuxrc
  43. if [ -d /tmp/tmpfs/mntpt/dev0 ];then
  44. rmdir /tmp/tmpfs/mntpt/dev
  45. mv /tmp/tmpfs/mntpt/dev0 /tmp/tmpfs/mntpt/dev
  46. fi
  47. #mkdir /tmp/tmpfs/mntpt/.root_ro
  48. #mkdir /tmp/tmpfs/mntpt/.root_rw
  49. ## Make sure we have any block devices that might be needed:
  50. #SLOPPY_DEV_LIST=$(cat /proc/partitions)
  51. #for device in $SLOPPY_DEV_LIST ; do
  52. # if [ ! -r $SOURCE_TREE/dev/$device -a -b /dev/$device ]; then
  53. # cp -a /dev/$device $SOURCE_TREE/dev
  54. # fi
  55. #done
  56. # Unmount the initrd and move it into place:
  57. sync
  58. umount /dev/loop2
  59. rmdir /tmp/tmpfs/mntpt
  60. #gzip -9 /tmp/tmpfs/initrd-tmp
  61. #rm -f $OUTPUT_IMAGE
  62. #mv /tmp/tmpfs/initrd-tmp.gz $OUTPUT_IMAGE
  63. sync
  64. #attempt size reduction, that huge empty space...
  65. rm -f initrd
  66. rm -f initrd.gz
  67. DOWNSIZE=`expr $SIZE \- $TRIMOFF` #800 700
  68. sync
  69. resize2fs -pf /tmp/tmpfs/initrd-tmp $DOWNSIZE
  70. sync
  71. dd if=/tmp/tmpfs/initrd-tmp of=initrd bs=1k count=$DOWNSIZE
  72. sync
  73. e2fsck -y -f initrd
  74. sync
  75. rm -f /tmp/tmpfs/initrd-tmp
  76. gzip -9 initrd
  77. sync
  78. umount /tmp/tmpfs
  79. rmdir /tmp/tmpfs
  80. #v2.15 save the size, needed by createpuppy...
  81. echo -n "$SIZE" > /tmp/initrdsize.txt
  82. sync
  83. ####END####