Sunday, March 14, 2010

WinPE and DISM/PEimg to boost Scratch Space (Ram Disk)

Soon after I had posted this Custom Win PE Boot Disk Building: Step Four – Pulling it all together walkthrough binding all the elements on making a custom PE boot disk, I started getting comments that followers were unable to get CubicExplorer working in it.

The solution was a long time coming, but revelation of the solution culminated in the Solved: Run CubicExplorer in Win PE with no Crashes... post.

I’m not revisiting that one, but one path I and parities played with in the process was to fiddle with the PE Ram Disk size.

As this may or may not be something amateur PE builders and hobbies may be familiar with (I really wasn’t fully) I thought I would take a few moments to post some related links about it for future reference.

Very Basic info on RamDisk/ScratchSpace in PE

By default, Windows PE builds “by the book” allocate 32 MB of writeable memory to the PE environment.

I like to think of it (very roughly) like this.

The space of my yard would correspond to the System RAM.

The PE system (containing all the stuff in your PE wim-image file) would correspond to a kiddie-pool placed in the back-yard.

The scratch space would correspond to how big the kiddie-pool is and, thusly, how much water fills it up for everyone to play in.

Now generally, for most stock PE builds, 32 MB of scratch space works very well.  PE environments (base) run a CLI shell box and a simple background.  The services are simple and it’s not like you are running a lot of GUI apps.  This small and shallow pool is more than sufficient to let the kids play happily and safely.

But say you then get a lot of neighborhood kids coming to join in.  And some of them aren’t five-year olds.  These are third and fourth graders.  Suddenly there isn’t enough water in the pool for everyone to feel comfortable in.  Kids get cranky and don’t behave.

Under these circumstances you need to get a larger kiddie-pool!

Microsoft describes it like this:

If your Windows PE environment becomes unresponsive when running an application, you may have run out of memory. By default, Windows PE allocates 32 megabytes (MB) of writeable memory, known as scratch space.

Typically, you don’t need to do anything as the standard 32 MB scratch space size is adequate.  But if you need to, you do have the option to manually set the scratch space size larger…assuming the yard (system RAM) is large enough to accommodate things…

In WinPE, scratch space can be set at 32, 64, 128, 256, or 512 MB levels.

It does make a difference, particularly with GUI-heavy applications running in the WinPE environs.  I’ve personally  observed some applications either not running at all, running very sluggishly, or even not fully displaying all the expected graphical elements.

When I rolled out the larger kiddie-pool, they suddenly sprang to life and made things much more pleasant.

The drawback is you have to know the systems you intend to deploy these specific solutions on, and ensure you find the sweet-spot.  If your supported desktop systems have just 256 MB of RAM, and you go to boot it with a WinPE disk set at a 512 MB scratch-space size, it won’t be pretty.  Then again, if you don’t really use a lot of additional memory-intensive applications in WinPE, then you also don’t probably need a 512 MB scratch space wrapped WinPE setup.

In other words, your kiddie-pool can’t be larger than your yard or else it just won’t fit in there.

WinPE 3.0 and Increasing Scratch Space

WinPE 3.0 is based on the Windows 7 platform.  As such, you have to use a WinPE 3.0 specific tool to make changes to the default scratch-space settings.

The beauty of it is that once you get this basic process down, the rest is gravy.  I’ll come back to that in a minute.

Under WinPE 3.0 building, you must use the DISM.exe command tool.

Go ahead and create your WinPE 3.0 “wim” file image using your own technique or the ones I outlined in the first link of this post.

This assumes you have already installed and are familiar with the Windows® AIK for Windows® 7.  There are a few other related Microsoft WinPE building packages/tools as well that should include the tool (Microsoft Deployment Toolkit).

Launch the “Deployment Tools Command Prompt” and use the following format to adjust the scratch-space of your wim file. (note in this case I am using standard locations to mount the wim file for servicing as well as using the name “winpe.wim” for this example. You will need to adjust to your own particular wim-file and mounting location accordingly.)

