I have a KVM server and one of my guest machine is crashed and prompting form fsck check. Now I dont have console access or dont have the root access of the guest VM.
Is there any way that I can run the fsck from the hypervisor ?
I use centos 6.1 as my hypervisor
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!
+1 looks like an interesting set of tools to try out
Broken in debian7 for me.
This looked promising, but unfortunately I get the following error at the time I type “run”: libguestfs: error: /usr/bin/supermin exited with error status 1.
. This is happening using Ubuntu 16.04.
– user30747Oct 17, 2016 at 15:39
when I typed “run” I got the error “libvirt: XML-RPC error : Failed to connect socket to ‘/var/run/libvirt/libvirt-sock’: No such file or directory…” but that was fixed by finding that libvirtd was not running. After “systemctl start libvirtd” it worked. Thanks @mrc
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.
This will only work on raw images, not qcow2
Long shot, the image could be converted to raw, fsck’d, then converted back. Roundabout, but could work.
– Bart SilverstrimApr 17, 2012 at 12:54
might take days, if the image is large and/or is on a slow lun
shrug if it works when other options fail…it’s still something that could be tried.
– Bart SilverstrimApr 17, 2012 at 16:44
to complete the answer: when finished with repairing, the partition mapping and loop device can be removed like this: sync; kpartx -dv /dev/loop0; losetup -d /dev/loop0
– maxschlepzigMar 17, 2016 at 22:19
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
this source from : https://serverfault.com/questions/380186/how-to-run-fsck-on-guest-vms-from-kvm