View this PageEdit this PageUploads to this PageVersions of this PageHomeRecent ChangesSearchHelp Guide

Usar el gestor de volumenes de RHEL4 y reparar el arranque del grub legacy




Guía básica de cómo montar un volumen LVM2 en Linux:

1. Se buscan las particiones:
 pvs
2. Se hace un lvdisplay del VolGroup que haya encontrado
 lvdisplay VolGroup01
3. En este caso dice que está en "/dev/VolGroup01/LogVol00", con un LV Name de "LogVol00". Primero se generan los nodos en /dev:
 vgscan --mknodes
 /etc/init.d/lvm2 start
4. Se monta:
 mount /dev/VolGroup01/LogVol00 /data/backup_database/orig
5. Se copia lo que se tenga que copiar
(...)
6. Cuando se ha terminado, se desmonta
 umount /data/backup_database/orig
7. Y se quita el dispositivo del /dev/mapper
 lvchange -an /dev/VolGroup01/LogVol00


Reparar el arranque del grub legacy


Se supone que se ha conectado el disco a otro PC Linux y se ha montado como un chroot.

En mi caso, el disco a reparar está en /dev/sdg, con el /boot en la primara partición de dicho disco.

El disco destino está montado en /data/backup_database/orig (/boot incluído).

mount -t auto /dev/sdg6 /data/backup_database/orig
mount -t auto /dev/sdg1 /data/backup_database/orig/boot/
cd /data/backup_database/orig
sed -i "s:/dev/VolGroup00/LogVol00:/dev/sda6:g" boot/grub/grub.conf
mount --bind /dev /data/backup_database/orig/dev
chroot . /bin/bash
grub
device (hd0) /dev/sdg
root (hd0,0)
setup (hd0)
quit
exit
umount /data/backup_database/orig/dev
cd ..
umount orig/boot
umount orig


Cambiar la partición de root en el initrd


Para cambiar el disco de arranque en el initrd se han seguido estas instrucciones.

Básicamente se ha hecho un unpack del initrd y se ha ejecutado este comando para editar el init:

sed -i "s:mkrootdev /dev/root:ln -s /dev/sda6 /dev/root:g" init


mount -t auto /dev/sdg6 /data/backup_database/orig
mount -t auto /dev/sdg1 /data/backup_database/orig/boot/
cd /data/backup_database/orig/boot/
./initrd-unpack.sh initrd-2.6.9-5.EL.img.orig
cd initrd-data
sed -i "s:mount -o defaults --ro -t ext3 /dev/root /sysroot:mount -o defaults --ro -t ext3 /dev/sda6 /sysroot:g" init
cd dev
mknod sda b 8 0
mknod sda1 b 8 1
mknod sda2 b 8 2
mknod sda5 b 8 5
mknod sda6 b 8 6
cd ../..
./initrd-pack.sh initrd-2.6.9-5.EL.img
./initrd-unpack.sh initrd-2.6.9-5.ELsmp.img.orig
cd initrd-data
sed -i "s:mount -o defaults --ro -t ext3 /dev/root /sysroot:mount -o defaults --ro -t ext3 /dev/sda6 /sysroot:g" init
cd dev
mknod sda b 8 0
mknod sda1 b 8 1
mknod sda2 b 8 2
mknod sda5 b 8 5
mknod sda6 b 8 6
cd ../..
./initrd-pack.sh initrd-2.6.9-5.ELsmp.img
cd ../..
umount orig/boot/
umount orig



initrd-unpack.sh


#!/bin/bash
if [ ! -e "$1" ] ; then
        echo "Syntax: $0 initrd.img"
        exit 1
fi
# https://access.redhat.com/solutions/24029
rm -rf initrd-data
mkdir -p initrd-data
cd initrd-data
( cd .. && zcat "$1" ) | cpio -idmv
echo "Contents have been unpacked to initrd-data"



initrd-pack.sh


#!/bin/bash
if [ ! -e "$1" ] || [ ! -d initrd-data ] ; then
        echo "Syntax: $0 initrd.img"
        exit 1
fi
# https://access.redhat.com/solutions/24029
( cd initrd-data && find . | cpio -o -c | gzip -9 ) > "$1"
echo "Contents have been repacked to $1"


Cómo ha quedado al final el init del initrd-2.6.9-5.ELsmp.img


#!/bin/nash

