FOGProject / fogproject

An open source computer cloning & management system
https://fogproject.org
GNU General Public License v3.0
1.08k stars 216 forks source link

Deployment with multiple drives. #587

Closed aUniqueUser closed 3 months ago

aUniqueUser commented 3 months ago

In my usage of fog, we often have systems configured with multiple drives (eg. 250SSD with win11 + 500gb mechanical secondary with no data on it), I would like to have the ability for the 250gb ssd to be dynamically sized (eg work with a 240gb, size up to a 500gb, 1tb etc). While still being able to have that secondary drive. The issue is right now all we can do is Multiple Partitions (Non-Resizeable) since their is multiple disks, this causes the image to not work for if example we have a 240gb SSD or a not scale to a larger SSD automatically.

What I have tried

Current hacky method to make it "work" is just to have the single disk image and then reinstall and setup the mechanical again after the image deployment process is done. This works but I'd like to see if there is another way.

I'm not sure if this a supported feature but I'd like to hear of any Ideas that may be able to point me in the right direction. Thank you, your project is very well appreciated.

lukebarone commented 3 months ago

You can use the Multiple Partitions (Non-Resizeable) option, then run either a SetupComplete.cmd script or FOG Snapin to resize the original C:, such as:

diskpart /s ResizeCDrive.txt

Contents of ResizeCDrive.txt:

SELECT DISK 0
SELECT VOLUME C
EXTEND
EXIT

... Of course, make sure that Volume C is the correct volume number. This is C: drive for the booted OS.

lukebarone commented 3 months ago

Let us know if that works for you. If so, I'll close this issue

aUniqueUser commented 3 months ago

The main issue is that currently the WinRE partition is to the right of C, therefore cannot expand inside of windows, usually have to use a winpe partition manager after the deployment to resolve the issue since the unallocated space will be to the right of the winre in a fresh fog deployment. This also does not resolve the issue with having a smaller drive then the image, and it not shrinking to fit (eg a 500gb image, but only ~28gb used since its just a fresh windows, works fine with single disk but not on multi disk setup since it does not do the resizing).

lukebarone commented 3 months ago

So this is one reason we recommend building your images within a VM.

You can alter the disk part script to move the winre partition further to the right (although I build my images without it in the first place).

Unfortunately, I don't know all the disk compression commands, so I don't know how much more help I can be in this thread. Hopefully another member can jump in to help

On Sat, Apr 6, 2024, 10:40 a.m. Interloper @.***> wrote:

The main issue is that currently the WinRE partition is to the right of C, therefore cannot expand inside of windows, usually have to use a winpe partition manager after the deployment to resolve the issue since the unallocated space will be to the right of the winre in a fresh fog deployment. This also does not resolve the issue with having a smaller drive then the image, and it not shrinking to fit (eg a 500gb image, but only ~28gb used since its just a fresh windows, works fine with single disk but not on multi disk setup since it does not do the resizing).

— Reply to this email directly, view it on GitHub https://github.com/FOGProject/fogproject/issues/587#issuecomment-2041147651, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTQQFV7IWO3BJRF4QGTZ4LY4AXPTAVCNFSM6AAAAABFXSGNR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGE2DONRVGE . You are receiving this because you commented.Message ID: @.***>

darksidemilk commented 3 months ago

Have you tried using the single disk resizable image and set the primary disk on the fog host in the gui?

See also https://docs.fogproject.org/en/latest/management/web/hosts/?h=primary+disk#primary-disk

That should make the image only touch the first disk and expand it as normal.

Technically it should just detect the standard primary disk and work but it not expanding is an issue. I will see if I can test this virtually to recreate it, but all my images are created on the smallest disk possible so it can expand to bigger ones.

There could also be a question of 4kn vs 512e sector sizes. If one of the 2 disks is different than it's a more complicated issue.

darksidemilk commented 3 months ago

Are you wanting the second drive to be untouched by the imaging process? Or are you wanting something to be added to the second drive as part of the imaging?

darksidemilk commented 3 months ago

