RMPartUSB FAQs

Tip: Set the options in RMPrepUSB, untick the ‘No user prompts’ box and click ‘6 Prepare Drive’ – the RMPartUSB parameters will be displayed before they are executed and you can see the parameters that will be used. RMPrepUSB also has an ‘Info box’ – just hover over an option to see what it does.

To understand the RMPartUSB options better, read the RMPrepUSB User Guide.

Q1. How can I use RMPartUSB in my Windows script files (e.g. .cmd or .bat files)?

A1. Most functions of RMPrepUSB are available in RMPartUSB and so can be scripted – except you will need to use XCOPY to copy files to the USB drive once it has been formatted.

Some special commands and code examples are shown below (code in bold, keywords in red bold):

RMPARTUSB LIST

  • RMPARTUSB v2.1.600 (c)2008-10 RM Education plc [SSi]
  • ====================================================
  • *DRIVE 1 – 7.5GiB TakeMS MEM-Drive Smart USB Devi Fw=0.00 H:
  • DRIVE 2 – 7.5GiB Verbatim STORE N GO USB Device Fw=5.00 J:
  • RMPARTUSB LIST ALLDRIVES
  • RMPARTUSB v2.1.600 (c)2008-10 RM Education plc [SSi]
  • ====================================================
  • *DRIVE 0 – 232.8GiB ST3250820AS ATA Device Fw=3.ADG Sno=202020202020202 C:
  • DRIVE 1 – 7.5GiB TakeMS MEM-Drive Smart USB Devi Fw=0.00 H:
  • DRIVE 2 – 7.5GiB Verbatim STORE N GO USB Device Fw=5.00 J:
  • RMPARTUSB FIND > drv.cmd
  • example drv.cmd file produced is:
  • SET DRIVE=1
  • SET DRIVEDESC=TakeMS MEM-Drive Smart USB Device
  • SET DRIVESIZE=8086618112
  • SET DRIVELETTER=H:
  • SET DRIVE1DESC=TakeMS MEM-Drive Smart USB Device
  • SET DRIVE1SIZE=8086618112
  • SET DRIVE1LETTER=H:
  • SET DRIVE2DESC=Verbatim STORE N GO USB Device
  • SET DRIVE2SIZE=8011120640
  • SET DRIVE2LETTER=J:
  • SET DRIVE3DESC=0
  • SET DRIVE3SIZE=15800762880
  • SET DRIVE3LETTER=G:
  • SET DRIVE4DESC=0
  • SET DRIVE4SIZE=1998743040
  • SET DRIVE4LETTER=I:
  • SET DRIVE5DESC=0

etc. etc. up to DRIVE26xxxx

(Note: DRIVE, DRIVEDESC and DRIVELETTER are used for the FIRST USB DRIVE to be found, if more than one USB drive is expected to be in the system then use the DRIVEn variables).

Example of how to use in a batch file:
RMPartUSB FIND > drv.cmd
call drv.cmd
del drv.cmd
echo Drive 1 is a %DRIVE1DESC% with a size of %DRIVE1SIZE% and a volume letter of %DRIVE1LETTER%

Or an alternative that does the same thing without needing a temporary file:
FOR /F “tokens=*” %%A IN (‘RMPartUSB FIND’) DO %%A
echo Drive 1 is a %DRIVE1DESC% with a size of %DRIVE1SIZE% and a volume letter of %DRIVE1LETTER%

Detect if a single USB drive is present and get it’s drive number

@echo off
setlocal enabledelayedexpansion
"C:\Program Files (x86)\RMPrepUSB"\RMPartUSB FIND > drv.cmd
set DRIVE=
call drv.cmd > nul
del drv.cmd
if "%DRIVE%"=="" echo NO USB DRIVE FOUND! & pause & goto :eof
set /A NXT=%DRIVE%
:ff
set /a NXT=%NXT%+1
if "%NXT%"=="27" goto :gg
set S=!DRIVE%NXT%SIZE!
if not "%S%"=="0" goto :gg
if "%S%"=="0" goto :ff
:gg
setlocal disabledelayedexpansion
if NOT "%S%"=="0" echo MORE THAN ONE USB DRIVE FOUND! & pause & goto :eof
echo USB DRIVE %DRIVE% CONNECTED

