Jump to content











- - - - -

Question about "Zero and random device driver" (found on Olof's homepage)


  • Please log in to reply
14 replies to this topic

#1 Guest_AnonVendetta_*

Guest_AnonVendetta_*
  • Guests

Posted 19 February 2020 - 11:05 PM

So I was browsing around Olof's website and found this tool. Does it use all the same command line options as dd in Linux? How does it compare to Chrysocome's dd? How the the driver initialize without rebooting Windows?

 

If I wanted to run the Windows equivalent of this example command, what would be the syntax?:

 

dd if=/dev/zero of=/dev/sda

 

Are the bs and count options functional/the same?

 

Thanks!



#2 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1448 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 21 February 2020 - 09:34 PM

Zero and Random device driver is just a driver, it has no command line tool associated with it. If you use it with some kind of dd compatible tool, you can use \\.\zero or \\.\random and input files and a disk device as output file like this:

dd if=\\.\zero of=\\.\PhysicalDrive1

But it depends on the particular dd tool that you use how other parameters work or if they accept these kind of parameters at all.

 

As an alternative to dd, you could also use my tool "rawcopy". Parameters are not compatible with dd-style tools, but essentially the same things can be done. http://ltr-data.se/files/rawcopy.zipfor x86 or http://ltr-data.se/f...4/rawcopy64.zip for x64.

Usage:
rawcopy [-lvirwxsdD] [-f[:count]] [-m[:bufsize]] [-o:writeoffset]
       [[[[[skipforward] copylength] infile] outfile]

Default infile/outfile if none or blank given is standard input/output device.
-l     Access devices without locking access to them. Use this switch when you
       are reading/writing physical drives and other processes are using the
       drives.
       Note! This may destroy your data!

-v     Verbose mode. Writes to stderr what is being done.

-f     Number of retries on failed I/O operations.

-m     Try to buffer more of input file into memory before writing to output
       file.

       Buffer size may be suffixed with K,M or G. If -m is given without a
       buffer size, 512 KB is assumed. If -m is not given a buffer size of 512
       bytes is used and read/write failures can be ignored.

-i     Ignores and skip over read/write failures without displaying any dialog
       boxes.

-r     Read input without intermediate buffering.

-w     Write output without intermediate buffering.

-x     Write through to output without going via system cache.

-s     Creates output file as sparse file on NTFS volumes and skips explicitly
       writing all-zero blocks.

-D     Differential operation. Skips rewriting blocks in output file that are
       already equal to corresponding blocks in input file.

-d     Use extended DASD I/O when reading/writing disks. You also need to
       select a compatible buffer size with the -m switch for successful
       operation.

-a     Adjusts size out output file to disk volume size of input. This switch
       is only valid if input is a disk volume.

Examples:
rawcopy -m diskimage.img \\.\A:
  Writes a diskette image file called "diskimage.img" to a physical diskette
  in drive A:. (File extension .img is just an example, sometimes such images
  are called for example .vfd.)
rawcopy \\.\PIPE\MYPIPE ""
  Reads data from named pipe "MYPIPE" on the local machine and write on
  standard output.
rawcopy 512 \\.\PhysicalDrive0 parttable
  Copies 512 bytes (partition table) from first physical harddrive to file
  called "parttable".


#3 Guest_AnonVendetta_*

Guest_AnonVendetta_*
  • Guests

Posted 21 February 2020 - 11:06 PM

@Olof: Yeah, I realized it was only a driver after I read the description again. I just don't like having to reboot into Linux to use dd. I will take a look at rawcopy.

 

Do you know how to get a list of physical drives/volumes/partitions in command prompt?


  • Olof Lagerkvist likes this

#4 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 22 February 2020 - 04:47 PM

Open diskpart and type:

list volume or list vol and enter as following:

 

DISKPART > list vol

Attached Thumbnails

  • Vol.png

  • Olof Lagerkvist likes this

#5 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1448 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 22 February 2020 - 06:54 PM

So, for example to clear out contents of disk 2, you would type:

rawcopy -rwxdm:2M \\.\zero \\.\PhysicalDrive2

The -rwxd switches are there to make sure that we are talking to disk at as low level as possible, bypassing OS or file system limitations, buffering etc. -m:2M makes it use a 2 MB buffer and copy 2 MB data blocks. You could also add -v to get updates at console about which block is currently copied.

 

Edit: To get a list of physical disks, you could use diskpart command line tool. Type list disk to get a list of disk numbers, or you can type list vol to get a list of file system volumes and their drive letters. To clear out contents of drive D:, you would type:

rawcopy -rwxdm:2M \\.\zero \\.\D:


#6 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 February 2020 - 08:02 PM

Only for the record, IMNSHO Diskpart is about the worst tool about the topic (listing disks/physicaldrives and partition/volumes).

 

You can have disks (PhysicalDrives) BUT NOT volumes in them.

You can have volumes BUT NOT disks hosting them.

 

To have an overlook you have to:

1) list disks
2) select each disk

3) list partition(s) for the selected disk

4) select each partition

5) detail partition

6) loop to 4) for next partition
4) loop to 1) until all disks are selected and partitions are detailed

So you will likely need a diskpart script

 

Compare with - say - dd for windows (Crysocome) dd --list and (shameless plug ;) ) its results ordered (and with disk,partiton notation):

 

http://reboot.pro/to...st-and-ddlistw/

 

On the other hand, if you know the drive letter (other plug):

http://reboot.pro/to...er-under-winpe/

 

Or, easy, GUI:

http://reboot.pro/to...1472-volumemgr/

http://reboot.pro/fi.../574-volumemgr/

 

:duff:

Wonko



#7 Guest_AnonVendetta_*

Guest_AnonVendetta_*
  • Guests

Posted 24 February 2020 - 07:09 AM