mount -t proc /proc /proc
echo Mounted /proc filesystem
echo Mounting sysfs
mount -t sysfs none /sys
echo Creating /dev
mount -o mode=0755 -t tmpfs none /dev
mknod /dev/console c 5 1
mknod /dev/null c 1 3
mknod /dev/zero c 1 5
mkdir /dev/pts
mkdir /dev/shm
mknod /dev/sda b 8 0
mknod /dev/sda1 b 8 1
mknod /dev/sda2 b 8 2
mknod /dev/sda5 b 8 5
mknod /dev/sda6 b 8 6
echo "Loading ext3.ko module"
insmod /lib/ext3.ko 
umount /sys
echo Mounting root filesystem
mount -o defaults --ro -t ext3 /dev/sda6 /sysroot
mount -t tmpfs --bind /dev /sysroot/dev
echo Switching to new root
switchroot /sysroot
umount /initrd/dev



Para preparar que arranque con un núcleo de debian


cd /data/backup_database/
mount -t auto /dev/sdg6 /data/backup_database/orig
mount -t auto /dev/sdg1 /data/backup_database/orig/boot/
cd orig/boot/
scp boromir:/boot/*2.6.30* .
sed -i "/hiddenmenu/a        boot" grub/grub.conf
sed -i "/hiddenmenu/akernel /vmlinuz-2.6.30-2-686 ro root=/dev/sda6 rhgb quiet" grub/grub.conf
sed -i "/hiddenmenu/a        root (hd0,0)" grub/grub.conf
sed -i "/hiddenmenu/atitle Red Hat Enterprise Linux AS (2.6.30-2-686)" grub/grub.conf
cd ../lib/modules/
scp -r root@boromir:/lib/modules/*2.6.30-2-686* .
cd ../../dev/
( cd  ../boot/initrd-data/dev/ && tar -cf - .) | tar -xvf - 
rm -rf VolGroup00/
cd ../..
umount orig/boot/
umount orig



Para cambiar el grub-legacy por el grub2


Información adicional: cómo generar un grub.cfg básico

cd /data/backup_database/
mount -t auto /dev/sdg6 /data/backup_database/orig
mount -t auto /dev/sdg1 /data/backup_database/orig/boot/
cd orig/boot/
mv grub grub-legacy-redhat
cp -rv /boot/grub .
grub-install --root-directory=/data/backup_database/orig/boot /dev/sdg
cd ../..
cat > orig/boot/grub/grub.cfg <<'EOF'
insmod ext2
set root='(hd0,msdos1)'

menuentry "GNU/Linux, 3.18.0-trunk-amd64" {
        linux  /vmlinuz-3.18.0-trunk-amd64 root=/dev/sda6 ro
        initrd /initrd.img-3.18.0-trunk-amd64
}
EOF
cd orig/boot
cp /boot/*3.18.0-trunk-amd64* .
cd ../lib/modules
cp -Rv /lib/modules/*3.18.0-trunk-amd64* .
cd ../../etc/udev/devices
mknod ptmx c 5 2
cd ../../../../
cd orig
cd root
mkdir modprobe_amd64
cd modprobe_amd64
cp /lib64/ld-linux-x86-64.so.2 .
cp /lib/x86_64-linux-gnu/libc.so.6 .
cp /sbin/modprobe .
cat > modprobe.sh <<'EOF'
#!/bin/bash
LANG=C
LC_ALL=C
export LANG LC_ALL
LD_LIBRARY_PATH=/root/modprobe_amd64 /root/modprobe_amd64/ld-linux-x86-64.so.2 /root/modprobe_amd64/modprobe "$@"
EOF
cd ../../sbin
mv modprobe modprobe.orig
ln -s /root/modprobe_amd64/modprobe.sh modprobe
umount orig/boot/
umount orig



cd /root
mkdir grub-install_amd64
cd grub-install_amd64/
scp dario@3.0.1.3:/usr/sbin/grub-install .
ls ../modprobe_amd64/
cp ../modprobe_amd64/*so* .
cat ../modprobe_amd64/modprobe.sh 
cp /dev/tty grub-install.sh
chmod a+ grub-install
ln -s /root/grub-install_amd64/grub-install.sh /usr/sbin/grub-install
chmod 755 grub-install.sh 
./grub-install.sh --help
scp dario@3.0.1.3:/tmp/a/* .
./grub-install.sh --help
./grub-install.sh --root-directory=/boot /dev/sda
ls -l /usr/lib/grub/
mkdir lib
scp -r dario@3.0.1.3:/usr/lib/grub lib/
ln -s /root/grub-install_amd64/lib/grub/ /usr/lib/grub
mknod /dev/sda b 8 0
./grub-install.sh --root-directory=/boot /dev/sda
cd /boot/grub
cat > grub.cfg <<'EOF'
insmod ext2
#set root='(hd0,msdos1)'

linux /vmlinuz-3.18.0-trunk-amd64 root=/dev/sda6
initrd /initrd.img-3.18.0-trunk-amd64
boot
EOF
cp grub.cfg /boot/boot/grub/