Find all USB drives in system

(note drive letter is one of the volumes if drive has more than one partition it could be any one on drive):

@echo off
 setlocal enabledelayedexpansion
 "C:\Program Files (x86)\RMPrepUSB"\RMPartUSB FIND > drv.cmd
 set DRIVE=
 call drv.cmd > nul
 del drv.cmd
 if "%DRIVE%"=="" echo NO USB DRIVE FOUND! & pause & goto :eof
 set /A NXT=%DRIVE%-1
 :ff
 set /A NXT=%NXT%+1
 if "%NXT%"=="27" goto :gg
 set S=!DRIVE%NXT%SIZE!
 if "%S%"=="0" goto :ff
 :: we have a USB drive, now check it
 echo FOUND DRIVE%NXT% SIZE=%S% !DRIVE%NXT%DESC! !DRIVE%NXT%LETTER!

 echo Now use %NXT% as drive number for any commands you like

 goto :FF

 :gg
 setlocal disabledelayedexpansion
C:\temp>dousb
 FOUND DRIVE4 SIZE=32045690880 Corsair Voyager GT 3.0 K:
 Now use 4 as drive number for any commands
 FOUND DRIVE5 SIZE=128034708480 SanDisk Extreme Pro P:
 Now use 5 as drive number for any commands

Ask user to select a USB drive, wipe and format it and copy files to it:


RMPARTUSB LIST
set /P DD=Please enter the USB Flash drive number you want to use:
rmpartusb DRIVE=%dd% WINPE FAT32 2PTN VOLUME=WINPE
if errorlevel 1 echo COMMAND FAILED!
if errorlevel 1 goto :EOF
rmpartusb DRIVE=%dd% GETDRV > drv1.cmd
set USBDRIVELETTER=
call drv1.cmd
del drv1.cmd
If "%USBDRIVELETTER%"="" goto :EOF
xcopy /herky C:\mysourcefiles\*.* %USBDRIVELETTER%\*.*
echo all files copied!

example drv1.cmd file produces:

  • SET USBDRIVE=1
  • SET USBDRIVEDESC=TakeMS MEM-Drive Smart USB Device
  • SET USBDRIVESIZE=8086618112
  • SET USBDRIVELETTER=H:

Tip: add SURE before the WINPE parameter if you don’t want to ask the user if he is sure he wants to wipe the drive (don’t add SURE to the end after VOLUME as it won’t work!)

If testing for drive sizes using Windows command shell, maximum number is +/- 1TB (31 bits).

You can reduce the number returned to MB units using

set USBDRIVESIZE=%USBDRIVESIZE:~0,-6%

this will chop off the last 6 digits. You can then test the size using

if “%USBDRIVESIZE%”==”” echo ERROR!

if %USBDRIVESIZE% LSS 137400 echo Drive is below 137GB

Ask user to select the USB drive, partition and format the drive, add grub4dos and copy files to it:

