Merge with git+ssh://hera.kernel.org/pub/scm/libs/klibc/klibc.git
diff --git a/usr/kinit/fstype/fstype.c b/usr/kinit/fstype/fstype.c
index fc20aef..beb7959 100644
--- a/usr/kinit/fstype/fstype.c
+++ b/usr/kinit/fstype/fstype.c
@@ -7,7 +7,7 @@
  *  FSSIZE - filesystem size (if known)
  *
  * We currently detect (in order):
- *  gzip, cramfs, romfs, xfs, luks, minix, ext3, ext2, reiserfs, jfs, swap
+ *  gzip, cramfs, romfs, xfs, luks, lvm2, minix, ext3, ext2, reiserfs, jfs, swap
  *
  * MINIX, ext3 and Reiserfs bits are currently untested.
  */
@@ -30,6 +30,7 @@
 #include "ext3_fs.h"
 #include "xfs_sb.h"
 #include "luks_fs.h"
+#include "lvm2_sb.h"
 
 /*
  * Slightly cleaned up version of jfs_superblock to
@@ -202,6 +203,26 @@
 	return 0;
 }
 
+static int lvm2_image(const void *buf, unsigned long long *blocks)
+{
+	const struct lvm2_super_block *lsb;
+	int i;
+
+	/* We must check every 512 byte sector */
+	for (i = 0; i < BLOCK_SIZE; i += 0x200) {
+		lsb = (const struct lvm2_super_block *)(buf + i);
+
+		if (!memcmp(lsb->magic, LVM2_MAGIC, LVM2_MAGIC_L) &&
+		    !memcmp(lsb->type,  LVM2_TYPE,  LVM2_TYPE_L)) {
+			/* This is just one of possibly many PV's */
+			*blocks = 0;
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 struct imagetype {
 	off_t		block;
 	const char	name[12];
@@ -214,6 +235,8 @@
 	{ 0,		"romfs",	romfs_image	},
 	{ 0,		"xfs",		xfs_image	},
 	{ 0,		"luks",		luks_image	},
+	{ 0,		"lvm2",		lvm2_image	},
+	{ 1,		"lvm2",		lvm2_image	},
 	{ 1,		"minix",	minix_image	},
 	{ 1,		"ext3",		ext3_image	},
 	{ 1,		"ext2",		ext2_image	},
diff --git a/usr/kinit/fstype/lvm2_sb.h b/usr/kinit/fstype/lvm2_sb.h
new file mode 100644
index 0000000..6c4361c
--- /dev/null
+++ b/usr/kinit/fstype/lvm2_sb.h
@@ -0,0 +1,18 @@
+#ifndef __LVM2_SB_H
+#define __LVM2_SB_H
+
+/* LVM2 super block definitions */
+#define LVM2_MAGIC_L		8
+#define LVM2_MAGIC		"LABELONE"
+#define LVM2_TYPE_L		8
+#define LVM2_TYPE		"LVM2 001"
+
+struct lvm2_super_block {
+	char 		magic[LVM2_MAGIC_L];
+	__be64		sector;
+	__be32		crc;
+	__be32		offset;
+	char		type[LVM2_TYPE_L];
+};
+
+#endif