Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.


  Search this Thread
Old 01-23-2013, 01:20 AM   #1
Senior Member
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,506

Rep: Reputation: 100Reputation: 100
Keeping size of VM file down - QEMU/KVM guest running Centos 6, inside Centos 6 host

Hi guys

I'm running a Centos 6 physical host with a virtual QEMU KVM Centos 6 machine guest.

E. g. a "Centos inside a Centos".

The KVM file format is a qcow2 file.

I backup by periodically (once a day) stopping the VM and copying the qcow2 file away to another computer. The file is about 24GB in size (when creating the qcow2 file, I set its max size to 100GB).

However, as I use the VM, the file is slowly growing, every day (obviously) as it runs and log files are created, etc. E. g. slowly (but still) the backup is taking longer as the file grows.

How can I keep the size of the file to the minimum? E. g. I already am doing this in a cronjob at night inside the VM to try and keep the disk image size down:

00 23 * * * rm -rf /var/log/samba/*.old
01 23 * * * rm -rf /var/log/boot/log-*
02 23 * * * rm -rf /var/log/cron-*
03 23 * * *rm -rf /var/log/maillog-*
04 23 * * *rm -rf /var/log/messages-*
05 23 * * *rm -rf /var/log/secure-*
06 23 * * *rm -rf /var/log/spooler-*
07 23 * * *rm -rf /var/log/Xorg.*.log.old
08 23 * * *rm -rf /var/log/dmesg.old*
09 23 * * *rm -rf /var/log/audit/audit.log.*
10 23 * * *rm -rf /var/named/data/*
What else can I do to trim logs / other things to keep the size of the VM as small as possible by having no superfluous log files / text logs being created in the Centos 6 guest?
Old 01-24-2013, 02:59 PM   #2
Registered: Mar 2008
Posts: 17,000

Rep: Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513Reputation: 2513
Might look at using the change feature. Save the original file and then a smaller file of only changes ought to be saved. I have not tried this but in other vm's it works. The qcow2 format and qcow3 ought to support this.

Two things are going on. One is that you start with a nothing of a file. Then you load on an OS and apps and the file grows to match. Then you make changes both in terms of data like logs an such but maybe also swap files and temp locations that needed to be created at the time. In other vm formats you can undo or compress it back. I'd think qemu could do that but I haven't seen it.

It could be that you already have change enabled and that is what is growing.
Old 01-24-2013, 03:22 PM   #3
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
virt-sparsify is the answer.

a longer approach is:
in the guest:
1. dd if=/dev/zero of=/zerofile
2. wait for it to fill the disk and fail
3. rm -f /zerofile
4. init 0

on the host use qemu-img convert on the disk image (from qcow2 to qcow2 is fine), delete the original and replace it with the converted image

qemu-img convert, when directed at a qcow2 image file, will not copy any blocks containing zeroes, so you end up with a tightly sparse file


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CentOS 6.3 kvm-qemu problem with Debian guest zoltan1 Linux - Virtualization and Cloud 2 10-25-2012 06:45 PM
KVM Guest network unable to connect to Host in CentOS-6.3 mglaris Linux - Virtualization and Cloud 5 10-05-2012 05:01 AM
[SOLVED] Qemu-kvm file sharing Linux host Xp guest problems Linux.tar.gz Linux - Virtualization and Cloud 6 11-23-2010 05:57 AM
Share between Qemu-Kvm host and guest Alexvader General 1 06-13-2010 03:07 PM
[SOLVED] Qemu kvm : No eth0 inside a Slackware-13.0 guest, although listed in lspci and lsmod Linux.tar.gz Slackware 9 02-08-2010 06:36 PM > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 06:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration