Welcome to Symantec Connect.  Log in or register to participate.
Login to participate
Endpoint Management & Virtualization ArticlesRSS

Installing WinPE on a USB Device, Part II: The Menu

trb48's picture

I know that it has been a while, but I finally found some time to follow up on an article that I wrote a while back. If you need a refresher, here is a link to the article: Installing WinPE on a USB Device

I promised two follow-up articles. This article will talk about how to make a killer menu for your WinPE powered USB hard drive.

Review:

Last time, our goal was to make a USB hard drive much more useful. I talked about how to install WinPE (a highly useful, portable operating system made by Microsoft -- learn more here) onto a hard drive. Why? Using that setup you can deploy a 4GB image onto a computer in just minutes.

Here are the basic steps you need to follow to get up the drive:

  1. Make the hard drive bootable.
  2. Install WinPE on the drive.
  3. Add in the appropriate scripting (the purpose of this article).
  4. Use your new tool to save some time.

Overview:

I am going to show you what you can do to create a menu for your USB hard drive. Then I will show you some very useful scripting for your drive.

First, we need to edit the bat file that controls this entire process. After you have setup your hard drive, and installed WinPE, navigate to: minint/system32. Look for a file named startnet.cmd. Basically this file contains everything that WinPE needs to set up tcpip, netbios, and msclient. You can also add scripting to this file to automate almost anything. If you want to learn more about scripting in WinPE, read this article: Include a Custom Script in a Windows PE Image

You can also run the AClient in WinPE, and this is where you would add this in if you wanted to do that.

To get these features you must make sure that you have your machine's network drivers installed correctly. Here are some resources that will help you do that:

I only want to use WinPE to dump an image, so I don't care about these extra features when I am using WinPE on my hard drive, so I generally delete all the scripting from startnet.cmd.

In the next section I will show you the menu that we used to make WinPE really useful.

The Menu:

I have to admit, I did not find this menu. One of my co-workers, Jeremy, found it (it was actually his first assignment, and he found it so fast that it really impressed me). I will add comments to explain the important parts of the file.

Here is the code:

 
@ECHO OFF
CLS 
:LOOP
REM This is the menu that appears after WinPE is done loading
REM A B and C deploy an image to the computers hard drive using different rdeploy tags
ECHO A. Dell GX620
ECHO B. HP - 1
ECHO C. HP - 2
REM This takes you to a normal command prompt while in WinPE
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter: 
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO ItemA
IF /I '%Choice%'=='B' GOTO ItemB
IF /I '%Choice%'=='C' GOTO ItemC
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
REM Each letter will run a separate bat file - you don't have to do that you can add the code directly into this file
:ItemA
GX620.bat
GOTO End
:ItemB
D1.bat
GOTO End
:ItemC
D2.bat 
:Quit
:End

This menu works really well (thanks Jeremy). After WinPE loads, it allows you to dump the image on the computer the USB hard drive is connected to.

You might ask, why are there menu items for a Dell GX620 and two different HP menu items? Well, I found that each hardware type handles their drives differently. Because of that, we had to tweak the rdeploy tags to accomodate each hardware type. Basically, you can use one script for all Dell computers, and another for all HP computers.

In the next section, I will talk about some of the RDeploy tags that I used in the bat files that the menu calls (GX620.bat, D1.bat and D2.bat).

The A-Tools:

To deploy images, we are going to use Altiris RDeploy (of course!). It is an amazing program, I don't know where I would be without it. Because WinPE is a 32 bit environment, we can use the Windows version of RDeploy. In order for everything to work, we have to copy the Windows RDeploy files to the WinPE USB hard drive. I like to copy the files to minint\system32. Why? If it is sitting in the system32 folder, you can access the RDeploy files no matter where you navigate in WinPE.

I like to have all of this scripted, and in order to script an image deploy, you have to know the tags that you can use with RDeploy. Here are some useful resources when it comes to RDeploy command-line switches:

There are a few command-line switches that I like to use, here they are with descriptions of what they do:

