How to run zerofree on Centos7

General support questions
Post Reply
jcobban
Posts: 16
Joined: 2015/07/20 01:37:30

How to run zerofree on Centos7

Post by jcobban » 2016/10/01 23:43:52

I am trying to compress a virtualbox vm containing a Centos7 system. Following advice from the network I believe that I have to run zerofree (or equivalent) to zero the contents of all of the unused blocks on the file systems so that when the .vdi is compressed it will be as small as possible.

I have rebooted the system in rescue mode, but when I try to remount the file system in read-only mode I get mount point / is busy:

Code: Select all

#df
Filesystem                            1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos_centos7server-root  37820372 7415020  30401535  20% /
...
/ve/mapper/centos_centos7server-home   18462720 2495744  15966976  14% /home
# mount -o remount,ro /dev/mapper/centos_centos7server-root
mount: / is busy
How can I safely zero out the unused blocks in these two filesystems so I can compress the .vdi?

jcobban
Posts: 16
Joined: 2015/07/20 01:37:30

Re: How to run zerofree on Centos7

Post by jcobban » 2016/10/02 01:47:43

I now realize that I cannot use zerofree because zerofree only works for ext filesystems, and my Centos7 system is using xfs as shown in fstab:

Code: Select all

/dev/mapper/centos_centos7server-root /                       xfs     defaults        0 0
UUID=9a05d384-4daa-4db7-9204-dddaf2e0090f /boot                   xfs     defaults        0 0
/dev/mapper/centos_centos7server-home /home                   xfs     defaults        0 0
/dev/mapper/centos_centos7server-swap swap                    swap    defaults        0 0
So how can I shrink the .vdi for this system?

User avatar
avij
Forum Moderator
Posts: 2711
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: How to run zerofree on Centos7

Post by avij » 2016/10/02 06:52:20

dd if=/dev/zero of=/tmp/empty.dd bs=1048576; rm /tmp/empty.dd works on every filesystem. You may want to repeat that with of=/home/empty.dd to take care of the /home partition.

Post Reply