Created
March 30, 2022 20:41
-
-
Save jeremyd2019/a9986cc4b7d377699b064e1af8830980 to your computer and use it in GitHub Desktop.
CMD scripts for creating/mounting/umounting VHDX base and differential disk images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL | |
IF "%~f1" == "" GOTO :usage | |
IF NOT EXIST "%~f2" GOTO :usage | |
if "%~3" == "" GOTO :usage | |
REM just to be sure... | |
CALL "%~dp0\vhdumount.cmd" "%~1" | |
DEL /F /Q "%~f1" | |
( | |
@echo.CREATE VDISK FILE="%~f1" TYPE=EXPANDABLE MAXIMUM=%~3 | |
@echo.SELECT VDISK FILE="%~f1" | |
@echo.ATTACH VDISK NODRIVELETTER | |
@echo.CREATE PARTITION PRIMARY | |
@echo.FORMAT FS=NTFS QUICK | |
@echo.ASSIGN MOUNT="%~f2" | |
) | diskpart | |
GOTO :EOF | |
:usage | |
ECHO.Usage: %0 base.vhdx mountpath size_in_mb | |
ECHO. | |
ECHO.NOTE: base.vhdx will be umounted, deleted and re-created. | |
ECHO.NOTE: mountpath must be an empty directory | |
ECHO. | |
ECHO base.vhdx will be mounted on mountpath | |
EXIT /B 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL | |
IF NOT EXIST "%~f1" GOTO :usage | |
IF "%~f2" == "" GOTO :usage | |
IF NOT EXIST "%~f3" GOTO :usage | |
REM just to be sure... | |
CALL "%~dp0\vhdumount.cmd" "%~2" | |
DEL /F /Q "%~f2" | |
( | |
@echo.CREATE VDISK FILE="%~f2" PARENT="%~f1" | |
@echo.SELECT VDISK FILE="%~f2" | |
@echo.ATTACH VDISK NODRIVELETTER | |
@echo.SELECT PARTITION 1 | |
@echo.ASSIGN MOUNT="%~f3" | |
) | diskpart | |
GOTO :EOF | |
:usage | |
ECHO.Usage: %0 base.vhdx snapshot.vhdx mountpath | |
ECHO. | |
ECHO.NOTE: snapshot.vhdx will be umounted, deleted and re-created. | |
ECHO.NOTE: mountpath must be an empty directory | |
EXIT /B 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL | |
IF NOT EXIST "%~f1" GOTO :usage | |
( | |
@echo.SELECT VDISK FILE="%~f1" | |
@echo.SELECT PARTITION 1 | |
@echo.REMOVE ALL DISMOUNT | |
@echo.DETACH VDISK | |
) | diskpart | |
goto :EOF | |
:usage | |
ECHO.Usage: %0 snapshot.vhdx | |
EXIT /B 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment