Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Sunday, February 8, 2015

Adding yourself back into the sudo group on Raspberry Pi

Greetings, weary tech[no] traveler!

Have you ever lock yourself out of the sudo group, on your Raspberry Pi, by accident...and your user was the only one that had sudo permissions?  It happened to me once.  I was worried that I would need to reformat my SD card, reinstall Raspbian, and reconfigure my Raspberry Pi all over again.  However, that is completely unnecessary.  Here's what you need to do:



  1. Power down your Raspberry Pi.
  2. Remove the SD card and insert it into your PC.
  3. Change directory to your mounted SD card.  Since I am using OSX:

    cd /Volumes/boot/

  4. Open the file named "cmdline.txt" with your favorite text editor.
  5. Add the following text to the end of the existing text.  It will drop you into a root shell upon reboot:

    init=/bin/sh

    Make sure it is all one line!

  6. Save "cmdline.txt" and eject the SD card from the PC.
  7. Put the SD card back into the Raspberry Pi.
  8. Connect a USB keyboard and monitor to the Raspberry Pi.
  9. Power on the Raspberry Pi.
  10. Once you see a flashing cursor, remount the filesystem as read-write, add your user back into the sudo group, and shutdown the Raspberry Pi.  To do that, enter the following commands at the prompt:

    mount -o remount,rw /
    usermod -a -G sudo <username>
    shutdown -P now

  11. Remove the SD card, reinsert it into your PC, and open the "cmdline.txt" file again with a text editor.
  12. Delete the “init=/bin/sh” text you added in step 5.
  13. Save "cmdline.txt" and eject the SD card from the PC.  One last time.
  14. Put the SD card back into your Raspberry Pi, reboot, and rejoice in your reclaimed sudoer privileges!

Sunday, August 17, 2014

Fixing up Raspberry Pi with apt-get update woes.

Greetings, weary tech[no] traveler!

Lately, I've been having some trouble updating the software on my Raspberry Pi (running Raspbian) via 'apt-get update'.  Every time I would run:

sudo apt-get update

I would get the following output:

Hit http://archive.raspberrypi.org wheezy Release.gpg
Hit http://mirrordirector.raspbian.org wheezy Release.gpg
Hit http://archive.raspberrypi.org wheezy Release
Hit http://mirrordirector.raspbian.org wheezy Release
Hit http://archive.raspberrypi.org wheezy/main armhf Packages        
Ign http://archive.raspberrypi.org wheezy/main Translation-en       
Hit http://raspberrypi.collabora.com wheezy Release.gpg             
Hit http://raspberrypi.collabora.com wheezy Release
Hit http://raspberrypi.collabora.com wheezy/rpi armhf Packages
Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en
Get:1 http://mirrordirector.raspbian.org wheezy/main armhf Packages [6891 kB]
Hit http://mirrordirector.raspbian.org wheezy/contrib armhf Packages               
Hit http://mirrordirector.raspbian.org wheezy/non-free armhf Packages                                                                                                                                     
Hit http://mirrordirector.raspbian.org wheezy/rpi armhf Packages                                                                                                                                          
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en                                                                                                                                      
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en                                                                                                                                         
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en                                                                                                                                     
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en                                                                                                                                          
100% [1 Packages xz 0 B]

And it would just hang there.  Until the SSH connection would time out.

It is important for me to successfully run updates on my Raspberry Pi.  If you're running something like Apache or a MySQL server you've got to be able to patch them.  Also, I have a healthy case of paranoia when it comes to software updates and information security.  Anyway...

It turned out I was running an older version of the Raspberry Pi firmware, which was impeding my ability to successfully run apt-get update && apt-get upgrade.

I'm sure I'm not the only one who had this problem.  Now that I've fixed this problem for myself, I thought I'd show you how to fix it yourself.

  1. First, make sure your Raspberry Pi has a solid connection to the internet. 
  2. Log in.
  3. Update the Raspberry Pi firmware:

    sudo rpi-update

    If rpi-update terminates with the following (or similar) error:
     *** Relaunching after update
     *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
     *** We're running for the first time
     *** Backing up files (this will take a few minutes)
     *** Backing up firmware
     *** Backing up modules 3.12.20+
    cp: cannot stat `//lib/modules/3.12.20+': No such file or directory

    Then create a directory called in 3.12.20+ in the directory /lib/modules/:

    sudo mkdir /lib/modules/3.12.20+and then run sudo rpi-update again.
  4. This will take about 10 minutes, so go for a walk, grab a beer, etc.
  5. If no errors appeared, your firmware was successfully updated.  Reboot your Raspberry Pi to activate the new firmware:

    sudo reboot
  6. Once the Raspberry Pi has rebooted, log in, and run your updates:

    sudo apt-get update && sudo apt-get upgrade