Removed kernels & /lib/modules/ modules.order & modules.built - now usb devices are not working i.e. I cannot control the pi?

Hi, I’m running Ubuntu Mate 16.04 on a Pi2.

I’m not 100% sure what I did, but when I tried to purge some generic-kernel-headers or raspberry-pi-kernel headers my USB devices stopped working completely.

Now I cannot control the pi anymore via a mouse/keyboard. How can I fix this ?

I tried enabling SSH by placing an empty “ssh” file on the root of a sd card using another PC but it didn’t seem to work.

I need to somehow re-install the kernel-headers to get my USB devices working again - but HOW ?

Please, any feedback is appreciated.

Thanks

Can you put the SD card into another linux machine and chroot onto it?

This should enable you to configure sshd to start on boot. Then you can ssh onto the pi and reinstall your headers/firmware.

@SFromley Hi, yes I can put the SD card into a another Linux machine.

I’m not an expert on this so could you please explain the steps on how exactly I can enable SSH using the other Linux machine including the chroot part ?

I am not 100% sure if the headers are the issue. I was also fiddling around with the /lib/modules/ folder and I may have deleted modules.order and modules.built files which I think may be the real issue here since it seems that no modules are being loaded on boot. Do you know how I can fix this ?

Also, is it possible to re-install the headers or the modules directly onto the SD card using the other Linux machine without the need for SSH ?

I really need to get this sorted since I am unable to do anything on the Pi until I can get the modules loaded again. I’m pretty sure this is an issue with the modules not being loaded on boot.

Thanks

I’d be more inclined to fix the problem on the pi itself because of different architectures. You just need to be able to ssh onto it then the world is your oyster.

depmod and initram will be your friends in fixing the kernel module loading, I think; and you’d want to run those on the machine itself rather than in a chrooted environment from another.

It’s been a while since I’ve had to fix stuff (usually grub) this way, so I’m running on shaky memory here, but I think you

sudo chroot /path/to/mounted/sd /bin/bash

then enable sshd on startup by

sudo systemctl enable ssh

Then type ‘exit’ to leave the chroot, unmount and put the sd into the pi, boot it up and ssh onto it. Assuming it still has a working network interface.

@SFromley Thanks, I’ll give it a go and see if I can get ssh to work. In terms of the /path/to/mounted/sd would I just mount the whole device or a specific partition. I’ll have to check again what’s the command for finding the path for the SD. I assume the SD mounts automatically when I plug it in using a USB SD card adaptor.

Chroot to whatever / is on the sd.

And yeah, your Linux will probably mount all the partitions when you plug
the sd in.

@SFromley I’ve really messed up my Pi’s filesystem now.

I did the following:

sudo mkdir /mnt/RPI
sudo mount /dev/sde2 /mnt/RPI
sudo chroot /mnt/RPI /bin/bash

Then I got the error: chroot: failed to run command ‘/bin/bash’: Exec format error

I very stupidly followed another guide which said to do this: sudo cp -r /bin /lib /mnt/RPI

Now my Pi will not even boot into the OS since I have messed up my /bin and /lib folders. Is there anyway that I can restore them ? I don’t know why on Earth I did that.

Thanks

I’d say you had now reached the point where a reinstall would be your best and least troublesome path.

Copy your home folders off the pi if there’s anything you want to keep, reimage it, put your home folders back on.

@SFromley I actually managed to fix it by mounting the messed up sd card on a previous backup I had of the image when it was still working.

I did:

sudo mkdir /mnt/RPI
sudo mount /dev/sde2 /mnt/RPI
sudo cp -rpf /bin /lib /mnt/RPI

And that also solved the USB not working problem I was having initially.

2 Likes

Nice.

Glad to hear you got it working.

1 Like