中国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-15 12:51
47,813 topics / 349,903 posts / today 1 new / 48,257 members
DOS疑难解答 & 问题讨论 (解答室) » How to automatically format an NTFS partition using DOS batch processing
Printable Version  2,366 / 12
Floor1 yojainika Posted 2007-07-01 10:52
新手上路 Posts 2 Credits 6
There are multiple partitions on the server, and there are too many steps to format when organizing regularly. Can you write a batch script to let it format all partitions one by one by itself?
Floor2 wudixin96 Posted 2007-07-01 11:31
银牌会员 Posts 931 Credits 1,928
sorry sorry
Didn't look carefully, :-)

[ Last edited by wudixin96 on 2007-7-1 at 12:59 PM ]
Floor3 lianjiang2004 Posted 2007-07-01 12:48
金牌会员 Posts 1,884 Credits 3,946
Originally posted by wudixin96 at 2007-7-1 11:31:
Something like this?

Note that the owner wants to format an NTFS partition, heh.
You can take a look at gdisk.
Floor4 yojainika Posted 2007-07-02 10:19
新手上路 Posts 2 Credits 6
Is it just copying the content on the second floor directly into a BAT file and running it can automatically format all partitions?
Floor5 lianjiang2004 Posted 2007-07-02 10:22
金牌会员 Posts 1,884 Credits 3,946
Floor6 lotus516 Posted 2007-07-02 13:13
高级用户 Posts 246 Credits 551
I think the LZ's idea should not be under pure DOS. As long as it's not under pure DOS, it's okay!!!

Format a disk in a specified volume to accept Windows files.

Syntax
format volume

format volume

format volume

format volume

format volume

Parameters
volume
Specifies the mount point, volume name, or drive letter of the drive to format. If none of the following command-line options are specified, format uses the volume type to determine the default format of the disk.
/fs:file-system
Specifies the file system to use: FAT, FAT32, or NTFS. Floppy disks can only use the FAT file system.
/v:label
Specifies the volume label. If the /v command-line option is omitted or used without specifying a label, format prompts for the label after formatting is complete. Use the syntax /v: to prevent prompting for the label. If formatting multiple disks with one format command, specify the same label for all disks. For more information about disk volume labels, click Dir, Label, and Vol in the Related Topics list.
/a:UnitSize
Specifies the allocation unit size to use on a FAT, FAT32, or NTFS volume. If UnitSize is not specified, it is chosen based on the size of the volume. The following table lists the valid values for UnitSize. Value Description
512 512 bytes per cluster.
1024 1024 bytes per cluster.
2048 2048 bytes per cluster.
4096 4096 bytes per cluster.
8192 8192 bytes per cluster.
16K 16K bytes per cluster.
32K 32K bytes per cluster.
64K 64K bytes per cluster.

/q
Performs a quick format. Deletes the file table and root directory of a previously formatted volume, but does not scan for bad areas between sectors. Using the /q command-line option should only format a previously formatted, healthy volume.

Of course, the system disk cannot be formatted!

[ Last edited by lotus516 on 2007-7-2 at 01:15 PM ]
Floor7 NEWDOS Posted 2007-07-02 13:21
初级用户 Posts 10 Credits 25
As long as it is determined to be NTFS.
Floor8 NEWDOS Posted 2007-07-02 13:21
初级用户 Posts 10 Credits 25
Floor9 NEWDOS Posted 2007-07-02 13:24
初级用户 Posts 10 Credits 25
By the way, there's also the thing I wrote earlier about not adding the system drive letter in there, haha
Floor10 lianjiang2004 Posted 2007-07-02 20:11
金牌会员 Posts 1,884 Credits 3,946
Isn't this about DOS batch processing? The original poster didn't understand what DOS is and then set a question? Hehe.
Floor11 shanliang8008 Posted 2007-07-03 04:58
银牌会员 Posts 514 Credits 1,148 From 河北
Low-level formatting, which is relatively aggressive

[ Last edited by shanliang8008 on 2007-7-3 at 05:01 AM ]
Floor12 shanliang8008 Posted 2007-07-03 05:05
银牌会员 Posts 514 Credits 1,148 From 河北
Has anyone used DM in a virtual machine?
Floor13 DXSX Posted 2010-01-07 10:38
中级用户 Posts 147 Credits 247
Using gdisk to Automatically Format All Partitions Except C: Under DOS (Including NTFS)

If the booted DOS system is on a restore partition, then the partition where the restore system is located must be C:. Sometimes, before restoring the system using Ghost or TI, etc., it is necessary to automatically format all partitions except the partition where the restore system is located to avoid the virus in other partitions from infecting again when entering the system. And formatting NTFS partitions manually under DOS is quite troublesome. But if not formatted, once there is a virus on these NTFS partitions?

So consider editing this script, using awk to analyze the partition structure, and using gdisk to format all partitions except the C drive. NTFS partitions are still formatted to the NTFS format.

gdf2 1 means operating on the first hard disk, and gdf2 2 means operating on the second hard disk.

The code of gdf2.bat is as follows: Note that the red part is the GDISK command, which I have commented out with ECHO. If you need to run this script in a real situation, you must remove the ECHO in front.
@echo off
cls
set d=%1
if *%1*==** set d=1
echo Format all partitions in HD%D% ,but C: !
echo Please wait....
gdisk %d%|awk 'substr($0,20,3)=="LOG"&&substr($0,2,2)!="C:";substr($0,20,3)=="PRI"&&substr($0,2,2)!="C:"'>gdf1.txt
if exist gdf1.txt type gdf1.txt
awk 'substr($0,53,10)!~"NTFS" {print "/del /p:"substr($0,6,1)" /y";print "/cre /"substr($0,20,3)" /for /Q /Y" }' gdf1.txt>gdf2.txt
awk 'substr($0,53,10)~"NTFS" {print "/del /p:"substr($0,6,1)" /y";print "/cre /"substr($0,20,3)" /For /NTFS /Q /Y" }' gdf1.txt>>gdf2.txt
awk '{if (substr($0,15,1)=="A") print "/act /p:"substr($0,6,1)" /y"}' gdf1.txt>>gdf2.txt
if exist gdf1.txt del gdf1.txt
echo.
if not exist gdf2.txt goto end
type gdf2.txt
pause
echo gdisk %d% /batch:gdf2.txt
del gdf2.txt
:end
set d=

--------------------------
Script Interpretation:
1. Use awk to analyze the partition list obtained from gdisk, pass the information of logical partitions and primary boot partitions except the C drive to the file gdf1.txt, and display gdf1.txt.
2. Use awk to analyze gdf1.txt, find partitions whose format is not NTFS, and pass the gdisk script commands for deleting these partitions and rebuilding and formatting these partitions to the file gdf2.txt.
3. Use awk to analyze gdf1.txt, find partitions whose format is NTFS, and append the gdisk script commands for deleting these partitions and rebuilding and formatting these partitions to the file gdf2.txt.
4. Use awk to analyze gdf1.txt, find activated partitions, and append the gdisk script commands for activating these partitions to the file gdf2.txt.
5. Use gdisk to call the instructions in gdf2.txt.
The entire process uses 2 text files gdf1.txt, gdf2.txt and an environment variable %d%.
gdf1.txt---------Stores the partition list except the C drive on the hard disk
gdf2.txt---------Stores the script commands called by gdisk
%d%-------------Used to store the number of the hard disk to be operated

http://bbs.wuyou.com/viewthread.php?tid=158594&extra=page%3D1
http://bbs.wuyou.com/viewthread.php?tid=158553&extra=page%3D1

[ Last edited by DXSX on 2010-1-7 at 10:44 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023