I'm trying something I made a single disk resizable image where I didn't let windows make the winre partition at the end (doing this with an autounattend.xml I added to the iso so the partitioning and install of windows and entering audit mode all happens automatically) I am adding to my provisioning process (sysprep/setupcomplete) this function to recreate the winre partition during the sysprep specialize phase so that I maintain that winre partition on the system drive, but I am also making it dynamically bigger based on 1% of the C drive to prevent update issues like what happened in some recent windows updates. This is the powershell I'm using for that, I have it in a function but this is the contents for reference

reagentc /disable
        $sysLtr = $env:systemdrive.replace("`:","")
        $disk = Get-Volume | Where-Object DriveLetter -eq $sysLtr | Get-Partition | Get-Disk
        $curLastPartition = $disk | Get-Partition | select-object -Last 1;
        if ($curLastPartition.DriveLetter -ne $sysLtr) {
            "The last partition in the table is already a recovery partition, deleting and recreating..." | out-host;
            #delete the partition
            $curLastPartition | Remove-Partition -Confirm:$false;
            #extend the C/system partition
            $maxsize = Get-PartitionSupportedSize -DriveLetter $sysLtr | Select-Object -ExpandProperty SizeMax
            Resize-Partition -Size $maxsize -DriveLetter $sysLtr -Confirm:$false;
        }
        $size = (Get-Partition -DriveLetter $sysLtr).size;
        $winReSize = $size * 0.01;
        if ($winReSize -lt 1024) {
            $winReSize = 1024; #always use at least 1GB to avoid update errors
        }
        # $sizeGB = [math]::round($size.sizemin/1024/1024/1024,2);
        # $sizeGB += $sizeGB*0.1
        # "Setting partition size to smallest allowed plus 10%, which is $sizeGB GB" | out-host
        # $size = $sizeGB*1024*1024*1024
        "Shrinking system drive by 1% or at least 1GB to make room for new winre partition" | out-host;
        Resize-Partition -DriveLetter $sysLtr -Size ($size-$winReSize) -Confirm:$false;
        #see also https://support.microsoft.com/en-us/topic/kb5028997-instructions-to-manually-resize-your-partition-to-install-the-winre-update-400faa27-9343-461c-ada9-24c8229763bf

        New-Partition -DiskNumber $disk.number -UseMaximumSize -GptType "{de94bba4-06d1-4d40-a16a-bfd50179d6ac}" -DriveLetter R;
        Format-Volume -FileSystem NTFS -NewFileSystemLabel "Recovery" -Force -DriveLetter R -Confirm:$false
        Set-Partition -DriveLetter R -NoDefaultDriveLetter $True -Confirm:$false -ea 0;
        Get-Partition -DriveLetter R | Remove-PartitionAccessPath -accesspath "R:"
        reagentc /enable

I tested that bit yesterday and it worked to expand my image created on a 64 GB disk VM and deployed to a 100 GB VM and it expanded and then made a 1 GB recovery partition.

I'm now testing the image again on the same VM where I added a second disk. I hadn't initialized the disk or put anything on it, so I expect it to be raw. I'll run it a second time after I add some data to the second disk to see if it, as expected, doesn't touch that second disk.

If you're looking to have the first drive expand and have the second drive be emptied by the fog process that can also be done by either sysprep/setupcomplete or custom fog post install scripts.

I am also using sysprep unattend.xml to do a failsafe OS partition extension during the specialize phase, just for reference. I'm pretty sure Fog is the one actually expanding the partition based on log files, I should probably watch it closer to be sure, but I'm doing the tests passively, it's the weekend.

TL;DR With a bit of configuration (that may be easier than it sounds) we can make this work as expected. I also think that this used to work before windows changed their partition format, which is why I am trying to recreate their partitions differently.

darksidemilk commented 3 months ago

Test worked If you remove the recovery partition the resize works as expected and the second drive is untouched. I will gladly help you get this implemented if it's what you're looking for. Just need a little ore clarity on your setup and your end goal to help find the best solution.

darksidemilk commented 3 months ago

@aUniqueUser Also, my understanding is that we cannot shrink an image to smaller than the size it was captured from, even though the image size itself is shrunk. The code is designed to deploy to the same size or bigger. If capturing from a VM isn't an option, then you could likely work around this by shrinking the OS partition before you capture. This might work to make fog see it as a smaller disk, but it may just look at the full disk size regardless.

aUniqueUser commented 3 months ago

Thank you for the help, have implemented based on the info and everything is now working well 👍