After installing openvpn I cannot connect to my raspberrypi

So I installed openvpn on my Raspian distro on my Raspberry Pi 2. As soon as I started it up, I lost all connectivity to my Pi.

And I don’t have a display, keyboard, or mouse — all my management has been over the network.

How to recover?

I tried a bunch of things, but here’s what worked, in brief.

  • Power off PI and put SD card in my Mac.
  • Copy the SD card to an image file using `dd`
    • dd bs=32768 if=/dev/rdisk2 of=raspberrypi.raw
    • VBoxManage convertdd raspberrypi.raw raspberrypi.vdi --format VDI

Use Disk Utility to see which device is your card reader. The Pi’s SD card has two partitions, and the first can be mounted by your mac. Note by using ‘rdisk2’ instead of ‘disk2’ it does unbuffered reading which is faster, or so I’m told.

Now we edit the image. If you have a way to open ext4 filesystems already, just remove the files (see rm step below). Here’s how I did it:

  • Install VirtualBox with the latest Finnix Recovery Distro.
  • Add the .vdi file created above to the Finnix VM.
  • Boot Finnix
  • Mount the image
  • mkdir -p /mnt && mount -t ext4 /dev/sda2 /mnt
  • The reason RPi doesn’t boot with open vpn is because ifplugd tries to HOT plug it.  To fix this, explicitly list the real network interfaces in `/etc/default/ifplugd`:
    • Replace
    • INTERFACES="auto"
    • with
    • HOTPLUG_INTERFACES="eth0 wlan0"

    Failling that, you can always just remove all the init scripts that start openvpn.

  • rm /mnt/etc/rc*/*openvpn
  • Unmount
    • umount /mnt
  • Power off Finnix
    • shutdown -h now
  • Convert back to RAW format
    VBoxManage clonehd raspberrypi.vdi raspberrypi.raw --format RAW
  • Copy the image back onto the SD card:
    • sudo dd bs=32768 if=raspberrypi.raw of=/dev/rdisk2

Put the SD card in your Raspberry Pi and reboot!