1

After several months without accessing to my raspberry (Model B, Raspbian Wheezy - Linux 4.1.19+), I did encounter a severe issue:

sudo apt-get update
-bash: /usr/bin/sudo : cannot execute binary file

md5sum /usr/bin/sudo gives me c96f196fa9d3a575c6ba7423700d8ac9 but I don't know where is the reference sum I can compare with.

apt-cache policy sudo gives me:

- Installed : 1.8.5p2-1+nmu3+deb7u3
- Candidate : 1.8.5p2-1+nmu3+deb7u3

ls -l /usr/bin/sudo gives:

-rwsr-xr-x 2 root root 98720 may  31  2017 /usr/bin/sudo

file /usr/bin/sudo gives /usr/bin/sudo: setuid data

Do you think this a hardware problem (SD card failure) or a corrupted file ? What could I do now ? I can't do anything without sudo privileges (root user is disabled). Does that mean I have to create a new SD card and reinstall from scratch ?

  • Edit the md5dsum and the sudo version into your question. apt-cache policy sudo will show the version number. We can then compare. Your Pi model may be relevant and software version (cat /etc/os-release. Edit this information into your question. – joan Apr 3 at 8:33
  • md5sum /usr/bin/sudo e6a11c46bed327e58f21afbe5b0cdb1e and apt-cache policy sudo Installed: 1.8.19p1-2.1 – joan Apr 3 at 8:53
  • Edited my question with your remarks ! – Beinje Apr 3 at 9:28
  • It is futile trying to update - Wheezy is unsupported and has been for years. (It has been 18 months since Jessie was supported.) – Milliways Apr 3 at 10:03
  • Sure, but updating was just an example, the real problem here is that sudo command can't be executed anymore. – Beinje Apr 3 at 10:12
1

The output from the file command suggests that the sudo file has become corrupt and is not recognised as an executable. For comparison here's what I get if I run the same command:

file /usr/bin/sudo
/usr/bin/sudo: setuid ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=02ae0f4b730edb6e01fb34a818cd7ee4a58fc033, stripped

Correcting the problem on a "live" system is not going to be easy as you no longer have a means of elevating your privileges in order to change the file (I think the graphical versions are just wrappers around sudo).

If you have another Linux OS to hand you can just mount the SD card and copy the file over. Otherwise you could...

  1. Copy the file to the first partition on the SD.
  2. Add init=/bin/sh to the end of cmdline.txt to enable the emergency shell.
  3. Boot your Raspberry Pi and wait for the shell prompt.
  4. Mount the second partition of the SD card: mount /dev/mmcblk0p2 /mnt
  5. Move the new file over:

mv /mnt/usr/bin/sudo /mnt/usr/bin/borked_sudo # backup of bad file

mv /boot/sudo /mnt/usr/bin/sudo # copy new file

chown root:root /usr/bin/sudo && chmod u=rws g=rx o=rx /usr/bin/sudo # set permissions

  1. Shutdown the Pi, revert cmdline.txt and then re-boot the Pi as normal.

Even if you did have a means of gaining the required privileges for swapping the file, where would you get a good copy of sudo to replace it with? Possible steps to do this would be to download the Raspbian image corresponding to your install and extract the file from it. I'm not aware of a way to do this on Windows but you can mount the image using a loop-back with Linux. If you have a spare USB drive or SD card you could burn the image to that but you'd still need somehow to mount it on Windows to copy the file.

All told it might be easier to just flash the SD card with a new image?

EDIT

You mention you have another Linux OS to hand. If this is the case could download the DEB package containing the latest sudo for Wheezy and extract the binary to the SD card, something along the lines of...

wget "wget http://raspbian.raspberrypi.org/raspbian/pool/main/s/sudo/sudo_1.8.5p2-1+nmu3+deb7u4_armhf.deb"
ar xv "sudo_1.8.5p2-1+nmu3+deb7u4_armhf.deb"
mount "/dev/RasperryPiSDCardp2" "/mount/point"
tar xzvf "data.tar.gz" -C "/mount/point" "./usr/bin/sudo"
rm control.tar.gz data.tar.gz debian-binary
umount /mount/point

It's a filthy hack but it might get you out of a bind. The URL for the DEB was found by grepping this for "Package: sudo". For refence running file should then give you:

ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.26, BuildID[sha1]=be4082fba3219f9b829d2a9e0def8d5114161574, stripped
  • I do have another Linux to hand but it is not the same version of sudo. So I probably need to get an image of the same version of Raspbian to copy the file. My question is : is there a chance that other files may be corrupted as well so that I won't be able to recover a healthy system ? If so, I may have to flash the card as pointed out. Do we agree that flashing the card means a fresh new install of Raspbian (for which I need to install all the necessary softwares and config files) ? – Beinje Apr 3 at 12:18
  • Getting sudo back would give you a fighting chance at restoring any other broken files on the card but I'd point out that the more corrupt files you find the more effort involved and the easier just flashing a new card seems in relative terms (unless you're the kind of person who enjoys solving that kind of puzzle more than actually using the Pi as intended!). Flashing the card would mean initially a fresh Raspbian install to which you can then copy any backups you have. If you have no backups you could try saving them from the old card first, but how would you know they're not also corrupt? – Roger Jones Apr 3 at 13:16
  • I wish I would but I'm not sure to be skilled enough, neither patient enough to solve this kind of puzzle. You're right, I'd rather go for a fresh new install. I have backups for most of my configuration files (ftp, git, and web server mostly), I'll start from here. Finally, do you think I should go for a new SD card (this one has 2-3 years) ? – Beinje Apr 3 at 13:44
  • your hack did the trick. It will give me some time to prepare the future and prepare a new card :). Thanks ! – Beinje Apr 3 at 18:26

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.