Friday, February 12, 2016

Running Windows Nano server on QNAP NAS device

How to run Windows Nano server on QNAP



Prerequisites:





Steps.


1.  Download and extract Windows 2016 ISO somewhere on HDD (I use 7-zip for this purposes)
2. Build WIM image by utilizing script below. At the end of the script you shall end up with c:\nanoserver folder with a bunch of subfolders beneath it

$Target_Drive = "C:"  
$cd_drive = "C:\win2016"  
###################  
$NanoTarget = join-path $Target_Drive "Nanoserver"  
$NanoServer = join-path $cd_drive "Nanoserver"  
$Nanosource = join-path $cd_drive "Sources"  
$DismPath = Join-Path $NanoTarget "DISM"  
New-Item -ItemType Directory $NanoTarget  
New-Item -ItemType Directory $DismPath  
foreach ($Filter in "*api*downlevel*.dll","*dism*","*provider*")  
    {  
    Get-ChildItem -Filter $Filter -Path $Nanosource | Copy-Item -Destination $DismPath -PassThru  
    }  
Copy-Item "$NanoServer\*" $NanoTarget -Recurse  

3. Convert VIM image into VHD file with powershell commad below

.\convert-windowsimage.ps1 -SourcePath .\NanoServer.wim -Edition CORESYSTEMSERVER_INSTALL -VHDPath .\nano.vhd -VHDFormat VHD -DiskLayout BIOS

4. You will end up with VHD file in your nano server directory
5. Update you VHD image with OEM drivers below. Make sure "mountdir" folder created first in your build folder.

dism\dism /Mount-Image /ImageFile:.\Nano.vhd /Index:1 /MountDir:.\mountdir
dism\dism /Add-Package /PackagePath:.\packages\Microsoft-NanoServer-OEM-Drivers-Package.cab /Image:.\mountdir  
dism\dism /Add-Package /PackagePath:.\packages\en-US\Microsoft-NanoServer-OEM-Drivers-Package.cab /Image:.\mountdir  
dism\dism /Unmount-Image /MountDir:.\MountDir /Commit  

6. You have fully working VHD now which you can import into Hyper-V if you want, but we need to convert it to qcow2 format used by QNAP by using qemu-img.exe tool

.\qemu\qemu-img.exe  convert -O qcow2 .\nano.vhd dest.img

7. Create new VM in QNAP with this image as HDD and you have yourself a working Nano server running on QNAP


Friday, January 15, 2016

Move any physical/virtual servers to Azure with free tools

Below are steps which can be taken to move physical/virtual servers to Azure. All tools used are freely available.


 Depending which architecture is being moved (physical/virtual) you might start on any of the steps below bypassing some of earlier steps (for example if you want to move Hyper-V managed server). I assume we are moving either from Vmware or physical machine for this flow.

1. Download disk2vhd tool and run on your target machine. Uncheck "VHDx" since Azure supports only VHD files.



2. Create new Virtual Machine and attach generated VHD file to it (Generation 1). Boot machine and uninstall any software which will not be needed in Azure. (Vmware tools for example)



3. Enable firewall for all networks and make exception for remote desktop


4.  If you have system reserved partition then delete it using instructions available on this link


5.  Install or update Hyper-V Integration services components and Azure VM agent (https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-extensions-agent-about/)



6. Make sure you HDD is not bigger then it needs to be once it'll be in Azure. For this to happen you need to defrag disk and move all the files to the start of HDD so you can shrink it to desired size. You will have to do offline defrag in some cases to move all the files to start of HDD. I used Puran Defrag for this purposes.


7. After resize you need to shrink OS partition in Windows to desired final size. 


8. Final 2 steps for VHD is to shrink it and convert it to Fixed size. I used VHDResizer for this purpose.

9. Upload your VHD to Azure storage. I use CloudBerry Explorer. For this you need to register account in Cloudberry by providing account name and key which you can find in Azure portal.
10. Upload your VHD file as Page Blob


11. After upload is complete, go to classic portal and add VHD like below


12. The last step is to create VM based on this VHD


If everything was done right then you will have exact image of you machine running in Azure cloud