1、准备一个linux盘
2、进入linux rescue
3、重建initrd
在紧急修复模式下输入
chroot /mnt/sysimage
mkinitrd -f /boot/initrd-uname.img
uname //uname依照自己的情况输入,这里我加入-f是强制,懒得mv了
reboot
以下是原文:
How to recover Linux from booting failed because of LVM change?
I have a CentOS Linux test server, now because of some change and
upgrading, the hard disks changed from /dev/hda to /dev/sda, and
because of it, the server could not boot up.
I only have 2 partitions, /dev/sda1 is /boot, which is ext2 I
think, then /dev/sda2 is a lvm partition, it has 2 logical volumes,
one is LogVol00 mapped as /, another is LogVol01 as swap.
So I boot up with a rescue cd, which could rescan the pv and lv
by:
pvscan
vgchange -ay
Now I could mount the lvs, but if I reboot to CentOS again, it
still fail.
Which file should I change on my hard disk so that it could update
itself to know now /dev/hda is /dev/sda?
Thanks,
Steve
Clarification added December 21, 2009:
ok, to make it more clear:
I've changed /etc/fstab and /boot/grub/menu.1st
They all pointing to /dev/VolGroup00/LogVol00, which is ok.
The problem is VGs are not updated/refreshed to see the PVs which
are changed.
I want to sync the VG settings or recreate the VG so it sees the
correct PVs which are on /dev/sda now. How to manually change some
files to make it work? as my centos could not boot up any more.
Clarification added December 22, 2009:
Hi all,
As Bil suggested, I tried chroot, here is the steps:
# modprobe dm-mod
# pvscan
# vgchange -ay
# mount /dev/sda1 /boot
# mount /dev/VolGroup00/LogVol00 /mnt/sda2
# mount -t proc none /mnt/sda2/proc
# mount -t sysfs none /mnt/sda2/sys
# mount -o bind /dev /mnt/sda2/dev
# chroot /mnt/sda2
# pvscan
# vgchange -ay
# exit
# umount /mnt/sda2/{proc,sys,dev}
# umount /mnt/sda2
# reboot
Every steps are successfully done, all seems
good, but guess what? the problem is still the same after
reboot.
Here is the error message:
...
kernel /vmlinuz-xxx ro root=/dev/VolGroup00/LogVol00 rhgb
quiet
...
initrd /initrd-xxx.img
...
Momory for crash kernel (0x0 to 0x0) notwithin permissible
range
...
Red Hat nash version 5.1.19.6 starting
Reading all physical volumes. This may take a while...
Volume group "VolGroup00" not found
Unable to access resume device (/dev/VolGroup00/LogVol01) # this is
the swap
mount: could not find filesystem '/dev/root'
setuproot: moving /dev failed: no such file or directory
setuproot: error mounting /proc: no such file or directory
setuproot: error mounting /sys: no such file or directory
switchroot: mount failed: no such file or directory
kernel panic - not syncing: attempted to kill init!
Oh man, is there anything did I missed?
Clarification added December 22, 2009:
OK, Great, I've fixed it by rebuild initrd, thanks to all you
experts, :D fstab, grub are all ok, the problem is with initrd. Here is what I
did: # modprobe dm-mod # pvscan # vgchange -ay # mount /dev/VolGroup00/LogVol00 /mnt/sda2 # mount -t proc none /mnt/sda2/proc # mount -t sysfs none /mnt/sda2/sys # mount -o bind /dev /mnt/sda2/dev # chroot /mnt/sda2 # mount /dev/sda1 /boot # pvscan # vgchange -ay #cd /boot #mv initrd-2.6.18-164.6.1.el5.img initrd.bak
#mkinitrd /boot/initrd-2.6.18-164.6.1.el5.img
2.6.18-164.6.1.el5
#grub-install --recheck /dev/sda # exit # umount /mnt/sda2/{proc,sys,dev} # umount /mnt/sda2/boot # umount /mnt/sda2 # reboot Just for your reference, here are the booting error
message: ... kernel /vmlinuz-xxx ro root=/dev/VolGroup00/LogVol00 rhgb
quiet ... initrd /initrd-xxx.img ... Momory for crash kernel (0x0 to 0x0) notwithin permissible
range ... Red Hat nash version 5.1.19.6 starting Reading all physical volumes. This may take a
while... Volume group "VolGroup00" not found Unable to access resume device (/dev/VolGroup00/LogVol01) # this is
the swap mount: could not find filesystem
'/dev/root' setuproot: moving /dev failed: no such file or
directory setuproot: error mounting /proc: no such file or
directory setuproot: error mounting /sys: no such file or
directory switchroot: mount failed: no such file or
directory kernel panic - not syncing: attempted to kill
init! Thanks again, Linux gurus!~~~ Steve