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 ]