Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

树莓派快速入门配置 #27

Open
anyesu opened this issue Sep 23, 2019 · 0 comments
Open

树莓派快速入门配置 #27

anyesu opened this issue Sep 23, 2019 · 0 comments

Comments

@anyesu
Copy link
Owner

anyesu commented Sep 23, 2019

前言


最近刚入坑树莓派,在这里做个分享。

购物清单


设备 价格 说明
Raspberry Pi 3B+ ( 单独主板 ) ¥228 按网上的说法,E14 和 RS 除了产地没区别
树莓派 5V3A 电源 + 开关电源线 ¥29.7 大功率电源可以接更多设备,开关可以减少插拔
闪迪 32g 内存卡 class10 存储 sd卡 ¥28.50 已有十年前的 8G TF 卡和读卡器,为了保险起见还是买了张新卡
树莓派3B+ 彩虹层叠外壳 + 散热片 + 风扇 ¥31 看中的是不一样的外观

其他已有的调试必备硬件:

  • 显示器 + HDMI 线

  • USB 键鼠

  • TF 读卡器

  • 网线 ( 非必须 )

淘宝链接就不给了,自己去货比三家吧,都差不多。如果不清楚要买什么,还是推荐购买卖家提供的基础套件大礼包。对了,我买的主板 电源指示灯 是不亮的 ( 应该是硬件坏了 ) ,折腾完系统才发现这茬事,虽然能正常使用还是有点不爽。

安装系统


1. 下载镜像

上面都是亲测可用的系统,下文以 2019-04-08-raspbian-stretch-full 举例。使用迅雷通过种子方式下载还是比较快的,下载后要 解压Ubuntu MATE 对于 WiFi 的兼容性不太好,家里旧的路由器只有小概率能连上。

2. TF 卡格式化

使用 SDFormatter 格式化 TF 卡 ( 报错失败就重试 ) ,点此下载

3. 烧录系统

使用 win32diskimager 或者官网推荐的 Etcher ,烧录速度取决于 TF 卡 的写入速度。烧录完成由于系统无法识别 TF 卡,会弹框提示 格式化,千万别手贱去点。重新 烧录系统前记得先 格式化 TF 卡

系统配置


由于安装的系统默认都没有开启 SSH , 所以还得先用上显示器、键鼠和网线。

1. 树莓派插入 TF 卡,连接显示器、网线、键鼠,再启动树莓派

注意顺序,先通电再连显示器可能会无法识别显示器。

2. 根据开机引导设置国家和密码,其他设置跳过,重启树莓派
3. 开启 SSH 和 VNC ,现在可以摆脱显示器和键鼠,通过电脑远程连接了

点击任务栏左上角的 草莓图标 -> 首选项 -> Raspberry Pi Configuration -> Interfaces 选项卡 ,对应项选择 Enable ,点击 OK 保存。

4. 修改为中科大的软件源
# 1. 备份原来的数据源配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
# 2. 修改数据源配置文件
sudo sh -c 'echo "deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi" > /etc/apt/sources.list'
# 3. 更新配置
sudo apt-get update
5. 自带的 vi 编辑器有点问题,可以安装 vim 或者使用 nano 代替
sudo apt-get install -y vim
6. 设置 WiFi ( 参考 )

任务栏点击 WiFi 图标选择自己的网络即可。配置文件为 /etc/wpa_supplicant/wpa_supplicant.conf 中,可自己手动添加配置,如果 WiFi 禁用了广播 SSID ,还需要添加配置项 scan_ssid=1 ( 重启树莓派后自动连接 )

7. 安装 zsh

这个看个人需求了,不需要的请略过此步骤。

# 安装 zsh
sudo apt-get -y install zsh
# 修改账户的默认 shell
chsh -s `which zsh`
# 下载配置 ~/.zshrc
curl -L https://raw.githubusercontent.com/skywind3000/vim/30b702725847bac4708de34664bb68454b54e0c0/etc/zshrc.zsh > ~/.zshrc

# 修改主题, 参考:https://github.com/robbyrussell/oh-my-zsh/wiki/themes
sed -i 's$# antigen theme fishy$antigen theme ys$' ~/.zshrc

# zsh 按键补齐
cat >> ~/.zshrc <<EOF
# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history

# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix

# Fix numeric keypad  
# 0 . Enter  
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3  
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6  
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9  
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + - * /  
bindkey -s "^[Ol" "+"
bindkey -s "^[Om" "-"
bindkey -s "^[Oj" "*"
bindkey -s "^[Oo" "/"
EOF

# 配置修改完重新执行 zsh
zsh

备份系统


上面辛辛苦苦终于配置完系统了,还剩下一个问题:如果系统玩坏了或者买了新设备,难道又要花一堆时间重复上面的步骤?当然不必,我们可以针对配置好的系统进行备份,方便以后快速恢复。

备份前先清空下历史命令

echo > .bash_history
# echo > .zsh_history
  • 方案一:使用 Raspbian 系统自带的工具 SD Card Copier

    将另一张 TF 卡 通过读卡器插入树莓派的 USB 接口,点击任务栏左上角的 草莓图标 -> 附件 -> SD Card CopierCopy From Device 选择 /dev/mmcblk0Copy To Device 选择 /dev/sda , 点击 Start 开始备份,时间约 10 ~ 30 分钟。这个方案比较简单快速,但需要一张额外的 TF 卡

  • 方案二:使用 win32diskimager

    上文中烧录系统使用 win32diskimager 的写入功能,备份就是使用它的读取功能,将 TF 卡 中的数据备份到指定的文件中。新建一个txt文件,带后缀名 一起重命名为 backup.img,然后在 win32diskimager 中选择这个空文件,插入装好系统的 TF 卡,开始读取。备份结束就可以使用这个镜像来烧录系统了。这个方法也比较简单,但是比较浪费空间和时间,因为卡容量有多大,备份的镜像就有多大,所以还是尽量选容量小一点的卡 ( 8G ) 来备份。

  • 方案三在树莓派中借助别人写好的脚本导出备份到镜像中 ( 参考 )

    该方法能成功导出镜像,但是启动会卡在四个草莓的界面,所以该方法无效。

扩展阅读


上文中到一些概念没有细讲如:SSHVNCZSH,还有一些 Linux 相关的使用,可以参考我的另一篇文章 - Windows10内置Linux子系统初体验

结语


经过上面的配置,树莓派已经正式成为了一台微型家用服务器了,如果止步于此的话还不如买一台云服务器玩玩呢。树莓派于我的意义在于丰富的硬件和传感器控制,再配合天猫精灵还有云服务器,打造属于自己的智能家居场景。


转载请注明出处:https://www.jianshu.com/p/742c2697a007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant