Raspbian backup on Mac

I already wrote how to install Raspbian on Mac, but how to backup it?

Check how your card looks in system..

sudo su -
diskutil list

My card is there as /dev/disk2. Now umount the partition boot which is mounted automatically.. Do not forget to change disk number!

diskutil unmountDisk /dev/disk2s1

Go to the folder where you want to have backup and create a backup of SD card (it will take time – depends on your SD card size..).

cd /where_you_backup_will_be
dd bs=1m if=/dev/rdisk2 of=raspbian_backup_`date +%Y%m%d`.img

It will create raspbian_backup_20130727.img (for example).

And onliner for h4x0rZ (you need to rewrite the path and diskX

cd /where_you_backup_will_be; diskutil umount /dev/diskXs1; dd bs=1m if=/dev/diskX of=raspbian_backup_`date +%Y%m%d`.img

WiFi AP (RT5370) on Raspberry Pi

26.02.2017: Howto tested & working šŸ™‚

Today, we will look at howto create AP hotspot on Raspberry Pi usingĀ Ralink RT5370 chipset (see previous article).

First step should be update your repositories and update system to lastest:

sudo aptitude update; sudo aptitude -y upgrade

Then, reboot will be good thing to do..

sudo shutdown -r now

After boot, login, run sudo su – and lsusb command and you should see something like this:

pi@raspberrypi ~ $ sudo su -
root@raspberrypi:~# lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

Install hostapd and dnsmasq:

aptitude install hostapd dnsmasq

Edit file with network settings to some static IP of wlan0:

nano /etc/network/interfaces

And wlan0 section should like:

allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.100.1
  netmask 255.255.255.0

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual

(close nano with Ctrl+X, then Y and Enter)

After that, get down and up wlan0 interface and check, if you have your IP set it up on interface

ifdown wlan0; ifup wlan0
ifconfig wlan0 # this command should wrote these informations

# as you can see, there is right IP
wlan0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.100.1 Bcast:192.168.100.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Create new configuration for hostapd in /etc/hostapd/hostapd.conf and put there this info:

# you can create it with command
nano /etc/hostapd/hostapd.conf

#write info below into file
interface=wlan0
driver=nl80211
ssid=RaspberryPi_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Your_fav_super_password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Edit files /etc/default/hostapd and uncomment DAEMON_CONF, and add path to config. So line will looks like this:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Then, you can finally restart hostapd, and you have your hotspot up and running.

/etc/init.d/hostapd restart

# allow hostapd after boot
update-rc.d hostapd enable

Your hotspot is running, but you need to run some DHCP client for your clients which will use your hotspot. Edit and change these parameters in dnsmasq (and restart it):

#edit dnsmasq by following command
nano /etc/dnsmasq.conf

#find and change following parameters.. (or you can add these on end of the file 
interface=wlan0Ā 
except-interface=eth0
dhcp-range=192.168.100.2,192.168.100.150,255.255.255.0,12h

# restart dnsmasq
/etc/init.d/dnsmasq restart

# allow dnsmasq after boot
update-rc.d dnsmasq enable

Then, you need to do NAT.. so..

#edit file /etc/sysctl.conf and uncomment this line
net.ipv4.ip_forward=1

# run this command to load it
sysctl -p

#run these command for allow forwarding..
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

# save iptables to file which will load after start
iptables-save > /etc/iptables.nat

# create file with forwarding in /etc/network/if-up.d
echo '#!/bin/bash' > /etc/network/if-up.d/forwarding; echo 'iptables-restore < /etc/iptables.nat' >> /etc/network/if-up.d/forwarding; chmod +x /etc/network/if-up.d/forwarding

I found problem after reboot (and hostapd start) that wlan0 doesnt have IP assigned. You can solve it by chage fileĀ /etc/default/ifplugd and change it like this:

INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"

Source:Ā http://elinux.org/RPI-Wireless-Hotspot

Help with hostapd and IP:Ā http://sirlagz.net/2013/02/10/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-3b/

Red prompt when you are root

Prompt - no color
Prompt – no color

I was disapointed about prompt color when I install Raspbian. As user pi, you have cool green prompt. But as user root, there are no colors.

So what I want is some color for root user also. You just need to add this to files /etc/profile:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '

You can do it by one command as user root:

echo "PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '" >> /etc/profile
Prompt color Raspbian
Prompt with colors

If you are user pi, just add sudo before whole command. Then you will have this prompt (after you relogin).