On 5/25/20, Christopher Barker <[email protected]> wrote:
> On Mon, May 25, 2020 at 10:59 AM Steve Barnes <[email protected]>
> wrote:
>
>> On Windows
>> https://freetechtutors.com/create-virtual-hard-disk-using-diskpart-windows/
>> gives a nice description of creating a virtual disk with only operating
>> system commands. Note that it shows the commands being used interactively
>> but it can also be scripted by starting diskpart /s script.txt -
>
> ...
>
>> it does need to be run as admin.
>>
>
> Well, darn. That seriously reduces its usefulness.
Creating and mounting a VHD can be implemented in PowerShell as well,
but it requires installing the Hyper-V management tools and services
(not the hypervisor itself). The hyper-v cmdlets for managing virtual
disks (e.g. mount-vhd) also require administrator access, since the
underlying API does (e.g. AttachVirtualDisk). A new system service and
client application would have to be developed in order to allow
standard users to manage virtual disks.
Here's a PowerShell example to create, format, and mount a volume on a
10 MiB virtual disk. This example mounts the volume both at "V:/" and
at "C:/Mount/vhd_mount":
$vhdpath = 'C:\Mount\temp.vhdx'
$mountpath = 'C:\Mount\vhd_mount'
# create and mount the physical disk as a RAW volume
new-vhd -path $vhdpath -fixed -sizebytes (10 -shl 20)
mount-vhd -path $vhdpath
# create a partition on the disk, format it as NTFS, and assign
# the DOS device name "V:" and label "vhd"
$nd = (get-vhd -path $vhdpath).DiskNumber
new-volume -disknum $nd -filesys ntfs -drive V -friendly vhd
# set a folder mountpoint
mkdir $mountpath
add-partitionaccesspath -drive V -accesspath $mountpath
If no drive letter is desired, use the -accesspath option of the
new-volume cmdlet instead of the -driveletter option.
The following command dismounts the disk:
dismount-vhd -path $vhdpath
The mountpoint on the empty directory remains set but inaccessible
once the disk is dismounted. You can can delete this directory if the
disk won't be mounted again. Or, while the disk is mounted, you can
remove the mountpoint via remove-partitionaccesspath.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/3EEZV32XMNGLGB6Q267MGYHPBSTO55FH/
Code of Conduct: http://python.org/psf/codeofconduct/