set timeout=1
-insmod msdospart
-insmod ext2
-
-root=(hd0,msdos1)
-
menuentry 'Kernel' --class os {
+ #insmod ext2
+ set root='(hd0,msdos1)'
multiboot /boot/Kernel root=hda0 delay=2
+ #multiboot2 /boot/Kernel root=hda0 delay=2
+ boot
}
TMP=build/tmp
MNT=$TMP/mnt
-dd if=/dev/zero of=$HDIMG bs=512 count=49152
-lodev=`losetup -f --show $HDIMG`
-
-sleep 1
+# 生成硬盘
+dd if=/dev/zero of=$HDIMG bs=512 count=24576
-parted ${lodev} mklabel msdos
+# 挂载到loop设备
+lodev=`losetup -f --show $HDIMG`
+echo "(hd0) ${lodev}" > ${TMP}/device.map
sleep 1
+# 创建主分区并设置为活动分区
+parted ${lodev} mklabel msdos
parted ${lodev} mkpart primary ext2 200k 100% -a minimal
-
-sleep 1
-
parted ${lodev} set 1 boot on
-
sleep 1
-#partx -a ${lodev}
-
-#sleep 1
-
ls -l ${lodev}*
+# 在分区上创建ext2文件系统
PART=${lodev}p1
-
-sleep 1
-
mke2fs -b 4096 $PART
-
sleep 1
-mkdir -p $MNT
+# 挂载文件系统
+mkdir -p $MNT
mount $PART $MNT
-
sleep 1
-echo "(hd0) ${lodev}" > ${TMP}/device.map
-
-mkdir -p ${MNT}/boot/grub2/
+# 创建目录
+mkdir -p ${MNT}/boot/grub2
+mkdir -p ${MNT}/bin/
-grub2-install --target=i386-pc \
- --grub-mkdevicemap=${TMP}/device.map \
- --modules="biosdisk part_msdos ext2 configfile normal multiboot" \
- --root-directory=$MNT \
+# 安装grub
+grub2-install --no-floppy \
+ --grub-mkdevicemap=${TMP}/device.map \
+ --target=i386-pc \
+ --modules="biosdisk part_msdos ext2 configfile normal multiboot multiboot2" \
+ --boot-directory=$MNT/boot \
${lodev}
+# 拷贝grub配置文件
cp grub.cfg ${MNT}/boot/grub2/
-cp ../KERNEL.BIN ${MNT}/boot/Kernel
-
-mkdir -p ${MNT}/bin/
+sleep 1
+# 拷贝内核文件
+cp ../KERNEL.BIN ${MNT}/boot/Kernel
sleep 1
umount $MNT
-
sleep 1
partx -d ${lodev}
-
sleep 1
losetup -d ${lodev}