China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 07:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch script to add a GRUB4DOS entry to the Vista boot menu View 2,895 Replies 10
Original Poster Posted 2008-01-29 17:04 ·  中国 广东 深圳 联通
初级用户
Credits 89
Posts 36
Joined 2007-12-20 15:37
18-year member
UID 106247
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
429499381 +2 2008-01-30 01:10
Floor 2 Posted 2008-01-29 17:16 ·  中国 安徽 黄山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Give it a support. There is still room for further improvement.
Windows 一键还原
http://www.yjhy.com
Floor 3 Posted 2008-01-29 17:57 ·  中国 广东 深圳 联通
初级用户
Credits 89
Posts 36
Joined 2007-12-20 15:37
18-year member
UID 106247
Gender Male
Status Offline
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 ]
Floor 4 Posted 2008-01-30 01:09 ·  中国 湖北 武汉 武昌区 电信
中级用户
★★
Credits 452
Posts 202
Joined 2006-12-21 13:46
19-year member
UID 74161
Gender Female
Status Offline
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.
Floor 5 Posted 2008-01-30 19:28 ·  中国 广东 深圳 联通
初级用户
Credits 89
Posts 36
Joined 2007-12-20 15:37
18-year member
UID 106247
Gender Male
Status Offline
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.
Floor 6 Posted 2008-02-20 00:41 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 452
Posts 202
Joined 2006-12-21 13:46
19-year member
UID 74161
Gender Female
Status Offline
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?
Floor 7 Posted 2008-04-20 16:06 ·  中国 四川 成都 电信
初级用户
Credits 37
Posts 17
Joined 2007-01-27 09:48
19-year member
UID 77838
Gender Male
Status Offline
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
Floor 8 Posted 2008-04-23 11:23 ·  中国 上海 浦东新区 电信
初级用户
Credits 122
Posts 10
Joined 2004-03-09 00:00
22-year member
UID 19637
Gender Male
Status Offline
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!
Floor 9 Posted 2008-05-11 09:26 ·  中国 江苏 苏州 电信
初级用户
Credits 32
Posts 16
Joined 2007-01-25 02:19
19-year member
UID 77579
Gender Male
Status Offline
Just happen to need to study
Floor 10 Posted 2008-05-12 23:22 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
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 ]
Floor 11 Posted 2009-02-03 22:02 ·  中国 福建 福州 亿力电力通信有限公司
新手上路
Credits 4
Posts 2
Joined 2009-02-01 15:18
17-year member
UID 137769
Gender Male
Status Offline
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.
Forum Jump: