FelixHsp 2015-10-16
树莓派(Raspberry Pi)是 Raspberry Pi Foundation 推出的迷你电脑,它只有信用卡大小,但可以完成一台普通 PC 能完成的大部分工作,并且价格很便宜,是电脑爱好者的不二选择,如果你是一名 Linuxer 更应该拥有一台这样的迷你电脑。
Raspberry Pi 自 2012 年发布以来,依次发布了 Raspberry Pi 1 A , Raspberry Pi 1 B ,Raspberry Pi 1 B+ ,Raspberry Pi 1 A+ ,Raspberry 2 B 五个版本,这些版本硬件上有不少变化,具体可以查阅 Wikipedia Raspberry Pi ,另外 Raspberry Pi 2 B 将支持 Windows 10 iot ,这对非 Linux 用户来说也是一个福音,因为你可以完全把 Raspberry Pi 2 B 当成你的另一台 Windows PC ,详情可以查看 Raspberry Pi Windows 10 iot。
Raspberry Pi 到底能拿来做什么呢?它的玩法多的数不清了,因为这取决于我们的创意,作为一块开发板,它给我们提供了很大的自由。
下面是几张引用文章内的图:
由于 Raspberry Pi 几乎是为 Linux 而生的,所以 Raspberry Pi 的操作系统也是多样的,为此以下介绍几个操作系统。
以上操作系统都可以在 Raspberry Pi 主页 找到相关信息。
笔者只是将 Raspberry Pi 当成个人电脑使用而已,因此,未选择 Raspbian 而是选择了 Arch Arm。
下面是我选择的配件
首先参照 Arch Arm Installation 安装系统。
为 SD 卡分区(用你 Linux 上的 sd 卡设备代替 sdX ):
<span class="kwd">fdisk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdX</span>
第一步请先删除原来的分区并重新创建:
创建和挂载 vfat 文件系统(用你 Linux 上的 sd 卡设备代替 sdX ):
<span class="kwd">mkfs</span><span class="pun">.</span><span class="pln">vfat </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdX1</span>
<span class="kwd">mkdir</span><span class="pln"> boot</span>
<span class="kwd">mount</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdX1 boot</span>
创建个挂载 ext4 文件系统(用你 Linux 上的 sd 卡设备代替 sdX ):
<span class="kwd">mkfs</span><span class="pun">.</span><span class="pln">ext4 </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdX2</span>
<span class="kwd">mkdir</span><span class="pln"> root</span>
<span class="kwd">mount</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdX2 root</span>
使用 root 用户下载和解压 根文件系统:
<span class="kwd">wget</span><span class="pln"> http</span><span class="pun">:</span><span class="com">//archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz</span>
<span class="pln">bsdtar </span><span class="pun">-</span><span class="pln">xpf </span><span class="typ">ArchLinuxARM</span><span class="pun">-</span><span class="pln">rpi</span><span class="pun">-</span><span class="lit">2</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz </span><span class="pun">-</span><span class="pln">C root</span>
<span class="kwd">sync</span>
移动启动文件到第一分区:
<span class="kwd">mv</span><span class="pln"> root</span><span class="pun">/</span><span class="pln">boot</span><span class="com">/* boot</span>
卸载挂载点:
<span class="kwd">umount</span><span class="pln"> boot root</span>
将 SD 卡插入 Raspberry Pi ,连接以太网和 5v 电源。
默认用户是 alarm 密码 alarm。(ssh 请先用此用户登录,再修改 ssh 配置允许 root 登录)
root 的默认密码是 root。
注意 :以下用到 sudo
命令的,若你未配置 sudo
请直接用 root
用户执行。
首次使用应该按如下格式 ssh
登录:
<span class="pln">$ </span><span class="kwd">ssh</span><span class="pun">-</span><span class="pln">p </span><span class="lit">22</span><span class="pln"> alarm@</span><span class="pun">地址</span>
进去后使用 su
切换到 root
,并修改密码:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">su</span><span class="pun">-</span><br><span class="com">#</span><span class="pln"> password</span>
为了能使 root
通过 ssh
登录,编辑 /etc/ssh/sshd_config
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">nano</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="kwd">ssh</span><span class="pun">/</span><span class="pln">sshd_config</span>
将 #PermitRootLogin
这行去掉注释,并将值设置为 yes
:
<span class="typ">PermitRootLogin</span><span class="kwd">yes</span>
编辑 /etc/pacman.d/mirrorlist
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">nano</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">pacman</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">mirrorlist</span>
在顶部增加以下代码,这是中科大的源
<span class="com">##</span><span class="pln"> USTC</span>
<span class="typ">Server</span><span class="pun">=</span><span class="pln"> http</span><span class="pun">:</span><span class="com">//mirrors.ustc.edu.cn/archlinuxarm/armv7h/$repo</span>
编辑好后按 ctrl +x
,然后按 y
保存,然后升级整个系统:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="typ">Syu</span>
首先安装 xorg
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S xorg</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S xorg</span><span class="pun">-</span><span class="pln">xinit</span>
然后安装 lxqt
桌面:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S lxqt</span>
首先配置 vncviewer,本机与 Raspberry Pi 都需要安装 tigervnc
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S tigervnc</span>
在 Raspberry Pi 中执行 vncserver
<span class="pln">$ vncserver </span>
<span class="typ">You</span><span class="pln"> will </span><span class="kwd">require</span><span class="pln"> a password to access your desktops</span><span class="pun">.</span>
<span class="typ">Password</span><span class="pun">:</span>
<span class="typ">Verify</span><span class="pun">:</span>
<span class="typ">Would</span><span class="pln"> you like to enter a view</span><span class="pun">-</span><span class="pln">only password </span><span class="pun">(</span><span class="pln">y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">)?</span><span class="pln"> n</span>
<span class="typ">New</span><span class="str">'ArchRaspi:1 (locez)'</span><span class="pln"> desktop </span><span class="kwd">is</span><span class="typ">ArchRaspi</span><span class="pun">:</span><span class="lit">1</span>
<span class="typ">Creating</span><span class="kwd">default</span><span class="pln"> startup </span><span class="kwd">script</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">locez</span><span class="pun">/.</span><span class="pln">vnc</span><span class="pun">/</span><span class="pln">xstartup</span>
<span class="typ">Starting</span><span class="pln"> applications specified </span><span class="kwd">in</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">locez</span><span class="pun">/.</span><span class="pln">vnc</span><span class="pun">/</span><span class="pln">xstartup</span>
<span class="typ">Log</span><span class="kwd">file</span><span class="kwd">is</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">locez</span><span class="pun">/.</span><span class="pln">vnc</span><span class="pun">/</span><span class="typ">ArchRaspi</span><span class="pun">:</span><span class="lit">1.log</span>
然后编辑 ~/.vnc/xstartup
,将原来的内容替换为以下内容,你也可以直接删除原文件,再新建一个同名文件:
<span class="com">#</span><span class="pun">!</span><span class="str">/bin/</span><span class="pln">sh</span>
<span class="kwd">unset</span><span class="pln"> SESSION_MANAGER</span>
<span class="kwd">unset</span><span class="pln"> DBUS_SESSION_BUS_ADDRESS</span>
<span class="kwd">exec</span><span class="pln"> startlxqt</span>
然后杀掉 vnc 服务,并重启它:
<span class="pln">$ vncserver </span><span class="pun">-</span><span class="kwd">kill</span><span class="pun">:</span><span class="lit">1</span>
<span class="typ">Killing</span><span class="typ">Xvnc</span><span class="pln"> process ID </span><span class="lit">400</span>
<span class="pln">$ vncserver </span>
<span class="typ">New</span><span class="str">'ArchRaspi:1 (locez)'</span><span class="pln"> desktop </span><span class="kwd">is</span><span class="typ">ArchRaspi</span><span class="pun">:</span><span class="lit">1</span>
<span class="typ">Starting</span><span class="pln"> applications specified </span><span class="kwd">in</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">locez</span><span class="pun">/.</span><span class="pln">vnc</span><span class="pun">/</span><span class="pln">xstartup</span>
<span class="typ">Log</span><span class="kwd">file</span><span class="kwd">is</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">locez</span><span class="pun">/.</span><span class="pln">vnc</span><span class="pun">/</span><span class="typ">ArchRaspi</span><span class="pun">:</span><span class="lit">1.log</span>
记住上面的 :1
可能根据实际情况不同,这个端口是你用 vncviewer
连接时用的端口。
然后本机中执行:
<span class="pln">$ vncviewer address</span><span class="pun">:</span><span class="pln">port</span>
然后输入密码就可以了
小屏幕显示
现在我们看见这个不是全屏的,但是可以在启动 vncserver 的时候增加参数,来指定分辨率:
<span class="pln">$ vncserver </span><span class="pun">-</span><span class="kwd">kill</span><span class="pun">:</span><span class="lit">1</span>
<span class="pln">$ vcnserver </span><span class="pun">-</span><span class="pln">geometry </span><span class="lit">1920x1000</span>
这下就全屏了
全屏
然后你可以在不另外配显示屏的情况下正常使用 Raspberry Pi ,将它配置成一个 samba
服务器,或者做成一个下载器,这仅仅取决于,你想将 Raspberry Pi 拿来干什么。
笔者还尝试将 Raspberry Pi 直接连入手机 Wi-Fi ,把手机当成路由器使用,获取手机内网 IP 后,直接在手机上 ssh
内网登录,从而实现 Raspberry Pi 使用手机流量上网,并且不用借助路由器就可以连接 Raspberry Pi。
这里笔者推荐的是 juiceSSH ,手机上简单实用的一款 ssh 工具。由于篇幅原因,此处不再详述如何使用手机直连 Raspberry Pi,动手能力强的同学可以参看上面我给的思路,自行折腾。
后来笔者,买了键盘以后,又利用 tmux
将手机纯粹当屏幕使用。
首先 手机先 ssh
登陆 Raspberry Pi,执行
<span class="kwd">tmux</span>
然后在看不见屏幕的情况下,使用键盘盲打输入 用户名 、 密码 进行登录,然后执行
<span class="kwd">tmux</span><span class="pln"> attach</span>
此时键盘与手机屏幕的输入已经是同步的,一台个人作品就此完成!
下面几张图,是笔者在学校折腾的时候拍的: