tpylkko
Posts: 412
Joined: Tue Oct 14, 2014 5:21 pm

Manually place kernel.img on boot partition

Thu Mar 23, 2017 7:56 pm

I was updating a remote pi when it was powered down in the midst. After it was rebooted, it only gives 7 flashes which I think translates to "unable to find/load kernel.img". I took out the sd-card mounted it on a laptop running Debian and /boot has start.elf and boocode.bin but no kernel.img (also no kernel7.img). So, now I am thinking that perhaps I could attempt to boot a kernel placed there manually and then use apt and dpkg to finish try to salvage the broken install. However, I wonder where I could get a precompiled Raspbian kernel.img?

EDIT: it appears I found it.
https://github.com/raspberrypi/firmware

User avatar
DougieLawson
Posts: 40485
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Manually place kernel.img on boot partition

Thu Mar 23, 2017 8:30 pm

It's not that simple. But you can repair things on your RPi if you have (or can make) a second bootable SDCard.

Get your second SDCard with Jessie and boot your RPi from that. Get your "broken" SDCard in a USB reader, insert that in your RPi.

for i in /dev/sda*;do sudo umount $i; done
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot
sudo mount -o bind /dev /mnt/dev
sudo mount -o bind /sys /mnt/sys
sudo mount -t proc proc /mnt/proc
cd /mnt
sudo chroot .
sudo rpi-update
exit
cd /
for i in t/boot t/dev t/sys t/proc t; do umount /mn$i; done
poweroff


Swap cards and reboot. That will get you a 4.9.16 kernel on your broken SDCard.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

tpylkko
Posts: 412
Joined: Tue Oct 14, 2014 5:21 pm

Re: Manually place kernel.img on boot partition

Thu Mar 23, 2017 9:20 pm

Actually, the reason I was hoping this would work is so that I don't have to chroot into it. But if it doesn't work then that the next step, unless you can say for sure that there is a reason why this easier first step could not work...?

BTW. I just want to point out that I wasn't wanting to get a 4.9 kernel, this occured on a card that has not been updated in months (mainly because it is not online when under normal operation). So the apt upgrade was performing a 4.4 update on top of a 4.4. I definetely do not want to run a 4.9 kernel on this one untill that is in stable repo. The git I linked to above has a stable branch.

User avatar
DougieLawson
Posts: 40485
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Manually place kernel.img on boot partition

Thu Mar 23, 2017 9:41 pm

The problem is that you need bootcode, kernel and /lib/modules to all match. Running rpi-update in a chroot is the easiest thing to do. (I've used it a few times when an experiment doesn't work and a system is unbootable.)
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

tpylkko
Posts: 412
Joined: Tue Oct 14, 2014 5:21 pm

Re: Manually place kernel.img on boot partition

Sat Mar 25, 2017 8:48 pm

Well, I can tell you that copying the kernel images did not work. Nor did copying the entire contents of /boot... so I guess chroot now, if onlyI can find my usb-sd reader soon (just spent like 15 min looking for it). If not, it might be more efficient time/moneywise to buy a new one tomorrow... it was around 1€ IIRC...

ozwoz
Posts: 2
Joined: Wed Oct 25, 2017 8:23 am

Re: Manually place kernel.img on boot pahttps://www.raspberrypi.org/products/rtition

Wed Oct 25, 2017 8:29 am

I have the same problem. Just wanted to ask if I run the code suggested by Dougie on my 'broken' sd card will I lose all data from it or just change the bootcode, kernel and /lib/modules and leave the rest of the data ?

User avatar
DougieLawson
Posts: 40485
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Manually place kernel.img on boot partition

Thu Oct 26, 2017 11:33 pm

It's not really a beginner's thing, because if it goes wrong you'll get a jigsaw with no photo on the box.

But as long as you follow the instructions it should work for most folks.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

amfasis
Posts: 2
Joined: Sun Jul 28, 2019 9:35 pm

Re: Manually place kernel.img on boot partition

Sun Jul 28, 2019 9:48 pm

I was actually able to fix my broken kernel-state (resulted from an accidental reboot while doing apt upgrade with a kernel update) by the following procedure (performed on a Debian machine).

- install fresh raspbian on new SD card (I actually installed Buster, while my broken card was Stretch)
- remove all folders except
* /boot
* /lib/modules
* /opt/vc
( I got these pointers by looking at the firmware github referenced in the edit of the first post)
- copy all files from broken SD card except the above mentioned folders

Please note you will have to use `sudo rsync -arv` since the linux host actually see all the files on the SD-card are set to specific users, including the root user.

This made my kernel upgrade to what is current (which I intended anyway ;-) ) and kept all files from my previous running installation, including Raspbian Stretch, usernames, ssh-keys, influxdb, and whatever more. I ended up with my new SD card leaving in the Pi, but you can of course shuffle stuff around once more if it's working

MaikelK
Posts: 1
Joined: Tue Sep 10, 2019 5:07 pm

Re: Manually place kernel.img on boot partition

Tue Sep 10, 2019 5:10 pm

This piece of code saved my life, kinda.
Saved me from a lot of re-installing everything i have build in the last years. I know make backups regurly but i deleted it to save some HDD space a few weeks ago...

Only thing i had to change was:

for i in t/boot t/dev t/sys t/proc t; do umount /mn$i; done

had to be done before the

exit

command otherwise nothing was happening, message operation not permitted came on the screen.

Thanks for this!

mrmeeseeks
Posts: 4
Joined: Sun Nov 27, 2016 1:14 pm

Re: Manually place kernel.img on boot partition

Mon Oct 07, 2019 9:38 am

Help I am getting the following error after "sudo chroot .":

Code: Select all

/bin/bash: error while loading shared libraries: /lib/arm-linux-gnueabihf/libc.so.6: only ET_DYN and ET_EXEC can be loaded

wvk
Posts: 1
Joined: Tue Apr 21, 2020 2:25 pm

Re: Manually place kernel.img on boot partition

Thu Apr 23, 2020 7:57 am

A shorter version of the instructions, using rpi-update parameters:
Allows you to perform an "offline" update, ie update firmware on an SD card you are not currently booted from.

To check which device is used for the SD card that needs to be rescued: fdisk -l
In my case: /dev/sda

Code: Select all

sudo mkdir -p /mnt/rescue/{boot,root}
sudo mount /dev/sda1 /mnt/rescue/boot
sudo mount /dev/sda2 /mnt/rescue/root
sudo ROOT_PATH=/mnt/rescue/root BOOT_PATH=/mnt/rescue/boot SKIP_BACKUP=1 rpi-update
umount /mnt/rescue/{boot,root}

hexolite
Posts: 11
Joined: Fri May 08, 2020 2:13 pm

Re: Manually place kernel.img on boot partition

Sat May 09, 2020 9:46 am

Hi,

Can I apply this technique to my problem stated here?

viewtopic.php?f=28&t=273469&p=1657763#p1657763

I am a noob, so, can I just copy/paste the code presented by @DougieLawson?

User avatar
DougieLawson
Posts: 40485
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Manually place kernel.img on boot partition

Sat May 09, 2020 10:01 am

hexolite wrote:
Sat May 09, 2020 9:46 am
Hi,

Can I apply this technique to my problem stated here?

viewtopic.php?f=28&t=273469&p=1657763#p1657763

I am a noob, so, can I just copy/paste the code presented by @DougieLawson?
No, because you really do NOT want to run rpi-update right now. It'd give you a very experimental kernel and bootcode with unknown bugs in it.

Start a new thread, describe your problem in exquisite detail and we'll go from there. Don't bump ancient old threads from Raspbian Jessie in 2017.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 27718
Joined: Sat Jul 30, 2011 7:41 pm

Re: Manually place kernel.img on boot partition

Sat May 09, 2020 12:50 pm

Locking, thread probably out of date.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Return to “Beginners”