Fix broken Linux vm without restoring / re-installing


jimbo45

Well-known member
Pro User
VIP
Local time
12:02 PM
Posts
4,033
Location
Hafnarfjörður IS
OS
Windows XP,7,10,11 Linux Arch Linux
Hi folks
If you use Linux VM's (or Hosts) and you need to fix bootloader etc after say copying partitions -- you want to move / increase say '/' (the root) partition then you can often do it easily by simple command chroot which uses a "temporary" root system on a device or file.

Easy enough to do

say I'm running on /dev/sdb but I want to reinstall the boot loader on /dev/sda

1) as root mount /dev/sda2 /mnt (where /dev/sda2 is your root partition you want to use

2) run this next :
sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /sys /mnt/sys


You need those to access the programs etc


now simply chroot /mnt /bin/bash

Note if you need network access inside chroot do this BEFORE the chroot command. Also if you have a spearate /boot and /efi partition that you want to use mount them on /mnt before the chroot too.

cp -L /etc/resolv.conf /mnt/etc/resolv.conf

Then you can re-install grub/grub2 , reinstall kernel etc etc
after -- simply reboot although better first to "unbind" everything

so exit root by typing exit

sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt

reboot your repaired device.


cheers
jimbo
 
Last edited:

My Computer

System One

  • OS
    Windows XP,7,10,11 Linux Arch Linux
    Computer type
    PC/Desktop
    CPU
    2 X Intel i7

Latest Support Threads

Back
Top Bottom