From: acevest Date: Tue, 26 Oct 2021 06:27:12 +0000 (+0800) Subject: fix new version of grub2 can not load /boot/Kernel X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=a8b29a72f0fa9752004004216406d56fd65ba391;p=kernel.git fix new version of grub2 can not load /boot/Kernel --- diff --git a/scripts/grub.cfg b/scripts/grub.cfg index 08efd8b..fd98c0f 100644 --- a/scripts/grub.cfg +++ b/scripts/grub.cfg @@ -2,11 +2,10 @@ set default="0" 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 } diff --git a/scripts/init.sh b/scripts/init.sh index bb17b97..65dc7a2 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -5,67 +5,59 @@ HDIMG=out.img 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}