[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: status: how to install grub to non-bootable RAID-formatted drive?



On 1/23/26 20:29, D. R. Evans wrote:
...
So, given all the above, I intend to proceed with:

cp -r /dev/ /tmp/RFS/dev/
chroot /tmp/RFS /usr/bin/bash
grub-install /dev/sda
sync
exit
reboot

after I've given people a bit of time to shout at me not to do that if something in what I've written above looks bad. 
"cp -r /dev/ /tmp/RFS/dev/"  is wrong! Don't do that. 
Think about it, "cp" command will copy block devices such as /dev/sda like files into /tmp/RFS, basically into itself until it runs out of free space.

You need to double check if "/dev/sda" is the disk you want to recover.
Commands like: 
    blkid
    ls -la /dev/disk/by-id 
    smartctl -i /dev/sda
    mdadm --misc --detail /dev/md126
should help you identify it correctly.

Taking everything into consideration the right sequence of commands should be:
    mkdir /tmp/RFS
    mount /dev/md126 /tmp/RFS    #Mount root filesystem
    mount --bind /dev /tmp/RFS/dev    #Mount bind real /dev to populate chroot-ed /dev
    mount --bind /proc /tmp/RFS/proc    #Mount bind real /proc 
to populate chroot-ed /proc
    mount --bind /sys /tmp/RFS/sys    #Mount bind real /sys to populate chroot-ed /sys
    chroot /tmp/RFS /usr/bin/bash    #Change root into directory /tmp/RFS
    grub-install --target=i386-pc /dev/sda    #Install grub stage 1 and stage 2 MBR bootloader into /dev/sda and /boot
    sync    #Sync filesystems
    exit    #Exit chroot
    umount /tmp/RFS/dev
    umount /tmp/RFS/proc
    umount /tmp/RFS/sys
    umount /tmp/RFS
    systemctl reboot


Hopefully grub-install will recognize raid partition correctly and create working grub config.
Before exiting chroot you can check "/boot/grub/grub.cfg" for filesystem UUIDs and compare them to the output from "blkid" command:
    cat /boot/grub/grub.cfg | grep -iE -- "--set=root"
...
search --no-floppy --fs-uuid --set=root 155380c9-4578-4a85-80c3-a78c7ffa7cb1
...
    blkid --uuid 155380c9-4578-4a85-80c3-a78c7ffa7cb1
/dev/nvme0n1p5


"/dev/nvme0n1p5" is my boot partition, your UUIDs and blkid output will be different.


--
 With kindest regards, Alexander.
 Debian - The universal operating system
 https://www.debian.org

Reply to: