Monday, August 18, 2014

Linux - Erased Your /boot partition?

If you accidently removed/deleted your /boot partion, the following steps might help you get your /boot partition back.

Assuming your /boot partition is on /dev/sdb1:

1. Boot up using a live CD (Your distro live CD is better)

2. Create a boot partiton, make sure you use the same FS (you can use the fdisk http://tldp.org/HOWTO/Partition/fdisk_partitioning.html) command.

3. Install Linux images on your boot partition
# chrooting into the system
# mount /dev/sdbx /mnt/myroot (where sdbx is your root partition)
# mount /dev/sdby /mnt/myroot/boot (we need to mount boot because it is on another partition /dev/sdby)
# mount ‐‐bind /dev /mnt/myroot/dev
# mount ‐‐bind /proc /mnt/myroot/proc
# mount ‐‐bind /sys /mnt/myroot/sys

# Copy resolv.conf
# cp -L /etc/resolve.conf /mnt/gentoo/etc/resolve.conf

# Then do a chroot:
# chroot /media/xx..xx

4. Install the missing kernel images
# Remove initrd.img symlink from your root because it can stop apt-get install command
# mv initrd.img initrd.img.OLD

# Install Linux image that you want
# apt-cache search 'linux-image'
# apt-get install linux-image-3.0.0-17-generic (For centOS use yum list)

# If you got error about missing memtest86+ do this then first
# sudo apt-get --reinstall install memtest86+

5. Finally lets restore grub
# sudo grub-install /dev/sdb

No comments: