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-06-22 13:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to make a batch file automatically identify which partition a certain drive letter is in under DOS? View 7,263 Replies 24
Original Poster Posted 2004-04-22 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
Foreword: When using the GHOST command-line form under DOS, when restoring an image to a partition, GHOST will automatically recognize the D drive as the second partition, the E drive as the third partition, and so on. However, if there are NTFS-formatted partitions and hidden partitions in between, the E drive is not the third partition, and the F drive is not the fourth partition. Example: If the C drive is a FAT32 partition, the D drive is a hidden partition, the E drive is an NTFS partition, and the F drive is a FAT32 partition, the D drive and E drive will not be displayed under DOS, and the F drive becomes the D drive. Problem proposal: How to make the batch processing automatically recognize the D drive (actually the F drive) as the fourth partition in the hard drive instead of the second partition under DOS?
Floor 2 Posted 2004-04-22 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Are you overcomplicating the problem? GHOST never relies on drive letters for restoration; it can be said that it only recognizes partitions. Think carefully about what you want to do, and then decide how to do it.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2004-04-22 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
Simply put, I want to package the boot files such as IO.SYS, COMMAND.COM and the GHOST.EXE file required for the IBM one-key recovery partition into a *.gho file using GHOST, then use PQMAGIC to divide a primary partition (such as drive E, volume label SYS_GHOST) on the hard drive, and then restore the *.gho file to drive E using GHOST (of course, I just want this process to be automatically executed in DOS). Then I can press the F11 key to restore the system when booting.

However, during the process of restoring the *.gho file to drive E with GHOST, since GHOST does not use the drive letter as the basis for restoration, it only recognizes the partition. If there are no hidden partitions and NTFS format partitions on the hard drive, the SYS_GHOST partition (drive E) is the third partition; but if drive D is an NTFS format partition, this SYS_GHOST partition becomes drive D in DOS.

So how to make DOS recognize which partition the SYS_GHOST partition is becomes complicated.
Floor 4 Posted 2004-04-23 00:00 ·  中国 北京 联通
初级用户
Credits 146
Posts 14
Joined 2004-04-23 00:00
22-year member
UID 23108
Gender Male
Status Offline
I can't understand what you're trying to say. Hope the following is helpful
rem d:\ghost.exe -clone,mode=pload,src=e:\recover.gho:1,dst=1:1 -sure -rb
rem -sure ------Indicates to answer YES to all questions
rem -rb ------Indicates automatic reboot after completion
rem -fx ------After GHOST finishes working, it doesn't display (Press Ctrl-Alt-Del to reboot), but directly returns to the DOS state
mode=pload Restore partition
dst=1:1 First hard disk, first partition
If it's not easy to determine with src=, you can use if exist to test one by one
Floor 5 Posted 2004-04-24 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
Alas, you all don't understand. Fortunately, Rao Xiaochao, the author of One-key Recovery Elf, can understand and is preparing to develop a program with such a function.
Floor 6 Posted 2004-04-24 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
After looking at it for a long time, I still don't quite understand what you mean.

Hope these methods are useful to you:

1: If you know in advance which partition it is in the physical hard drive arrangement for the purpose of the operation you want to perform, then there will be no problem at all when restoring with GHOST, because when GHOST restores from the image file to the partition, it uses the format of "disk:partition" to specify the destination partition. (For example, DST=1:3)

2: If you don't know which physical partition the partition is, but you know what the volume label of the partition is, then you can use the two tools Gdisk and lmod together to find out which physical partition it is. The specific operation is a bit complicated, but it is still feasible.

Briefly talk about the process:
Gdisk 1 >temp.txt Get the partition list of the specified hard drive to a temporary text
find "label" temp.txt >temp1.txt Extract the relevant partition line using the volume label as the keyword
Analyze the information in this line with lmod (the specific operation is omitted) Because the partition list obtained by Gdisk has a fixed format
So lmod can be used for comprehensive analysis to get the desired information.
Determine whether it is a primary partition or a logical partition by finding whether this line is "PRIMARY" or "LOGICAL".
Because the numbering of partitions in Gdisk is different from that in Ghost. There will be an "EXTENDED" extended partition numbered between the primary partition and the logical partition in Gdisk. So, the partition number displayed by Gdisk needs to be processed before being used in Ghost.
In fact, the specific processing is also easy, that is: if it is a primary partition, just use the number directly; if it is a logical partition, just subtract 1 from the number.

