樹莓派入坑指南,自己踩過的一些坑,在此處記錄分享一下,并附上處理方法。不定期更新
0.初始化相關(guān)
1./boot/config.txt --顯示初始化相關(guān)
2./etc/lightdm/lightdm.conf --屏保睡眠設(shè)置
3./etc/network/interfaces --網(wǎng)絡(luò)設(shè)置
4./etc/resolv.conf --DNS設(shè)置
5./etc/rc.local --自啟動腳本執(zhí)行
6.~/.config --自定義圖形化應(yīng)用程序自動啟動
7./etc/resolvconf.conf --自定義DNS服務(wù)器
0.初始化相關(guān)
1.系統(tǒng)安裝:官網(wǎng)現(xiàn)在推薦使用noobs這個工具,是樹莓派官方推薦的系統(tǒng)安裝方式,使用非常簡單,下載后是一個壓縮包,解壓后放在格式化好的tf卡內(nèi)即可啟動,圖形化的界面,選擇需要安裝的系統(tǒng)即可,或者是用磁盤映像,直接寫入到tf卡也是一樣的.都非常簡單需要用的工具:SD Formatter,NOOBS,Win32 Disk Imager.
2.系統(tǒng)初始化:進入系統(tǒng)后默認(rèn)是英國英文,鍵盤布局之類都和國內(nèi)不同,需要修改配置,然后系統(tǒng)默認(rèn)沒有中文支持,需要配置和安裝字體。
sudo passwd
設(shè)置su的密碼。設(shè)置后, 可以運行
sudo raspi-config
進行配置,可以設(shè)置的項目都比較簡單基本可以直接看懂,包括樹莓派的超頻以及顯存分配都可以直接在這里配置,這里介紹一下語言配置Internationalisation Options,可以設(shè)置地區(qū),時區(qū)以及鍵盤布局。這里需要增加美國英語的支持以及中文支持,需要加選,
en_US.UTF-8 UTF-8
zh_CN GB2312
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
隨后會提示設(shè)置系統(tǒng)的默認(rèn)語言,推薦選擇en_US,然后保存退出,然后設(shè)置時區(qū)以及鍵盤布局,鍵盤布局需要設(shè)置成en_US
然后重啟
sudo reboot
重啟后,樹莓派不會默認(rèn)安裝設(shè)定語言的字體,需要自己安裝:
sudo apt-get install ttf-wqy-zenhei
如果需要安裝中文輸入法:
sudo apt-get install scim-pinyin
1.config.txt
配置樹莓派基本的顯示和初始化相關(guān)的基本配置,包括分辨率,屏幕旋轉(zhuǎn),HDMI輸出邊界檢測,和睡眠時間等等.
display_rotate配置表示屏幕順時針旋轉(zhuǎn)如display_rotate=3表示順時針旋轉(zhuǎn)3*90度
overscan_left|top|righrt|buttom分別表示樹莓派使用HDMI輸出的時候個方向屏幕防越邊界檢測
# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1920
#framebuffer_height=1080
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# NOOBS Auto-generated Settings:
#display_rotate=3
display_rotate=0
hdmi_force_hotplug=1
config_hdmi_boost=4
#overscan_left=24
#overscan_right=24
#overscan_top=16
#overscan_bottom=16
disable_overscan=1
#disable_overscan=0
2./etc/lightdm/lightdm.conf
xserver-command=X -s 0 dpms
禁用屏保和休眠
3./etc/network/interfaces
樹莓派的網(wǎng)絡(luò)配置文件其中包含有線網(wǎng)絡(luò)和wlan網(wǎng)絡(luò),理論上可以在此處配置IP地址和DNS服務(wù)器,但是DNS配置后從未生效過,待問題解決后更新
/etc/network/interfaces
#默認(rèn)的配置文件
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
設(shè)置有限網(wǎng)絡(luò)為靜態(tài)ip地址
auto ethiface eth0 inet static
address 10.52.91.222 ## 設(shè)定的靜態(tài)IP地址
netmask 255.255.255.0 ## 網(wǎng)絡(luò)掩碼
gateway 10.52.91.1 ## 網(wǎng)關(guān)
4./etc/resolv.conf --DNS設(shè)置
resolv.conf文件每次重新啟動會重新根據(jù)配置文件初始化,所以手動設(shè)置后只會在本地系統(tǒng)未重啟動時生效,一旦系統(tǒng)重啟,需要重新設(shè)置。本來這個文件是不需要自己手動設(shè)置的,只是因為在/etc/network/interfaces文件中手動配置DNS服務(wù)器不生效,所以設(shè)置此文件臨時起效,待問題解決后更新.
設(shè)置DNS的方式:
sudo echo "nameserver xxx.xxx.xxx.xxx" > /etc/resolv.conf
5./etc/rc.local
根據(jù)官方的文檔資料,如果想要配置自定義的自啟動的服務(wù)或者腳本,那么就是寫在/etc/rc.local中 ,如果是python腳本需要在執(zhí)行命令前指定python,例如:
python /home/pi/myscript.py &
6.~/.config
使用樹莓派的時候遇到了這樣的一個需求:需要桌面啟動之后自動運行一個圖形化的應(yīng)用程序(我們是使用了nw.js來做輕客戶端的),在這里使用/etc/rc.local是無效的,圖形化程序是需要桌面啟動之后才能夠運行的,所以這里使用~/.config目錄來達到目的,這是一個隱藏目錄,需要使用ls -al來顯示出來.進入后先創(chuàng)建一個目錄:
mkdir autostart
進入目錄,創(chuàng)建我們的自啟動應(yīng)用程序腳本:
sudo vi my.desktop(或sudo nano my.desktop 文件名可自定義)
寫入以下內(nèi)容:
[Desktop Entry]
Type=Application
Exec=你的程序啟動腳本
6./etc/resolvconf.conf
使用很多種方式設(shè)置樹莓派的DNS地址,但是每次系統(tǒng)重啟之后都會被重新指定到網(wǎng)關(guān)地址。后來發(fā)現(xiàn)DNS地址可以在這個文件里手動指定:
name_servers=202.98.0.68
設(shè)置后,不會在系統(tǒng)重啟之后重置。