@echo off
REM change to our working folder
pushd "C:\Program Files (x86)\RMPrepUSB"
REM list all USB drives so user can see them and their drive number
RMPARTUSB LIST
REM Ask user for a drive number
set /P DD=Please enter the USB Flash drive number you want to use:
REM execute RMPARTUSB (insert SURE if you don't want the user prompt)
RMPARTUSB DRIVE=%dd% MSDOS FAT32 2PTN FORCELBA VOLUME=WINPE
if errorlevel 1 echo RMPARTUSB COMMAND FAILED!
if errorlevel 1 goto :EOF
set USBDRIVELETTER=
REM get the drive letter of the newly formatted drive
FOR /F "tokens=*" %%A IN ('RMPARTUSB DRIVE^=%dd% GETDRV') DO %%A
If "%USBDRIVELETTER%"=="" goto :EOF
REM install grub4dos
grubinst -v --skip-mbr-test (hd%dd%)
If errorlevel 1 goto :EOF
REM use touchdrv to ensure MBR changes are not removed by Windows!
touchdrv %USBDRIVELETTER%
REM copy grldr file over which is needed by grub4dos
copy grldr %USBDRIVELETTER%
If errorlevel 1 goto :EOF
REM copy over boot files (assumes a menu.lst file has been added for use by grub4dos)
xcopy /herky .\mybootfiles\*.* %USBDRIVELETTER%\*.*
If errorlevel 1 goto :EOF
echo Finished - All files copied!

How to find the drive number for a given drive letter

Place the following text in a file called getdnum.cmd

@echo off
 echo.
 SET FIND=%1
 IF "%FIND%"=="" echo ERROR - Usage: %0 [driveletter]:    (e.g. %0 H:) && goto :EOF
 SET FIND=%FIND:~0,1%
 SET FIND=%FIND%:
 FOR /F "tokens=" %%A IN ('RMPartUSB FIND') DO %%A REM FOR /F "tokens=" %%A IN ('RMPartUSB FIND ALLDRIVES') DO %%A
 SET DRIVENUM=
 SET DRIVESIZE=
 if /i "%DRIVE1LETTER%"=="%FIND%" SET DRIVENUM=1 && SET DRIVESIZE=%DRIVE1SIZE%
 if /i "%DRIVE2LETTER%"=="%FIND%" SET DRIVENUM=2 && SET DRIVESIZE=%DRIVE2SIZE%
 if /i "%DRIVE3LETTER%"=="%FIND%" SET DRIVENUM=3 && SET DRIVESIZE=%DRIVE3SIZE%
 if /i "%DRIVE4LETTER%"=="%FIND%" SET DRIVENUM=4 && SET DRIVESIZE=%DRIVE4SIZE%
 if /i "%DRIVE5LETTER%"=="%FIND%" SET DRIVENUM=5 && SET DRIVESIZE=%DRIVE5SIZE%
 if "%DRIVENUM%"=="" echo DRIVE NUMBER FOR %FIND% NOT FOUND! && goto :EOF
 echo %FIND% is Drive %DRIVENUM%  Size=%DRIVESIZE%

You can use this by calling (for example) getdnum.cmd h or getdnum.cmd H: , the variable DRIVENUM will contain the physical drive number of the USB drive or be empty if it is not found. Add the ALLDRIVES parameter to the RMPartUSB FIND command if you want all drives to be listed and not just USB drives (remove the word REM from the grey line so that it will run and then add the word REM to the beginning of green the line just above it).

Example using only Diskpart (not for XP)

Call as .cmd file with drive letter as parameter – e.g.

@ECHO OFF 
 SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION 
 IF "%1."=="." ECHO Missing Parameter&GOTO :EOF 
 SET MyVol=%1 
 SET MyDisk= 
 FOR /F "delims=" %%A IN (' ^( ECHO Select Volume %MyVol%^&ECHO list disk ^)^|diskpart^|FIND "* " ') DO SET Mydisk=%%A 
 IF NOT DEFINED Mydisk ECHO ERROR: NO DISK NUMBER FOUND&GOTO :EOF 
 FOR /F "tokens=1 delims=0123456789" %%A IN ("%MyDisk%") DO SET /A Mydisk=!Mydisk:%%A=! 2>nul 
 ECHO %MyVol%: is on DISK %MyDisk%

Find the drive number of the drive containing the batch file FindMe.cmd

(RMPartUSB must be in same folder or in the %path% variable)

Place FindMe.cmd on the USB flash drive and RMPartUSB.com. Admin rights required.

FindMe.cmd

@echo off
 setlocal enabledelayedexpansion
 FOR /F "tokens=*" %%A IN ('RMPartUSB FIND') DO %%A
 For /L %%a in (1,1,26) do (
                 IF [%~d0]==[!DRIVE%%aLETTER!] (
                                 Echo %%a is a match
                                 Set MyDrive=%%a
                                 Goto :EOF
                 )
 )

The variable MyDrive will contain the USB drive number.

Thanks to D.Roberts for this code!

For a way to find the drive number without using RMPartUSB (under a full Windows OS, not WinPE) – see here.

Place SwitchMe.cmd on the USB drive (below) + RMPartUSB.exe – when SwitchMe.cmd is run, it will switch a Removable Flash drive’s partition 2 with partition 1, to make partition 2 accessible to Windows.

Run it again and it will swap back the partitions.

Admin rights required.

SwitchMe.cmd

@echo off
 setlocal enabledelayedexpansion
 FOR /F "tokens=*" %%A IN ('RMPartUSB FIND') DO %%A
 For /L %%a in (1,1,26) do (
                 IF [%~d0]==[!DRIVE%%aLETTER!] (
                                 Echo %%a is a match
                                 rmpartusb.exe drive=%%a Firstpart=2 sure
                                 Goto :EOF
                 )
 )

Thanks to D.Roberts for this code!

Q2 How can I determine the correct command for RMPartUSB?

  • Type RMPartUSB for command line usage. Typing RMPARTUSB on the command line should give some help.
  • Read the manual.
  • Use RMPrepUSB, set your options and click the Prepare Drive button and note down the command line that it uses to call RMPartUSB (uncheck ‘No user prompts’ checkbox).

Q3. How can I modify bytes of a sector (or sectors) under Windows (e.g. MBR) ?

You can use USBTOFILE to save any sector or group of sectors to a file.

Then you can modify the file using dd.exe for Windows

e.g. to remove the 3rd partition table entry, use:

dd bs=1c count=16 seek=478 skip=478 if=/dev/zero of=C:\temp\test.bin

You can then write back the file using RMPartUSB FILETOUSB.

To change certain bytes to certain values, try setbytes

For a native 64-bit MBR utility (and 32-bit version) try mbrFix.exe and mbrFix64.exe

OTHER SNIPPETS

Get drive letter of partition with Volume label of “E2B”

Not case sensitive as /i used

@echo off
 set myDrive=
 for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do vol %%a: 2>nul | find /i "E2B" >nul && set myDrive=%%a:
 if "%myDrive%"=="" (echo Cannot find volume
 ) else (
 echo Drive letter is %myDrive%)
 )

