My qcow2 VM image for Home Assistant seems corrupted, thoughts?


Go to solution Solved by ghost82,

Recommended Posts

I had some issues with my server. Longs story short, I now have a seemingly corrupted qcow2 image file.

 

Every time I try to use it it either doesn't load or crashes my system. Tried to copy it to my windows machine but it fails part way through.

 

Is there any way to open it up or search through the files? I'm desperately trying to get my backups hidden inside and really don't want to start from scratch again.

 

Any help would be greatly appreciated.

Link to comment

You can use qemu-nbd command line.

First backup your qcow2 file.

Then in a terminal:

Load kernel module:

modprobe nbd max_part=8

Create nbd0 block device:

qemu-nbd --connect=/dev/nbd0 /replace/with/path/to/file.qcow2

Use fdisk to list partitions and see if you get any output:

fdisk -l /dev/nbd0

Yiu can also use fsck to try to repair partitions:

fsck /dev/nbd0p1

nbd0p1 being partition 1.

 

You can also mount the partition (in this example nbd0p1) somewhere:

mount /dev/nbd0p1 /mnt/somepoint/

 

Once done, disconnect:

qemu-nbd --disconnect /dev/nbd0

 

Edited by ghost82
Link to comment

I did the first 2 commands and received this on the 3rd.

 

fdisk -1 /dev/nbd0
fdisk: invalid option -- '1'

 

I tried the first 2 again and received this message. I assume this means the first 2 commands worked.

 

qemu-nbd: Failed to blk_new_open '/mnt/disks/00000000000000001358/domains/home_assistant/haos_ova-7.5.qcow2': Failed to get "write" lock
Is another process using the image [/mnt/disks/00000000000000001358/domains/home_assistant/haos_ova-7.5.qcow2]?

 

Link to comment

I tried fsck /dev/nbd0p1 and received this message.

 

fsck /dev/nbd0p1
fsck from util-linux 2.37.4
fsck.fat 4.2 (2021-01-31)
Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
[12?q]? 

 

Should I go ahead and try to remove dirty bit?

 

Thanks for the help btw 👍

Link to comment
6 hours ago, RyanServer711 said:

I had some issues with my server. Longs story short, I now have a seemingly corrupted qcow2 image file.

 

Every time I try to use it it either doesn't load or crashes my system. Tried to copy it to my windows machine but it fails part way through.

 

Is there any way to open it up or search through the files? I'm desperately trying to get my backups hidden inside and really don't want to start from scratch again.

 

Any help would be greatly appreciated.


I've had loads of trouble in the past with the HA qcow2 image corrupting. I've always kept a spare backup qcow2 after i've set HA how i need it, and while you are at it run the Google drive backup pluygin on HA. Its also saved me before to load back an old config. On a few occasions its been the boot config which got messed up on the VM, so diving into the virtual bios and resetting the boot device has fixed it, but normally i just blow away the old qcow2 and recover from the backup image. 

Link to comment

This is what I have with the correct list command

Device        Start      End  Sectors  Size Type
/dev/nbd0p1    2048    67583    65536   32M EFI System
/dev/nbd0p2   67584   116735    49152   24M Linux filesystem
/dev/nbd0p3  116736   641023   524288  256M Linux filesystem
/dev/nbd0p4  641024   690175    49152   24M Linux filesystem
/dev/nbd0p5  690176  1214463   524288  256M Linux filesystem
/dev/nbd0p6 1214464  1230847    16384    8M Linux filesystem
/dev/nbd0p7 1230848  1427455   196608   96M Linux filesystem
/dev/nbd0p8 1427456 67108830 65681375 31.3G Linux filesystem

 

Also I did the dirty bit removal on this copy of qcow2

Edited by RyanServer711
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.