How to run fsck on guest VMs from KVM
Solution 1:
install libguestfs:
# yum install libguestfs-tools
use guestfish to open the disk image:
# guestfish -a /path/to/diskimage.img
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
<fs> run
<fs> list-filesystems
/dev/vda1: ext4
/dev/system/lv_root: ext4
/dev/system/lv_swap: swap
and fsck the problematic filesystem:
<fs> fsck /dev/system/lv_root
fsck should have 2 parameter(s)
type 'help fsck' for help on fsck
<fs> fsck ext4 /dev/system/lv_root
...
good luck!
Solution 2:
You might be able to mount the file on the loopback interface and fsck it. From the site www.ingent.net/en/tag/kvm/ , use:
losetup -f
/dev/loop0
...to see that loop0 here is the next free device, then assign the disk image to that point.
losetup /dev/loop0 disk.raw
kpartx is used to create devices to access it.
kpartx -av /dev/loop0
Then you should be able to use fsck.
fsck.ext3 -f /dev/mapper/loop0p1
fsck.ext3 -f /dev/mapper/loop0p2
...and so on. The page is about converting systems to run on KVM, but this part cited above may put you on track to do an fsck repair; I'd add the caution that you should do this with a copy of your image file instead of the base image file, just in case something goes wrong.
Solution 3:
Besides what Bart Silverstrim suggested, I can see two ways:
- use libguestfs to mount and manipulate the images
- boot the VM with a liveCD ISO attached, and either reset the fsck flag or run it using the liveCD