中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-11 06:57
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Batch script to add a GRUB4DOS entry to the Vista boot menu
Printable Version  2,892 / 10
Floor1 hnfeng Posted 2008-01-29 17:04
初级用户 Posts 36 Credits 89
Under XP, you can directly modify boot.ini to add a GRUB4DOS entry, but it's not that simple under Vista.

Since both the company and home computers are XP + Vista, I experimented with GURB4DOS functions many times a few days ago. Previously, I added this menu item manually. Today, I made a batch script and share it. To prevent newbies..., I added some junk at the front.

The following batch script will automatically add the GRUB4DOS boot entry to the Vista boot menu:

===== Add_GRUB4DOS_Menu.bat =====

@echo off
echo This batch script automatically adds the GRUB4DOS boot entry to the Vista system's boot menu.
echo If it's not a single Vista (there are also XP, 2K), it must be run under Vista.
echo Also, it needs to be run as an administrator.
echo .
pause

ver | find "6.0." > NUL && goto START
ver | find "XP" > NUL && goto XP2K
ver | find "2000" > NUL && goto XP2K
goto EXIT

:XP2K
echo Cannot run this batch script in WinXP or Win2000.
goto EXIT

REM ============= The above content is purely...... ==============

:START
cls

bcdedit | find "\grldr.mbr" > NUL && echo There is already grub4dos in the boot entry, no need to install repeatedly.&& goto EXIT
bcdedit /create /d "Boot From GRUB4DOS" /application bootsector >GrubID.txt
rem The above GRUB menu name to be added can be modified to "GRUB For DOS", "DOS + GHOST", etc.

for /f "tokens=2" %%i in (GrubID.txt) do set GrubID=%%i
del GrubID.txt > NUL
bcdedit /set %GrubID% device partition=%SystemDrive%
bcdedit /set %GrubID% path \grldr.mbr
bcdedit /displayorder %GrubID% /addlast

echo .
echo The above should have 3 "Operation completed successfully."
echo .
echo Please copy grldr.mbr to %SystemDrive%\ by yourself
echo .
echo Please copy grldr to C:\ by yourself
echo .
echo According to needs, please copy other related files by yourself, such as menu.lst, fonts, memdisk.gz and background pictures, etc., to the corresponding positions.

:EXIT

====== THE END =====
Everyone may use GRUB4DOS in different ways, so there is no automatic copying of grldr.mbr and other files. It's still safer to copy them yourself.

[ Last edited by hnfeng on 2008-1-30 at 01:09 PM ]
Floor2 lianjiang2004 Posted 2008-01-29 17:16
金牌会员 Posts 1,884 Credits 3,946
Give it a support. There is still room for further improvement.
Floor3 hnfeng Posted 2008-01-29 17:57
初级用户 Posts 36 Credits 89
There is a problem with the batch script in the first floor: when deleting this menu item, manual operation is required:
Enter CMD, run bcdedit, find "Real - mode boot sector", copy the "identifier" (the string containing curly braces) below it, type bcdedit /delete and paste the just - copied content, and press Enter.

For convenience, I slightly modify Add_GRUB4DOS_Menu.bat, and then can use the following Del_GRUB4DOS_Menu.bat to automatically delete the GRUB4DOS boot item.

===== Add_GRUB4DOS_Menu.bat =====

@echo off
echo This batch script automatically adds the boot item of GRUB4DOS to the boot menu of Vista system.
echo If it is not a single Vista (there are also XP, 2K), it must be run under Vista.
echo In addition, it needs to be run as an administrator.
echo .
pause

ver | find "6.0." > NUL && goto START
ver | find "XP" > NUL && goto XP2K
ver | find "2000" > NUL && goto XP2K
goto EXIT

:XP2K
echo This batch script cannot be run in WinXP or Win2000.
goto EXIT

REM ============= The above content is purely...... ==============

:START
cls

bcdedit | find "\grldr.mbr" > NUL && echo There is already grub4dos in the boot item, no need to install repeatedly.&& goto EXIT
bcdedit /create /d "Boot From GRUB4DOS" /application bootsector >%SystemRoot%\GrubID.txt
rem The above GRUB menu name to be added can be modified to "GRUB For DOS", "DOS + GHOST", etc.

for /f "tokens=2" %%i in (%SystemRoot%\GrubID.txt) do set GrubID=%%i

bcdedit /set %GrubID% device partition=%SystemDrive%
bcdedit /set %GrubID% path \grldr.mbr
bcdedit /displayorder %GrubID% /addlast

echo .
echo The above should have 3 "Operation completed successfully."
echo .
echo Please copy grldr.mbr to %SystemDrive%\ by yourself.
echo .
echo Please copy grldr to C:\ by yourself.
echo .
echo According to the need, please copy other relevant files, such as menu.lst, fonts, memdisk.gz and background pictures and other files to the corresponding positions.

:EXIT
====== THE END =====

===== Del_GRUB4DOS_Menu.bat =====
@echo off
bcdedit | find "\grldr.mbr" > NUL && goto START

echo The grub4dos item is not found in the boot menu.
goto EXIT

:START
cls
if not exist %SystemRoot%\GrubID.txt goto ERROR
for /f "tokens=2" %%i in (%SystemRoot%\GrubID.txt) do set GrubID=%%i
bcdedit /delete %GrubID%
Del %SystemRoot%\GrubID.txt > NUL
goto EXIT


