Convert From maildir To outlook eml

September 10th, 2016 by Andrea Matesi

 

 

To successfully import a "maildir"-type of mailbox into Outlook, you first need an intermediate step.

The intermediate step involves the conversion of the "maildir" mailbox into the "mbox" format first.

Once you have the single mbox-file, you can then extract the *.eml messages (& subsequently open them with Outlook).

 

1) "maildir" To "mbox" conversion.

Login to your Cpanel server and locate the user's maildir mailbox.

cd into the ~/user.name/cur-folder.

Create/Launch the "mdir2mbox.sh" script on the "cur" folder:

root@www-wa-01 [~/user.name/cur]# cat mdir2mbox.sh
#!/bin/sh
set -x
for file in `find ./ -type f`
do
cat $file | formail >> mbox
done

The above script will create a single “mbox”-file whithin which you will find all the original e-mails.

 

2) "mbox" To "eml" conversion.

Now transfer the single mbox file into a Windows PC, then Download the free tool MBOX Email Extractor and Run it.

MBOX Email Extractor is a freeware utility made by those guys: http://www.outlookimport.com

IF you Open the mbox file thru MBOX Email Extractor, you'll then be able to extract all the eml messages, ready to import into Outlook (or any other app that supports the eml format)!

 

You end result should be similar to as follows:

Posted in Tips and Tricks. | No Comments »

How to migrate your Profile From Local User Account To Domain User Account.

May 14th, 2016 by Andrea Matesi

 

If you want to join your system to an Active Directory Domain, BUT you don't wanna lose your data & restart from scratch (ie. your Desktop, files, settings, shortcuts, you-name-it), here's how.

 

Gimme fuel.

Before actually doing your real Local User Account to Domain User Account "profile migration", make yourself a favour — do a "test" run first (ie. by creating a new Local "test" User Account) & check for yourself that it works!

For your "test"-scenario:

  • Create a new "test" User Account (BOTH on your local system & your Active Directory Domain Controller).
  • Now login to the Local System w/the "test" Local User Account.
    This way, a new "C:\Users\test" is created on your PC.
  • While logged in as the "test" User, feel free to replicate some of your "REAL" Local User Profile settings (ie. things you wish to migrate to the new Domain-enabled Account, like your "Google Drive"-setup, your Libraries, etc.).

Once you're done playing, it is now time to migrate ("map") your "test" Local User Account to your "test" Domain User Account.

That will retain all your settings and customisations as-is (including your Desktop icons location).

To do that, we'll rely on a wonderful application named User Profile Wizard ("Profwiz.exe" for friends) from ForensIT.

 

Spark-plug magic.

Proceed as follows:

Once on the Domain:

  • Login to the PC with your "test" Domain Account.

By so doing, you'll get a new (default, empty) "C:\Users\test.domain"-folder on your local system.

  • Now Logout & login as (Local) Administrator Account.
  • Run Profwiz.exe from your Desktop and follow the wizard prompts according to your requirements.
    Namely, make sure to map the Local "test" User to the Domain "test" User.
  • Logout when finished.

 

Gimme fire.

  • Login to the System w/the "test" Domain Account.

You will notice the "test" Domain Account has all its previous Local "test" User Profile settings untouched!

  • IF the Local "test" User Profile previously had "Local Administrator" privileges, you will notice some apps might not work.

You can grant the test User Profile Local Administrator permissions by providing him Membershit to the (Local) "Administrators" group.

Proceed as follows:

  1. Open Control Panel.
  2. Click on Manage User Accounts.
  3. Browse for the "test" Domain Account -> "Properties" and grant it membership to (Local) "Administrators"-Group.

Or perhaps you might wish to read one of my previous guides on this subject:

  1. 3 ways to grant "Local Admin" permissions to Domain Users.
  2. Secure Restricted Groups to grant Local Admin Credentials to Domain Users.
  3. How to setup Per-Computer “Local Admins” on a Domain.

 

Gimme that which I desire.

Alright, now that "Fuel is pumping engines" (cit. Metallica), repeat the above with you real user.

 

Posted in Microsoft, System Administration, Tips and Tricks. | No Comments »

11 exim cpanel golden checks for quick mail troubleshooting.

March 19th, 2016 by Andrea Matesi

 

The following is just some random advice derived from my experience on dealing with email-related issues.

More specifically, here I'll be referring to exim (a very popular mail daemon), Cpanel/WHM & CentOS.

  1. Check if the user & password combination is correct.
  2. Check if the SMTP Authentication is enabled.
  3. Check if the User's mailbox is full.
  4. Perform an nslookup of the domain thru a public DNS Server.
  5. Perform an nslookup of the MX RRs thru a public DNS Server.
  6. Verify that the SPF RR is applied to the domain.
  7. Telnet (or putty with the telnet option enabled) to the destination server address to see if it answers.
  8. Check if the domain name is present inside /etc/localdomains.
  9. Check the logs with exigrep /var/log/exim_mainlog.
  10. Check with vi /etc/userdomains
    Look for some blank spaces or broken lines near the domain that is having incorrect authentication data issue error 535
  11. Check whether the folder "etc" within /home/"cpanel-username"/etc/ is owned by cpanel-username:mail
    If it is not then change it with:
    chown username:mail /home/username/etc/ -R

Hope you might find those useful & feel free to share your own special/unique checks on the comments section.

 

Posted in LINUX, System Administration, Tips and Tricks. | No Comments »

3 commands to INSTALL Unsigned Drivers (by disabling driver signing w/bcdedit).

December 16th, 2015 by Andrea Matesi

 

RUN "CMD" As Administrator.

First things first - run a command prompt As Administrator!

[Win 7] Win + R -> cmd -> CTRL + SHIFT + ENTER

[Win 8/8.1/10] Win -> cmd -> CTRL + SHIFT + ENTER.

[GUI]:

01.run-cmd-as-admin

02.run-cmd-as-admin

 

To DISABLE "Driver Signing" (so you CAN install UNSIGNED Drivers):

1) Disable "Integrity Checks".

2) Enable "Test Mode".

3) Restart your System.

Copy-Paste code to install unsigned drivers:

bcdedit -set loadoptions DISABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING ON
shutdown /r /t 0

# above commands will:

  1. "DISABLE Integrity checks" so unknown drivers could be installed.
  2. Allow "Test" signatures.
  3. Restart your computer.

 

 

To ENABLE "Driver Signing" (so you CAN'T install UNSIGNED Drivers):

1) Enable "Integrity Checks".

2) Disable "Test Mode".

3) Restart your System.

Copy-Paste below code:

bcdedit -set loadoptions ENABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING OFF
shutdown /r /t 0

# above commands will:

  1. "Enable Integrity checks" so unknown drivers won't be installed.
  2. Disable/Disallow "Test" signatures.
  3. Restart your computer.

Posted in Tips and Tricks. | No Comments »

Include non-indexed (network) locations to your Libraries.

April 18th, 2015 by Andrea Matesi

Thanks to the following (awesome) blog post: http://blog.ryankempt.com/2012/09/windows-library-add-non-indexed-location.html, today I was able to add/show non-indexed network locations into my Documents Library.

This workaround is especially useful whenever you're storing, say, your family Pictures on a (Linux-based) NAS that does not support indexing.

For convenience’s sake, I’ll report what's involved the way "it worked for me":

  1. Win+E –> C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Libraries\
  2. Right-Click on the Library you wish to customise (ie. Pictures).
  3. Select "Open with..." and open w/your fav txt editor.
  4. Scroll to EOF and locate the last "</searchConnectorDescription>".
  5. Copy the following code:

    <searchConnectorDescription>
    <isDefaultSaveLocation>false</isDefaultSaveLocation>
    <isDefaultNonOwnerSaveLocation>false</isDefaultNonOwnerSaveLocation>
    <isSupported>true</isSupported>
    <simpleLocation>
    <url>\\your-file-share\location\folder</url>
    </simpleLocation>
    </searchConnectorDescription>
    </searchConnectorDescriptionList>

  6. Paste the above code BEFORE "</searchConnectorDescriptionList>" AND BELOW/AFTER the last "</searchConnectorDescription>".
  7. Update "<url>\\your-file-share\location\folder</url>" with your desired Network Location.
  8. Save and close, then browse to, say, your Pictures Library (as you normally would).

[BONUS UPDATE]: On Windows 8/8.1, Libraries have been disabled (by default).

To enable/show Libraries on your folders list, proceed as follows:

Show Libraries

  1. Open File Explorer and move your mouse to the vertical/left navigation list (Favorites, This PC, etc.).
  2. Right Click on a blank spot in that area (ie. on the white empty space between Favorites & This PC).
  3. Select "Show Libraries" to bring Libraries back.