Dism /Mount-Wim /WimFile:C:\winpe_x86\winpe.wim /index:1 /MountDir:C:\winpe_x86\mount

dism /image:C:\winpe_x86\mount /Set-ScratchSpace:256

Dism /Unmount-Wim /MountDir:C:\winpe_x86\mount\ /Commit

In the second line of the example above I used the “256” value to set the scratch-space to 256 MB RAM.  Adjust the value you use accordingly (32, 64, 128, 256, or 512 MB levels).

Then toss the updated wim image file either into the correct location of your USB-bootable storage device, or into the proper folder and build/burn your WinPE ISO file to optical media.

To verify that you were successful, launch your PE build, navigate in a CLI window to the X: drive (RamDisk) and run a DIR command.  The size shown should equal the scratch-space size you set.

Easy!

Related WinPE 3.0 Resources:

WinPE 2.0 and Increasing Scratch Space

WinPE 2.0 is based on the Windows Vista  platform.  As such, you have to use a WinPE 2.0 specific tool to make changes to the default scratch-space settings such as the Windows Automated Installation Kit (AIK) for Vista or (even better) the Automated Installation Kit (AIK) for Windows Vista SP1 and Windows Server 2008.

Under WinPE 2.0 building, you must use the PEimg.exe command tool.

The principle is basically the same as before, and again assumes you already have build your WIM image file and now need to adjust its scratch space.

I’d type it again, but fortunately, The Deployment Guys have already done the hard work so from their post Expanding the Scratch Space in Windows PE 2.1 we have the following:

“With the introduction of Windows PE 2.1 (supplied with the Windows Automated Installation Kit (Windows AIK) 1.1), the scratch area can be changed from the command line. Below is the process for creating a larger scratch area.

   1. Create a temporary mount folder on your hard disk - MD c:\temp\mount
   2. Go to the Windows AIK tools folder for the platform of PE that you will be changing (ie x86/x64) - CD "Program Files\Windows AIK\Tools\x86"
   3. Mount the default Windows PE image supplied with Windows AIK to your temporary mount folder - imagex.exe /MOUNTRW "C:\Program Files\Windows AIK\Tools\PETools\x86\winpe.wim" 1 c:\temp\mount
   4. Go to the Windows AIK PETools folder - CD "C:\Program Files\Windows AIK\Tools\PETools"
   5. Run the PEIMG command to adjust the scratch size in the mounted image using /SCRATCHSPACE flag to set the size of the drive you want (in this case 128Mb)  - peimg.exe /SCRATCHSPACE=128 c:\temp\mount\windows
   6. Change back to the PETools directory - CD "Program Files\Windows AIK\Tools\x86"
   7. Unmount the image and commit the changes - imagex.exe /UNMOUNT /COMMIT c:\temp\mount

“That's it - the scratch area will now be set at 128 Mb for all boot images based on this source - which means all boot images created by MDT will now have the set scratch space set….”

Again, pretty easy stuff.  Just adjust your recipe accordingly.

Related WinPE 2.0 Resources:

Gravy

So earlier in the post I said that once you get down the commands to modify your WIM boot image file, you can easily crank out various versions.

If you are using optical media based WinPE builds, then you just have to carry a few disks in each of the scratch-space flavors you created.

However, if you are using a bootable USB disk, and it has sufficient space, you can get all crazy!

On my own bootable USB flash stick, in addition to the required “SOURCES” folder and contents, I also have a “SOURCES-ALT” folder.  In there I keep all my additional and scratch-space-adjusted WIM files.  So I have a  Boot-32.wim, Boot-128.wim, Boot-256.wim, and a Boot-512.wim file stored in there.  Typically, I have the 512 MB set scratch-space boot.wim file in my SOURCES folder to boot with.  However, if I know I need to WinPE boot a system that that wouldn’t work on, then I can delete the boot.wim file out of my SOURCES folder on the USB stick, and copy another more appropriate version from my SOURCES-ALT folder over into it, say the Boot-128.wim one.  Then I rename it to boot.wim and I am good to go!

