【树莓派】系统安装 & 初始化配置

概述

官网、社区

树莓派官网:https://www.raspberrypi.org/
树莓派实验室:http://shumeipai.nxez.com/
Linux 中国:https://linux.cn/tech/raspberrypi/

安装系统

下载系统

raspbian 历史版本:http://downloads.raspberrypi.org/raspbian/images/

写入镜像

TF卡插入电脑,使用 Etcher 等工具写入系统镜像

设置wifi和ssh

# 在boot文件夹下新建 ssh 和 wpa_supplicant.conf 文件  

# wpa_supplicant.conf 文件:
country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="Tooi"
        psk="zx123456"
        priority=1
}
## ssid:wifi名称
## psk:wifi密码
## prioity:优先级(越小优先级越高)

使用 ssh 连接树莓派

账号:pi
默认密码:raspberry

解锁root账户ssh登录

# 修改 root 密码
# sudo passwd root

# 启用 root 账号登录
passwd --unlock root

# 更改ssh配置文件
sudo nano /etc/ssh/sshd_config
### PermitRootLogin yes

# 重启
reboot

更换源

查看有哪些源:https://www.raspbian.org/RaspbianMirrors

# 修改树莓派源
sudo nano /etc/apt/sources.list.d/raspi.list
# 将内容替换成:
deb https://mirrors.ustc.edu.cn/archive.raspberrypi.org/ stretch main ui

# 修改 Ubuntu 源
sudo nano /etc/apt/sources.list
# 将内容替换成:
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

# 更新
sudo apt-get update

设置 DNS:

sudo nano /etc/resolv.conf     
###  
domain DHCP 
search DHCP HOST   
nameserver 8.8.8.8  
###  

更换 pip 源

sudo mkdir ~/.pip
sudo nano ~/.pip.conf

[global]
timeout = 10
index-url =  http://mirrors.aliyun.com/pypi/simple/
extra-index-url= http://pypi.douban.com/simple/
[install]
trusted-host=
    mirrors.aliyun.com
    pypi.douban.com

配置树莓派

sudo raspi-config

image
  • Change User Password:

修改当前用户的密码

  • Localisation Options

本地化设置(修改地区,时区,wifi)

  • Interfacing Options

打开Camera(相机)、SSH、Serial、Remote GPIO

  • Advanced Options

选择Expand Filesystem,将根目录扩展到这个SD卡,充分利用SD卡的存储空间
选择Overscan,在整个屏幕上显示
选择Audio,选择Force 3.5mm('headphone' jack),树莓派的声音会从耳机孔输出
选择Resolution,选择默认设置,自动根据显示屏调整分辨率
选择Pixel Doubling,增加桌面显示画质

使用 VNC 连接

# 进入 Interfacing Options 配置,开启 VNC
sudo raspi-config  

# 新建配置文件
sudo nano /etc/init.d/vncserver
### begin ###
#!/bin/sh
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop vncserver
### END INIT INFO
# More details see:
# http://www.penguintutor.com/linux/vnc
### Customize this entry
# Set the USER variable to the name of the user to start vncserver under
export USER='pi'
### End customization required
eval cd ~$USER
case "$1" in
start)
# 启动命令行。此处自定义分辨率、控制台号码或其它参数。
su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1024x768 :1'
echo "Starting VNC server for $USER "
;;
stop)
# 终止命令行。此处控制台号码与启动一致。
su $USER -c '/usr/bin/vncserver -kill :1'
echo "vncserver stopped"
;;
*)
echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;
esac
exit 0
### end ###

# 修改权限
sudo chmod 755 /etc/init.d/vncserver  

# 开机启动  
sudo update-rc.d vncserver defaults

# 重启 
sudo reboot

# 开机后就可以连接了
账户:pi
默认密码:raspberry
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。