SRC: http://blog.ryankempt.com/2012/09/windows-library-add-non-indexed-location.html

Posted in Tips and Tricks., Windows 8/8.1 | No Comments »

[Solved] Chrome "Waiting for cache" (WSOD) & How to Open all your Synched Tabs back.

February 14th, 2015 by Andrea Matesi

Chrome broke my heart <3 by not loading pages anymore.

So instead of going out with my beloved ones, here I am, fighting with Chrome :)

This error seems to be referred to as "White Screen of Death" (WSOD) because of a white background and a ”Waiting for cache…”-message on the lower left Status bar while no page is being loaded.

While searching for a solution, I tried the “Clear browsing Data…”-Button from:”the beginning of time”.

I cleared the following:

image

  • Clear browsing history.
  • Clear download history.
  • Delete cookies and other site and plug-in data.
  • Empty the cache.
  • Clear data from hosted apps.

After a couple of days, the dreaded “Waiting for cache…”-blank page started reappearing again(!).

To fix the “Waiting for cache…” issue, I adopted a radical approach - uninstall Chrome!

Before rushing into uninstalling Chrome, there was an issue I had to take care of first – …153 Open Tabs!

Since I adopted Chrome as tool of trade, I “bought” into the Google Sync Service, which promises to Save you all your Open Tabs:“in the cloud” – sweet!

To allow Chrome Tabs Sync with Google, you’ll have to:

  1. Be signed in to Chrome with your Gmail Account.
    image
  2. Make sure “Open Tabs” is checked (even though your browser is not working…).
    image
    Go to chrome://settings/syncSetup and flag “Open Tabs”.
  3. Verify that your Google Dashboard says you have xXx “Open Tabs”.
    image
    153 is just a Number.

If you can confirm the previous steps, uninstalling Chrome should just be a matter of:

  1. Clearing your browsing data (as explained above, at the beginning of my post).
  2. Uninstalling Chrome from your Control Panel –> Programs (as usual).
  3. Opening your AppData & Searching/Deleting any “Chrome-related”-remnants.
  4. Rebooting your Computer.

Time to Install Chrome…

While installing Chrome back, I also experimented with “Chrome for Business” MSI Installer Package (& related Administered Settings), to deploy it through Group Policy (but that’s another story…).

Install Chrome as usual then Sign in to Chrome with your Google Account.

You will notice all your Web Apps will re-appear back, but not your Tabs…

To reopen all your Open Tabs:

  1. Open a New Empty Tab.
    image
    CTRL (or Command) + T or Click on the “PLUS”-Symbol.
  2. Click on “Other Devices” (Bottom right).
    image
    You never noticed that…eh?
  3. Click on the miniscule Small Arrow near your “ComputerName” and Click on “Open all”.
    image
    ALL your Tabs are belong to US!

I hope “Waiting for cache…” is now a thing of the past also for you!

Cheers,

Andrea.

Posted in Tips and Tricks. | No Comments »

5 easy steps to tweak your jailbroken iPhone 4 w/iOS 6.x.

July 13th, 2014 by Andrea Matesi

 

If jailbreaking your iPhone 4 is not enough and you wish to squeeze that little small extra performance off it, then proceed as follows...

funny_lemon_if_you_squeeze_me_ill_be_your_iphone_case

1. Login (SSH) into your iPhone.

  • SSH to your iPhone with your favourite SSH client.

 

2. Create a New "backup dir" to which to move some useless daemons.

Why move? Because this way you'll never accuse me of telling you to delete iPhone System files.

Type:

mkdir Sys-Lib-LaunchDaemons-bck

 

3. Go to the (real) location of those useless daemons.

You'll need to first locate those files.

Type:

cd /System/Library/LaunchDaemons

 

4. Relocate those daemons' files out of your iPhone RAM!

Now move the files listed below From "/System/Library/LaunchDaemons" To "/var/root/Sys-Lib-LaunchDaemons-bck" ("mv" command follows, just copy/paste).

