This site is now 100% read-only, and retired.

XML logo

lvm in initramfs shell
Posted by drgraefy on Tue 21 Oct 2008 at 18:44
The emergency shell in the debian initramfs is a wonderful thing. I recently had to use it when I encountered some disk mounting problems when migrating system disks to a new machine. The problem I ran into was that the rootfs was on LVM on a raid array that was not properly detected during boot. I was able to use mdadm to get the raid going, but then I had to get LVM going so that I could mount the root file system and get the rest of the boot going.

However, at first glance, it appeared that the only LVM utility in the initramfs is /sbin/vgimport. This one utility was not sufficient for me to get LVM going. I remembered, though, that lvm on a full system is in fact just a single utility linked by various names:
servo:~ 0$ readlink -f $(which vgimport)
servo:~ 0$ 
It turns out that this is also true on the initramfs: the full lvm binary is available on the initramfs, it's just called 'vgimport'. To get around this, I just linked /sbin/vgimport to /sbin/lvm, and was then able to get full lvm capability with the "lvm < subcommand>" syntax.


Comments on this Entry

Re: lvm in initramfs shell
Posted by dkg (216.254.xx.xx) on Thu 23 Oct 2008 at 23:46
[ View Weblogs ]
This is really useful, thanks! I just tested creating a modified initramfs with all 42 LVM symlinks in it, and it had no perceptible effect on the size of the compressed cpio archive (my gzipped cpio archive was actually slightly smaller with the links included). You can test this yourself:
mkdir -p cleandir/root
cd cleandir/root
gzip -d < /boot/initrd.img-$(uname -r) | fakeroot -s ../frs cpio --extract
fakeroot -i ../frs -s ../frs mv sbin/vgchange sbin/lvm
for link in $(find $(dpkg -L lvm2 | grep ^/sbin/) -type l | cut -f3 -d/); do
  fakeroot -i ../frs -s ../frs ln -s lvm sbin/$link
find * | fakeroot -s ../frs cpio --create | gzip > ../initrd.img.withlvm-$(uname -r)
ls -l /boot/initrd.img-$(uname -r) ../initrd.img.withlvm-$(uname -r)

Is there any reason why these links should not be included by default, as long as lvm is being included in the initramfs? It'd certainly make things easier during recovery.

[ Parent ]

Re: lvm in initramfs shell
Posted by drgraefy (72.227.xx.xx) on Fri 24 Oct 2008 at 22:11
[ View Weblogs ]
First of all, why the would the initramfs be smaller with more links? That doesn't make any sense, does it? There has to be some difference in how you repacked the archive. Can you compare it to a repack of the archive without the extra links?

Second, about why think links aren't included by default, I have no idea. It sure would make things easier. Maybe it's worth filing a bug, but I'm not sure which package it would be against. initramfs-tools? yaird?

[ Parent ]

Re: lvm in initramfs shell
Posted by dkg (216.254.xx.xx) on Fri 24 Oct 2008 at 23:53
[ View Weblogs ]
You're right: it seems unlikely that the size would go down with more links (though it is probably possible with some compression routines).

Anyway, comparing against a clean repack of the initramfs, i get:

[0 dkg@squeak root]$ ls -l ../initrd.img.*
-rw-r--r-- 1 dkg dkg 7045782 2008-10-24 18:42 ../initrd.img.repacked-2.6.26-1-686
-rw-r--r-- 1 dkg dkg 7046618 2008-10-24 18:43 ../initrd.img.withlvm-2.6.26-1-686
[0 dkg@squeak root]$ 
so it increases in size by 836 bytes.

I think this is definitely a bug, and i'd file it against lvm2, since that package supplies /usr/share/initramfs-tools/hooks/lvm2 (that looks like the most sane place to insert the symlinks into the initrd).

[ Parent ]