murphy78 DiskPart and Apply Image Script

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

  1. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,404
    11,646
    240
    #1 murphy78, Apr 2, 2014
    Last edited: Apr 30, 2023
    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
    • 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:
    • Windows ADK matching build for boot.wim you are installing to if manually integrating
    • Brain (Not required thanks to Enthousiast script installer I modified)

    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)
    • Windows 11 support on machines that don't have Secure Boot or TPM comparable hardware

    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 handles wim, swm, and esd format.

    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. Some freeware programs like Rufus
    can fool your computer into making extra partitions to handle extra large files, but many
    computers may not be able to handle this. What's more, Microsoft itself does not allow it.

    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 as the EULA will fail to be detected in the first file,
    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?
    Recently @Enthousiast made a script installer and I've modified his first version:

    So now you can run add-Diskpart_Apply_Image_Tool_murphy78_custom_v1.1.cmd with an
    iso in the source_iso folder and it will spit out an already integrated diskpart/apply image iso
    The script gives you a choice to include a winpeshl.ini which will start the script automatically
    If you choose that option you can still choose to exit the script when running the setup media.
    It will just run the setup program after exiting. Instead of the characteristic blue setup screen,
    it will be white to denote that it is not running a normal setup routine. This is MS's way of telling
    people that it has ran an abnormal startup routine for setup. There is no other alteration to setup.

    Below are the basic manual install instructions:
    Mount boot.wim index 2
    Copy the files from the appropriate architecture folder
    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.
    
    dism /unmount-wim /mountdir:c:\mount /commit
    
    :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 Win ADK
    If you've copied the files into a normal win 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 . 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 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) 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.

    3) 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:
    New:

    https://mir.cr/OTWIBYSA
    File Name: murphy78-Diskpart-Apply-v1.3.1.zip
    File Size: 2.4.1 MB
    SHA1: D0D59CB47AE8A3135998D309CD4A46AC660CC327
    File type: zip/pw
    PW: MDL2021

    Old:

    https://mir.cr/8JPSNYIV
    File Name: murphy78-DiskPart-Apply-v1.3.0.zip
    Size: 2.41 MB
    SHA1: 18DEC4C16F73A021E8473CF51FDE63E308F6DEA4
    Format: zip/pw
    PW: MDL2021

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


    Changelog:
    1.3.1 Added Media Creation Tool style x86/x64 $oem$ folder copying that would detect the architecture of the install applied and seek the appropriate $oem$ subfolder to copy
    Re-worked the add diskpart apply image script to be in line with the support for the default and dual boot format
    Added esd and split wim support for the add diskpart apply image script for the line that used to detect information from the install.wim
    Minor other tinkerings not worth mentioning, mostly wording or spacing issues
    1.3.0 Removed Recovery Partition Support. Option has been deprecated and seems to only have been supported on Win8.x
    Added v1.1 custom script installer compliments @Enthousiast
    Added default winrecfg.exe & winrecfg.exe.mui en-us files
    Removed winrecfg packages and information about package integration
    Added winpeshl.ini option
    Fixed error in bios boot winre copy option syntax that prevented toggling

    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, @Enthousiast, Microsoft, TechNet
     
  2. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,404
    11,646
    240
    Reserved JIC

    I'm brain-fried gents... i'ma take a break now haha
     
  3. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    174
    10
  4. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    7,202
    2,269
    240
    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
    7,404
    11,646
    240
    PW: 2014

    It was in my file spoiler...
     
  6. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    7,202
    2,269
    240
    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
    21
    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,990
    935
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,404
    11,646
    240
    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.
     
  10. amsk98

    amsk98 MDL Junior Member

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

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,404
    11,646
    240
    #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.
     
  12. amsk98

    amsk98 MDL Junior Member

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

    Thanks
     
  13. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,404
    11,646
    240
    Added ver 1.2.1 to the OP
     
  14. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    174
    10
  15. venioni

    venioni MDL Senior Member

    Mar 28, 2014
    479
    121
    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
    479
    121
    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
    7
    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
    526
    372
    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
    7,404
    11,646
    240
    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?