-rw-r--r-- 1 root wheel 540 Oct 20  2012 com.apple.AOSNotification.plist
-rw-r--r-- 1 root wheel 162 Oct 20  2012 com.apple.CrashHousekeeping.plist
-rw-r--r-- 1 root wheel 207 Oct 20  2012 com.apple.DumpBasebandCrash.plist
-rw-r--r-- 1 root wheel 142 Oct 20  2012 com.apple.DumpPanic.plist
-rw-r--r-- 1 root wheel 333 Oct 20  2012 com.apple.ReportCrash.DirectoryService.plist
-rw-r--r-- 1 root wheel 303 Oct 20  2012 com.apple.ReportCrash.Jetsam.plist
-rw-r--r-- 1 root wheel 306 Oct 20  2012 com.apple.ReportCrash.SafetyNet.plist
-rw-r--r-- 1 root wheel 330 Oct 20  2012 com.apple.ReportCrash.SimulateCrash.plist
-rw-r--r-- 1 root wheel 306 Oct 20  2012 com.apple.ReportCrash.StackShot.plist
-rw-r--r-- 1 root wheel 300 Oct 20  2012 com.apple.ReportCrash.plist
-rw-r--r-- 1 root wheel 230 Oct 20  2012 com.apple.mobile.profile_janitor.plist
-rw-r--r-- 1 root wheel 403 Oct 20  2012 com.apple.powerlog.plist

  • Type the following "mv" terminal command to move the above files:

mv com.apple.AOSNotification.plist com.apple.CrashHousekeeping.plist com.apple.DumpBasebandCrash.plist com.apple.DumpPanic.plist com.apple.ReportCrash.DirectoryService.plist com.apple.ReportCrash.Jetsam.plist com.apple.ReportCrash.SafetyNet.plist com.apple.ReportCrash.SimulateCrash.plist com.apple.ReportCrash.StackShot.plist com.apple.ReportCrash.plist com.apple.mobile.profile_janitor.plist com.apple.powerlog.plist /var/root/Sys-Lib-LaunchDaemons-bck

files-to-move-so-iphone-becomes-faster

5. Reboot your iPhone.

On the terminal, type:

reboot

After you reboot your iPhone, the above daemons won't be loaded into RAM anymore.

 

BONUS.

If you want your GUI to "go faster", install "Accelerate" (from the Cydia repos).

Accelerate will speedup your iPhone GUI transition speed for free. Also, nitrous is worth a mention (though it costs 0.9c).

SRC:

http://www.geek.com/apple/the-best-cydia-apps-2-1534009//6/

Posted in Apple, Tips and Tricks. | Comments Off on 5 easy steps to tweak your jailbroken iPhone 4 w/iOS 6.x.

RDP inside a SSH tunnel.

June 2nd, 2014 by Andrea Matesi

I'm gonna post some infos on how once I did gain access to my Windows rig at home by using the RDP protocol inside a secure shell tunnel, FROM my office workstation TO my home computer!

What's the point of this? Since the RDP protocol does not encrypt traffic by default, it can be easily captured and analyzed, instead SSH encrypts everything it transports and no protocol analyzer can identify what's being transported by it.

First and foremost, the PCs involved in such a technique are the followings:

  1. My Windows XP gaming rig at home (which from now on I'll refer to as "gaming").
  2. My Ubuntu Home Server (server), connected at the same gaming lan at home.
  3. My Ubuntu Desktop Workstation at work (workstation).

There is also my home-router in between, a standard, browser configurable appliance (you mat have to configure the one given to you by your provider, YMMV).

My gaming rig was a PC with a powerful GFX card and a standard install of Windows XP; its firewall was disabled and it was directly connected with a hand made cat.5E cable to my 8 ports Gigabit Ethernet Switch.

My server was a standard low end PC with a bare install of Ubuntu 8.04 Server flavour sitting near my gaming rig. By bare install, I mean that, while installing the OS, I deselected all the features and services. I choose just the useful bare minimum to obtain a booting system. When booted, this system did offer only some vtys. This host was also directly connected to my home switch.

The other appliance I had was a browser-managed router. This router, on one side was connected to my Switch (with local IP Address), on the other side it was connected to the Internet via my ISP ADSL. I had an always-on account.

The internet browsing was automatic since the router was configured according to my ISP settings.

What I wanted to accomplish was to gain RDP access to my gaming rig from the office.

There were 2 different networks involved:

  1. My Home Network.
  2. The Office Network.

The Home LAN was the classic home network, 192.168.0.0/24

gaming's IP was 192.168.0.3

server's IP was 192.168.0.2

home-router IP was 192.168.0.1 inside and ISP-offered public IP address outside (knowing this address was crucial).

The PCs inside my home network were all able to ping each other and no firewall was enabled.

the next step consisted accessing the

server

and installing on it the ssh server service daemon.

For the sake of simplicity, I took Ubuntu 8.04 Server and manually installed OpenSSH:

  • apt-get install ssh

I then used the default options by simply pressing Return.

The next thing I needed was to configure port forwarding on my router, so, from my gaming rig I pointed my browser to 192.168.0.1 and, after inserting the right credentials (router's user name and password), I went to a page referring to as "port forwarding".

On the port forwarding section I made a custom rule that pointed port 22 to my internal home server, with this custom rule:

  • All the Inbound connections relevant to port 22 from the Internet to my router, should be sent to port 22, to my internal server IP address 192.168.0.3.

I took note of the public IP address of my router, you can simply go to www.whatismyip.com and read what your public IP address is (at the time, mine was something like 72.16.125.23 and it always changed because it was a public dynamic address) or you may decide to use a service like dynDNS.

Another thing to take care of is to set your home-router to respond to ping requests coming from the Internet, so find the right page and set it to respond to pings, because i found I had problems by not enabling this.

Back at the office I had a standard pc, wich I'm referring to as my workstation; Workstation was able to access the Internet similarly to my home gaming rig scenario.

First thing first, I tried to ping my home router's public dynamic IP address:

  • ping 72.16.125.23

If you receive your responses, then you are halfway to doing this.

The next thing I tested was the SSH connectivity to my ubuntu server, so I simply did:

  • ssh yourconfiguredserveruser@72.16.125.23

If you received a prompt asking for a password, then you configured it correctly: the ssh home server is responding and you are allowed to access it.

This also means that the forwarding rule previously applied to your home router functioned correctly.

Now just take a break and experiment with it: you're at your home server!

Since your server is inside your home network, making a tunnel is just a matter of sending him the right commands.

The magic of all this lies in the ssh server capability to stream all the data between your PC (my workstation in this case), to another PC inside your home LAN, not by accessing it directly, but by using the server as a BRIDGE that links you to the other computers inside the lan.

Open a terminal (or PuTTY if you have Windows in place of a linux workstation), and write the following:

  • ssh -L 3389:gaming's-IP:3389 srvusr@Internet-router'sIP

You'll be asked for a password; insert your home server's password and, if you receive a shell, you're done!

Now, from workstation, open up an RDP client (like the Remote Desktop or a free alternative) and simply connect to localhost. You should be able to receive the Remote Desktop session of your gaming rig :D

At this point it is just a matter of inserting the right credentials to access Windows XP and you're done: a relatively fast and secure way to remotely control your home desktop gaming rig: too bad videogames streaming wasn't still possible by using only free/Open Source alternatives (for proprietary ones, there seems there are for-pay solutions like stream my game that seem to work somehow, but I haven't tried and tested those kind of services yet).

Posted in Tips and Tricks. | Comments Off on RDP inside a SSH tunnel.

[SOLVED] How to correctly integrate Google Drive with "My Documents".

May 27th, 2014 by Andrea Matesi

 

Today I was messing with Google Drive and the Windows Libraries.

 

Google Drive logoWindows Libraries

My idea was to integrate both products so I could access my data from everywhere.

If you want to skip the details and jump to the conclusion, please refer to the heading named SOLUTION (or How to correctly integrate your "My Documents" with Google Drive) - scroll below.

 

Windows Libraries for infants.

For newborns, Windows Libraries are a "catalog"-type of a special folder.

Instead of standard files & folders, they contain "links" that point to other folders.

For example, when you open Windows Explorer.exe (Win+E), by default you'll find a "Libraries" list (on the left).

Each Library (let's say Documents), shows you your files & folders, 'though the actual files and folders are located somewhere else.

For example, the Documents Library holds your Documents Folder Content (ie. C:\Users\%username%\My Documents\), along the Public Documents (normally located by default at C:\Users\Public\Documents).

To manage what to show within a specific Library:

  • Right Click on the Library (ie. Libraries -> Pictures).
  • Click on "Properties".
  • On the popup window, Add/Remove the folders locations you'd like to include.

Now, for the readers who agree on Google Drive's value, what I wanted to achieve was a convenient integration between "My Documents" Library (on my PC) with Google Drive (in the Cloud).

In other words, I wanted to host my "C:\Users\andrea\My Documents" within my Google Drive root.

That way, C:\Users\andrea\Google Drive\My Documents would still be available within my "Documents"-Library.

 

How to NOT integrate Google Drive with "My Documents".

So I went into C:\Users\andrea\ with explorer.exe and right-clicked on Mt Documents.

Then "Properties" -> "Location"-tab and I pointed the Destination to C:\Users\andrea\Google Drive (since I thought my ENTIRE "My Documents"-folder would've been relocated as-it-was to my Google Drive root).

The expected end result would've been C:\Users\andrea\Google Drive\My Documents.

 

Error No.1

Unfortunately something went wrong and I ended up with a C:\Users\andrea\Google Drive == C:\Users\andrea\My Documents folder.

 

Error No.2

Since this IMHO is suboptimal, I tried to rollback by relocating "My Documents" to somewhere else.

Whoa! that definitely killed my Google Drive folder!

 

Error No.1 & No.2 FIX.

To fix the above scenario, I had to "unlink" my computer from Google Drive first (which is a PITA, since after you uploaded a couple of gigs to it, you have to clean it from the web side, then re-upload everything - unless you're OK with downloading all your duplicates, that is!).

 

SOLUTION (or How to correctly integrate your "My Documents" with Google Drive).

Lesson learned: if you wish to relocate your Documents to Google Drive:

  1. Please first create a NEW Folder inside C:\Users\%username%\Google Drive\ and name it (conveniently) "My Documents".
  2. Make sure the New Folder is synched to Google Drive.
  3. Right Click on your (real) "My Documents"-folder Properties.
  4. Click on the "Location"-tab.
  5. Click on the "Move"-Button.
  6. Select the New Folder created at step No.1
  7. Click OK to Confirm and wait for the file transfer process to relocate all your stuff over there.

This way you'll end-up with a "My Documents" subfolder of C:\Users\andrea\Google Drive\ (ie. C:\Users\andrea\Google Drive\My Documents).

  • The advantage of this setup is that it allows you to store, say, your "My Documents" and your "My Pictures" on Google's Drive.

Also, if you happen to have an "home" folder on your Mac and/or your Linux-based system, the separation allows you to distinguish between each OS.

That is good since some Windows Programs have the (good or bad?!) habit of dumping stuff (ie. Savegames, etc.) into your "My Documents"-folder (that you don't want to "see" when on a Mac or Ubuntu).

Now, if Documents doesn't come up on your Libraries, right click then & add your "C:\Users\andrea\Google Drive\My Documents" to it!

Happy cloud computing!

 

I made a mess of my files, please help?!

[BONUS]: did you happen to mess it badly and now, after you Right Click on your "My Documents"-folder, the "Location"-Tab is missing?!

No problem:

  1. Fire regedit
  2. Go to "HKEY_CURRENT_USER\Software\Microsoft\ Windows\CurrentVersion\Explorer\User Shell Folders".
  3. Specify on which folder the Location-Tab should appear!

 

SRC:

http://www.online-tech-tips.com/windows-vista/move-my-pictures-to-different-location/

Posted in dirty hacks, Microsoft, Tips and Tricks., Windows 8/8.1 | Comments Off on [SOLVED] How to correctly integrate Google Drive with "My Documents".

2 ways to compact your Dynamically expanding VHDs.

March 15th, 2014 by Andrea Matesi

 

When you play with Hyper-V 2012 Virtual Machines on your lab, it is a best practice to use Dynamically expanding Virtual Hard Disks (VHDs) for your VMs.

The difference in performance is simply unjustifiable.

'Though, the moment you start Installing/Uninstalling Applications & Adding/Removing Data on your VMs (based off dynamic VHDs), those VHDs start growing indefinitely in size (ie. even if you uninstalled/deleted data from the VM).

For example, you could end-up with a dynamic VHD which:

  • On your Hyper-V Host uses ~70GBs of physical hdd space.
  • Inside your VM the used space is reported as ~20GBs.

Now that's a ~50GB difference!

I'm sure you might want to allocate those 50GBs to more pr0n ^..^ "other" projects.

That is especially important when those 50GBs are hosted on your expensive SSDs.

 

2 ways to compact your differential VHDs.

The 2 ways I'm referring to will provide you the same result.

One is GUI-based while the second is CLI-based:

  1. With the "Edit Disk..."-wizard (from Hyper-V Manager).
  2. With diskpart (on an Admin CMD).

Your choice.

 

Compact VHD Requirements.

To successfully compact VHDs, there are 2 important requirements.

  1. You'll have to delete all the Snapshots.
  2. You'll have to Shutdown the VMs (not "Turn Off").

Dynamically expanding VHDs are an excellent choice for your lab.

In production environments, Dynamically expanding VHDs are more expensive to maintain.

...And Snapshots are NOT an excuse to not perform Backups!!!

 

 

1. Compact VHD with "Edit Disk..."-wizard (from Hyper-V Manager).

  • Open Hyper-V Manager.

Make sure you've satisfied the "Compact VHD Requirements".

  • Click on "Edit Disk..." (on the right).

The Edit Virtual Disk Wizard will start.

Edit Virtual Hard Disk Wizard

Edit Virtual Hard Disk Wizard

Click on Next to Select the VHD.

 

 

Edit Virtual Hard Disk Wizard - Locate Disk

Edit Virtual Hard Disk Wizard - Locate Disk

  • Click on Browse.
  • Select you Dynamically expanding VHD.
  • Click on Next to Continue.

 

 

Edit Virtual Hard Disk WIzard - Choose Action

Edit Virtual Hard Disk WIzard - Choose Action

  • Select "Compact".
  • Click on "Next" to Continue.

 

 

Edit Virtual Hard Disk WIzard - Summary

Edit Virtual Hard Disk WIzard - Summary

The last part of the wizard will show you a Summary of your selections.

Click on the "Finish"-Button to Compact your Dynamically expanding VHD.

 

 

2. Compact VHD with diskpart (on an Admin CMD).

With diskpart the process is easier to document.

Make sure your VM has been Shutdown and there are no Snapshots.

  • Run a Command Prompt as Administrator.
  • Type "diskpart" to launch MS' CLI Disk partitioning super-tool.
diskpart

diskpart while it compacts a vhd.

After you run diskpart, the prompt will change to "DISKPART>".

To compact your Dynamically expanding VHD, type the following commands at the diskpart prompt:

select vdisk FILE=C:\HyperV\Virtual Hard Disks\vm01.vhdx
compact vdisk

"FILE=" points to your VM's VHD Location while "compact vdisk" starts the compaction process.

 

Conclusion & Proof.

As I said at the beginning, you might end-up saving up-to ~50GBs!

Proof - after running diskpart on one of my mistreated VMs ("famx11.vhd"):

famx11.vhd Before compaction:

02. compact-VHD-before

 

famx11.vhd After compaction:

03. compact-VHD-AFTER

 

BONUS: Sdelete Vs Precompact.

Now, if you don't get the desired results, that means hidden data (somehow) is still on your drive...

That is especially true when the steps described above give you risible results.

Not everything is lost!

Compaction alone might not always work because the data might still be within your dynamic VHD(X) in the form of hidden (ignored) data.

To get rid of this hidden data, you might wish to zero-fill all the extra (free but ignored) space.

I don't want to get into a discussion of what tool is "best".

'Though, in my experience, sdelete and precompact have worked quite well and are my best favourites zero-fill free space Windows tools.

They both have a very simple syntax and are pretty easy to use.

 

sdelete.

sdelete is another iteration of Mark Russinovich's excellent tools.

Among other things it makes coffee it zero-fills your dynamically expanding VHD(X)s.

Open a cmd prompt as admin and type:

Sdelete Example And Command Switches

Sdelete Example And Command Switches

sdelete -z H:

Where "H:" is the drive to zero-fill.

 

Precompact.

Precompact is a quite "old" MS-Virtual PC remnant (perhaps inherited by the glorious Connectix!).

Precompact does just that - prepares you dynamically expanding VHD(X) for compaction.

The tool simply cleans all your deleted data off your VHD(X) and that's all there it is to it.

  • You can simply Double Click on precompact.exe and it will automatically compact ALL you disks (usually you don't want that unless you have plenty of time...).

Here's a screenshot of precompact doing its sh1t in action on a Windows Server 2012 Virtual Machine:

Microsoft Virtual Disk Pre-Compactor Example and precompact parameters

Microsoft Virtual Disk Pre-Compactor Example and precompact parameters

Posted in Tips and Tricks., Virtualization | 5 Comments »

« Previous Entries