In fact, once the contents of the WIM file are loaded into the scratch-space/RAM Disk, it is then released.  That means if you are going from a system that uses the 512 MB scratch-space, and then progress on to one that will require the 64 MB scratch-space version, it seems you can do the boot.wim delete/copy/rename routine on your USB stick still from within your WinPE boot session!  I’ve done this on a number of occasions.

Even more fun is making up not just different scratch-space flavors of the boot.wim file, but even wholly different versions of the boot.wim file itself!  You could have a custom WinPE 2.0 boot.wim file, a custom WinPE 3.0 boot.wim file, an AntiVirus PE Disk to offline-scan a Windows system, or maybe, say, a Win(FE) forensics build boot.wim, and so on…limited only by the size of your USB storage device and your imagination and efforts.  Even different WIM files with different hardware drivers injected for various system platforms.  Instead of carrying a mess of optical disks, just a single large USB storage may do the trick (assuming the system BIOS supports USB based booting).

Of course, you do have to reboot the system to then load whichever WIM file you have swapped out…but I’m sure you knew that already.  Just keep the originals safely and alternatively named in your “storage” folder location and delete/copy/rename the original boot.wim file as needed.

One more Bonus Find

The real find on this tip comes at the bottom of the page.

CatPawz has three helpful CLI sections documented that deal with “Build a Windows 7 AIO DVD”, “To Modify a Win7PE Disk”, and “To Create a Win7 Disk”.   If you aren’t familiar or comfortable with CLI usage in WinPE building and servicing, these could be great examples to follow and learn from.

Cheers!

--Claus V.

8 comments:

Bret said...

Hi Claus,

Instead of copying and renaming your boot-*.wim files, have you thought about using bcdedit to add entries to display a bootmgr menu with choices of each wim? You could keep all of the wims in your sources folder, too. I like to have a menu with a 4-second timeout to the default.

I enjoy reading your blog because I think I do a lot of the same stuff with WinPE as you do. Thanks for sharing your knowledge and experiences.

Claus said...

@ Bret - No I hadn't even thought of that. That is brilliant in its simplicity and elegance!

Looks like I have a new project on my hands! ;-)

Thank you very much for sharing that tip. I'm already thinking of the fun and excitement this will bring.

Awesome tip and thank you kindly for sharing!

--Claus V.

Unknown said...

I stumbled across your blog looking for what I thought was a very simple question, but so far I can find no answer. How do I increase the size of X: in WinPE? I need free disk space to run apps I have added, but there is none because X: is only 3086KB. This makes no sense to me as X: can't only be 3MB as the files on it (i.e. the boot.wim) are over 180MB. Also, nothing in your or other articles on the subject of the "RAM Disk" which I assume is referring to the X: drive that is carved out of system memory, indicates that it could be anything other than 32MB which also makes no sense.
If you have any helpful hints on what I'm missing, why I can't find any intelligent reference to X:, and how I force there to be say 100mb of free "drive space" on X: so apps can write temp files and whatnot to actually function instead of kicking errors due to no space, I'd be most grateful :)

Claus said...

@ Ebon - I'm certainly no expert in the WinPE field, but I'll try to answer your question with the information I know.

According to this Technet post: Walkthrough: Create a Custom Windows PE Image the following Note explains the relationship between the X: drive you see and the "scratch-space" which is also could be your RAM-drive.

"A Windows PE RAM disk boots directly into memory and is assigned the drive letter X, which does not correspond to the media (for example, a UFD or a CD-ROM) from which you booted. Ensure that you have sufficient memory to support the size of your Windows PE image plus any additional memory requirements, for example, if you plan on running any customized applications that need additional working memory."

See also this post where someone else was wrestling with the X: RAM drive under WinPe 2.0:  WinPE 2.0 booting from usb memory to ram, ram disk size increase

