7

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

3 Answers 3

13

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!

4
  • +1 looks like an interesting set of tools to try out
    – Coops
    Apr 17, 2012 at 13:55
  • Broken in debian7 for me.
    – sjas
    Jun 19, 2015 at 13:55
  • 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.
    – user30747
    Oct 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
    – sdjuan
    Sep 10, 2019 at 5:12
3

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.

5
  • This will only work on raw images, not qcow2
    – dyasny
    Apr 17, 2012 at 12:48
  • Long shot, the image could be converted to raw, fsck'd, then converted back. Roundabout, but could work. Apr 17, 2012 at 12:54
  • 1
    might take days, if the image is large and/or is on a slow lun
    – dyasny
    Apr 17, 2012 at 16:28
  • 3
    shrug if it works when other options fail...it's still something that could be tried. Apr 17, 2012 at 16:44
  • 2
    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 Mar 17, 2016 at 22:19
1

Besides what Bart Silverstrim suggested, I can see two ways:

  1. use libguestfs to mount and manipulate the images
  2. boot the VM with a liveCD ISO attached, and either reset the fsck flag or run it using the liveCD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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