How do fsck at corrupted vm guest in Oracle OVM or Xen Server from vm images.

Hello guys!

Sometimes after an incident in Oracle OVM could be that some virtual machines will go in corrupted and it will need to do an fsck about one o more filesystems.
Often we don’t have the possibility to use an live cd (ex ubuntu,debian,oracle linux or redhat) for to make a filesystem check.

But don’t worry! i will explain you an method how to do fsck without use a live cd.

  • Shutdown vm
xm shutdown domainname
  • how many partitions the image has.
file /OVS/Repositories/0004fb00000300009471703af52bc769/VirtualDisks/0004fb00001200006ff9f87b9279c6dd.img
/OVS/Repositories/0004fb00000300009471703af52bc760/VirtualDisks/0004fb00001200006ff9f87b9279c6dr.img: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 2048, 208896 sectors; partition 2: ID=0x83, starthead 0, startsector 210944, 24954880 sectors, code offset 0x48

we can see this vm images has two partitions and consequently will make the filesystem check for each partition.

  • Mount with devloop the virtual machine images
losetup /dev/loop7 -o $((2048 * 512)) /OVS/Repositories/0004fb00000300009471703af52bc769/VirtualDisks/0004fb00001200006ff9f87b9279c6dd.img

The “variable” $((2048 * 512)) are the start sector (2048) and size of block (default is 512) so will do two mount one for the sector 2048 and one for the sector 210944, because the virtual machine images has two partitions.

  • Execute the fsck depending the filesystem used.
e2fsck -f -y /dev/loop7

fsck.xfs /dev/loop7
  • Umount the loop partition
umount /dev/loop9

Will do the same steps for each partition.

losetup /dev/loop7 -o $((210944 * 512)) /OVS/Repositories/0004fb00000300009471703af52bc769/VirtualDisks/0004fb00001200006ff9f87b9279c6dd.img
e2fsck -f -y /dev/loop7
umount /dev/loop

I hope this guide helps you as it has helped me.

This guide could be work also with images kvm. But I will do a specific post for KVM virtualization Oracle and Non-Oracle (Ovirt or Redhat)

Leave a Reply

Your email address will not be published.