Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

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!

share|improve this answer
    
+1 looks like an interesting set of tools to try out –  Coops Apr 17 '12 at 13:55
add comment

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.

share|improve this answer
    
This will only work on raw images, not qcow2 –  dyasny Apr 17 '12 at 12:48
    
Long shot, the image could be converted to raw, fsck'd, then converted back. Roundabout, but could work. –  Bart Silverstrim Apr 17 '12 at 12:54
    
might take days, if the image is large and/or is on a slow lun –  dyasny Apr 17 '12 at 16:28
1  
shrug if it works when other options fail...it's still something that could be tried. –  Bart Silverstrim Apr 17 '12 at 16:44
add comment

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
share|improve this answer
add comment

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.