1

I accidentally deleted my /boot partition but I was able to get it back with grub-install

I'm trying to chroot and install the kernels again via this guide:How to restore a system after accidentally removing all kernels?

However when I tried to remove or install the package I get the following error:

root@ubuntu:/# apt-get install -f

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  thermald
Use 'apt-get autoremove' to remove it.
The following packages will be REMOVED:
  linux-image-extra-4.2.0-25-generic
0 upgraded, 0 newly installed, 1 to remove and 33 not upgraded.
2 not fully installed or removed.
After this operation, 162 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 411666 files and directories currently installed.)
Removing linux-image-extra-4.2.0-25-generic (4.2.0-25.30) ...
depmod: FATAL: could not load /boot/System.map-4.2.0-25-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.2.0-25-generic /boot/vmlinuz-4.2.0-25-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.2.0-25-generic /boot/vmlinuz-4.2.0-25-generic
Running in chroot, ignoring request.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.2.0-25-generic /boot/vmlinuz-4.2.0-25-generic
update-initramfs: Generating /boot/initrd.img-4.2.0-25-generic
mv: ‘/boot/initrd.img-4.2.0-25-generic.new’ and ‘/boot/initrd.img-4.2.0-25-generic’ are the same file
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.2.0-25-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-4.2.0-25-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Update: It seems to be stuck on the following command

root@ubuntu:/# update-initramfs -c -t -k 4.2.0-25-generic -b /boot
update-initramfs: Generating /boot/initrd.img-4.2.0-25-generic
mv: ‘/boot/initrd.img-4.2.0-25-generic.new’ and ‘/boot/initrd.img-4.2.0-25-generic’ are the same file

root@ubuntu:/# ls -l /boot

ubuntu@ubuntu:~$ ls -l /boot

total 5430
-rw-r--r-- 1 root root 1268815 Apr 17  2015 abi-3.19.0-15-generic
-rw-r--r-- 1 root root  177656 Apr 17  2015 config-3.19.0-15-generic
drwxr-xr-x 1 root root      60 Jan 20 21:39 grub
-rw-r--r-- 1 root root  164216 Mar  6  2015 memtest86+.bin
-rw-r--r-- 1 root root  165892 Mar  6  2015 memtest86+.elf
-rw-r--r-- 1 root root  166396 Mar  6  2015 memtest86+_multiboot.bin
-rw------- 1 root root 3615358 Apr 17  2015 System.map-3.19.0-15-generic

root@ubuntu:/# apt-get install --reinstall linux-image-4.2.0-25-generic

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 33 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for linux-image-4.2.0-25-generic:amd64

root@ubuntu:/# dpkg --configure linux-image-4.2.0-25-generic

Setting up linux-image-4.2.0-25-generic (4.2.0-25.30) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
initrd.img(/boot/initrd.img-4.2.0-25-generic
) points to /boot/initrd.img-4.2.0-25-generic
 (/boot/initrd.img-4.2.0-25-generic) -- doing nothing at /var/lib/dpkg/info/linux-image-4.2.0-25-generic.postinst line 491.
vmlinuz(/boot/vmlinuz-4.2.0-25-generic
) points to /boot/vmlinuz-4.2.0-25-generic
 (/boot/vmlinuz-4.2.0-25-generic) -- doing nothing at /var/lib/dpkg/info/linux-image-4.2.0-25-generic.postinst line 491.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.2.0-25-generic /boot/vmlinuz-4.2.0-25-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.2.0-25-generic /boot/vmlinuz-4.2.0-25-generic
Running in chroot, ignoring request.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.2.0-25-generic /boot/vmlinuz-4.2.0-25-generic
update-initramfs: Generating /boot/initrd.img-4.2.0-25-generic
mv: ‘/boot/initrd.img-4.2.0-25-generic.new’ and ‘/boot/initrd.img-4.2.0-25-generic’ are the same file
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-4.2.0-25-generic.postinst line 1025.
dpkg: error processing package linux-image-4.2.0-25-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 linux-image-4.2.0-25-generic

How can I fix this?

  • 1
    Before you chroot do a mount /dev /chrooted/system/dev -o bind and then mount /dev/pts /chrooted/system/dev/pts -o bind where /chrooted/system is a directory you mounted your old system. – nsilent22 Jan 20 '16 at 21:56
  • I'm doing this from a live disk, /dev/pts seems to be empty – Tek Jan 20 '16 at 21:59
  • You mean /dev/pts on your live system? – nsilent22 Jan 20 '16 at 22:00
  • @nsilent22 Yeah, I meant to say I'm using an Ubuntu Live CD and there's nothing in /dev/pts. So when I mount it in /home/ubuntu/Desktop/root/ along with all the other mounts /dev/pts/ seems to be empty and I still get the same error above. – Tek Jan 20 '16 at 22:07
  • Ok, I understand /home/ubuntu/Desktop/root is a directory where you mount your 'old' filesystem. Then try mounting devpts explicitly: mount devpts /home/ubuntu/Desktop/root/dev/pts -t devpts – nsilent22 Jan 20 '16 at 22:09
2

There was a hint above at not being able to process something about postinst.d so I looked at what scripts it was running and found them.

I did a rm -rf /var/lib/dpkg/info/linux-image-4.2.0-25-generic.* which had some .postrm and .list files that were being used and those were faulty for whatever reason. I removed them, ran dpkg --configure -a and no more reinstall errors! Yay. Thanks all for pointing me in the right direction. There was another hint about reinstalling grub which I did with Boot Repair and after that I was able to pinpoint better where things were broken.

  • When I do a uname -r I get 4.2.0-25-generic . But when I do dpkg --configure linux-image-4.2.0-25-generic I get dpkg: error processing package linux-image-4.2.0-25-generic (--configure): no package named 'linux-image-4.2.0-25-generic' is installed, cannot configure Errors were encountered while processing: linux-image-4.2.0-25-generic . Do you have an idea? – kwoxer Jun 4 '16 at 19:08
  • @kwoxer did you run uname -r to see what kernel version you have? – Tek Jun 7 '16 at 18:09
  • I was already able to solve it. Thanks anyway: serverfault.com/questions/780980/… – kwoxer Jun 9 '16 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.