-dnumber
This tag specifies what disk you are deploying the image to. This is really important because you technically have two disks on the computer (your USB hard drive, and the local drive). If you don't have this, you may end up deploying your image to the hard drive that has WinPE on it (it would give you an error, so don't worry about ruining your drive). Here is an example of what the tag looks like: -d1
-moption
This tag tells RDeploy that you are deploying the image. Instead of d you can use the following options (depending on the situation, of course): u(Upload image) - mu, d (Download image) - md, b (Multicast only) - mb, ub (Upload and multicast image) - mub, db (Download and multicast image) - mdb, client (Client mode) - mclient. In this situation, where we are deploying an image, we will use -md
-szf
This is one of the most important and useful tags in my opinion. This tag maintains the images original size. For example, if you take and image of a 11 gig partion, and you use the -szf tag when deploying, the image will maintain it's 11 gig size. I find this really useful. If you want the deployed image to fill the hard disk on the computer don't use this tag.
-nobw
This option removes everything to do with bootworks from the image and the hard drive that the image is deployed to. Most of the time, this is just a saftely measure.
-nooem
This tag gets rid of the OEM partition. These days every computer maker is packaging some type of partition on the hard drive on delivery. It may be a diagnostic partition, or the partition may have Windows on it (this allows the user to reinstall the OS). I don't want or need the extra partition, so I let RDeploy delete it. If you want to keep the OEM partitions make sure to take that into account. You will have to make sure you use the right drive and partition numbers.
-fpath to image and filename
Probably the most important tag in the whole lot. This is what points RDeploy to the image that you want to deploy. I usually store my images in the minint\system32 folder. That way I don't have to worry about file paths. You can just script: -fimagename.img, and you are good to go.

The Menu Bat Files:

GX620.bat

Here are the contents of GX620.bat file:

@ECHO OFF
TITLE Dell Deployments
COLOR F9
REM GX620
echo y | format c: /fs:ntfs /v: /x /q
rdeploy -d1 -szf -md -nobw -nooem -fpartnership.img
diskpart /s delpart2.txt
exit

To learn more about the diskpart and the format commands, follow the links below

D1.bat

Here are the contents of D1.bat file:

@ECHO OFF
TITLE HP Deployments
COLOR F9
echo y | format c: /fs:ntfs /v: /x /q
rdeploy -d1 -szf -md -nobw -nooem -fpartnership.img
diskpart /s delpart.txt
exit

To learn more about the diskpart and the format commands, follow the links below

D2.bat

Here are the contents of D2.bat file:

@ECHO OFF
TITLE HP Deployments
COLOR F9
echo y | format c: /fs:ntfs /v: /x /q
rem rdeploy -d1 -szf -md -nobw -nooem -fpartnership.img
rdeploy -d2 -szf -md -nobw -nooem -fpartnership.img
diskpart /s delpart.txt
exit

To learn more about the diskpart and the format commands, follow the links below

Hopefully the three files above will give you a feel of how to use the command-line tags with RDeploy. The only advice that I can give you is that you just need to play around with the tags (isn't that called troubleshooting?) until you get them right (and working the way that you want them to).

Useful Commands in WinPE:

Not only can images be deployed from WinPE, there are a ton of different things you can do in the command-line. Here are a few that I like to use:

Format: Formats the disk in the specified volume to accept Windows files.

Click to view.

Diskpart: is a small, scriptable command-line utility that allows you to create, convert and delete disk partitions and software RAID arrays.

Click to view.

For more info on these commands, click on the links above.

Conclusion

Now we have a complete picture. We have a hard drive and it has a menu that will help us deploy an image. WinPE is a really powerful tool, make sure that you use it to its potential. Having WinPE installed on a hard drive has really helped me get more work done.

riva11's picture

Thanks for sharing these

Thanks for sharing these information, your effort to collect and document the WinPE installation process is really appreciated.

Regards
PM

jayhawk's picture

Great Thanks! I was just

Great Thanks! I was just about to do this myself for my enterprise!

dark_harmonics's picture

Everybody should be using

Everybody should be using the WAIK to create their USB winpe images. I actually made a nice dos script and added it into the boot.wim of the winpe2.0. It allows you to deploy statically located images (its a large usb drive) or create new images at incredible speeds!

Anyhow the point of this post is that you should use WinPE2.0 from the vista WAIK (you do not need vista). there is a wonderful CHM that comes with the install that walks you though creating it. Its very very easy.