Here are some Diskpart scripts – they do not rely on 3rd party utility – work on 64-bit or 32-bit WinPE

Count number of Removable Drives (Win7 or later only)

Assumes English language:

:CountRem
 @echo off
 set myDrive=
 set CNT=0
 For /L %%a in (1,1,26) do (
 (echo sel disk %%a & echo det disk ) | diskpart.exe | find.exe "Removable" >nul && echo %%a IS REMOVABLE DISK && Set myDrive=%%a && set /A CNT=CNT+1 > nul
         )
 echo %CNT% Removable drives found
 goto :EOF

If only one Removable drive then myDrive has it’s drive number

Get first Removable disk in system

Assumes English language:

:GetRem
 @echo off
 set myDrive=
 For /L %%a in (1,1,26) do (
 (echo sel disk %%a & echo det disk ) | diskpart.exe | find.exe "Removable" >nul && set myDrive=%%a && goto :EOF
         )
 goto :EOF

Get size of a USB drive:

in a batch file where DD is the drive number…

for /f "delims== tokens=2" %%s in ('rmpartusb "DRIVE=%DD% GETDRV" ^| FIND "SIZE"') do set DSZ=%%s

Easy2Boot (E2B) is popular multiboot USB solution that also contains agFM and Ventoy. It supports both Legacy and UEFI.
Simply copy on your bootable ISO files to the E2B USB drive and boot! Boot to DOS, Linux, Windows Install ISOs (XP>Win11),
automate Windows installs, WIM files, VHD files, images of flash drives, Linux ISO+persistence, etc.
E2B is unique in that it uses partition images which allows you to directly boot from Secure Boot images (no need to disable Secure Boot or run MOK manager or modify your UEFI BIOS).

eBooks (multi-buy discount 10%)

The following eBooks (in PDF format) are available from the developer (rated 4.5/5 stars).

Also visit Easy2Boot.xyz and the my blog – please subscribe for the latest news, tips, USB boot articles and news of free eBook updates.