Raspberry Pi‎ > ‎Raspbian Setup‎ > ‎


Boot Up

    Normally, you have to login as Username : PI and Password : raspberry, when you first boot up. it would not go to GUI but i will show you how later on. you have to type "startx" to start GUI.

Do it all the time

  • Open Terminal (LXTerminal)
  • Keep update : sudo apt-get update 
  • Clear Up Disk Space : $ sudo apt-get clean
  • Go to Basic Setup from Terminal : sudo raspi-config
  • Remore Application : sudo apt-get --purge autoremove packagename
  • Check Disk Space : $ df 
  • Search All linked file : sudo find . -type l -exec ls -l {} \; | grep [someString] > allfile.txt 
  • sudo rpi-update ( Update Raspi Frimware )

Auto Start on Boot


If Linux Script
  • $ sudo chmod +755 myScript.sh
  • $ sudo nano /etc/rc.local
  • Add : sudo ./xxx/myScript.sh & to end of rc.local
  • Reboot
  • Create a .conf file into /etc/init 
  • E.g. 
  • # gps data logger service

    description "GPS Data Logger service"
    author "User"

    start on runlevel [2345]
    stop on runlevel [016]
    chdir /home/user/
    exec python /home/user/gps_data.py
  • Script file into /etc/init.d
  • E.g.
#!/bin/bash # /etc/init.d/servoblaster ### BEGIN INIT INFO # Provides: servoblaster # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Example initscript # Description: This service is used to manage a servo ### END INIT INFO case "$1" in start) echo "Starting servoblaster" /home/pi/servoblaster/PiBits/ServoBlaster/user/servod ;; stop) echo "Stopping servoblaster" killall servod ;; *) echo "Usage: /etc/init.d/servod start|stop" exit 1 ;; esac exit 0
  • If Python
    • $ Add : sudo python myScript.py


  • Auto Start Folder and Sample :
    • $ cd /home/pi
    • $ cd .config
    • $ mkdir autostart
    • $ cd autostart
    • Create xxxx.desktop 
    • Or copy Desktop xxx.desktop to /home/pi/.config/autostart
Kill Background Process
  • $ sudo killall my_project.a

Wifi and VPN

    If you not connect with internet that mean you can't do anything, right. Two way to do it, buy a USB wifi connecter e.g. IEEE802.11n and plug into USB or Connect with Cable if you like. 


    After you plug you USB Wifi connecter then Click "WIFI Config", Scan and Add to list and connect, Easy !


  • (Recommanded)
  • Make Sure your system is enabled SSH from basic config otherwise go back to "sudo raspi-config" to enable before continues.
  • Test by MAC : "ssh <IP> -l <username>" e.g. ssh -l pi  


tightvncserver(View Only)

  • Install VNC Server : sudo apt-get install tightserver
  • Inital password : vncserver :1
  • Run :  vncserver :1

Make VNC Server Always On

  • $ cd /home/pi
  • $ cd .config
  • $ mkdir autostart
  • $ cd autostart
  • $ nano tightvnc.desktop
  • Input following Coding 
    • [Desktop Entry]
    • Type=Application
    • Name=TightVNC
    • Exec=vncserver :1
    • StartupNotify=false
  •   ctrl-X and Y to Save

x11VNC (Full Function) 

  • (Recommanded)
  • Step 1 : sudo wget http://goo.gl/MbfUEp -O isx11.sh
  • Step 2 : sudo bash isx11.sh
  • Setp 3 : sudo reboot
  • Best Viewer : bVNC Free (Android) , tightvnc (Mac) 
  • sudo x11vnc -storepasswd PaSSwoRD /etc/x11vnc.pass

LAN and Wifi Stiatic Setup

  • Use a mobile phone as a WiFi hotspot with home WiFi settings
  • Or Set static IP Address as following, for direct cable connect with Computer :
    • Edit file : nano /etc/network/interfaces
    • Add following lines at the end of file 
      • auto eth0:1
      • iface eth0:1 inet static
      • address
      • netmask
    • sudo apt-get purge ifplugd
    • sudo reboot
  • and then use this command via LX Terminal
  • sudo apt-get purge ifplugd
  • And then re-boot.
  • LAN Static 
  • $ sudo nano /etc/network/interfaces
    auto lo
    iface lo inet loopback
    # iface eth0 inet dhcp
    auto eth0
    iface eth0 inet static
    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp
  • WIFI Static 
  • iface wlan0 inet static
    wpa-ssid SSID
    wpa-psk PSK

    iface default inet static

    $ sudo service networking restart

    reference : 

PL2303 Direct Terminal Cable

  • learn_raspberry_pi_gpio_closeup.jpg 
  • The red lead should be connected to 5V, 
  • The black lead to GND, 
  • The white lead to TXD.
  • The green lead to RXD.

Backup / Restore SD Card Image on Mac 

  • Backup 
  • List /dev/diskX : diskutil list 
  • Cloning SD : sudo dd if=/dev/disk2 of=~/Desktop/raspberrypi.dmg

  • Restore
  • diskutil unmountDisk /dev/diskX
  • sudo newfs_msdos -F 16 /dev/disk2
  • sudo dd if=~/Desktop/raspberrypi.dmg of=/dev/disk2
  • (Take 3 Hours More, So, PLease think about it before do that)
        Simple Way
  • MAC / Linux: 
  • Check Disk Number X : diskutil list
  • (~20 Mins)  : sudo dd if=/dev/diskX bs=1m | gzip > ~/Desktop/20140408RPi.gz 
  • (~2 Hour) : gzip -dc ~/Desktop/20140408RPi.gz | sudo dd of=/dev/diskX bs=1m
  • Window
  • Win32 Disk image

Install img.xz to SD Card

  • Unarchiver .img.xz into .img
  • Pifiller (MAC) write to SD Card 
    • Unplug SD CARD
    • Open Pifiller and Select .img
    • Plug SD CARD

Mount an External Hard Disk

  • Check disk structure : sudo fdisk -l
  • Mount : sudo mount /dev/sdaX /mnt
  • Change permissions to access the drive : sudo chmod 775 /mnt
  • Auto Mount : 
    • sudo nano /etc/fstab
    • Add : /dev/sdaX /mnt /ntfs defaults 0 0
    • sudo reboot
  • Unmount : sudo unmount /mnt

Apk and dpkg

  • dpkg -i bluefish_1.0.3-0.1_i386.deb (安裝 .deb 套件)
  • dpkg -l | more (列出所有己安裝的清單)
  • dpkg -l | grep nano (查 nano 是否已安裝了?)
  • dpkg -L nano (列出 nano 所有的安裝目錄及檔案內容)
  • dpkg -S /usr/bin/passwd (查 passwd 屬於那一個套件?)
  • dpkg -I bluefish_1.0.3-0.1_i386.deb (查套件資訊)
  • dpkg -c bluefish_1.0.3-0.1_i386.deb (列出未安裝套件的內容)
  • dpkg -P bluefish (移除, 連同設定檔)
  • dpkg -r bluefish (只移除主程式, 但留下設定檔)
  • ----------------------------------------------------------
  • apt-get update (更新套件索引清單)
  • apt-get upgrade (套件升級更新)
  • apt-get install nano (安裝套件 nano)
  • apt-get remove nano (移除套件 nano, 但會留下設定檔)
  • apt-get --purge remove nano (完全移除套件 nano)
  • apt-cache search nano (由套件索引清單中查查看是否有這個套件?)
  • apt-setup (用來設定 /etc/apt/sources.lst)
  • apt-get source 套件名稱 (若 sources.lst 中設定 deb-src,
  • 就可以用此指令來抓取程式的原始碼)
  • apt-get clean (清除已下載的 deb 檔 cache, 位於 /var/cache/apt/archive 中)
  • ----------------------------------------------------------
  • dpkg-reconfigure 套件名稱 (重設套件的相關設定或選擇)
  • ----------------------------------------------------------
  • apt-get upgrade 之後, 要注意處理的事項.

Clone Installed Package to next computer

  1. Read Installed Package List : $ dpkg --get-selections >pkg-list
  2. Copy to New Computer and :
  3. ## Update dpkg's database of known packages
    # avail=`mktemp`
    # apt-cache dumpavail > "$avail"
    # dpkg --merge-avail "$avail"
    # rm -f "$avail"
    ## Update dpkg's selections
    # dpkg --set-selections < pkg-list
    ## Ask apt-get to install the selected packages
    # apt-get dselect-upgrade
  4. Reinstall Demaged Package
    # apt-get --reinstall install postfix

Manage Disk

  • Install gparted (GUI Part) : sudo apt-get install gparted
  • Create and Modify Partitions
  • Mount : sudo mount /dev/xxxxxx /mnt/<new dir>
  • Set automount on : sudo nano /etc/fstab
         # /etc/fstab: static file system information.
         # <file system>     <mount point>   <type>  <options>   <dump >  <pass>
         /dev/hda1            /               ext2    defaults    0       1
         /dev/hda3            none            swap    sw          0       0
         proc                 /proc           proc    defaults    0       0
         /dev/hda5            /tmp            ext2    defaults    0       2
         /dev/hda6            /home           ext2    defaults    0       2
         /dev/hda7            /usr            ext2    defaults    0       2
         /dev/hdc             /cdrom          iso9660 ro,noauto   0       0
         /dev/fd0             /floppy         auto    noauto,sync 0       0
         /dev/xxxx            /media/newspace   ext4    defaults     0       0
  • Mount and Create Directory on /media can view on file manager

Screen Blank Control

  • xset s off         # don't activate screensaver
    xset -dpms         # disable DPMS (Energy Star) features.
    xset s noblank     # don't blank the video device

    into the


Compess and decompress - file or filder

  • Compress : tar -zcvf xxx.tar.gz <file or folder name>
  • De-Compress : tar -zxvf xxx.tar.gz -C <target directory>
  • Check : tar -jtv xxx.tar.gz

Change Host Name and Password

Change Host Name

  • sudo nano /etc/hostname
  • sudo nano /etc/hosts
  • sudo reboot

Change Password

  • sudo passwd root

User Control

Add User

  • useradd <username>
  • passed <username>

Add Group

  • useradd -G {group name} <username>
  • grep group name /etc/group
  • groupadd {group Name}
  • useradd -G {group name} <user name>
  • passwd <user name>
  • id <user name>

Change default user pi to your name

  • sudo usermod -l <new name> pi
  • sudo usermod -m -d /home/<new name>  <new name>



Services Start and Stop

Under Debian Linux startup files are stored in /etc/init.d/ directory and symbolic linked between /etc/rcX.d/ directory exists. Debian Linux uses System V initialization scripts to start services at boot time from /etc/rcX.d/ directory. Debian Linux comes with different utilities to remove unwanted startup file: 

(A) rcconf

This tool configures system services in connection with system runlevels. It turns on/off services using the scripts in /etc/init.d/. Rcconf works with System-V style runlevel configuration. It is a TUI(Text User Interface) frontend to the update-rc.d command. 

Install rcconf in Debian

#apt-get install rcconf

To start rconf, login as root user and type rcconf

# rcconf

Select the service you would like to enable or disable.

(B) sysv-rc-conf 

sysv-rc-conf provides a terminal GUI for managing "/etc/rc{runlevel}.d/" symlinks. The interface comes in two different flavors, one that simply allows turning services on or off and another that allows for more fine tuned management of the symlinks. Unlike most runlevel config programs, you can edit startup scripts for any runlevel, not just your current one. 

Install sysv-rc-conf in debian

#apt-get install sysv-rc-conf

This will install sysv-rc-conf.Now you need to run the following command

# sysv-rc-conf

Select the service you would like to enable or disable. 

Both sysv-rc-conf and rcconf are best tools to use on Remote Debian Linux or when GUI is not available

You can also use update-rc.d script as follows (update-rc.d removes any links in the /etc/rcX.d directories to the script /etc/init.d/service):

# update-rc.d -f {SERVICE-NAME} remove

For example to stop xinetd service you can type command as follows:

# update-rc.d -f xinetd remove

IP Address Control and list

  • $ iwlist wlan0 scanning
  • Get IP Address : ifconfig | grep inet | cut -d':' -f2 | cut -d' ' -f1 | grep -v 127