How to mount and unmount hard drives under Windows (the unix way)

38

12

On my work computer I have two USB hard drives that I use rarely. They have a power save mode that sends them into sleep after a couple of minutes of them being idle.

Whenever I open a context menu on a file, the drives are woken up (most likely caused by the "send to" handler). So I eject the drive, but I can't find a way to get it back, other than unplugging and replugging it in.

Is there a way to unmount the drives, and then remount them only when I actually need them? (On Windows 7 Ultimate.)

Der Hochstapler

Posted 2011-06-11T21:11:24.970

Reputation: 77 228

If it's any help, I summarized all option within my answer for this question

– Albin – 2018-09-25T22:45:17.457

Answers

40

Remove the drive letters using mountvol or diskmgmt.msc. Without a drive letter, they won't appear under Computer or Send To.

mountvol Q: /p

Using /p will actually dismount the device. On older Windows versions, you only have /d, which only unassigns the drive letter, but keeps the volume mounted.

Reassign when needed, using the volume ID printed by mountvol:

mountvol Q: \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\

You can also mount the volume on an empty folder (Unix style) using the same tools:

mkdir C:\fs\backup-disk
mountvol C:\fs\backup-disk \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\

All these operations require Administrator privileges.


(In fact, you might even be able to directly use the volume ID in your backup scripts, without having to mount it anywhere. For example, \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\projects instead of Q:\projects.)

user1686

Posted 2011-06-11T21:11:24.970

Reputation: 283 655

@grawity, Regarding "you might even be able to directly use the volume ID in your backup scripts", How would you get \\?\Volume{...}\ to work? It doesn't seem to work in file explorer, and cmd also complains " does not support UNC paths as current directories.". – Pacerier – 2015-05-03T14:04:51.000

1@Pacerier: Well, that applies to cmd specifically, not to external tools like robocopy or rsync. And even in cmd it's limited to using UNC as current directory – you can very well do dir \\foo\bar or copy \\foo\bar \\baz\qux. – user1686 – 2015-05-03T15:44:47.903

@grawity, I don't think I'm following here.... I can't seem to get it working in cmd: http://i.stack.imgur.com/m3uBr.png

– Pacerier – 2015-05-24T15:24:45.487

6By the way, is that GUID tied to the device? Will it be the same if I plug the device into another Windows machine? Is it even static between reboots on the same machine? – Der Hochstapler – 2011-06-11T21:53:33.247

2@OliverSalzburg: The volume GUID is tied to that specific volume, and persists after reboots. (It has to, in order for persistent drive letter assignments and filesystem mounts to work.) But unfortunately it's local to the machine. (As far as I know, Windows has no way to reference volumes by label or filesystem UUID yet.) – user1686 – 2011-06-12T08:39:31.060

2

@OliverSalzburg: Although if you browse the Object Manager using WinObj, you'll find more symlinks pointing to the same \Device\...: for example, to access my iPod I can use E:\Music or \\?\STORAGE#RemovableMedia#7&bec343e&0&RM#{53f5630a-b6bf-11d0-94f2-00a0c91efb8b}\Music... But again, those appear to be variable between machines.

– user1686 – 2011-06-12T08:50:26.723

3Is this really the same as unmounting in UNIX? On a UNIX box, once the volume is umounted, it's safe to rip it out of the computer. (Maybe it'll make your SATA bus upset, if you don't have the appropriate hardware support for that, and you might need to reboot, but you won't lose any data.) If you can still access the disk as \?\Volume{...}, doesn't that mean the filesystem is still available to the OS, and therefore might have unflushed data in write cache and so on? – Glyph – 2013-02-08T06:22:02.263

1@Glyph: UNIX is dead – better compare this to Linux or another modern operating system. On Linux, a single fs can be mounted on multiple places, usually using "bind mounts", and all of them must be unmounted to detach a filesystem. On Windows, you could also say that the OS has a few automatic mountpoints (\\?\Volume{…}), and the mountvol command manages additional mountpoints. So the filesystem remains attached as long as there is at least one mountpoint – even when you remove all user-facing mountpoints from mountvol's list, you still have the internal \\?\Volume{…} one. – user1686 – 2013-02-08T11:29:53.550

1

@Glyph: (The device nodes on Windows would be \\.\Device\HarddiskVolume23 in the NT namespace /// Also, Windows does have a few functions to unmount volumes completely – the FSCTL_LOCK_VOLUME and FSCTL_DISMOUNT_VOLUME ioctls. They are only effective for as long as the program is running, however.

– user1686 – 2013-02-08T11:35:08.203

@grawity: Is there any way to issue those IOCTLs from a command-line or graphical administration tool? – Glyph – 2013-02-11T23:55:41.473

The /P option is described to additionaly "dismount the volume", compared to /D. Can someone elaborate on that? Does it unmount it "more" than just /D? – David Balažic – 2013-11-21T22:46:34.783

3@DavidBalažic: /D only removes the drive letter (or path) assignment. Dismounting means detaching all such assignments, as well as closing the filesystem itself. Remember that Windows mounts all filesystems by default on the \\?\Volume{…} paths, and therefore regular mountvol usage only adds/removes additional ones (like mount --bind /x /y on Linux). – user1686 – 2013-11-22T16:11:52.263

3So if I want Windows to completely "let go" of the volume, I have to use /P ? To get the same effect as umount on *nix? Using /D removes one letter/path assignment while the volume actually stays mounted? – David Balažic – 2013-11-22T20:10:12.713

2@DavidBalažic: Yes. – user1686 – 2013-11-22T20:13:00.990

@grawity, then the answer should updated, as it is misleading. Although it does answer the body of the question, but not its title. – David Balažic – 2013-11-23T00:22:45.443

6

Use DISKPART to set your disk offline
It will stay offline even after a restart or a new power on

Use DISKPART to set it back online

This can be done in scripts

command file to put disk 2 offline:

Offline.cmd

 echo list disk              > c:\windows\temp\namexxxx.none
 echo select disk 2         >> c:\windows\temp\namexxxx.none
 echo offline disk          >> c:\windows\temp\namexxxx.none
 echo exit                  >> c:\windows\temp\namexxxx.none
 diskpart /s c:\windows\temp\namexxxx.none
 erase c:\windows\temp\namexxxx.none
 pause

command file to put disk 2 online:

Online.cmd

 .
 echo select disk 2 ........
 echo online disk ......
 .

Execute as administrator

Opoedre

Posted 2011-06-11T21:11:24.970

Reputation: 61

"list disk" is not needed, it only displays drive list to the user – trogper – 2018-08-02T15:49:03.697

5

The correct answer is using the /P parameter to mountvol (see the comments in the accepted answer to understand why /D is not enough) but that only applies to recent windows versions (NT kernel version 6 and up).

The devcon utility as described in this answer works across all NT versions

Costin Gușă

Posted 2011-06-11T21:11:24.970

Reputation: 637