[玩转树莓派] 0x01 选个系统先

[TOC]

[玩转树莓派] 选个系统先

Install Raspbian

0x00 树莓派的安装配置(无显示器)

树莓派没有硬盘,我们拿到设备之后是不能直接用的,因此需要先给它配置一个装好系统的存储卡。这篇文字,给大家介绍如何安装并初始化树莓派系统。

Raspbian 是树莓派基金会官方支持的系统,我们可以直接下载他的安装文件或者使用官网推荐的 NOOBS 来完成安装操作。除了官方支持的系统,树莓派还有很多第三方支持的系统,如:UBUNTU MATESN ![Uploading win32diskimager_914364.png . . .]APPY UBUNTU COREWINDOWS 10 IOT COREOSMCOPENELECPINETRISC OSWEATHER STATION等,这里有我们比较熟悉的WINDOWS 10 IOTUBUNTUOSMC等。UBUNTU系统是非常火的一个Linux发行版本,WINDOWS 10 IOT是微软开发的物联网系统,OSMC可以作为家庭媒体中心使用,其他系统大家可以自行了解。

前一篇文章简单介绍了我的硬件环境,是没有显示器和外接键盘鼠标的,因此我会基于这个前提给大家介绍如何玩转树莓派。

这么多系统,初学者可能会很纠结如何选择。这里给大家推荐官方支持的Raspbian(基于Debian Jessie)系统,他预装了很多常用、编程、教育软件,如Python(python3)、Scratch、Sonic Pi、Java、Mathematica等等。Raspbian包含RASPBIAN JESSIE(Full desktop image based on Debian Jessie)和RASPBIAN JESSIE LITE(Minimal image based on Debian Jessie)两个版本,由于之后我们会用到桌面环境,因此我们最终选择RASPBIAN JESSIE,带桌面环境的版本。

0x01 下载

决定了使用RASPBIAN JESSIE(非RASPBIAN JESSIE LITE),我们只需要到树莓派的官网下载系统文件即可。他的最新版本是 March 2016:

  • 发布:2016-3-18
  • Linux内核:4.1
  • 文件名:2016-02-26-raspbian-jessie.zip
  • MD5: db41f2a8c6236c0ca9150fe4db2017c09e7871fb
  • 大小:1.3G

对下载的文件进行加压,得到2016-02-26-raspbian-jessie.img,大小4.03G,这个就是我们安装要用到的系统镜像文件。

0x02 安装

系统的安装比较简单,就是将我们刚下载的安装镜像文件写入到TF卡中。官方的 安装帮助文档 对系统的安装进行了详细的介绍。本着简化操作的原则,这里再做简单概述。

  • Windows系统

    Windows系统安装推荐使用win32diskimager,这是一个图形化工具,操作非常简单:以管理员方式打开,ImageFile选择刚下载的img镜像,Device选择我们的TF卡所在驱动器,点击Write即可。

    [玩转树莓派] 0x01 选个系统先_第1张图片
    win32diskimager
  • Mac系统

    跟Windows系统一样,我们推荐图形界面的ApplePi-Baker,操作界面如下:

[玩转树莓派] 0x01 选个系统先_第2张图片
ApplePi-Baker
左侧选择SDCard,右侧选择我们的镜像文件,点击Restore Backup按钮即可。
  • Mac系统命令行方式

    由于我用的Mac系统,所以简单介绍下这种稍微复杂点的方式但也就是简单几步操作:

    1. 插入SDCard卡,使用磁盘管理工具对其进行擦除,格式选择MS-DOS(FAT),完成后推出SDCard(推出并不是拔出)

    2. 使用df -h查看SDCard的路径,如下的 /dev/disk2s1,我们记下 disk2

