Kay Thomas Development

Navigation

How to fix "mounting [lvm-partition] on /sysroot failed: I/O error"

March 18, 2021

Recently, after booting up my laptop after it ran out of power, I ran into this error after being dumped into the initramfs emergency shell:

mount: mounting /dev/mapper/vg0-root on /sysroot failed: I/O error
This ended up happening because of some invalid blocks on my lvm partition (I have a fully encrypted LVM on LUKS setup on my machine). Here's how I was able to fix it (this was on Alpine Linux, hopefully it helps with other distros too):

Flash your distro's live image to a USB drive and boot into it

You need to be running an external environment to repair your partition.

Install the necessary packages

For me, this was lvm2, cryptsetup, and e2fsprogs:
apk add lvm2 cryptsetup e2fsprogs

Setup LUKS partition

In my case, /dev/sda2 was my LUKS container partition:
cryptsetup luksOpen /dev/sda2

Activate the logical volumes

vgchange -ay

vgscan with --mknodes

I found that this was needed for the repair to work. After running this command:
vgscan --mknodes
And running blkid, I found three new entires, one of them being:
/dev/dm-3
This entry had the same UUID as my /dev/mapper/vg0-root partition, so I knew this is the one I needed to repair.

Run fsck to fix the partition

Since my partition was an ext4 partition:
fsck -t ext4 /dev/dm-3
In my case, this detected some journal checksum errors that this program was able to fix. After fixing them, I was able to boot into my machine again. I hope this helps anyone running into this problem!