Grub4dos Command Primer


The following was translated by Google Translate from Chinese to English http://bbs.wuyou.net/forum.php?mod=viewthread&tid=322662&extra=page%3D1&page=1

WARNING: some formatting errors may be present.




Part 1 - ls, find, root, rootnoverify, map, cdrom, cat, cmp, dd, write, read, calc, checktime, echo, pager, clear

ls

Similar to the Linux ls command, similar to the dir command under Dos, list files and directories in the current directory (working directory) under

ls /boot

Lists the current directory (working directory) under names beginning with boot files and directories, do not use ls boot, it is only valid in the root directory.

ls /boot /

Lists the current directory boot directory of files and directories, do not use ls boot /, it is only valid in the root directory.

ls (hd0,0) /

Lists (hd0,0) files and directories, do not use ls (hd0,0), it is only valid in (hd0,0) for the current disk.

ls dev

Drive a list of all lists (not including drive partition)

ls /boot /> nul && echo exist

Determine the directory /boot /exists, if it exists, then the output exist (this method is invalid for an empty directory)

ls /boot> nul && echo exist! echo not exist

Determine whether there is a file name of the current directory (working directory) to boot the beginning of the file or directory, if it exists, then the output exist, otherwise the output not exist

ls (hd0,0) /boot /> nul && echo exist! echo not exist

Judgment directory (hd0,0) /boot /exists, if it exists, then the output exist, otherwise the output not exist

[Note: If no file folder, for the ls command is concerned that the folder does not exist. ]

[Note: Due to the illusion of the file name of the directory, the directory is called with the /generated by (ud) does not exist, so ls (ud) /time, lists (ud) all the files, but ls (ud) /boot /they can list all files in /boot /under, because the file names of these files are in /boot /beginning]

==============================

debug on

find

List all disks (disks, including partitions) (debug off = silent mode)

debug on

find +1

Lists all known file system disk (debug off = silent mode)

debug on
find checkrange 0x07 parttype

Lists all partitions of partition type 0x07 (NTFS) (debug off = silent mode)

find /ntldr checkrange 0x07 parttype

Find the partition type is 0x07 (NTFS) partitions which have /ntldr file and list partitions found.

find --set-root /ntldr

Finds equipment /ntldr file, the device is set to first found device, the current device is searched first.

find --set-root --ignore-floppies --ignore-cd /ntldr

Finds equipment /ntldr file, the device is set to first find the current device. Ignore the floppy and CD-ROM.

find --set-root --devices=upnhcf /ntldr

Finds equipment /ntldr file, the device is set to first find the current device. Specify search order: ud, pxe, network equipment, hard disk, CD-ROM, floppy disk. The current root is always searched first.

find --set-root --devices=upnh /ntldr

Finds equipment /ntldr file, the device is set to first find the current device. Specifies the search order, and ignore the floppy and CD-ROM.

find --set-root ls /grub/

Finds /grub/ directory of the device, the device is set to first find the current device. /grub /directory can not be empty, otherwise it will ignore the directory.

debug on
find --set-root makeactive --status

Find first active primary partition, current device is searched first. (debug off = silent mode)

find --set-root=/boot/grub /boot/grub/menu.lst

Find device contains /boot/grub/menu.lst, current device searched first, and set the working directory to /boot /grub

find root

Finds all formatted partitions and lists them... (requires 2016 or later version)

(hd0,0) Filesystem type is ntfs, partition type 0x07
(hd0,0)
(hd0,1) Filesystem type is ntfs, partition type 0x07
(hd0,1)

========

root

Displays the current device name and related information.

root (hd0,0)

The (hd0,0) as the current disk, the working directory is /, effects and root = (hd0,0)/ .

root (hd-1,0)

The (hd-1,0) is first ptn of last hard disk, set as the current disk, root working directory is /

root (hd0,0)/boot

The (hd0,0) as the current disk, the working directory is /BOOT, effects and root = (hd0,0)/boot/ .

root ()/boot

Modify the working directory is /BOOT directory under the current disk, effects and root = ()/boot.

root (hd0,0) > nul && echo ok ! echo fail

root (hd0,0) > nul || echo fail ! echo ok

The (hd0,0) is set to the current device, if successful, output ok, if unsuccessful, output fail. (The above two commands have the same effect)

==============================

rootnoverify (hd0,0)

Equivalent to root (hd0,0), but does not test the contents of the partition. This is used in some systems installed outside the GRUB can access the disk area, but still need to set the right circumstances the root partition. Some parameters need to be installed in order to determine the partition may be a problem.

The following commands can be executed correctly, but would not replace the root:

rootnoverify (hd0)
chainloader +1
boot

==============================

Device Types:

(fd0) first floppy disk = (0x00)

(fd1) second floppy = (0x01)

(hd0) first hard = (0x80)

(hd1) second hard drive = (0x81) [0xA0 - 0XFF are CD devices, so max is hd31]

(hd-1) last hard disk

Use (hd) to create a new virtual hard disk after the last hard disk

(cd0) first drive, equivalent to (hd32), --init created by cdrom

(cd1) a second optical drive, which is equivalent to (hd33), --init created by cdrom

Due to the ability to identify cdrom is too low, while optical devices on the market almost all been replaced by U disk, so (cd?) This format may be phased out.

(hd0,0) on a hard disk of the first primary partition

(hd0,4) on a hard disk first extended partition

(hd-1,0) and finally the first primary partition a hard drive, or (hd-2,0) in this format, (hd-1, -1) not allowed in this format.

(hd #, 0) of the first primary partition (hard disk on #)

(hd #, 1) second primary partition (hard disk on #)

(hd #, 2) third primary partition (# on the hard disk)

(hd #, 3) fourth primary partition (hard disk on #)

(hd #, 4) first logical partition (# on the hard disk)

(hd #, 5) a second logical partition (on the hard disk #)

(hd #, 6) a third logical partition (on the hard disk #)

(hd #, 7) The fourth logical partitions (on hard disk #)

(hd32) first optical drive = (0xA0)

(hd33) second optical drive

(0xFF) final drive (hd127)

() The current disk

(bd) the initial boot device (devices including disk and drive)

(cd) from the CD to start, Grub4Dos captured bootable CD, if not booted from the CD, there is no (cd) device

(ud) Fbinst way to start making a hidden partition

(pd) PXE network boot device

(nd) network drives, now is not commonly used (nd no longer exists and has been replaced by pd)

(md) memory drive, to achieve the whole memory as a disk drive to visit

(rd) random storage drives.

(md) device accesses memory from physical address 0, has 512 byte 'sectors'

(rd) can be accessed starting at any base memory address

Named in digital equipment:

fd0 - fd126: 0x0 - 0x7E (virtual floppy diskettes and exclude 0x21 and 0x23)

pxe: 0x21 (network boot device)

ud: 0x23 (Fbinst hidden partition)

rd: 0x7F (random memory storage drive)

hd0 - hd30: 0x80 - 0x9E (hard disk and virtual hard disks)

cd: 0x9F (captured bootable CD, this is not necessarily correct, depending on the bios may be)

hd32 - hd127: 0xA0 - 0xFF (CD and virtual CD-ROM)

+1 Indicates the rest of the device following the first sector of a device as a single file view:

(hd0)+1 will be the first sector of the entire hard disk as a file (of a sector)

(hd0,0)+1 will be the first sector of the partition as a whole file (of a sector)

(fd0)+1 will be the first sector of a floppy disk as a whole file (of a sector)

(cd0)+1 will be the first sector of the entire disc as a file (of a sector - sectors usually 2048 bytes)

(md)+1 will be the first sector of the entire memory as a file (of a sector)

(rd)+1 this rather special, all the contents of the specified memory as a file

[Note: (rd)+1 This always represent the file, which contains all the bytes are stored in the (rd) ]

Can also use + 2, + 3, etc., represents the first two or first three sectors viewed as a single file:

(hd0)+2 first two sectors entire hard disk as a file (of two sectors)

(hd0,0)+3 first three sectors throughout the district as a file (a total of three sectors)

(fd0)+5 entire first 5 sectors of the floppy disk as a file (a total of five sectors)

(cd0)+10 first 10 sectors of the entire disc as a file (of 10 sectors)

(md)+32 32 sectors across the front of memory as a file (a total of 32 sectors)

(rd)+2 first two sectors of the specified memory as a file (of two sectors)

You can also use a similar approach 32+5:

(hd0)512+2 the first two sectors after 512 sectors of the entire hard drive as a file (two sectors)

(hd0,0)1+3 The three sectors starting at the 2nd sector of the first partition as a file (a total of three sectors)

(fd0)1+1 will be sector #2 of whole floppy disk as a file (one sector)

(cd0)128+1 will be sector 128 as a file (one sector)

(md)0+32 32 sectors the start of memory as a file (a total of 32 sectors)

(rd)0+1 is equivalent to (rd) +1, all the contents of the specified memory as a file

About the (rd) Device:

(rd) devices only references the memory region, the memory area (rd) device is not being referenced protected, you can (rd) be interpreted as pointing to a block of memory pointer. In Grub4Dos, many things are free, unprotected, without limitation, (rd) is one of them.

(rd) is not a int13 device, but merely a grub4dos device. In grub4dos inside presence (rd) device, but after entering the DOS, there is no (rd) equipment was.

(rd)+1 always represents the entire contents (rd) device, rather than the first sector.

You can get information (rd) device via the following address:

set /a rdnum=*0x82CC # get the (rd) device number

set /a rdbase=*0x82D0 # get the starting address (rd) devices

set /a rdsize=*0x82D8 # get the total size (rd) devices

Information can be freely set (rd) device through the following methods:

map --ram-drive=0xFF7F # set (rd) device number of (rd)

map --mem --rd-base=50000 # Set (rd) devices starting address

map --mem --rd-size=30000 # Set (rd) devices the total size

The following command only modifies the information (rd) devices:

map --mem /FILE (rd)

Here (rd) pointing a memory area which contains the content of /FILE file, but this memory is not protected, thus the memory at any time may be accessed by other code, and even modify Grub4Dos itself .

The following commands also modifies the information (rd) devices, but (rd) memory area pointed to is protected, because it (fd0) overlap, and (fd0) is protected:

map --mem /FILE (rd)

map --mem /FILE (fd0)

map --hook

If do not change the order of the first two lines or it won't work!


map --status

Display the status of disk emulation.

map /PE.ISO (0xFF)

map --hook

The /PE.ISO mapped to (hd127) simulation disk, /PE.ISO must be continuously stored in the disk can not be fragmented.

map --mem /PE.ISO (0xFF)

map --hook

/PE.ISO First loaded into memory, and then mapped to (hd127) simulation disk, /PE.ISO may have debris.

map --mem=-2880 /FLOPPY.IMG (fd0)

map --hook

/FLOPPY.IMG is first loaded into memory, and then mapped to (fd0) floppy disk emulation, (fd0) will occupy at least 1440KB (2880*512) of memory.

map --mem --top /PE.ISO (0xFF)

map --hook

The /PE.ISO loaded into high memory, and then mapped to (hd127) simulation disk to load the image into high memory can not use gzip compression, but not both achieve.

In grub4dos, the memory is divided into at 3.25G high memory and low memory ends 3.25G mirroring can not cross this point. If your memory is less than 3.25G, you do not have the high-end memory available.

map --unmap=0xFF

map --rehook

Uninstall (hd127) disk emulation. You can not use --unmap=(0xFF) method to uninstall, - unmap= must be followed by a number.

--rehook used to stop the simulation disk and frees up memory, equivalent --unhook then --hook (so it seems, map --unhook command does not seem to be used separately)

map --unmap=0,0x80,0xFF

map --rehook

Uninstall multiple simulations disks.

map --unmap=0:0xFF

map --rehook

Uninstall all disk emulation.

If you want to uninstall a device by device name using a different method, you can do:

map (hd127) (hd127)

map --rehook

map --read-only /FLOPPY.IMG (fd0)

map --hook

(fd0) can only read, cannot write, prevent /FLOPPY.IMG file is corrupted.

Mapped to emulate disk files can all be modified, whether it is IMG, ISO, VHD, etc., unless --read-only parameter.

map --fake-write /FLOPPY.IMG (fd0)

map --hook

(fd0) is false writing state, data can be written, but not recording to the (fd0), preventing /FLOPPY.IMG file from corrupted.

map --unsafe-boot /FLOPPY.IMG (fd0)

map --hook

Allow modification boot sector.

MBR is protected from writes unless --unsafe-boot is used - e.g. map --unsafe-boot (hd0,0)/image.vhd (hd1)

map --- disable-chs-mode /FLOPPY.IMG (fd0)

map --hook

Disable (fd0) of CHS access.

map --disable-lba-mode /FLOPPY.IMG (fd0)

map --hook

Disable (fd0) the LBA access.

map command can also be used to modify the information (rd) random access memory, the above have said.

[Note: The other map parameters seem not very common, but also do not understand its meaning, there is not summed up]

[Note: In the map on the command line, (hdm, n) +1 style of writing is interpreted as representative of the (hdm, n) partitions, rather than just the first sector of the partition. ]

[Note: - after unhook disk emulation, unless you then do --unmap, mapped disks will again be automatically mapped on next --hook]

==============================

Disk swapping on the map command:

# Intended to be mapped to the current device (hd0)

map () (hd0)

# Intend to (hd0) is mapped to the current device

map (hd0) ()

# Begin mapping now

map --rehook

==============================

cdrom --init

map --hook

Mount ATAPI interface drive (You can access the map --hook)


cdrom --stop

map --rehook

Uninstall ATAPI drive interface

==============================

cat /menu.lst

The display /menu.lst

cat --hex /grldr

To display the contents in hexadecimal of /grldr

cat --skip=1024 /menu.lst

display /menu.lst contents, skip the first 1KB

cat --length=10 /menu.lst

display /menu.lst contents only the first 10 bytes

cat --locate="\ x20" /menu.lst

Find two consecutive spaces (escape character + non escape character) in /menu.lst the (case-sensitive)

cat --locate=abc /menu.lst

Find abc string (non-escaped characters) in /menu.lst the (case-sensitive)

cat --locatei=abc /menu.lst

Find /menu.lst the string abc (case insensitive)

cat --locate=abc --number=3 /menu.lst

Find abc string /menu.lst show only the results of the previous three found

cat --locate=abc --replace=def /menu.lst

Find the abc string /menu.lst and replaced def

cat --locate=abc --replace=def --number=3 /menu.lst

Find /menu.lst the abc string and replaced def, just replace the three former results found

cat --locate=abc --replace=def --locate-align=16 /menu.lst

Find the abc string /menu.lst and replaced def, replace only 16 position aligned with results


By the following command to see the effect of --locate-align=16:

echo -n > /menu.lst

cat --locate=\x0 --replace=1 /menu.lst

cat /menu.lst

cat --locate=1 --replace=0 --locate-align=16 /menu.lst

cat /menu.lst

cat --length=0 ()-1

Fixed usage, access to the current partition address offset in bytes - e.g. %@retval% returns 0x7E00 (=63*512)

cat --length=0 () /menu.lst

Get /menu.lst file size (if file >4GB then returns max 4GB)


cat --length=0 ()/menu.lst > nul && echo exist ! echo not exist

/menu.lst Determine whether there is a file, if it exists, then the output exist, otherwise the output not exist

Escape character summary:

\nnn 1-3 octal character code representation (\377) octal maximum value of \377, exceeding the 377 code will then be converted modulo 377, for example, \400 represents \0

\xnn a 2-digit hexadecimal chracters (0-9 A-F) (\x00-\xFF) code indicates that the maximum value of \xFF

\ Blank space character

\\ \ Character (backslash)

\" " Character (double quotes)

\' ' Character (single quotes)

\a alert (bell)

\b backspace

\f formfeed

\n newline

\r carriage return

\t horizontal tab

\v vertical tab

[Note: Performing cat --locate= or cat --locatei =, you can get the position of the last occurrence using %?%]

For example:

cat --locate=b /File > nul

set /a Last=%?% > nul

Explanation: cat --locate=a /File returns results like 29 35 48 99 but the variable ? is set to the position of the last byte found.

With skill you can use &; operator to achieve this on one line (this does not work if you use &&)

set Last=-1 && cat --locate=a /File &; set /a Last =%?% > nul


sets a to a space character:

set "a= "

set multiple spaces before a string:

set "a= here are spaces"


cmp /menu.lst /m.lst

Compares two files are identical.

cmp --hex /menu.lst /m.lst

Compare two files are identical, and compare the results displayed in hexadecimal format.

cmp /menu.lst /m.lst > nul && echo same ! echo different

Compare two files are the same, if the same, then the output same, otherwise the output different.

==============================

dd command

dd if=()/menu.lst of=()/m.lst

Copy the contents of the /m.lst in /menu.lst

dd if=()/menu.lst of=() /m.lst bs=32 count=5

A block size of 32 (default 512), copy data from five blocks from /menu.lst into /m.lst

dd if=()/menu.lst of=()/m.lst bs=10 skip=5 seek=6

10 as block size, copy data from /menu.lst into /m.lst in. When copying, skip the first five blocks /menu.lst, and start reading from the first 6 blocks, a write, skip the first seven blocks /m.lst from the first eight blocks to start writing.

dd if=()/menu.lst of=()/m.lst buf=0x2000000 buflen=0x2000000

Copy the contents of the /m.lst /menu.lst, and when copying from 0x2000000 position memory (32M location) take 0x2000000 space (32M space) as a cache for copying large files, increasing the cache size dd can accelerate write speeds.

[Note: The source and target files must be present, the path must begin with a device name, the excess length of the file will be discarded, the target file can not be gz compressed files, source files can be compressed gz files, compressed files before replication be extracted. dd for the entire device can read and write operations: dd if=(fd0) of=(fd1), with caution. ]

==============================

write and read

write /menu.lst abc

Abc written in three characters at the beginning /menu.lst file, overwriting the original characters.

write /menu.lst "abc"

Write five characters "abc" at the beginning /menu.lst files, overwrite the original characters.