Immediate Solutions


Creating Partitions with Microsoft FDISK

Creating a partition with Microsoft FDISK from the command line is like scripting any program from the command line. The basic syntax to scripting a program from the command line is as follows :

  program options  

Here, program is the executable to be run, and options are the supported program parameters.

Creating a Primary Partition

To create a primary partition from the command line, enter the following:

 FDISK /PRI:  size disk  

Here, size is the size of the partition in megabytes, and disk is the physical disk number.

Tip  

Entering a partition size greater than the drive size will set the partition to the maximum size of the drive or the maximum size allowed by the selected file system. This is useful when creating generic scripts where you will not know the drive size in advance.

The /PRI option creates the primary partition and automatically sets it active. Any partition under 512MB will be set up as FAT16, and larger partitions will be set up as FAT32. To override this behavior and set up all partitions as FAT16, you can append an O (override) to the /PRI switch.

 FDISK /PRIO:  size disk  

To have all partitions set up as FAT32, you can add the /FPRMT switch:

 FDISK /FPRMT /PRI:  size disk  

Creating an Extended Partition

Scripting an extended partition creation is identical to scripting a primary partition creation, with the exception of the /PRI switch. To script the creation of an extended partition, enter the following:

 FDISK /EXT:  size disk  

Here, size is the size of the partition in megabytes, and disk is the physical disk number.

The /EXT option creates an extended partition.

Note  

You must already have a primary partition created before you can create an extended partition.

Creating a Logical Partition

To create a logical partition from the command line, enter the following:

 FDISK /EXT:  size disk  /LOG:  size  

Here, size is the size of the partition in megabytes and must be less than or equal to the remaining free space, and disk is the physical disk number.

The /EXT switch is required in order to use the /LOG switch.

Note  

You must already have a primary and extended partition created before you can create a logical partition.

To set up a logical partition with FAT16, you can append an O (override) to the /LOG switch.

 FDISK /EXT:  size disk  /LOGO:  size  

Combining Switches

You can combine all three partition creation switches to set up a new hard drive with one line of code:

 FDISK /PRI:  size disk  /EXT:  size disk  /LOG:  size  
Note  

You cannot have multiple /LOG switches per one line of code. If you need to create multiple logical drives , you need to add multiple lines of code.

Rewriting the Master Boot Record

With an undocumented FDISK option, you can rewrite the master boot record without rewriting the partition table. To rewrite the MBR, proceed as follows:

 FDISK /MBR 

Undocumented Microsoft FDISK Options

Even though the /? option is supposed to display all available command-line options, Microsoft FDISK has many undocumented options. Here are some of the most common undocumented options:

  • /ACTOK ”Skips drive integrity check

  • /EXT: size disk ”Creates an extended partition

  • / FPRMT ”Skips the large drive support startup screen

  • /LOG: size ”Creates a logical drive

  • / MBR ”Creates a new Master Boot Record

  • /PARTN ”Saves partition information to partsav.fil

  • /PRI: size disk ”Creates a primary partition

  • /STATUS ”Displays current partition information

Working with Free FDISK

Free FDISK provides the same functionality as Microsoft FDISK while adding more useful features. Tasks like deleting, creating, and autosizing partitions are just as simple to perform as any other FDISK option.

Creating Auto-Sized Partitions

To create partitions to the maximum size, enter the following:

 FDISK /AUTO 
Tip  

You can create individual partitions by following the above command with a partition number.

Deleting All Partitions

To delete all existing partitions (physical, extended, and logical), enter the following:

 FDISK /CLEAR 
Tip  

You can delete individual partitions by following the above command with a partition number.

Other Free FDISK Options

Here are some of the most common options:

  • /ACTIVATE: partition# drive# ”Sets the specified partition active

  • /C ”Checks marked bad clusters

  • /DELETE ”Deletes individual partitions

  • /FS: filesystem ”Specifies the file system to format with

  • /ONCE ”Formats a floppy disk without prompting

  • /REBOOT ”Reboots the machine

Scripting Disk Formats

The main purpose of scripting is to streamline a process. Manual disk formats contain user prompts and pauses. Scripting a disk format allows you to control how much, if any, prompting is allowed.

Scripting a Hard Disk Format

To perform a completely hands-free drive format and label, enter the following:

 FORMAT  drive  /AUTOTEST /V:  label  

Here, drive is the drive you want to format, and label is the label you want to give the drive.

The /AUTOTEST switch causes the FORMAT command to run while suppressing any prompts. The /V switch is used to assign a label to a disk. Disk labels can contain a maximum of eleven characters .

Tip  

You can follow this command with a /S to format the drive as a system drive.

Scripting a Floppy Disk Format

Combining the /AUTOTEST switch with the /V switch does not create labels on floppy disks. Instead, you can use two separate commands:

 FORMAT  drive  /AUTOTEST LABEL  drive alabel  

Here, drive is the drive you want to format, and alabel is the label you want to give the disk.

Scripting a Faster Disk Format