➜ ~ df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
devfs 185Ki 185Ki 0Bi 100% 640 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
/dev/disk2s1 60Mi 20Mi 40Mi 34% 512 0 100% /Volumes/raspi
➜ ~
```

3. 执行如下命令,将镜像文件烧录进SDCard,这个过程会因为你的SDCard卡的速度的不同而不同,期间你可以通过`Ctrl+T`来查看进度:

    `sudo dd bs=1m if=2016-02-26-raspbian-jessie.img of=/dev/rdisk2`

如果命令行方式有问题,请参考[官方说明](https://www.raspberrypi.org/documentation/installation/installing-images/mac.md)解决。

烧录完成之后SDCard内容如下:

[玩转树莓派] 0x01 选个系统先_第3张图片
raspbian jessie

0x03 配置——登录树莓派

完成以上操作,将SDCard插入树莓派加电就可以顺利跑起来了。我们再强调一遍,即使没有键盘鼠标显示器,也是可以操作树莓派的,包括安装时。简单的拓扑如下图:

[玩转树莓派] 0x01 选个系统先_第4张图片
简单拓扑

启动树莓派可以有两种方式:无外接键盘鼠标显示器有外接键盘鼠标显示器(虽然我假设自己没有多余的键盘显示器,但是我还是会在此介绍这种方式~~)。

这两种方式无论选择哪种,我们都需要先将树莓派通过RJ45接口与我们的路由器相连(说人话就是拿网线连接树莓派和路由器)。别问我为什么这么做,因为这样最简单,跟着做就好(当然,我知道你也可以直接拿根网线直接连接电脑和树莓派,但是非常不建议这么做,因为这么屌的你已经可以不用来看这篇文章了),或者你会说没有路由器,你真的没路由器?那赶紧买一个吧。

这里强烈建议通过路由器的设置给树莓派分配静态IP,否则会非常麻烦。更多获取树莓派的IP的方法可参考这里。

  • 无外接键盘鼠标显示器

    这种方式最简单。树莓派接入网络,我们只需要登录路由器,到DHCP服务器中的客户端列表中查看我们的树莓派的IP,然后通过ssh命令登录树莓派就可以操作了。[默认的用户名密码][c2]:piraspberryssh 命令如下:

ssh pi@
```

密码输入无回显

  • 外接键盘鼠标显示器

    如果你有多余的键盘鼠标显示器供给树莓派使用,那么第一次启动的时候,我们需要简单配置下树莓派使其支持HDMI输出。打开我们的SDCard,在根目录下,看到有这么一个文件:config.txt。我们需要修改他支持HDMI的显示(1080P的输出),下面是我配置的Demo:

    pi@raspi:/boot $ cat config.txt
    # 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=1280
    #framebuffer_height=720
    
    # 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=2
    hdmi_mode=82
    
    # 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
    device_tree=
    

    参考:

    1. 解决Raspberry Pi只能在默认640×480模式下显示的问题
    2. http://elinux.org/RPiconfig

0x04 配置——WIFI

如果你想摆脱网线的束缚,我们可以使用WIFI来接入网络。最新的树莓派3板载了WIFI,树莓派2代需要我们自己配置无线网卡。官方的配置参考这里。如何查看我们的无线网卡是否正确识别,可以使用lsusb命令,如:

pi@raspi:~ $ lsusb
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 004: ID 0bda:8178 Realtek Semiconductor Corp. RTL8192CU 802.11n WLAN Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

第二行的Devices 004 RTL8192CU就是我的无线网卡。RASPBIAN JESSIE系统默认集成了RTL8192CU的驱动,所以我插上去之后就能用了。如果你的无线网卡无法检测到,请检查驱动配置,由于无线网卡型号太多,驱动安装就不展开讲了,可以参考这里。

  • 直接修改配置文件

    树莓派的网络配置文件位于 /etc/network/interfaces/etc/wpa_supplicant/wpa_supplicant.conf文件中,我们将通过对其修改来使用我们的WIFI。修改之前建议先做备份:

sudo cp /etc/network/interfaces /etc/network/interfaces.bak
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
```

下面是默认的 `interfaces` 配置文件:

``` shell
$ cat interfaces
# 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
```

在默认的 interfaces 配置下,我们可以仅仅修改 /etc/wpa_supplicant/wpa_supplicant.conf来完成WIFI配置,比如我的 wpa_supplicant.conf文件如下:

``` shell
$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="my wifi ssid"
    psk="my password"
    key_mgmt=WPA-PSK
}
``` 
我的WIFI加密方式是 `WPA-PSK/WPA2-PSK` 因此配置 `key_mgmt=WPA-PSK` 加密方式可以在路由器的无线安全设置中查看。接下来我们还需要重启我们的WIFI:

 ``` shell

sudo ifdown wlan0
sudo ifup wlan0
```
或者直接重启系统 sudo reboot 。通过上面的设置,就可以连接我们的WIFI了。

当然,我们也可以不使用 `/etc/wpa_supplicant/wpa_supplicant.conf` 文件,仅仅修改 `interfaces` 来完成配置,如我的另一个配置:

``` shell
# 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 dhcp

# auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.56
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid 
wpa-psk 
```
更多的配置参数,可以参考[这里](TODO)。

>这里配置使用了静态IP
  • 通过GUI桌面环境进行配置

    这个就非常简单了,连接显示器键盘鼠标,登录桌面环境,点击右上角的WIFI图标,选择自己的WIFI,然后输入密码即可,如下图:

    [玩转树莓派] 0x01 选个系统先_第5张图片
    GUI WIFI Config

获取到IP并接入到网络,接下来,我们就可以开启我们的树莓派之旅。各位玩的开心~~

Create by ttdevs

你可能感兴趣的:([玩转树莓派] 0x01 选个系统先)