LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
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.

Notices

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

Rep: Reputation: 87
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:

Code:
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/named.run-*
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
jefro
Guru
 
Registered: Mar 2008
Posts: 11,076

Rep: Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362
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
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 827

Rep: Reputation: 91
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
 
  


Reply


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


All times are GMT -5. The time now is 08:52 AM.

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