Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Monday, July 11, 2011

How to shrink qcow2 file

While working with kvm/qemu virtual environment you might encounter need to shrink image file after a removal of unnecessary files, etc. You will be surprised that the space you freed in guest virtual machine is not actually released in host file. It's size remain the same. Here you will know how to shrink it to minimum.

Windows Guest

The idea here is simple, there are few things you have to do:
  1. Delete all unnecessary files, empty recycle bin
  2. Defragment drive (you might need to do this several times, until you see it "compacted" well)
  3. Use sdelete to zero free disk space. Please note that this operation will cause that all drive free space will be filled by zero, so the virtual machine image will grow to the maximum size.
    sdelete -c c:
    

Linux/FreeBSD Guest

dd if=/dev/zero of=./zero bs=1M
sync
rm -f ./zero
Note, the bs parameter is important, since it greatly reduce time necessary to complete this task.

Host

Convert image to the same format that is currently is (e.g. qcow2 => qcow2)... during this procedure it will release unused space.
qemu-img convert -O qcow2 w2k3.qcow2 \
 w2k3-shrinked.qcow2
The process is time consuming and each phase greatly depends on physical disk IO performance and available free space.

Sunday, July 3, 2011

Debian Samba Server

Samba is the protocol by which a lot of PC-related machines share files and printers.
apt-get install samba

Temporary File Space

We will create a simple network share tmp. All users in WORKGROUP will have read-write access. Let create a directory tree (under /srv/smb/) we are going to serve.
mkdir -p /srv/smb/tmp
Place the following in /etc/samba/smb.conf (backup the original file first):
[global]
workgroup = WORKGROUP
server string = Public File Server

# When clients connect to a share level security server, 
# they need not log onto the server with a valid 
# username and password before attempting to connect to
# a shared resource. Instead, the clients send 
# authentication information (passwords) on a per-share
# basis, at the time they attempt to connect to that 
# share.
security = share

# This parameter determines whether or not smbclient(8) 
# and other samba client tools will attempt to 
# authenticate itself to servers using the weaker 
# LANMAN password hash.
client lanman auth = no

# This parameter determines whether or not smbd(8) will 
# attempt to authenticate users or permit password 
# changes using the LANMAN password hash.
lanman auth = no

[tmp]
# If this parameter is yes for a service, then no 
# password is required to connect to the service.
public = yes
comment = Temporary File Space (cleaned up at midnight)
path = /srv/smb/tmp
read only = no
hide files = lost+found
Now from Windows machine you can access this share as \\samba-server-name\tmp. Here is a cron job to make daily clean ups (file /etc/cron.d/clean-samba-tmp):
#
# Regular cron jobs for removing everything 
# in samba tmp share
#
SHELL=/bin/sh

# Run daily at 1:35 AM
# m h dom mon dow user  command
35 1 * * * root /bin/rm -rf /srv/smb/tmp/*
See more configuration options here.

Saturday, April 16, 2011

How to Shutdown Windows Guest Gracefully in KVM

KVM uses ACPI to send shutdown event to the guest virtual machine. But it can't do that in case your windows settings prohibit shutdown when there is no user logged in, you have to change this settings. Here is how:
  1. Ensure the ACPI is enabled in your virtual machine settings.
  2. Login to your Windows guest and launch Group Policy Object Editor (gpedit.msc).
  3. Locate the following key and change the settings to enabled.
    Computer Configuration\Windows Settings\
    Security Settings\Local Policies\Security Options\
    Shutdown: Allow system to be shut down 
    without having to log on
    
  4. If you want to be able shutdown guest even there is a logged in user add the following to file ShutdownWarningDialogTimeout.reg and enter it into windows registry.
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]
    "ShutdownWarningDialogTimeout"=dword:00000001
    
Finally here is a simple command using virsh to shutdown guest:
virsh -c qemu:///system shutdown w2k3
Once the above settings is enabled you should be able gracefully shutdown your windows guests using virtual machine ACPI power management.

Thursday, April 14, 2011

Troubleshooting: Windows Guest on KVM

While migrating windows virtual machine from virtualbox to kvm you might experience an issue related to significant virtual hardware changes, in other words you get BSoD (bluescreen). Here are few findings that can help you:
  1. Windows 2003, BSoD. STOP: 0x0000007B. Here is a description. You need apply this before you convert image to kvm.
  2. Error message that computer does not have a parallel port: "The Parallel port driver service failed to start". Read more here.
  3. If your Windows host was configured in KVM configuration first choose IDE drive as disk bus, add SCSI controller. When guest starts let it scan for hardware changes, that might take few minutes, when it finds SCSI controller shutdown guest and change disk bus to use SCSI controller, you can remove IDE controller.
  4. Uninstall virtualbox guest tools, so windows doesn't complain (see system event log).
The above "fixes" should let you start your windows guest in kvm.

Saturday, May 15, 2010

How to start python IDLE in virtualenv on Windows

IDLE is an integrated development environment for Python. It is more convenient than plain python command prompt. In order to start IDLE in virtualenv environment you have to:
  • Copy tcl directory from your python installation folder to your environment directory.
  • Create shortcut with name IDLE to pythonw.exe that is located in Scripts directory of your environment.
  • Append "%PYTHON_HOME%\Lib\idlelib\idle.pyw" to the shortcut Target.
Once you are done you should be able start IDLE from within your environment.

Friday, May 14, 2010

Python development environment on Windows

Download Python msi installer from here. It is recommended to run the installer with administrator privileges. Point your installation directory to program files:
C:\Program Files\Python26
Create a system variable PYTHON_HOME and point it to the python installation directory. Append the following to PATH system variable:
;%PYTHON_HOME%;%PYTHON_HOME%\Scripts
Restart your computer so the environment changes take place.

Setuptools and easy_install

Setuptools available here. Download exe version and launch it. Once installer completes you will have easy_install available in %PYTHON_HOME%\Scripts directory.

MinGW

The easy_install needs C++ compiler in order to compile the C extensions that likely be distributed as source along with the python source. MinGW - is a native Windows port of the GNU Compiler Collection (GCC). You can download it from here. You need to select two options during install:
  • g++ compiler
  • MinGW Make
Point your installation directory to program files:
C:\Program Files\MinGW
Add the following to %PYTHON_HOME%\Lib\distutils\distutils.cfg file:
[build]
compiler=mingw32

Virtualenv

Virtual python environment builder can be installed this way:
easy_install virtualenv
Once you are done you can create isolated environment:
virtualenv --no-site-packages devenv
Please note that you must to run python, easy_install from your environment Scripts directory. You must manually copy %PYTHON_HOME%\Lib\distutils\distutils.cfg file to your environment e.g. devenv\Lib\destutils in order to be able compile C extension in your isolated environment.