If the disk has already been formatted, you can run a quick disk format that simply erases the disk address tables (not the disk data). To perform a faster disk format, start the command prompt and enter the following:

 FORMAT  drive  /Q /U 

Here, drive is the drive you want to format; /Q indicates a quick format; and /U indicates an unconditional format.

Other Format Options

The other commonly used options are:

  • /BACKUP ”Identical to /AUTOTEST except prompts for disk label

  • /C ”Checks for bad clusters

Suppressing Output when Shell Scripting

Although scripting does suppress most prompts, sometimes it does not suppress the command output. You can suppress the output of a shell command by sending the output to a NUL device. To suppress the output of a drive format, enter:

 FORMAT  drive  /AUTOTEST > NUL 

Creating Boot Disks

Any good administrator has a collection of boot disks ready and waiting in time of need. Boot disks are used when you need to bypass or perform a task before system bootup . Not only can you use scripting to create boot disks, but you can also use powerful scripts within them.

Creating a Hard Drive Setup Boot Disk

Follow these steps to create a boot disk that will automatically FDISK and format a hard disk:

  1. Make a bootable DOS diskette. On Windows XP, this can be done by opening Windows Explorer, right clicking on the floppy drive, choosing "Format" from the context menu, selecting "Create an MS-DOS startup disk", and clicking "Start."

  2. Copy FREE FDISK to the diskette.

  3. Copy FORMAT.COM to the diskette.

  4. Copy the script below to a file and save it as A:\AUTOEXEC.BAT:

     @ECHO OFF IF EXIST "A:\FORMAT.TXT" GOTO FORMAT IF NOT EXIST "A:\FORMAT.TXT" GOTO FDISK :FDISK ECHO This system will reboot when complete. ECHO. ECHO Deleting all current partitions ... FDISK /CLEAR > NUL ECHO Creating new partitions ... FDISK /AUTO > NUL ECHO. > A:\FORMAT.TXT GOTO REBOOT :REBOOT FDISK /REBOOT :FORMAT ECHO Formatting drive ... FORMAT  drive  /AUTOTEST /V:  label  /S DEL A:\FORMAT.TXT GOTO END :END CLS ECHO FINISHED FDISK AND FORMAT 

Here, drive is the drive you want to format, and label is the label you want to give the disk.

Warning  

This disk will automatically FDISK and format all partitions. You should clearly mark this disk and store it in a secure area. TRUST ME, I KNOW!

Working with the BOOT.INI

The boot.ini is a hidden, read-only, system file stored in the root of the system partition (Windows Boot Drive). It contains options about which operating system to load and the timeout to load the default selection. At boot up, the boot loader will display the options contained in the boot.ini, if it contains more than one entry. You can modify the boot.ini directly (not recommended), through the System Configuration Utility (Start Run Msconfig), through the System control panel applet (Control Panel System Advanced Startup and Recovery - Settings System Startup), or through the Bootcfg command.

Backing up the Boot.ini

To backup the existing boot.ini, enter the following:

 ATTRIIB -S -H  DRIVELETTER  :\BOOT.INI COPY  DRIVELETTER  :\BOOT.INI  DRIVELETTER  :\BOOT.BAK ATTRIIB +S +H  DRIVELETTER  :\BOOT.INI 

Here, the ATTRIB command is used to remove and later add the system and hidden attributes of the boot.ini.

Driveletter is the drive that contains the boot.ini file (e.g., C).

Related solution:

Found on page:

Setting File or Folder Attributes

57

Displaying the Boot.ini

The TYPE command displays the contents of a text file from the command prompt. To display the contents of the boot.ini using the TYPE command, enter the following:

 TYPE  DRIVELETTER  :\BOOT.INI 

Here, driveletter is the drive that contains the boot.ini file (e.g., C).

Displaying the Boot.ini Using Bootcfg

Bootcfg is a Windows XP/2003 command line tool that allows you to modify the boot.ini file of a local or remote system. To display the contents of the boot.ini on a remote system using Bootcfg, enter the following:

 bootcfg /query 

Here, the QUERY option displays the contents of the boot.ini.

Tip  

Many of Bootcfg options use entry ID numbers to reference each entry. Use the QUERY option to display entry ids.

Scanning and Rebuilding the Boot.ini Using Bootcfg

Bootcfg can scan for existing Windows NT, 2000, XP, and 2003 installations and prompt to have the entries added to the boot.ini. To scan for existing installations only, enter the following:

 bootcfg /scan /s  REMOTESYSTEM  /u  USERDOMAIN  \  USERNAME  /p  PASSWORD  

Here, the SCAN option displays the discovered Windows NT, 2000, XP, and 2003 installations and remotesystem is the name of the remote computer that contains the boot.ini file. The U and P options allow you to specify the domain name, user account name , and user account password of the user account with permissions to the remote computer.

To have Bootcfg scan and prompt to add discovered installations to the boot.ini, you can use the REBUILD option:

 bootcfg /rebuild /s  REMOTESYSTEM  /u  USERDOMAIN  \  USERNAME  /p  PASSWORD  
Tip  

You can always use the U and P options to run Bootcfg against a remote system.

Adding Safe Mode Entries Using Bootcfg

By default, Windows XP does not contain any safe mode boot.ini entries. To add safe mode entries to the default Windows XP boot.ini, enter the following:

 bootcfg /copy /d "Safe Mode with No Network" /id 1 bootcfg /raw "/safeboot:minimal /sos /bootlog" /id 2 bootcfg /copy /d "Safe Mode with Network" /id 1 bootcfg /raw "/safeboot:network /sos /bootlog" /id 3 

Here, the COPY option is used to copy the first entry (id 1). The /RAW option is used to replace any options with a specified string.

Deleting an Entry Using Bootcfg

To delete an entry, enter the following:

 bootcfg /delete /id  entrynumber  

Here, entrynumber is the ID number of the entry to delete.

Scripting Drive Image Pro

Drive Image Pro provides a command interpreter to allow complete control from the command line. There are two requirements to script Drive Image Pro: a script file and a command line to run the script. The script file is a basic text file with the custom commands that control Drive Image Pro. The command line consists of various switches that control how the script will be executed. Together, they provide a way to automate all the manual tasks of Drive Image Pro.

Creating an Image

To store partition 1 on drive 1 to an image, enter the following:

 SELECT DRIVE 1 SELECT PARTITION 1 STORE 

To store all partitions on drives 1 and 2 to an image, enter the following:

 SELECT DRIVE 1 SELECT PARTITION ALL STORE SELECT DRIVE 2 SELECT PARTITION ALL STORE 
Note  

The SELECT command can select only one drive or one set of partitions from a drive at a time. It cannot select two drives simultaneously , hence the need for two STORE commands.

Restoring an Image

To delete all partitions on drive 1 and restore the first image to drive 1's maximum size, enter the following:

 SELECT DRIVE 1 DELETE ALL SELECT FREESPACE FIRST SELECT IMAGE 1 RESIZE IMAGE MAX RESTORE 

To resize the second image to 500MB and restore it to the free space on drive 1, proceed as follows:

 SELECT DRIVE 1 SELECT FREESPACE LAST SELECT IMAGE 2 RESIZE IMAGE 500 RESTORE 

Running a Script

To run a script, enter the following:

 PQDI /CMD=  scriptfile  /IMG=  imagefile  /LOG=  logfile  ERR=  errorfile  

Here, scriptfile is the name of the script file, imagefile is the name of the image used for the STORE and RESTORE commands, logfile is a file that records the results of the imaging process, and errorfile is a file that logs any errors encountered while imaging.

Note  

If the /IMG switch is omitted, the STORE and RESTORE commands will produce an error.

Scripting Norton Ghost

Norton Ghost performs all its scripting from the command line. Although it does support the use of script files, these files are nothing more than a list of switches that can be performed at the command line.

Creating an Image

To create an image of drive 1 called image.gho on a remote drive Z, enter the following:

 GHOST.EXE -CLONE,MODE=DUMP,SRC=1,DST=Z:\IMAGE.GHO 

To create an image of the second partition of drive 1 called image.gho on a remote drive Z, enter the following:

 GHOST.EXE -CLONE,MODE=PDUMP,SRC=1:2,DST=Z:\IMAGE.GHO 

Restoring an Image

To restore an image called image.gho on a remote drive Z to drive 1, enter the following:

 GHOST.EXE -CLONE, MODE=LOAD, SRC= Z:\IMAGE.GHO, DST=1 

To restore an image called image.gho on a remote drive Z to the second partition on drive 1, enter the following:

 GHOST.EXE -CLONE,MODE=PLOAD,SRC= Z:\IMAGE.GHO,DST=1:2 

Performing a Drive Copy

To copy drive 1 to drive 2, enter the following:

 GHOST.EXE -CLONE,MODE=COPY,SRC=1,DST=2 

Performing a Partition Copy

To copy the first partition on drive 2 to the second partition on drive 1, enter the following:

 GHOST.EXE -CLONE,MODE=PCOPY,SRC= 2:1,DST=1:2 

Logging Errors

Norton Ghost records all errors in a log file called ghost.err . This file is normally stored in the program's root directory, but you can change the name and location of the file per use by using the -AFILE switch. Here is an example of how to use the -AFILE switch:

 GHOST.EXE -CLONE,MODE=PCOPY,SRC= 2:1,DST=1:2 -AFILE=  filename  

Using a Script File

Norton Ghost can also read a text file that contains all or additional command-line switches. This file must be in text format, and each command-line switch must be on a different line. Here is an example of a script file:

 -AFILE=z:\errorlog.txt -CLONE,MODE=PCOPY,SRC= 2:1,DST=1:2 

To run the script file, enter the following

 GHOST.EXE @  filename  

Here, filename is the name of the script file.

More Switches

Different versions of Norton Ghost support different switches. To see a brief description of the available switches, type "GHOST -H" at the command prompt.




Windows Admin Scripting Little Black Book
Windows Admin Scripting Little Black Book (Little Black Books (Paraglyph Press))
ISBN: 1933097108
EAN: 2147483647
Year: 2004
Pages: 89

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net