Extend your disk partition to max



  • Since I use “one image to rule them all”, I have to remember to shrink my partition down below the smallest disk in inventory before I sysprep it. Otherwise the image will fail on some systems. I have some disks that are 80GB and some that are 500GB. So I usually manually shrink my disk down below 80GB before I sysprep it. Then after imaging a system with larger disks, I have to extend the partition to the max size. I got tired of doing this manually, so I wrote a vbscript to do this for me. I’m sharing it in hopes that it helps others, but also to see if anyone has a better way.

    I actually use this snippet of code in a larger vbscript that does other things (local account creation, firewall exceptions, registry changes, printer installs, etc), but I’ve pulled out necessary the code below. Should be complete. Note it is actually two files. One is the vbscript that just runs diskpart, the other is a text file that contains the options to pass to diskpart.

    [B][U]extend_max.vbs[/U][/B]:

    ' ########## Extend Disk Partition (MAX) ##########
    LogFilename = "C:\Windows\Setup\InstallLog.txt"
    LogFile.writeline "-------------------------------"
    LogFile.writeline "Extending partition to max size:"
    LogFile.writeline "-------------------------------" & VbCrlf
    
    diskpartScript = "C:\Windows\Setup\Scripts\extend_max.txt"
     
    Set oShell = CreateObject("Wscript.Shell")
    Set oShellExec = oShell.Exec("cmd /c diskpart -s " & diskpartScript)
    set oStdOutputText = oShellExec.StdOut
     
    Do While Not oStdOutputText.AtEndOfStream
    diskpartOutput = oStdOutputText.ReadLine
    LogFile.writeline diskpartOutput
    Loop
    

    [B][U]extend_max.txt[/U][/B]:

    select disk 0
    detail disk
    list disk
    select volume c
    extend disk 0
    list disk
    exit
    

    I call this script by adding a line to my SetupComplete.vbs script. Something like:

    REG ADD %KEY%\005 /VE /D “Extending disk partition size to max” /f
    REG ADD %KEY%\005 /V 1 /D “%systemroot%\Setup\Scripts\extend_max.vbs” /f

    astrouga



  • EDIT: Haha. Well after long last I managed to get the script to work with just a few clicks and no errors. Thanks anyways, and thank you astrouga. (if you still visit here)

    I know this is an old post, but I was using astrouga’s Script and it works great, however, I get a Error: Object Required “Log Script”

    It says it’s on the last line character 1

    The script actually runs all of the way through and extends the hard drive, but I am very very new to scripting ( like maybe a week ago I started ) and was wondering if this would ever be a problem.

    Thanks!



  • thanks I will try this Monday morning I post results



  • @golpemortal, post: 9308, member: 2653 said:

    ok can you point me out to a good tutorial… this one here is a bit complicated for newbee like me

    I dont believe a guide exists but
    Go into the c:\Windows\Setup\Scripts folder (if you dont see a scripts folder then make one) in the scripts folder you should have 2 files to make this work. You need a diskpart.txt file that has the code below in it
    select disk 0
    select partition 2
    extend

    then in the SetupComplete.cmd file add this

    diskpart /s C:\Windows\Setup\Scripts\diskpart.txt
    del /Q /F C:\Windows\Setup\Scripts\diskpart.txt

    make any other changes that you need to then sysprep and upload your image. When you go to deploy
    it should work.

    that’s all you need to make this work



  • ok can you point me out to a good tutorial… this one here is a bit complicated for newbee like me



  • @golpemortal, post: 9293, member: 2653 said:

    Dealman can you give me a steps by steps on implenting this tutoral from A to Z.
    the error message that I got was when I ran the setupcomplete.cmd on the command prompt and was complanning about REG ADD format…

    could it been that I was not doing it right , since this is my first time messing with fog cloning I would like some help…

    I didn’t do the whole reg add part. i called the disk part from SetupComplete.cmd script like what David suggested



  • Dealman can you give me a steps by steps on implenting this tutoral from A to Z.
    the error message that I got was when I ran the setupcomplete.cmd on the command prompt and was complanning about REG ADD format…

    could it been that I was not doing it right , since this is my first time messing with fog cloning I would like some help…



  • @golpemortal, post: 9246, member: 2653 said:

    I am having hard time implementing this tutor on Windows 7 ent…
    I trying to make it part of the image and follow steps from astrouga and no success

    added this to the script

    REG ADD %KEY%\005 /VE /D “Extending disk partition size to max” /f
    REG ADD %KEY%\005 /V 1 /D “%systemroot%\Setup\Scripts\extend_max.vbs” /f

    added exactly the same but got error on the command prompt

    What error did you get?



  • I am having hard time implementing this tutor on Windows 7 ent…
    I trying to make it part of the image and follow steps from astrouga and no success

    added this to the script

    REG ADD %KEY%\005 /VE /D “Extending disk partition size to max” /f
    REG ADD %KEY%\005 /V 1 /D “%systemroot%\Setup\Scripts\extend_max.vbs” /f

    added exactly the same but got error on the command prompt



  • @astrouga, post: 8537, member: 907 said:

    Since I use “one image to rule them all”, I have to remember to shrink my partition down below the smallest disk in inventory before I sysprep it. Otherwise the image will fail on some systems. I have some disks that are 80GB and some that are 500GB. So I usually manually shrink my disk down below 80GB before I sysprep it. Then after imaging a system with larger disks, I have to extend the partition to the max size. I got tired of doing this manually, so I wrote a vbscript to do this for me. I’m sharing it in hopes that it helps others, but also to see if anyone has a better way.

    I actually use this snippet of code in a larger vbscript that does other things (local account creation, firewall exceptions, registry changes, printer installs, etc), but I’ve pulled out necessary the code below. Should be complete. Note it is actually two files. One is the vbscript that just runs diskpart, the other is a text file that contains the options to pass to diskpart.

    [B][U]extend_max.vbs[/U][/B]:

    >' ########## Extend Disk Partition (MAX) ##########
    LogFilename = "C:\Windows\Setup\InstallLog.txt"
    LogFile.writeline "-------------------------------"
    LogFile.writeline "Extending partition to max size:"
    LogFile.writeline "-------------------------------" & VbCrlf
     
    diskpartScript = "C:\Windows\Setup\Scripts\extend_max.txt"
     
    Set oShell = CreateObject("Wscript.Shell")
    Set oShellExec = oShell.Exec("cmd /c diskpart -s " & diskpartScript)
    set oStdOutputText = oShellExec.StdOut
     
    Do While Not oStdOutputText.AtEndOfStream
    diskpartOutput = oStdOutputText.ReadLine
    LogFile.writeline diskpartOutput
    Loop
    >```
     
    [B][U]extend_max.txt[/U][/B]:
    

    select disk 0
    detail disk
    list disk
    select volume c
    extend disk 0
    list disk
    exit

    I call this script by adding a line to my SetupComplete.vbs script. Something like:

    REG ADD %KEY%\005 /VE /D “Extending disk partition size to max” /f
    REG ADD %KEY%\005 /V 1 /D “%systemroot%\Setup\Scripts\extend_max.vbs” /f

    astrouga

    I modified my image to include this and it seems work on those pesky advance format drives



  • @David Atkinson, post: 9134, member: 2696 said:

    FWIW, I have a much shorter diskpart.txt file:

    >select disk 0
    select partition 2
    extend
    >```
     
    I just call it from the SetupComplete.cmd script:
     
    

    @echo off
    diskpart /s C:\Windows\Setup\Scripts\diskpart.txt

    del /Q /F C:\Windows\System32\Sysprep\unattend.xml
    del /Q /F C:\Windows\Panther\unattend.xml
    del /Q /F C:\Windows\Setup\Scripts\diskpart.txt

    sc config “Sophos AutoUpdate Service” start= auto
    sc config “Sophos Agent” start= auto
    sc config “Sophos Message Router” start= auto

    But, of course, I’m blessed with very consistent, almost homogeneous hardware.

    Whoa this is all interesting what image types are you using for the master image and your deployment image?



  • FWIW, I have a much shorter diskpart.txt file:

    select disk 0
    select partition 2
    extend
    

    I just call it from the SetupComplete.cmd script:

    @echo off
    diskpart /s C:\Windows\Setup\Scripts\diskpart.txt
     
    del /Q /F C:\Windows\System32\Sysprep\unattend.xml
    del /Q /F C:\Windows\Panther\unattend.xml
    del /Q /F C:\Windows\Setup\Scripts\diskpart.txt
     
    sc config "Sophos AutoUpdate Service" start= auto
    sc config "Sophos Agent" start= auto
    sc config "Sophos Message Router" start= auto
    

    But, of course, I’m blessed with very consistent, almost homogeneous hardware.


Log in to reply
 

473
Online

38923
Users

10690
Topics

101416
Posts

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.