4

I accidentally deleted files in the boot directory and now the system cannot boot anymore. Is it possible to restore the boot directory and especially the file /boot/vmlinuz-3.11.0-12-generic ?

I saw a similar problem here : System doesn't boot anymore. Error: file initrd.img-3.11.0-20-generic not found

The solution would be to mount the local partition in a live environment and re-install the files. As I am a real newbie (as you can see from my problem itself) I have difficulties to adjust the solution to my specific case.

I have access to my computer from a live USB and the result of

sudo blkid

is

/dev/loop0: TYPE="squashfs" 
/dev/sda1: UUID="BD1B-FB3E" TYPE="vfat" 
/dev/sda2: UUID="ad8e18f0-dccd-4aa6-acbe-b3db9f5634a3" TYPE="ext4" 
/dev/sda3: UUID="b8b1b2fc-cebb-4bb7-8739-899147dcd776" TYPE="swap" 
/dev/sdb1: UUID="CDC9-DC5D" TYPE="vfat" 
/dev/sdc1: UUID="E6A3-F52D" TYPE="vfat"

Do you know if it is possible to restore the files or, if not, to save my data (which is not on a specific partition as it should be...) ?

Thanks a lot for your help.

Edit : I use a version of Linux Mint. Response to lsb_release --all is

    LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-
3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-
4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-
4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID: LinuxMint
Description:    Linux Mint 16 Petra
Release:    16
Codename:   petra
MylR
  • 43

2 Answers2

3

From the live USB mount your root partition:

$ sudo mkdir /mnt/ubuntu

$ sudo mount -t ext4 /dev/sda2 /mnt/ubuntu

Type the following to allow DNS resolution from within the chroot:

$ sudo cp /etc/resolv.conf /mnt/ubuntu/etc/resolv.conf

Mount proc filesystem

$ sudo mount -o bind /proc /mnt/ubuntu/proc

Now chroot to that installation:

$ sudo chroot /mnt/ubuntu /bin/bash

Reinstall kernel image package (that should also trigger grub-update):

(chroot)$ apt-get install --reinstall linux-image-generic

If it will not trigger kernel upgrade, then (still in chroot):

(chroot)$ update-grub

Exit chroot with Ctrl+d. Reboot system without live USB.

0

Apart from @marek-bettman's answer, there're some hints may be useful (suppose you're under sudo -i prompt):

The root partition can be anywhere

One can use fdisk -l to confirm the partition table structure. Sometimes lsblk could be better.

Not installed with the whole disk?

You may have your Ubuntu installed with not whole disk (by customized partition schema), so if your / is /dev/sda4, you will also need mount other mandatory partitions:

  • /boot (obviously why)
  • /var (where apt places its cache files)

chroot error: sudo: unable to allocate pty: No such device

You can bind the /dev recursively:

mount --rbind /dev/ /mnt/dev/

For more explanation, see https://askubuntu.com/a/1449987/1624531.

apt/dpkg be locked

After chroot, apt or dpkg can still not work since the previous processes may be interrupted by reboot or a sudden power outage. You need remove the locks in this scenario:

rm /var/lib/apt/lists/lock
rm /var/lib/dpkg/lock
rm /var/lib/dpkg/lock-frontend
dpkg --configure -a

Need latest kernel?

apt clean
apt update --fix-missing
apt install -f
dpkg --configure -a
apt upgrade
# You can even upgrade the whole distribution, e.g. 22.04 => 24.04
apt dist-upgrade
reboot
Yu Sun
  • 86
  • 3