Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to run zerofree on Ubuntu 11.04 so that I can compact the VirtualBox vdi image using:

VBoxManage modifyhd Ubuntu.vdi --compact

In order to run zerofree the disk image has be mounted as read-only. I'm following these instructions which says to use this to remount as read-only from the recovery mode (Drop to root shell prompt):

mount -n -o remount,ro -t ext2 /dev/sda1 /

But when I do this I get the error:

mount: / is busy

Any ideas on how to do this?

Follow up: Following Jari's answer and this post by running these commands resolves the issue.

service rsyslog stop
service network-manager stop
killall dhclient
share|improve this question

3 Answers 3

up vote 8 down vote accepted

Some processes are keeping files open for writing. These could be, for example, programs that write logs, like rsyslogd, networking tools, like dhclientor something else. Shutting these down one by one and trying the remount might work.

You can find processes that use certain files by using the program fuser. For example, fuser -v -m / will return a list of processes. However, I am not sure if it is one of these which keeps the file system busy.

share|improve this answer

You can only remount the filesystem read-only if there is no process that has a file open for writing. Run lsof / to see what processes have files open on the root filesystem. Files open for writing will be indicated in the FD column. You can filter these with

lsof / | awk '$4 ~ /[0-9].*w/'

To filter the process IDs automatically, parse the output of lsof -F pa:

lsof -F pa /home | awk '/^p/ {pid = substr($0, 2)} /^a.*w/ {print pid}'
share|improve this answer

I assume you try to run the mount command in the VM. Anyway you probably have a different root partition than the author of the forum post.

Try:

mount -o ro,remount /

Which does not depend on the fs or mount option. If this does not work you can also try to determine your root fs with grep " / " /proc/mounts or cat /proc/cmdline. If your root filesystem is for example /dev/mapper/system-rootfs you can use:

mount -o ro,remount /dev/mapper/system-rootfs /
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.