:ERROR
echo %SystemRoot%\GrubID.txt is not found, and automatic deletion cannot be performed.

:EXIT
====== THE END =====

[ Last edited by hnfeng on 2008 - 1 - 30 at 01:10 PM ]
Floor4 429499381 Posted 2008-01-30 01:09
中级用户 Posts 202 Credits 452
Since it is for the convenience of beginners, please be sure to provide links to relevant tools!

I think you should make this batch processing a general XP 2003 VIST multi-boot menu (excluding LINUX)

The requirements are as follows:
- Automatically identify how many systems this computer has
- Write a mutually bootable menu in the system file (boot)
- General for XP 2003 VIST
- Do not damage the original boot menu
- Have a safe uninstall function

I think it shouldn't be difficult for you!! Hehe, after writing it, I will pin this post for a while.
Floor5 hnfeng Posted 2008-01-30 19:28
初级用户 Posts 36 Credits 89
Originally posted by 429499381 at 2008-1-30 01:09 AM:
……
The requirements are as follows:
Automatically identify how many systems this computer has
Write a mutually bootable menu in the system file (boot)
Universal for xp 2003 vist
Do not destroy the original boot menu
Have a safe uninstall function
...

The first one can basically be ignored. The following three are not a big deal.
The last one is difficult because I don't know how to delete specific lines in the file for the time being.
If a backup file is used to replace it, then all changes made to the boot menu during this period (such as newly installed systems or manual modifications) will all disappear, which is not appropriate.

Also, it seems that no one is interested in this topic. I'd better not continue to mess around.
Floor6 429499381 Posted 2008-02-20 00:41
中级用户 Posts 202 Credits 452
If every little thing requires a lot of people to be interested, I'm afraid there will be a lot of disappointment.

Why don't you prove that you can do it, why don't you find a way to make more people interested in this topic?
Floor7 zg888 Posted 2008-04-20 16:06
初级用户 Posts 17 Credits 37
Originally posted by 429499381 at 2008-1-30 01:09 AM:
Since it is for the convenience of beginners, then please be sure to provide a link to the relevant tools!

I think you should make this batch processing a universal multi-boot menu for XP 2003 VIST (excluding LINUX)...


For XP/2003, it's very easy with the system's own bootcfg command
pushd %SystemDrive%\
set btini=boot.ini
attrib -s -h -r %btini%
FIND /I "c:\grldr" %btini%
::If not, add a startup item c:\grldr="grubdos"
IF "%ERRORLEVEL%"=="1" @echo.c:\grldr="grubdos">>%btini%
for /f "tokens=1,2* delims=: " %%i in ('bootcfg/query^|findstr /I /n "c:\grldr"') do set /a hang=%%i - 2
for /f "tokens=1-5 delims=: " %%i in ('bootcfg/query^| findstr /i /n "Startup Item"') do if "%%i"=="%hang%" set qdid=%%l
bootcfg /Delete /ID %qdid%
pause

Because I have not used VISTA, so I don't know about VISTA
Floor8 yankaiqian Posted 2008-04-23 11:23
初级用户 Posts 10 Credits 122
Thanks!

A week or two ago, I also wanted to try to boot GRUB for DOS through the VISTA boot manager, and then saw this page introduction on the Internet:
http://grub4dos.sourceforge.net/wiki/index.php/Grub4dos安装和启动

I executed the following three statements under VISTA at that time:
bcdedit /create /d "Start GRUB4DOS" /application bootsector
bcdedit /set {id} device boot
bcdedit /set {id} path \grldr.mbr
bcdedit /displayorder {id} /addlast

Among them, {id} I replaced with the output content of the first command, but I did not change the boot after the second command, just entered it as it was. As a result, it could not be booted. I thought at that time that the grldr.mbr file was problematic...

Today, I saw this post and changed that "boot" to "partition=C:" and it worked!
Floor9 690712 Posted 2008-05-11 09:26
初级用户 Posts 16 Credits 32
Just happen to need to study
Floor10 NaturalJ0 Posted 2008-05-12 23:22
银牌会员 Posts 533 Credits 1,181
These days I'm just concerned about this. Just right, copy it back and study it well. Thanks.

--------------------------------------------------------------------------------------------------
After reading, I want to ask a question. I'm relatively green, please forgive me.

In the past, when using XP, I could add c:\grldr="Start GRUB4DOS" in BOOT.INI, and then only need a grldr file, no need for the grldr.mbr file. Why in Vista do I need to bring this file? Is there a way to be the same as before, only need a grldr, not bring grldr.mbr?

[ Last edited by NaturalJ0 on 2008-5-13 at 12:37 AM ]
Floor11 billbear Posted 2009-02-03 22:02
新手上路 Posts 2 Credits 4
Actually, although Vista and Win7 use BCD, they will still read boot.ini (if it exists). Therefore, the old method can be continued. Write a boot.ini in the root directory of drive C yourself:

[boot loader]
[operating systems]
c:\grldr.mbr="grub4dos"

Please note the quotes above. For XP, quotes are not needed, but they are required for Vista and Win7.
Then copy grldr and grldr.mbr to the root directory of drive C.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023