View previous topic :: View next topic |
Author |
Message |
grooveman Veteran
Joined: 24 Feb 2003 Posts: 1217
|
Posted: Sat Jan 02, 2010 8:33 pm Post subject: lvm (lvm2) root on Gentoo |
|
|
See my post below to find out how to do this without going through all this mess -- it is much simpler!
----------------------------------------------------------------------------------------------------------------------------------------------
Hello.
I have gotten this to work, but I'm not really happy with the "solution", as I feel it is more of a work-around. I am writing this for two reasons:
1) I hope to show people who are desperate a way to get this to work
2) I'm hoping someone will post with the proper Gentoo way of doing this, as I have found a surprising lack of documentation concerning this issue.
There used to be a great howto on the wiki before it took a nose-dive a little more than a year ago. No one has bothered to re-post this howto, but I found it cross-posted here. Unfortunately, since the Linux gods have decreed that initramfs is now the preferred way of doing this, and not initrd, this howto is no longer very helpful. The genkernel way discussed in this document is likewise depricated, the lvm2create_initrd script no longer works as indicated there, and the cowboy way is also outdated --and is just too much to go through every time you upgrade your kernel anyway.
This post is not intended to be a step-by-step walk-through of how to implement lvm2 on a gentoo system -- there is pleny of documentation out there for that. Instead, I am going to focus just on what it takes to boot to an lvm root.
So here is what I did to get this to "work":
Quote: |
I found it was important to avoid using the symbolic link for your vgs under /dev as the preboot environment does not seem to acknowledge them. Instead, I used the "real" device under /dev/mapper. It is important that your fstab reflect this nuance or boot will fail.
In my case, the root device is /dev/mapper/vg-slash, so my fstab line looks like this:
Code: | /dev/mapper/vg-slash / ext3 noatime 0 1 |
To get this to work, you will need an mdadm.conf. If you don't have one, make it like this:
Code: | mdadm --detail --scan >/etc/mdadm.conf |
I emerged genkernel.
Then, I issued this command:
Code: | genkernel --dmraid --lvm --real-root=/dev/mapper/vg-slash initramfs |
It created this initramfs: /boot/initramfs-genkernel-x86_64-2.6.31-gentoo-r6
It would not boot this way. It could not find the root fs, because, for some reason, the md devices and the vg devices were not being started. So I hacked the init script to ensure that they start.
I made a tmp dir, and copied the initramfs there like this:
Code: | cp /boot/initramfs-genkernel-x86_64-2.6.31-gentoo-r6 tmpdir/initramfs-genkernel-x86_64-2.6.31-gentoo-r6.gz
(It is important to note that despite its lack of a "gz" extension, this file is gziped, so I added the extension so gunzip would recognize it) |
I changed to tmpdir, and unzipped the initramfs file:
Code: | gunzip initramfs-genkernel-x86_64-2.6.31-gentoo-r6.gz |
I then extracted the contents of this initramfs file like so:
Code: | cpio -i <initramfs-genkernel-x86_64-2.6.31-gentoo-r6
rm initramfs-genkernel-x86_64-2.6.31-gentoo-r6 |
Still in my tmpdir, I entered the etc dir therein and copied my mdadm.conf there:
Code: | cd etc
cp /etc/mdadm.conf . |
Next, I hacked the init script, which is directly under the tmpdir:
I found the line "startVolumes", and immediatly after that I injected:
Code: | #My Hak
mdadm --assemble --scan
vgscan
vgchange -a y
#End My Hak |
I quit my editor, then made the new initramfs (overwriting the original):
Code: | find . |cpio -H newc -o >/boot/initramfs-genkernel-x86_64-2.6.31-gentoo-r6
cd /boot
gzip initramfs-genkernel-x86_64-2.6.31-gentoo-r6
mv initramfs-genkernel-x86_64-2.6.31-gentoo-r6.gz initramfs-genkernel-x86_64-2.6.31-gentoo-r6 |
My grub.conf looks like this:
Code: | default 0
timeout 3
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title=Gentoo
root (hd0,0)
kernel /boot/kernel udev dolvm root=/dev/mapper/vg-slash init=/sbin/init
initrd /initramfs-genkernel-x86_64-2.6.31-gentoo-r6 |
|
When you boot, you will notice a failure when init goes to start up your md devices. This is because my method above has already started them. Clearly, this is not the way the designers intended this to work, which is why I hope that someone smarter than me will post the "appropriate solution". If that doesn't happen... well at least this post may be of help to someone in the future. _________________ To look without without looking within is like looking without without looking at all.
Last edited by grooveman on Sun Jan 03, 2010 5:17 pm; edited 1 time in total |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Sat Jan 02, 2010 11:05 pm Post subject: |
|
|
That's probably not the gentoo way of doing this, but it's a generic way for sure.
Note that I have lvm confugure on top of a LUKS encrypted device. But you
should be able to just take what you need.
Code: | grep initramfs /usr/src/linux/.config
CONFIG_INITRAMFS_SOURCE="../initramfs/makefile"
|
Code: | ls /usr/src/initramfs/ -l
-rwxr-xr-x 1 root root 1131696 Jun 26 2009 busybox-1.13.4
-rw-r--r-- 1 root root 25230 Jun 26 2009 config-busybox-1.13.4
-rw-r--r-- 1 root root 2823 Jun 23 2009 fr.keymap
-rw-r--r-- 1 root root 5776 Jul 16 20:17 linuxrc-sam
-rw-r--r-- 1 root root 3805 Nov 9 00:10 makefile
|
/usr/src/initramfs/makefile: | # initramfs makefile
# /dev directory
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
nod /dev/null 0600 0 0 c 1 3
nod /dev/tty 0600 0 0 c 5 0
nod /dev/tty0 0600 0 0 c 4 0
# for framebuffer
nod /dev/tty1 0600 0 0 c 4 1
nod /dev/zero 0600 0 0 c 1 5
nod /dev/mem 0600 0 0 c 1 1
# Empty dirs
dir /root 0700 0 0
dir /proc 0755 0 0
dir /sys 0755 0 0
dir /tmp 1755 0 0
# Init
file /init /usr/src/initramfs/linuxrc-sam 0755 0 0
# /bin directory
dir /bin 0755 0 0
file /bin/busybox /usr/src/initramfs/busybox-1.13.4 0755 0 0
slink /bin/ash /bin/busybox 0755 0 0
slink /bin/cat /bin/busybox 0755 0 0
slink /bin/chroot /bin/busybox 0755 0 0
slink /bin/cp /bin/busybox 0755 0 0
slink /bin/fsck /bin/busybox 0755 0 0
slink /bin/loadkmap /bin/busybox 0755 0 0
slink /bin/ls /bin/busybox 0755 0 0
slink /bin/mdev /bin/busybox 0755 0 0
slink /bin/mknod /bin/busybox 0755 0 0
#slink /bin/modprobe /bin/busybox 0755 0 0
slink /bin/mount /bin/busybox 0755 0 0
slink /bin/mv /bin/busybox 0755 0 0
slink /bin/reboot /bin/busybox 0755 0 0
slink /bin/sleep /bin/busybox 0755 0 0
slink /bin/switch_root /bin/busybox 0755 0 0
slink /bin/umount /bin/busybox 0755 0 0
# /sbin directory
dir /sbin 0750 0 0
file /sbin/resume /usr/lib64/suspend/resume 0755 0 0
file /sbin/cryptsetup /sbin/cryptsetup 0755 0 0
file /sbin/lvm /sbin/lvm.static 0755 0 0
file /sbin/v86d /sbin/v86d 0755 0 0
slink /sbin/vgchange /sbin/lvm 0755 0 0
slink /sbin/vgscan /sbin/lvm 0755 0 0
#slink /sbin/fsck.ext3 /sbin/e2fsck 0755 0 0
#/etc directory
dir /etc 0755 0 0
file /etc/fr.keymap /usr/src/initramfs/fr.keymap 0644 0 0
file /etc/suspend.conf /etc/suspend.conf 0644 0 0
file /etc/mtab /dev/null 0644 0 0
# modules
#dir /lib 0700 0 0
#dir /lib/modules 0700 0 0
#dir /lib/modules/2.6.31.3 0700 0 0
#file /lib/modules/2.6.31.3/etc/fr.keymap /usr/src/initramfs/fr.keymap 0644 0 0
# Newroot
dir /newroot 0700 0 0
|
/usr/src/initramfs/linuxrc-sam: | #!/bin/ash
# Samlt aka truc
# optional arguments: real_init= real_root= crypted_device= verbose noresume
INIT_ARGS=
INIT="/sbin/init"
ARGS_ROOT_MOUNT=
NEWROOT="/newroot"
CRYPTED_DEVICE="/dev/sda4"
REAL_ROOT="/dev/mapper/gen-gentoo"
KEYMAP="/etc/fr.keymap"
VERBOSE='no'
# delay before starting the real_init
SLEEP=0
# suspend2disk:
RESUME='yes'
# emergency shell
START_SHELL="no"
verbose() { # {{{
[ "x$VERBOSE" = "xyes" ] && echo " * $@"
}
# }}}
die() { # {{{
verbose "Dying"
[ $# -ne 0 ] && echo "$@"
# Enable job control for the shell
#[ ! -c /dev/tty ] && \
#mknod /dev/tty c 5 0 && chown 0:tty /dev/tty
chown 0:tty /dev/tty
# Try to find a minimal shell
exec /bin/busybox ash
echo "FATAL ERROR: Could not even die elegantly"
echo "trying to force a reboot in 5 seconds"
sleep 5
reboot -f
}
# }}}
do_parse_kernel() { # {{{
# ok this one will be printed out only if VERBOSE is already defined in that file..
verbose "Parsing kernel line"
local CMD
for CMD in $(cat /proc/cmdline)
do
case "$CMD" in
crypted_device=*)
CRYPTED_DEVICE="${CMD#crypted_device=}"
;;
real_init=*)
INIT=${CMD#real_init=}
;;
real_root=*)
REAL_ROOT="${CMD#real_root=}"
;;
ro|rw)
ARGS_ROOT_MOUNT="-o $CMD"
;;
initramfs_verbose)
VERBOSE='yes'
;;
initramfs_noresume)
RESUME='no'
;;
initramfs_sleep*)
SLEEP="${CMD#initramfs_sleep}"
SLEEP="${SLEEP#=}"
SLEEP="${SLEEP//[^0-9]}"
[ "x${SLEEP}" = 'x' ] && SLEEP=10
;;
initramfs_startsh)
START_SHELL='yes'
;;
*)
INIT_ARGS="${INIT_ARGS} ${CMD}"
;;
esac
done
return 0
}
# }}}
do_dev() { # {{{
verbose "Populating /dev from sys"
mdev -s
# handle hotplug events
echo /sbin/mdev > /proc/sys/kernel/hotplug
return 0
}
# }}}
do_keymap() { # {{{
verbose "Loading $KEYMAP"
[ -r "$KEYMAP" ] && loadkmap < "$KEYMAP"
}
# }}}
do_not_resume() { # {{{
verbose "not resuming"
SUSPEND_DEVICE=$(busybox sed '/^[[:space:]]*resume[[:space:]]\+device[[:space:]]*=[[:space:]]*/{s/// ; s/[[:space:]]\+$// ; p}' /etc/suspend.conf)
[ "x" = "x$SUSPEND_DEVICE" ] && return
mkswap ${SUSPEND_DEVICE} > /dev/null 2>&1
echo 254:0 > /sys/power/resume
return 0
}
# }}}
do_cryptsetup() { # {{{
verbose "Opening encrypted device(s)"
cryptsetup luksOpen ${CRYPTED_DEVICE} ${CRYPTED_DEVICE##*/}
}
# }}}
do_lvm() { # {{{
verbose "Enable LVM2 support"
if [ "x$VERBOSE" != "x" ]; then
vgscan --mknodes --ignorelockingfailure
vgchange -a y --ignorelockingfailure
else
vgscan --mknodes --ignorelockingfailure >/dev/null 2>&1
vgchange -a y --ignorelockingfailure > /dev/null 2>&1
fi
return 0
}
# }}}
do_fsck_root() { # {{{
verbose "fsck'ing root device[$REAL_ROOT]"
trap : SIGINT SIGQUIT
FSTAB_FILE=/dev/null fsck -C0 -p $REAL_ROOT
case $? in
0) return 0;;
1) echo " *$0* : root filesystem repaired"; return 0;;
2|3|4) echo " *$0* : root filesystem repaired, but reboot needed"
reboot || return 1;;
8) echo " *$0* : operational error"; return 0;;
32) echo " *$0* : fsck interupted"; return 1;;
*) echo " *$0* : filesystem couldn't be fixed"
sleep 20 && reboot || return 1;;
esac
return 0
:
}
# }}}
do_realroot() { # {{{
verbose "Mounting $REAL_ROOT on $NEWROOT"
mount $REAL_ROOT $NEWROOT $ARGS_ROOT_MOUNT
return $?
}
# }}}
do_sleep() { # {{{
verbose "Sleeping for '$SLEEP' second[s]"
[ "$SLEEP" -gt 0 ] && sleep "$SLEEP"
}
# }}}
do_switch() { # {{{
verbose "Switching / to $NEWROOT"
# Better make sure these exist before switching
[ ! -c "$NEWROOT/dev/console" ] && mknod "$NEWROOT/dev/console" c 5 1
[ ! -c "$NEWROOT/dev/null" ] && mknod "$NEWROOT/dev/null" c 1 3
echo > /proc/sys/kernel/hotplug
umount /sys || umount -l /sys
umount /proc || umount -l /proc
verbose "exec switch_root $NEWROOT $INIT $INIT_ARGS"
exec switch_root $NEWROOT $INIT $INIT_ARGS
}
# }}}
main() { # {{{
# this one too will be printed out only if VERBOSE is already defined in that file..
verbose " * sam initramfs"
# mount proc ASAP
mount -t proc proc /proc
umask 0077
# finish mounting
mount -t sysfs sysfs /sys
# parse kernel command line
do_parse_kernel
# populate dev from sys
do_dev
do_keymap
# Start a shell
[ x"$START_SHELL" = 'xyes' ] && { verbose 'Starting a shell' ; ash ; }
# cryptsetup
do_cryptsetup || die
# LVM2
do_lvm || die
do_fsck_root
# sleep if requested to
do_sleep
# try resuming from disk (unless explicitly said not to)
if [ "x$RESUME" = 'xyes' ]; then
resume
else
do_not_resume
fi
do_realroot
do_switch
}
# }}}
main
die
# vim: sts=3 sw=3 et foldmethod=marker :
|
And I think that's all.
Make your kernel as usual, make && make modules_install, cp the bzImage to
/boot, and in your grub.conf:
Code: | title Gentoo Linux initramfs resume
# Partition where the kernel image (or operating system) is located
root (hd0,0)
kernel /kernel-2.6.31.3e quiet
title Gentoo Linux initramfs resume
# Partition where the kernel image (or operating system) is located
root (hd0,0)
kernel /kernel-2.6.31.3a quiet i915.modeset=1
title Gentoo Linux initramfs no_resume
# Partition where the kernel image (or operating system) is located
root (hd0,0)
#kernel /kernel-2.6.29.1-initramfs3 quiet crypted_device=/dev/sda6 real_root=/dev/mapper/vg-gentoo initramfs_verbose initramfs_sleep initramfs_noresume
kernel /kernel-2.6.31.3a quiet initramfs_noresume i915.modeset=1
|
and, just for your information:
from /etc/fstab: | UUID=7376f093-d73a-4c31-b6d7-bbc84f57ab0c /boot ext2 noauto,noatime 1 2
/dev/mapper/gen-s2disk none swap sw 0 0
/dev/mapper/gen-gentoo / ext4 noatime 0 1
/dev/mapper/gen-vlog /var/log ext4 noatime 0 0
/dev/mapper/gen-home /home ext4 noatime 0 0
/dev/mapper/gen-music /media/music ext4 noatime 0 0
/dev/mapper/gen-tmp /tmp ext4 noatime 0 0
/dev/mapper/gen-vtmp /var/tmp ext4 noatime 0 0
/dev/mapper/gen-vgentoo /var/gentoo ext4 noatime 0 0
/dev/mapper/gen-usrc /usr/src ext4 noatime 0 0
/dev/mapper/gen-bkp /mnt/backup ext4 noatime,noauto 0 0
|
Hope that helps. _________________ The End of the Internet! |
|
Back to top |
|
|
grooveman Veteran
Joined: 24 Feb 2003 Posts: 1217
|
Posted: Sun Jan 03, 2010 2:33 am Post subject: |
|
|
Well that is different to be sure.... looks like you are maybe referencing this article.
I may give this a shot, thank you for the post. The way I posted does work, but if this is the new Gentoo way of doing things, I want to be compliant (I don't like the [ !! ] mucking with my pretty boot!).
It just seems to me that there should be an easier way to do this... the only reason I have to do the gymnastics above is because the genkernel seems like it is creating an initramfs that is incapable of starting/recognizing my lvm root. it seems to me that passing the --dmraid and --lvm to genkernel should take care of this, but it doesn't. I don't know if this a bug, or if I'm missing a small piece of information here. I am still vexed.
(btw -- it does look like someone has re-posted my above reference here, and it looks like it is not quiet as outdated as the link in my original post, but still not current. Not sure how I missed that on my previous searches... _________________ To look without without looking within is like looking without without looking at all. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Sun Jan 03, 2010 9:47 am Post subject: |
|
|
Well, If it can help you make your choice, I don't have any [!!] _________________ The End of the Internet! |
|
Back to top |
|
|
grooveman Veteran
Joined: 24 Feb 2003 Posts: 1217
|
Posted: Sun Jan 03, 2010 3:41 pm Post subject: |
|
|
_________________ To look without without looking within is like looking without without looking at all. |
|
Back to top |
|
|
grooveman Veteran
Joined: 24 Feb 2003 Posts: 1217
|
Posted: Sun Jan 03, 2010 5:14 pm Post subject: |
|
|
Okay, I may have figured this out. I have it working with absolutely no haks (which makes me think it as an official gentoo method, although maybe not the official method )
I issued the
Code: | genkernel --dmraid --lvm --real-root=/dev/mapper/vg-slash initramfs |
As stated above.
Then I changed my grub.conf to this:
Code: | title=Gentoo
root (hd0,0)
kernel /boot/kernel udev dolvm doload=raid1 root=/dev/vg/slash lvmraid=/dev/md3
initrd /initramfs
|
The only catch is that I still get those darn !! when the boot sequence starts up the raid device... Not sure why that is, but everything seems to function perfectly, with no haks. _________________ To look without without looking within is like looking without without looking at all. |
|
Back to top |
|
|
ndse2112 Tux's lil' helper
Joined: 21 May 2007 Posts: 100
|
Posted: Sun Jan 03, 2010 6:28 pm Post subject: |
|
|
I boot a similar configuration with my initrd generated as follows:
Code: |
genkernel --kernel-config=/usr/src/linux-2.6.31-gentoo-r3/.config --mdadm --luks --lvm2 initramfs
|
I do not notice any [!!] during boot.
Code: |
title Gentoo Linux 2.6.31-gentoo-r3
root (hd0,0)
kernel (hd0,0)/kernel-2.6.31-gentoo-r3 root=/dev/ram0 init=linuxrc ramdisk=8192 crypt_root=/dev/md2 dolvm
initrd (hd0,0)/initramfs-x86_64-2.6.31-r3
|
|
|
Back to top |
|
|
grooveman Veteran
Joined: 24 Feb 2003 Posts: 1217
|
Posted: Mon Jan 04, 2010 6:05 pm Post subject: |
|
|
hmm... still give me those two exclamations... dunno why... _________________ To look without without looking within is like looking without without looking at all. |
|
Back to top |
|
|
Roman_Gruber Advocate
Joined: 03 Oct 2006 Posts: 3846 Location: Austro Bavaria
|
Posted: Mon Jan 04, 2010 6:44 pm Post subject: |
|
|
grooveman wrote: | Okay, I may have figured this out. I have it working with absolutely no haks (which makes me think it as an official gentoo method, although maybe not the official method )
I issued the
Code: | genkernel --dmraid --lvm --real-root=/dev/mapper/vg-slash initramfs |
As stated above.
Then I changed my grub.conf to this:
Code: | title=Gentoo
root (hd0,0)
kernel /boot/kernel udev dolvm doload=raid1 root=/dev/vg/slash lvmraid=/dev/md3
initrd /initramfs
|
The only catch is that I still get those darn !! when the boot sequence starts up the raid device... Not sure why that is, but everything seems to function perfectly, with no haks. |
well loks similar like here. I use only genkernel to get my initrd image => busybox, lvm, luks is all i need rom genkernel. its pretty nice and it works |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|