By modifying the above method, you can also use LMOD to check which partition the known drive letter is in the physical partition...

(Not applicable to NTFS partitions)

Floor 7 Posted 2004-04-25 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
@ECHO OFF
gdisk 1 > %temp%\temp.txt
TFind /f30,10 "label" %temp%\temp.txt >%temp%\temp1.txt
type %temp%\temp1.txt | lmod set type=set part= >%temp%\temp.bat
call %temp%\temp.bat
if %type%==LOGICAL count part -1
set type=
del %temp%\temp*.*
:end

The above is a batch script to find the partition number through the volume label (just change the third line "label" to the actual volume label).

If you want to find the partition number through the drive letter, replace the third line in the above batch script with the following line:
Tfind /f2,2 "E:" %temp%\temp.txt >%temp%\temp1.txt
(taking finding drive E: as an example here)

The execution result writes the partition number into variable %part%.

This batch script uses Norton's Gdisk and three small programs by Horst Schaeffer: LMOD TFind COUNT
Floor 8 Posted 2004-04-25 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re walu:

So how to make DOS recognize which partition the SYS_GHOST is becomes complicated.


Do you mean it can be expressed like this - how to determine which partition of the hard disk the disk recognized by the DOS system is, and then place this partition number in the command line parameters for GHOST to call?
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2004-04-25 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
The following is a quote from willsort on 2004-4-25 10:52:26:
Re walu:





Does your meaning mean that we can determine which partition of the hard disk the disk recognized by the DOS system is, and then place this partition number in the command line parameter for GHOST to call?



willsort is really brilliant! That's the very meaning.
In terms of batch processing, willsort and Climbing are both top-notch experts!
Can this problem be solved through batch processing?
Floor 10 Posted 2004-04-26 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
The problem has been basically solved, thanks to Brother Tamm!
Floor 11 Posted 2004-04-26 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
For the sentence by Brother Tamm: "If it's a primary partition, just use the number directly; if it's a logical partition, just subtract 1 from the number" (this sentence won't be wrong if you use PQMAGIC to split a primary partition on the first primary partition). There is still an error. Because if you use PQMAGIC to split a primary partition on an extended partition, directly using the number will cause an error, because although GDISK recognizes that this is a primary partition, it still includes it in the logical partitions to count the partition number.
Floor 12 Posted 2004-04-26 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
The following is a quote from walu on 2004-4-26 11:46:22:
......If you use PQMAGIC to divide a primary partition on an extended partition, directly using the number will cause an error because although GDISK recognizes this as a primary partition, it still includes it in the logical partition to count the partition number.



I don't understand...
You said "... If you use PQMAGIC to divide a primary partition on an extended partition ..."
How can you create a primary partition on an extended partition...?


Do you mean using PQ to shrink the extended partition, and then create a second primary partition in the part left behind after the extended partition on the hard disk?
That is, like this?:

I'm sorry, I didn't consider such a situation when I proposed this plan.
If that's the case, Gdisk will use the following numbering:

1 First primary partition
2 Second primary partition
3 Extended partition
4... Logical partitions under the extended partition

But I don't know how Ghost uses the partition number in such a situation......
Floor 13 Posted 2004-04-26 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
Brother Tamm, I have found another program to replace GDISK, which is perfect. But after executing this program, it all appears "Press any key to continue...", that is, it requires pressing any key to continue executing the subsequent program. I don't want to use manual key pressing, and I want to execute it and then automatically continue executing the subsequent program. How should I do it?
Floor 14 Posted 2004-04-26 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
Can you kindly give some advice...
What was used as a substitute?

^_^
Floor 15 Posted 2004-04-26 00:00 ·  中国 广东 河源 电信
高级用户
★★
Credits 916
Posts 201
Joined 2003-05-04 00:00
23-year member
UID 1849
Gender Male
Status Offline
It is a file with only 27K. See the attachment Open the attachment
Forum Jump: