Skip to content

Instantly share code, notes, and snippets.

@magopian
Last active December 30, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magopian/7854957 to your computer and use it in GitHub Desktop.
Save magopian/7854957 to your computer and use it in GitHub Desktop.
A few notes on how to deal with a Raspberry-pi

Raspberry-Pi tips and tricks

Backup SDCard to computer

Check the output of the lsblk command to find the correct device (eg: /dev/mmcblk0):

sudo dd bs=4M if=/dev/mmcblk0 of=FILENAME

If you wish to see the progress, use one of the following techniques:

  • with pv: sudo dd bs=4M if=/dev/mmcblk0 | pv | sudo dd of=FILENAME
  • with dcfldd: sudo dcfldd bs=4M if=/dev/mmcblk0 of=FILENAME

Write image to SDCard

sudo dcfldd bs=4M if=FILENAME of=/dev/mmcblk0

Mount an SDCard partition as read-write

This is an example to set a fixed IP address:

sudo mount -o rw  /dev/mmcblk0p2 /mnt/sdcard/

You can then modify the filesystem as if you were on the RPi (eg, modify the /mnt/sdcard/etc/modules file to enable ipv6).

Don't forget to unmount the partition when finished, and before ejecting the SDCard:

sudo umount /mnt/sdcard

Mount an image locally

In the .img file you downloaded to flash on your SDCard, there's two partitions. You probably want to mount the second one (the one that holds the filesystem), and not the first one (that hold the boot files).

To find where this second partition starts, use the file command:

$ file 2013-09-25-wheezy-raspbian.img
2013-09-25-wheezy-raspbian.img: DOS/MBR boot sector;
    partition 1 : ID=0xc, start-CHS (0x0,130,3), end-CHS (0x7,165,30),
        startsector 8192, 114688 sectors;
    partition 2 : ID=0x83, start-CHS (0x7,165,31), end-CHS (0x168,34,58),
        startsector 122880, 5662720 sectors

New lines have been added for the sake of readability. What you need is the startsector of the partition you want to mount, then:

sudo mount -o loop,offset=$(( 512 * 122880)) 2013-09-25-wheezy-raspbian.img /mnt/sdcard

Don't forget to unmount the partition when finished:

sudo umount /mnt/sdcard

Set a fixed IP address

Edit the /etc/network/interfaces file and fill in the following:

auto lo

iface lo inet loopback
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.13
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.254

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Use ipv6

Using ipv6, no need to set up an IP address.

First, you need to enable ipv6: add ipv6 to the end of the /etc/modules file.

Then connect to your RPi using the means of your choice, and send a broadcast ipv6 ping on the network interface used. Eg, if you connected your RPi to your computer using a network cable:

$ ping6 ff02::1%eth0
64 bytes from fe80::xxxx:xxxx:xxxx:xxxx: icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from fe80::xxxx:xxxx:xxxx:xxxx: icmp_seq=1 ttl=64 time=58.3 ms (DUP!)
64 bytes from fe80::xxxx:xxxx:xxxx:xxxx: icmp_seq=1 ttl=64 time=143 ms (DUP!)

In this case, the first one is the local eth0 interface, the second one is the router, and the third one is the RPi.

Then connect to your RPi using ssh:

ssh pi@fe80::xxxx:xxxx:xxxx:xxxx%eth0

Use IP Log

IP Log is a simple website that can be used to store the IP address of the visitor (and optionally some additional information).

There's a little tip on how to have your RPi automatically store its public and local IP address on the website: add the following line to your /etc/rc.local script:

curl "http://some.site.com/?store=true&note=`hostname -I`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment