murphy78 DiskPart and Apply Image Script

Discussion in 'Scripting' started by murphy78, Apr 2, 2014.

  1. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    #1 murphy78, Apr 2, 2014
    Last edited by a moderator: Apr 20, 2017
    murphy78's DiskPart and Apply script is a small WINPE project that allows users to utilize dism and diskpart techniques
    to set up BIOS-booting and UEFI-booting systems.

    Features:
    • Multi-boot support
    • Recovery Partition Image support
    • Add drivers to WinPE/Installed Image support
    • Split-Wim support
    • install.esd support
    • Ability to disable the extra system partition in BIOS/MBR
    • Ability to specify Recovery Image partition size
    • $OEM$ subfolder copies

    Requirements:

    What is this?: murphy78's DiskPart and Apply script is a small menu-based Windows partition and setup tool.
    Why use this over Windows Setup?:
    There are a few reasons:
    • Split-Wim support (script doesn't need to display the EULA, setup does; by default)
    • Recovery Partition option during setup makes it easy to store an install.wim for reset/refreshing

    If you've made an All-In-One version of a Windows Setup disc in the last year or two,
    you've noticed that it's fairly difficult to work with AIO versions and UEFI at the same time.
    Well, gents: you're in luck. This script not only handles recovery images by default,
    but it also handles split-wim images by default.

    So why does that help with UEFI?
    Well UEFI needs a fat32 partition when installing from a USB Flash drive.
    So if you try to copy over a giant 16GB AIO or even a sysprepped single-index
    Windows version, if any file is larger than 4GB it will fail to hold the file.
    Without fat32, there is no UFD UEFI booting.

    So what's the solution? Split-WIM support. Normally I would advocate for trying
    to use MS's own tools. Since that's not an option with the EULA fail, you have to
    apply your own image. Most people have no clue how to both apply your image, run bcdboot,
    and set the reagentc options for the winre.wim. I don't blame you. When I first took on
    this project, I had no clue either. But I wanted to get it to work, so I stuck with it.

    So how do we create this Split-WIM?
    It's actually very simple.
    You just run the command (3900 in this example is 4095 mb to fit in fat32):
    Code:
    dism /split-image /imagefile:c:\iso\sources\install.wim /swmfile: c:\iso\sources\install.swm /filesize:4095 /checkintegrity
    This command will create a file called install.swm, then install2.swm, install3.swm, etc.
    The way the apply works is when you are using a split-wim you specify /swmfile:install*.swm
    Example (You don't need to know this. This is just for reference):
    dism /apply-image /imagefile:D:\sources\install.swm /swmfile:D:\sources\install*.swm /applydir:W:\ /index:1 /verify /checkintegrity

    So what do we do with the install.wim?
    Just tuck it away somewhere on a spare drive or something and keep it safe in case you need it.
    You no longer need it for your install disc.

    So how do I use this project?
    Mount boot.wim index 2
    Copy the files from the appropriate architecture folder
    Add the winrecfg packages
    Add any additional packages you wish to your boot image (servicing stack, cumulative rollup, etc)
    Resetbase your image
    Commit the changes. You can re-export to compress it a little further if you wish.

    Integration Instructions:
    Code:
    dism /mount-wim /wimfile:c:\win10\sources\boot.wim /index:2 /mountdir:c:\mount
    
    :Copy over the x64 folder's contents to the c:\mount\ directory
    :Do not copy over the entire x64 folder, just the contents.
    
    :**Make sure to add-package the winrecfg packages. I'll use an example directory here:
    dism /image:c:\mount /add-package /packagepath:c:\murphy78-DiskPart-Apply-v1.2.8\x64-winrecfg-packages\
    :that should add both the base package and the en-us package
    :you can add any other packages at this point such as a win10 cumulative
    
    dism /image:c:\mount /cleanup-image /startcomponentcleanup /resetbase
    dism /unmount-wim /mountdir:c:\mount /commit
    
    :export to new boot.wim to reduce size
    dism /export-image /sourceimagefile:c:Win10\sources\boot.wim /sourceindex:1 /destinationimagefile:c:\temp\boot.wim /checkintegrity
    dism /export-image /sourceimagefile:c:Win10\sources\boot.wim /sourceindex:2 /destinationimagefile:c:\temp\boot.wim /checkintegrity
    move /y c:\temp\boot.wim c:\win10\sources\
    
    :Make boot-prompt image with UEFI boot support (press any key blah blah)
    oscdimg -o -u2 -udfver102 -bootdata:2#p0,e,bc:\win10\boot\etfsboot.com#pEF,e,bc:\win10\efi\microsoft\boot\efisys.bin -lYourImageLabelMax32chars c:\win10\ c:\temp\YourISOName.iso
    That's it. I recommend testing it in a VM for a bit until you know what you're doing.

    More detailed descriptions of a few things:
    Instructions here are for deployment tools copype versions using the Win10 ADK
    If you've copied the files into a normal win10 setup boot.wim, you don't need to know this.

    You don't need both amd64 and x86 winpe images. If you only plan on accessing computers with
    2 cores (64-bit) you can just use the amd64. However, if you plan on using any systems with
    only 1 core (32-bit) you will need to use x86. If you truly want a disc that supports both
    1-core systems and UEFI, you will use both. What we can do is modify the efi\boot\bcd and set
    it to boot2.wim and then rename the x64 version to boot2.wim of course. You could also try
    bootx64.wim if you want clarity on what you're doing.


    When you run copype it creates a directory where you specify, but it also makes a bare-bones
    boot.wim of the specified architecture and copies over firmware files such as the oldschool
    etfsboot.com (BIOS-Boot sector for iso files) and the efisys.bin (UEFI-Boot sector for iso files)
    It puts your basic iso in the c:\winpe_amd64\media\ folder (or winpe_x86)
    Inside the media is just the basic skeleton of a bootable winpe image. All it will run is
    the mounted directory's "x:\windows\system32\startnet.cmd"


    So my project just edits the startnet.cmd, removes the wpeinit call for speed, and then runs the
    menu.cmd script. I've also included in my project x86 and x64 versions of both winrecfg.exe,
    find.exe, and the associated en-US mui files. You *COULD* find the other language versions of
    the files, but there's no point. The whole script runs in English and it doesn't stop to give
    detailed readouts from the find or winrecfg commands. They are just for utility.

    DOs and DON'Ts:
    DOs:
    1) Utilize a few of the options such as driver-addition when applying an older image to a raid.
    After Install it will ask you if you wish to add drivers to the offline image.
    It just does a dism /image:w:\ /add-driver command, but you need it before the first boot
    on a raid because it won't be able to access the system drive if you don't. On win8+ it's not
    that much of an issue unless you have a specialized card that doesn't have native 8.x support.

    2) Try Fast Setup option if you're only installing a single-index. It's faster and less
    confusing, but it won't ask you to specify partition size. It will just use the maximum.
    You can use this with a Recovery Image. I've added the option in the Fast Setup options.

    3) Can't get your WinPE to detect your non-supported RAID? There's a WinPE drivers section also.
    It's not as easy to work with as you have to spell out the exact INF file name, but it's there.
    I also give a CMD prompt every time there's a driver add option, so that you can navigate around
    and figure out the directory names and file names. It's not as easy as the Windows Setup, but it's
    there and it should work. I also added a wpeinit option in case some people have some sort of
    Plug and Play drive that isn't normally detected.

    4) Don't be afraid to Multi-Boot. With the No System Partition option enabled in BIOS boot, you
    can create 4 primary partitions. If you don't enable Recovery Images, you can quad-boot your system
    in about an hour. It gets even more ridiculous for UEFI. GPT partitioning doesn't limit your
    primary partitions to 4, so you can go nuts. You can have as many system drives as you can fit
    drive letters. I believe I've calculated it at 21, though I haven't actually tested it. You
    could also have recovery images set up for each of those installs.

    DON'Ts:
    1) Don't choose wrong sizes for partitions or recovery images. If you choose a partition size of
    say 10000 (in megs) for a Windows 8 x64 image, it will STILL try to apply it. It doesn't mean it
    will work. A general rule of thumb for OS image size is 20GB for x64 versions and 16GB for x86
    versions. Obviously if you try to put more stuff in the image, you should make it larger.
    You can go into diskmgmt.msc later and create extra partitions for data files and such. I would
    actually recommend learning how to change the program files folders, or just give yourself some
    breathing room on your OS and make the partition about double the recommendation, just in case.

    2) Don't try to make too small of a recovery partition. I only kick back non-number entries, so
    you should really try to give yourself some wiggle room if you're not sure how big it's going to
    be. I'm not going to go through all the scripting that would be required to pre-determine the
    appropriate size of the captured image. If you create a recovery image of 200 megs, it will still
    try to capture an image to that tiny drive, it will just fail. The amount of room you need varies.
    I've set it to 5GB by default and that's more than enough room unless you're sysprepping huge
    images.

    3) Don't come crying to me if you lose your data on an important drive because winpe set the
    wrong one to disk 0. I give all the options to check disks, check volumes, change disk numbers, etc.
    If you don't know how to use them, that's on you. Try things with a VM until you get more comfortable
    if you are a newbie. If you still don't feel comfortable, don't use it; use a normal Windows disc.

    MISC NOTES:
    1) I've added an $OEM$ folder copy option if you're used to working with $oem$ folders. In Fast Setup it's
    enabled by default just like normal Windows Setup, but in the default Setup it gives you a choice. I haven't
    actually tested this one much. I've heard things like using $OEM$\$1\Drivers\ will make a c:\drivers folder
    and that when you enter the hardware config part of Windows setup it will look for appropriate drivers
    anywhere on your system, including dvds or usb, but if you wanted to copy that over and use it in a Recovery
    Image capture, $OEM$\$1\Drivers might be a good way to do it

    2) UEFI Recovery Image option was giving me trouble with Windows 7 installs. (Possibly 2008r2 as well)
    It could just be that VMWare was incompatible with the necessary uefi settings that need to be done. I would
    just recommend that people either know that it might not work for win7, or that Win7 might just not be compatible
    with UEFI Recovery Image options. It works fine in BIOS-boot on Win7 and also doesn't seem to have a problem
    in Win8+

    3) Set the WINRE boot key to F1 during boot. You can hold f1 during boot to go straight to the Recovery options
    You should still use f8 in the boot menu while over the appropriate multi-boot option if multi-booting tho.

    4) Is the boot menu using an old windows 7 boot menu for your multi-boot and you want the fancy win8 version?
    Boot into your win8 system. Make sure all partitions are assigned drive letters... (diskpart or diskmgmt.msc)
    then go into admin prompt and run:
    bcdboot c:\windows
    When you reboot, the nice fancy graphical win8 boot menu should be the default. Be warned that the win8 menu
    might be harder to enter recovery environment in.

    Few Project Screens:
    DiskPart-1.1.0-Main-Menu.jpg Applying-install.esd-Index.jpg WinPE-Add-Driver.jpg Sext-Boot-win8.jpg Multi-Boot-Recovery-Partitions.jpg

    Get the File:

    http://mir.cr/0TDW32QO
    File Name: murphy78-DiskPart-Apply-v1.2.8.7z
    Size: 442 KB
    SHA1: A754BA65CC1BE51AA5FE55ED4036C15805B7DCFC
    Format: LZMA1


    Changelog:
    1.2.8 Added Win10 Multi-Boot detection support for image files (x86\sources x64\sources)
    I had made a custom version of 1.2.7 for my superaio, but I've consolidated the detection for 1.2.8

    1.2.7 Added multi-lang source support by changing dism commands to output /english
    While the script will still be in English, it will allow for boot files from different locales*
    *You would need to add the appropriate language winre mui package from the ADK winpe files
    Removed the murphy78 folder and just used menu.cmd in the system32 folder

    1.2.6 Forgot I removed the winrecfg.exe and dll.mui files
    These get modified by the update 2934018, so you should add the 2 packages and then add the 2934018 update.
    After adding all the packages and updates, you should resetbase your latest version of winpe to reduce size and uninstall info
    So I added 2 folders that contain just the base winrecfg package and the en-us version.
    If you are translating the output of this script, you should use appropriate language files, including different dism mui stuff in
    the murphy78 folder. I may change the structure around or change things to specialize it more toward winpe 5+ since the choice.exe
    doesn't allow win7/server2008 anyway. Well, I could also just add both versions... I may play with it another time.

    1.2.5 Enabled display of currently selected disk number in the disk menu. (It helps to know :p)Changed the no-setup-option folder to USE-EXISTING-SETUP to clarify what it does.*
    *(This folder uses the existing setup by default, but adds a shortcut menu.cmd in the system32 folder
    so that when a user is running the existing setup, they can press shift-f10 to open admin prompt and
    just type "MENU" and the diskpart/apply menu will start - This is how I do it in my monthly stuff)


    1.2.4 Fixed an issue where Disk kept being set to 0 because of disk menu loop.

    1.2.3 Fixed a bug where setup prompt would fail if applied to an existing boot.wim

    1.2.2 Moved all the DART folder and menu.cmd files to murphy78 folder (you can delete the old menu.cmd and DART folder)
    Added updated versions of winrecfg.exe and dll.mui
    Changed image selection to a single parse at beginning and simply print/re-print file when re-displaying (listing many indexes was slow)

    1.2.1 Fixed last-minute swm bug
    Fixed split-wim apply bug in new changedir-less method

    1.2.0 Reworked many portions of the script but left the basic functionality intact
    Added Use Existing System Partitions and Windows Partition options
    Changed Disk Options to a single short menu rather than 2 superfluous options and menu
    Added Generalmx's subdirectory driver addition method from his script for WINPE drivers
    Changed a lot of variable handling to use !! instead of %% and enabledelayedblahblah
    Moved image detection to beginning of script
    Merged a few drive letter partition options
    Added few warnings for UEFI users trying to use Recovery image partitions for win7/2008/2011
    Changed default Recovery Partition size to 5 GB
    Changed a lot of the wording and choice strings

    1.1.1: Custom unreleased version for v2 of apr win8.1
    Added existing setup support and opt-out option
    Added detected recovery option into main menu

    1.1.0: Reworked diskpart scripts to use ramdrive txt imports and piping commands
    Added Multi-Boot support
    Added Fast Setup with Recovery Image
    Added No System Partition option to BIOS booting
    Added No WinRE movement option for BIOS boot, already disabled if NoSysPart
    Added Recovery Image partition support
    Added Driver addition support in both PE and Windows installs
    Added Sources\$OEM$ subfolder copies if detected
    Change to WINRECFG to allow mismatched x86/amd64 support replacing reagentc
    Added minimal error-handling
    Added DISM folder so user wouldn't need to integrate S14 updates
    Reworked the entire script over and over to verify things

    1.0.2: Powershell WinPE disk management version (not worth bothering)

    1.0.1: Fixed GPT diskpart scripts to not use "active" command. Causes diskpart to fail and subsequent application to fail.

    1.0.0: Initial prototype (broken UEFI diskparting)

    Credits: murphy78, Microsoft, TechNet
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    Reserved JIC

    I'm brain-fried gents... i'ma take a break now haha
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    457
    169
    10
  4. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    6,722
    1,952
    210
    Maybe I'm blind?! Password for the download?? Would like to test! Thanks.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    PW: 2014

    It was in my file spoiler...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    6,722
    1,952
    210
    Thanks! And that's why I was tell I'm blind!!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. generalmx

    generalmx MDL Novice

    Apr 15, 2014
    34
    20
    0
    #7 generalmx, Apr 15, 2014
    Last edited: Apr 15, 2014
    Hi murphy78 and MDL users:

    I'm a weirdo who likes coding, and as I am a fan of yours, I thoroughly cleaned up your script (the only version I could find, v1.1.0, was broken), and hopefully made it easier for you to improve upon, and/or to port to something a bit better than Windows Batch (I've been using more and more AutoITv3 myself). Feel free to remove my credit at the top of the file.

    I've been working a lot this year on tools for a local computer shop I volunteer at, trying to create easy-to-use powerful UEFI-capable USB tools and Boot DVDs. What got me interested in your script is not only gaps it can fill from the AFAIK-closed-source WinNTSetup3, but also I really like the idea of converting all my WIMs into ESDs, and WinNTSetup3 isn't so good with ESDs. (I've also been working on improving a few other tools I found on the web, like DriverSolutions and UEFI_MULTI.)

    Attached since this is my 1st post (I do have it uploaded to Mediafire, too).

    Edit: Thanks for the warm welcome :) Also, I totally forgot to mention that keeping in-line with murphy78's own use of password-protection, this archive uses the exact same password.
     

    Attached Files:

  8. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,487
    633
    60
    Good job. I'm sure Murphy78 has been burning the candle lately & knows you need "::" for comment.
    I also found that this would quit my batch file: "copype amd64 c:\winpe_amd64".
    I changed it to this: "call copype amd64 c:\winpe_amd64" & now it's fine.

    Hey, it may help someone looking at this stuff...:p
     
  9. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    I'll give it a look-see when I get some time bud. I was hoping someone would help clean it up a bit.
    You know how these things start, with a general idea, then you keep adding thing after thing, and eventually it gets kind-of ugly.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. amsk98

    amsk98 MDL Junior Member

    Sep 8, 2013
    56
    5
    0
    any new updates
     
  11. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    #11 murphy78, Apr 22, 2014
    Last edited: Apr 22, 2014
    (OP)
    Yes, I've incorporated some of the changes from generalmx's script such as the winpe driver addition directory recurse.
    I've also added method to allow installing to specific partitions without cleaning the hard drive.
    It's kind-of sloppy in MBR BIOS-boot mode because of the active partition situation and sometimes not doing the hardware check.

    During the hardware portion of setup (after first boot) it sets the windowsre /enable option automatically.
    Trying to install to an existing mbr partition messes up the active partition, and hence the bcdboot on said active partition.

    I guess I could put in an additional partition specification for people to specify their MBR active partition.

    I've also finally nailed down the damn install.esd error, and it wasn't solely setup.exe's fault.
    It turns out there may be some memory mis-management and a bcdedit /set {default} truncatememory 0x40000000
    seems to be the solution. It's really only a problem for x64 versions, but I've set it for both the efi\microsoft\boot\bcd and the \boot\bcd and it seems to have fixed the problem for me.

    I still have some stuff to test and sort out and I'll drop it in the OP.
    I have no idea when that will be. It really depends if I find bugs.
    I still need to code that active partition problem and then re-test everything.
    The next version might be a little spaghetti-codish, but hopefully when I get a lot more time I can re-work everything to simplify and organize everything.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. amsk98

    amsk98 MDL Junior Member

    Sep 8, 2013
    56
    5
    0
    NO hurry I am always wait for your stuff:rolleyes:

    Thanks
     
  13. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    Added ver 1.2.1 to the OP
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    457
    169
    10
  15. venioni

    venioni MDL Senior Member

    Mar 28, 2014
    444
    87
    10
    How can continue to install windows 8.1

    I make the step of murphy and when i go to install windows 8.1 i stuck here DiskPart and Apply Image Script.PNG what can i do for
    continue to install?:confused:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. venioni

    venioni MDL Senior Member

    Mar 28, 2014
    444
    87
    10
    Its ok i found my proplem sorry its work ok now. DiskPart and Apply.PNG :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. amn87

    amn87 MDL Novice

    Sep 11, 2011
    1
    0
    0
    Problems installing Win8.1 Update 1 v2 April 2014

    Hey murphy78 as mentioned above I not able to figure out how to install Windows onto a specified EXISTING partition. All options point offer to erase the entire HDD.Is there any way to choose an existing partition? And what abt the default Windows Setup will that work.?Does this script help in this regard.Plz help and thanks for all the hard work.
     
  18. eric33

    eric33 MDL Junior Member

    Nov 21, 2012
    80
    13
    0
    he has upload v4 and it have fixed
     
  19. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    527
    369
    30
    Very nice. Just wondering why you wouldn't put the contents of menu.cmd in startnet.cmd and the dism folder in system32 where many winpes already have dism?

    Maybe an option to apply with an unattend.xml too? Great little script regardless.
     
  20. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    6,787
    10,365
    210
    I don't know that much about unattend files since I never use them. That's a good idea though.
    Is it something that you just have to apply and specify the xml?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...