Fixing virtual disk problems

What if your grub loader on a virtual machine is broken – or you need to repair or resize a filesystem in one of your virtual machines?

You want to check the storage of your virtual machines on your virtualization server.

  1. shutdown the virtual machine (or virsh destroy $machine) to make sure nothing else is using the file system
  2. Check for the next available loopback device on your virtualization server: losetup -f  (let’s asume /dev/loop0 for the next steps)
  3. Now attach the device (disk) from your virtual machine as loopback device on your server: losetup /dev/loop0 /dev/mapper/$DEVICE
  4. Use kpartx to discover and device-map the partitions: kpartx -av /dev/loop0
  5. Check the partitioning: fdisk -l /dev/loop0
  6. Extend the partitioning, if you like/need (see the man pages for fdisk and resize2fs, if needed)
  7. Run fsck on the filesystem: fsck -vc /dev/mapper/loop0p2
  8. Mount the filesystem into your local system: mount /dev/mapper/loop0p2 /mnt
  9. Do whatever you want there (or chroot into the filesystem after bind-mounting /proc /sys and /dev for example)
  10. Detach the device from your local system: umount /mnt
  11. Delete the partition mapping for the device: kpartx -dv /dev/loop0
  12. Detach the loop device from your local system: losetup -d /dev/loop0
Advertisements

About Lars Vogdt

This is the private blog space of Lars Vogdt, the topics will be in first place work related.
This entry was posted in Infrastructure, openSUSE, SUSE Linux Enterprise, virtualization and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s