I have bricked a linux embedded device.

I was experimenting with it, and added my own path to /etc/ld.so.conf. The libc I included in my path is not compatible with this particular device, so I lost ssh access to it and of course it does not boot anymore.

I can enter a sort of download mode, where I can load in memory the bootloader, the kernel, the dtb and the initramfs. I can then tell the processor to jump to a certain address in memory, and have the system boot.

This does not solve the problem, because as soon as the root is switched from the initramfs to the flash memory of the device, the wrong libraries are used and the device stops working.

My plan is to add a custom script to the initramfs that mounts the flash, erases /etc/ld.so.conf and /etc/ld.so.cache. I don't care if the deivice does not boot then, as soon as the files are emptied and the device is reboot, it should fall back to use the standard libraries. I can then connect via ssh and clean up the mess.

I was not able to understand where exactly I should inject my fix in the initramfs, so the question is:

Where should I insert a few lines of bash so that they are executed at boot, before / is mounted?

  • If anybody needs further details or insights, please do ask in the comments and I will more than happily edit the question. – Vladimir Cravero Dec 28 '17 at 15:53
  • You could tell linux to only use initramfs as the root filesystem. Next you can mount flash and copy files around. Can you pass custom parameters to the kernel? – Arkadiusz Drabczyk Dec 28 '17 at 16:02
  • Hi @ArkadiuszDrabczyk, I do not know how to tell linux to use only initramfs. I am not able to pass parameters to the kernel because of my lack of understanding of the U-Boot structure. – Vladimir Cravero Dec 28 '17 at 16:04
  • Can you do printenv bootargs in uboot? – Arkadiusz Drabczyk Dec 28 '17 at 16:04
  • You could also recompile your linux with a modified init script that this operation once. Anyway, if you want to modify initramfs you need to recompile whole linux, that's how it works. – Arkadiusz Drabczyk Dec 28 '17 at 16:09

Add your shell script code into the file /init in your initramfs image.

Don't use anything too fancy - /bin/sh won't be bash, it will likely be busybox.

Read the sections starting with What is initramfs? in this doc.

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.