Well, not necessarily via diskpart, but preferably with a free/open source command line tool, or a command that is built into Windows, that outputs in a neat list like:

\\.\PhysicalDriveX
\\.\Volume
\\.\Partition

@Wonko: It is my understanding that a physical drive is exactly that (or virtual hosted as physical), no further explanation necessary. A volume is a formatted partition (either primary or logical) containing a filesystem. Or it could be a container for multiple partitions. And a partition, well it can be either raw/unformatted, or formatted. A disk generally contains partitions/volumes, but not vice versa. One is the whole, the others are the parts. A drive letter/mount point can be assigned to a volume/partition, but not a disk.

#8 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 February 2020 - 02:00 PM

Well, "your" /dev/sda is disk 0 or physicaldrive0, but - say -  /dev/sda1 is disk 0/partition 1 but there is no real structure in Windows to address a partition by disk, you can only address a volume either by its drive letter (if any) or by its UUID or - in some cases - by its volume number (i.e. \\.\HardDiskVolumen) hence the need to use a tool (and/or script) that provides the most "types" of addresses, to make sure you do not write 00's to the "wrong" target.

 

Only for the record, a Volume is not necessarily formatted, otherwise you wouldn't be able to format a blank (just created) or corrupted volume.

 

And of course a drive letter can be assigned to a non-partitioned disk (like many USB sticks, as an example) as that is a case of a disk that is a volume (or "super-floppy) or - now much little used - CFA cards/microdrives.

 

:duff:

Wonko



#9 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1448 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 24 February 2020 - 02:22 PM

In "modern" versions of Windows it is possible to address a partition by hard disk using the syntax :
\\.\Harddisk0Partition1

#10 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 February 2020 - 03:59 PM

In "modern" versions of Windows it is possible to address a partition by hard disk using the syntax :
\\.\Harddisk0Partition1

Yep :), but that may depend also on the specific tool support for that.

 

Since we were talking of Chrysocome dd for windows:

 

http://www.chrysocome.net/dd

 

it has support for the (good ol') NT4 names, aka \\?\Device\Harddisk0\Partition0

 

and BTW that program already has built-in /dev/zero and  /dev/random virtual devices (plus a /dev/null target)

 

:duff:

Wonko



#11 wimb

wimb

    Platinum Member

  • Developer
  • 3756 posts
  • Interests:Boot and Install from USB
  •  
    Netherlands

Posted 24 February 2020 - 08:14 PM

 

Compare with - say - dd for windows (Crysocome) dd --list and (shameless plug ;) ) its results ordered (and with disk,partiton notation):

 

http://reboot.pro/to...st-and-ddlistw/

 

 

ddlist.cmd and ddlistw.cmd work OK when launched properly from admin command window in Windows 10 x64   :)

 

ddlist.cmd and ddlistw.cmd FAIL when Run as admin or lauched from user command window in Windows 10 x64



#12 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 February 2020 - 06:42 PM

Well, most probably it is the underlying dd --list that needs that (in the - stupid - Windows 10), the batch part in itself is "plain enough" AFAICR.

Try a simple
dd --list
with the three possible credentials
1) User
2) Run as Admin
3) Admin

In the worst case it will be needed something *like* RunAsTI or similar, just the other day we were talking of these on MSFN:
https://msfn.org/boa...le-in-system32/
among the mentioned tools, superuser seems suitable:
https://github.com/m...ntmsi/superUser

:duff:
Wonko

#13 cdob

cdob

    Gold Member

  • Expert
  • 1469 posts

Posted 25 February 2020 - 08:49 PM

ddlist.cmd and ddlistw.cmd FAIL when Run as admin

.

Run as set the current work directory to %SystemRoot%\system32. dd.exe is not found.

Change the direcoty to dd: cd /d %~dp0

As for debug:

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
echo %~dpn0 %*
echo %cd%
pause
cd /d "%~dp0"
echo %cd%
pause

.
Or set full path to dd.exe, but use short (8.3) directory names.

For /F  "skip=4 tokens=*" %%A IN ('%~dps0\dd.exe --list 2^>^&1') DO (

.
Both works here at Win10 1809.



#14 wimb

wimb

    Platinum Member

  • Developer
  • 3756 posts
  • Interests:Boot and Install from USB
  •  
    Netherlands

Posted 26 February 2020 - 09:34 AM

Well, most probably it is the underlying dd --list that needs that (in the - stupid - Windows 10), the batch part in itself is "plain enough" AFAICR.

 

Try a simple

dd --list

with the three possible credentials
1) User

2) Run as Admin
3) Admin

 

 

Thanks for your reply  :)

 

I have made ddlist_only.cmd file for testing and the results are:

1) Run in User Command window - dd.exe is running, but is giving only partly output - In the "NT Block Device Objects" section the output for all Harddisk Devices is missing  :ph34r:

2) Run as Admin - no output at all

3) Run in Admin Command Window - dd.exe is running with correct output

 

So you are right. The problem occurs indeed due to the underlying dd --list not running properly in Windows 10 for case 1) and 2)

 

 

@cdob - Thanks for your reply  :)

 

 

Run as set the current work directory to %SystemRoot%\system32. dd.exe is not found.

Change the direcoty to dd: cd /d %~dp0

 

Both your solutions to solve the problem are working here OK for Windows 10 x64 1909  :)

 

Attached is ddlistbatch_2.zip where the working directory has been changed according to your first solution.

Now Run as Admin can be used as well as Running ddlist.cmd and ddlistw.cmd in Admin Command Window.  :cheers:

 

Thanks to both of you to help solving the problem  :)

Attached Files



#15 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 February 2020 - 09:54 AM

All's Well That Ends Well  :smiling9:

 

:duff:

Wonko


  • wimb likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users