UBCD on USB, Detecting Drive(s), check what drive UBCD is on

If you have a tutorial or tip related to the UBCD, why not share it with other users here?

Moderators: Icecube, StopSpazzing

Post Reply
Message
Author
hbrowser
Posts: 1
Joined: Sun Feb 20, 2011 4:26 am

UBCD on USB, Detecting Drive(s), check what drive UBCD is on

#1 Post by hbrowser » Sun Feb 20, 2011 6:26 am

Hi everyone,

Here's my situation:
I was asked to create a bootdisk which starts ghost automatically and puts a ghost image on the harddisk, then display hardware info.
So I found UBCD (which works great) and had this:
- UBCD on a USB drive
- Booting OK, added Ghost & HWinfo together in 1 archive, all working fine
- Autorun ghost on startup using MENU DEFAULT and TIMEOUT
- USB drive is recognised as Drive #1, with drive letter C: (%CDDRV% is C:)

However I ended up with an empty USB stick after each run because the ghost command was set to overwrite Disk#1.


So I needed something that would check all drives, and find out if
a. they exist
b. they don't contain %CDDRV% partition
c. they haven't been ghosted already.

first attempt: fdisk /dump
So first I added FDISK to the archive and read fdisk.exe /dump using the following.

Code: Select all

rem create file with relevant lines from fdisk
fdisk.exe /dump | xgrep ": [0-9]" > fdump.txt
rem this retrieves the line with drive info for %cddrv% from fdisk dump
xgrep -ni %cddrv% fdump.txt | lmod /S: [$1] | nset linenr=$0
call var set linenr=(%linenr%-1)
But I got stuck parsing the fdump.txt because there is no for /f loop and I have no idea how to loop through a file; I did manage to find the %CDDRV% though with xgrep and linenumbers. Using %linenr% you can read the drivenr from fdump.txt into a usable variable. Pretty straightforward, no looping required but I quit there because I needed more and it became messy real quick.

second attempt: fdisk /info #drivenr
I later found out you can call fdisk /info with a driveletter and this is the setup I now use:
the relevant lines without the plumbing and logging and stuff:

Code: Select all

rem loop drives 1 through 8
for %%A in (1 2 3 4 5 6 7 8) do call %0 : dsk %%A

    rem call fdisk with drive number and read output.
    fdisk /info %1 | xgrep -i ": [0-9]" | nset found=$0
    if "%found%"=="" goto eof

    rem call fdisk with drive number and retrieve the first partition
    fdisk /info %1 | xgrep -i "^ [A-Z]:" | lmod /S: [$1] | nset found=$0
    rem check for UBCD and erased drives
    if "%found%:"=="%cddrv%" goto cddrvnoterased
    if exist %found%:\erased.txt goto drivealreadyerased

    rem insert stuff to do with disk here...
Some issues:
- I am still looking for a way to display output to the screen between ghosts, sort of a progress indication instead of using a log file. (ghost clears the screen even when run without GUI.)
- I have added FDISK, GHOST and HWINFO to the same archive to be able to use them all directly - I don't want to open them manually from the menu and then start a batfile or something, no user input should be required. Is this possible without repacking everything you need in a single archive?
- Also, what if there are more than 8 drives? FDISK doesn't support that it seems, and I don't see it happening soon, but still..
- And if there is a way to read and loop through lines from a file, that would also help for other problems. I could not find anything usable - might create a dirty hack soon.
That's it for now :mrgreen:

Other suggestions to do things easier or better of course also welcome.

Below the complete listing, hope this helps someone.
One last thing, be very careful with this if you use it with ghost like me..
It resulted in some nice "hey it's not starting windows? .. erased drive?! nooo!!" moments :wink:

Code: Select all

@if "%debug%"=="" echo off
if "%1"==":" if not "%2"=="" goto %2

set log=ghostlog.txt

for %%A in (1 2 3 4 5 6 7 8) do call %0 : dsk %%A
echo --- Erase Log ---
type %log%
del %log%
set log=
pause
call hwinfo.exe
goto eof

:dsk
shift
shift
 echo checking drive %1 >> %log%
fdisk /info %1 | xgrep -i ": [0-9]" | nset found=$0
if "%found%"=="" goto eof

 echo  drive found.. inspecting drive.. >> %log%
fdisk /info %1 | xgrep -i "^ [A-Z]:" | lmod /S: [$1] | nset found=$0
if "%found%:"=="%cddrv%" goto cddrvnoterased
if exist %found%:\erased.txt goto drivealreadyerased
 echo   all OK.. erasing drive %1.. >> %log%
ghost.exe -fni -clone,mode=load,src=ERASE.GHO,dst=%1 -quiet -sure
 echo  drive %1 erased! >> %log%
goto eof

:cddrvnoterased
 echo   drive %1 contains boot partition %cddrv%\. erase cancelled. >> %log%
goto eof

:drivealreadyerased
 echo   drive %1 already erased. erase cancelled. >> %log%
goto eof

rem ** other stuff here **

:eof

Dan_Sitar
Posts: 1
Joined: Mon Dec 24, 2012 8:58 pm

Re: UBCD on USB, Detecting Drive(s), check what drive UBCD i

#2 Post by Dan_Sitar » Mon Dec 24, 2012 9:45 pm

Hi hbrowser, I hope that you solved your issue by now. Just in case you did not, I found this little DOS routine of a program that is searching on which drive it got booted on.

Code: Select all

@ECHO OFF
set RAMD=
set LglDrv=27 * 26 Z 25 Y 24 X 23 W 22 V 21 U 20 T 19 S 18 R 17 Q 16 P 15
set LglDrv=%LglDrv% O 14 N 13 M 12 L 11 K 10 J 9 I 8 H 7 G 6 F 5 E 4 D 3 C

c:\findramd

if errorlevel 255 goto no_ramdrive
if not errorlevel 3 goto no_ramdrive

goto do_shift

:loop
if errorlevel %1 goto no_shift

:do_shift
shift
shift
if not %1*==* goto loop
goto no_ramdrive

:no_shift
set ramd=%2

goto success

:no_ramdrive
set ramd=c:\

:success
path=%RAMD%:\
The variable %RAMD% is the letter of the drive.

Post Reply