As I shared in this particluar post, you can use the DISM utility when you build your WinPE 3.0 to adjust the size of the "scratch-space", and thus, increase the available RAM for applications to execute in; the default build size (if you don't manually adjust it) is 32 MB.

(continued in next comment...)

Claus said...

@ Ebon - continued from comment above...

What I suspect is happening is that the WinPE "internals" are hard-setting the X: drive size accordingly to match the scratch-space setting. However as you point out, I seriously doubt that all 180MB of the boot.wim actually get loaded into that memory. It probably only loads what it needs to get up and running, then can reference the conents of the boot.wim file if you need to do a "DIR" to list the contents....or if you need to call an application included, it then loads that application into the actual "scratch-space" RAM to execute. So not all of the entire contents of the boot.wim file get loaded into the X: / scratch-space all at once. What isn't needed gets called when requested.... At least that's how I understand it.

I'm not sure why you are seeing about 3 MB scratch space / X: space. I checked one of my "stock" WinPE 3.0 builds and it reports my X: drive capacity is reporting 31.9 MB with 2.42 MB "used" with the rest "free".

I also ran into application launching issues so that's why I typically build my custom WinPE 3.0 builds with either a 256 MB or 512 MB scratch space as I have outlined how to do with DISM above in this post. My 512 MB scratch-space work great and give me lots of application running room.

Again, these assume you have sufficient physical system RAM on the system you are booting to support that size scratch-space. If you don't, the WinPE won't be able to load. As I mentioned, you can manually use DISM to set the scratch-space / X: level above the default to 64, 128, 256, or 512 MB levels. I am not aware of any way to make it larger than 512MB.

If you haven't tried to do this yet using the steps above, please do so. A 512 MB custom scratch-space build made a big difference with how my "portable" applications run in WinPE over the default 32MB scratch-space size.

I hope this helps just a bit.

Cheers.

--Claus V.

Claus said...

@ Ebon - one more thing. After thinking about what you originally commented and pondering my response, I have a 2nd perspective now that may be closer to what you are askign about.

It appears that although you can can change the "scratch-space" setting as I mentioned to provide more overhead WinPE environmental RAM room (64, 128, 256, or 512 MB level) for your applications to play in, what you are looking for is to increase the actual size of the X: drive itself...not the scratch space.

It does appear the default 32MB size WinPE provides is "hard-coded" and independent of the "scratch-space" size. So setting that value upward doesn't appear to do anything to change the size of the X: reported.

After some more research I did find the following post you may (or may not have) found on how to "hack" the WinPE registry (pre-building) to adjust the X: drive size.

ScratchSpace at 1024 (ramdisk size) - Reboot Pro.

According to this detailed info, you can (theoretically) get the X: drive to report up to 1024 MB !

However, the posters found the effective limit at appx 470MB and anything over it unusable. When they hit the max level above, then the X: stopped being accessible.

I'd take their advice and try the hack at a 256 MB level instead if that gives you enough room.

I've not played with this at all in WinPE 3.0 so I can't comment on it.

If you try it and it works...please let me know!

Hope this helps!

Cheers!

--Claus V.

DonPick said...

In these modern days of WinPE 5.0 (from Win8.1), scratchspace is less of a concern?

http://deploymentresearch.com/Research/Post/352/WinPE-5-0-scratch-space-in-MDT-2013-and-ConfigMgr-2012-R2

Claus said...

@DonPick - that is a really good page you linked to!

My WinPE builds (Win 7) that I did back here have still been running well enough for use to this day that I haven't gone back and explored/updated them to the latest PE 5.0.

I really need to get going and bring them current.

When I do I'll be sure to include your information as it seems really cool that it now auto-sizes based on system RAM available.

That seems more flexible for all the conditions/hardware environments that one might use a PE build on.

Awesome comment! I really appreciate you sharing it and am sorry it took me so long to respond.

Cheers.

--Claus V.