22KERNEL=${1-build/ test_grub}
33DISK=${DISK-$KERNEL .grub.img}
44MOUNTDIR=${MOUNTDIR-/ mnt}
5- MOUNT_OPTS=" sync,rw"
6- BLOCKCCOUNT=10000
5+ MOUNT_OPTS=" rw"
6+
7+ # GRUB uses roughly 4.6 Mb of disk
8+ GRUB_KB=5000
9+
710set -e
811
912function unmount {
@@ -23,18 +26,25 @@ function clean {
2326
2427
2528function create_disk {
26- echo -e " >>> Creating FAT file system on $DISK with $BLOCKSIZE blocks"
27- # NOTE: mkfs with the '-C' option creates the disk before creating FS
28- # fallocate -l 10MiB $DISK
2929
3030 if [ -f $DISK ]
3131 then
3232 echo -e " >>> $DISK allready exists. Preserving existing image as $DISK .bak"
3333 mv $DISK $DISK .bak
3434 fi
3535
36+ # Kernel size in Kb
37+ KERN_KB=$(( ($(stat - c% s "$KERNEL ") / 1024 ) ))
38+
39+ # Estimate some overhead for the FAT
40+ FAT_KB=$(( ($KERN_KB + $GRUB_KB ) / 10 ))
3641
37- mkfs.fat -C $DISK $BLOCKCCOUNT
42+ DISK_KB=$(( $KERN_KB + $GRUB_KB + $FAT_KB ))
43+
44+ echo " >>> Estimated disk size: $GRUB_KB Kb GRUB + $KERN_KB Kb kernel + $FAT_KB Kb FAT = $DISK_KB Kb"
45+ echo " >>> Creating FAT file system on $DISK "
46+
47+ mkfs.fat -C $DISK $DISK_KB
3848}
3949
4050function mount_loopback {
@@ -58,6 +68,7 @@ function mount_loopback {
5868function copy_kernel {
5969 echo " >>> Copying kernel '$KERNEL ' to $MOUNTDIR /boot/includeos_service"
6070 sudo cp $KERNEL $MOUNTDIR /boot/includeos_service
71+ sync
6172}
6273
6374function build {
@@ -130,6 +141,9 @@ copy_kernel
130141echo -e " >>> Running grub install"
131142sudo grub-install --target=i386-pc --force --boot-directory $MOUNTDIR /boot/ $LOOP
132143
144+ echo -e " >>> Synchronize file cache"
145+ sync
146+
133147unmount
134148
135149echo -e " >>> Done. You can now boot $DISK "
0 commit comments