<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arch Linux ARM &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/arch-linux-arm/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Sun, 03 May 2020 12:29:29 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创]在Raspberry Pi(树莓派)上用OpenCV来操纵摄像头拍照/Use OpenCV on Raspberry Pi to Controll a Webcam to Take Photos</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b%e5%9c%a8raspberry-pi%e4%b8%8a%e7%94%a8opencv%e6%9d%a5%e6%93%8d%e7%ba%b5%e6%91%84%e5%83%8f%e5%a4%b4%e6%8b%8d%e7%85%a7use-opencv-on-raspberry-pi-to-controll-a-webcam-to-take-photos/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b%e5%9c%a8raspberry-pi%e4%b8%8a%e7%94%a8opencv%e6%9d%a5%e6%93%8d%e7%ba%b5%e6%91%84%e5%83%8f%e5%a4%b4%e6%8b%8d%e7%85%a7use-opencv-on-raspberry-pi-to-controll-a-webcam-to-take-photos/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 18 Oct 2012 07:46:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Raspberry Pi/树莓派]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Arch Linux ARM]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[webcam]]></category>
		<category><![CDATA[拍照]]></category>
		<category><![CDATA[摄像头]]></category>
		<category><![CDATA[教程]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=5014</guid>

					<description><![CDATA[<p>
<span style="background-color:#00ff00;">For non-Chinese readers:</span><br />
<span style="color:#0000ff;">I&#39;m a software engineer in Shanghai, China. Since I bought a Raspberry Pi, I spent some spare time on it and I&#39;m glad to share something with Pi users all over the world, so this article has two languages: Chinese &#38; English, and I try to translate the Chinese to English as&#160;accurately as possible, but, there might be some translation mistakes, so if you don&#39;t know what I mean in the article, just leave a comment, and I&#39;ll reply when I get an answer.</span>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b%e5%9c%a8raspberry-pi%e4%b8%8a%e7%94%a8opencv%e6%9d%a5%e6%93%8d%e7%ba%b5%e6%91%84%e5%83%8f%e5%a4%b4%e6%8b%8d%e7%85%a7use-opencv-on-raspberry-pi-to-controll-a-webcam-to-take-photos/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
<span style="background-color:#00ff00;">For non-Chinese readers:</span><br />
<span style="color:#0000ff;">I&#39;m a software engineer in Shanghai, China. Since I bought a Raspberry Pi, I spent some spare time on it and I&#39;m glad to share something with Pi users all over the world, so this article has two languages: Chinese &amp; English, and I try to translate the Chinese to English as&nbsp;accurately as possible, but, there might be some translation mistakes, so if you don&#39;t know what I mean in the article, just leave a comment, and I&#39;ll reply when I get an answer. Also welcome to contact me via <a href="http://www.codelast.com/?page_id=2" target="_blank" rel="noopener noreferrer">Email</a>.</span></p>
<p><a href="http://www.raspberrypi.org/" target="_blank" rel="noopener noreferrer">Raspberry Pi</a>是什么？简单地说，它就是一个基于ARM CPU的、信用卡那么大的迷你计算机。<br />
<span style="color:#0000ff;">In short, Pi is an ARM-based mini computer which has a credit card size.</span></p>
<p>本文主要内容：<br />
在Raspberry Pi上，通过调用OpenCV库，自己写一个简单的C程序来控制摄像头拍照，并保存图片。<br />
在阅读本文之前，请确保你已经阅读过我的另一篇<a href="http://www.codelast.com/?p=4945" target="_blank" rel="noopener noreferrer">配置Pi的文章</a>，因为本文是在它的基础上进行的。<br />
<span style="color:#0000ff;">The main content of this article:<br />
Write a simple C program by invoking the OpenCV library on Raspberry Pi to control a webcam to take photos &amp; save them.<br />
Before reading this article, please make sure that you&#39;ve read my another article about <a href="http://www.codelast.com/?p=4945" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">Pi configuration</span></a>, because this article is based on that.</span><br />
<span id="more-5014"></span></p>
<div style="text-align: center; ">
	<span style="background-color: rgb(0, 255, 0); "><img decoding="async" alt="my running Raspberry Pi" src="https://www.codelast.com/wp-content/uploads/2012/10/my_running_raspberry_pi.jpg" style="width: 400px; height: 538px; " /></span></div>
<div style="text-align: center; ">
	<span style="color:#a52a2a;">图：我的Pi正在运行中 / my running Raspberry Pi</span></div>
<p>
<span style="background-color: rgb(0, 255, 0); ">【1】</span>安装OpenCV <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Install OpenCV</span><br />
命令：<br />
<span style="color:#0000ff;">Command:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
pacman -S opencv opencv-samples
</pre>
<p>上面的命令连OpenCV的sample一起装上了，这样我们在安装好之后就可以编译几个sample来测试。<br />
<span style="color:#0000ff;">This command will install the samples of OpenCV, too. So we can compile &amp; run several samples to have a test after the installation.</span></p>
<p><span style="background-color: rgb(0, 255, 0); ">【2】</span>带动摄像头 <span style="color:#ff0000;">/ </span><span style="color:#0000ff;">Drive the webcam</span><br />
在驱动已经可用的情况下，把一个USB摄像头接在USB口上也不一定能让它工作，因为Pi的USB口的电流供应可能不足。请看<a href="http://eduardofv.com/read_post/189-DIY-Powered-USB-Cable-for-Raspberry-Pi" target="_blank" rel="noopener noreferrer">这个链接</a>的玩家自制的一根增强供电的USB线，如果你想简单安全，那么你可以把摄像头接在一个有外部供电的USB HUB上，再把Pi的USB接到USB HUB上，这样摄像头的供电就充足了。<br />
<span style="color:#0000ff;">Plug the USB webcam into the USB interface of Pi might not able to make it work, even the driver has been available, because the current provided by Pi&#39;s USB interface may not be&nbsp;sufficient to drive a camera. You can learn to DIY a current-enhancement USB cable via </span><a href="http://eduardofv.com/read_post/189-DIY-Powered-USB-Cable-for-Raspberry-Pi" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">this link</span></span></a><span style="color:#0000ff;">, but the easier way may be buying a powered USB HUB and use it to connect the webcam &amp; Pi.</span></p>
<p><span style="background-color: rgb(0, 255, 0); ">【3】</span>让opencv的sample跑起来 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Run a sample of OpenCV</span><br />
为了验证在Pi上安装的OpenCV是可用的，所以至少要让一个sample可以跑起来。<br />
为了不把安装目录弄得一团乱，首先把安装好的OpenCV的sample目录拷贝到其他地方：<br />
<span style="color:#0000ff;">To make sure that the installed OpenCV related packages are &quot;correct&quot;, I decided to run at least one of the OpenCV samples.<br />
Copy the installed OpenCV sample directory to other place for the sake of not messing up the installation directory:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
mkdir /root/opencv
cp -r /usr/share/OpenCV/samples/ /root/opencv/
</pre>
<p>我们看到里面有&ldquo;c&rdquo;，&ldquo;cpp&rdquo;和&ldquo;gpu&rdquo;三种sample，选最简单的，我们进入&ldquo;c&rdquo;，先为所有文件加上写权限：<br />
<span style="color:#0000ff;">There are 3 kinds of samples in it, &quot;c&quot;, &quot;cpp&quot; &amp; &quot;gpu&quot;, so I choose the&nbsp;simplest - &quot;c&quot;, and enter the &quot;c&quot; directory, add write&nbsp;permission to all files:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
chmod +w *
</pre>
<p>然后我们看到&ldquo;c&rdquo;目录里有编译脚本&nbsp;<span style="color:#b22222;">build_all.sh</span>，执行它，看到出了一堆相似的错误，没有一个程序可以成功编译，例如以下错误：<br />
<span style="color:#0000ff;">Execute the </span><span style="color:#b22222;">build_all.sh</span><span style="color:#0000ff;"> script to compile an sample, then I got lots of similar errors, e.g. :</span></p>
<blockquote>
<div>
		[root@alarmpi c]# ./build_all.sh contours.c&nbsp;</div>
<div>
		&nbsp;compiling contours</div>
<div>
		&nbsp;/usr/bin/ld: /tmp/cch4zRSn.o: undefined reference to symbol &#39;lrint@@GLIBC_2.4&#39;</div>
<div>
		&nbsp;/usr/bin/ld: note: &#39;lrint@@GLIBC_2.4&#39; is defined in DSO /usr/lib/libm.so.6 so try adding it to the linker command line</div>
<div>
		&nbsp;/usr/lib/libm.so.6: could not read symbols: Invalid operation</div>
<div>
		&nbsp;collect2: error: ld returned 1 exit status</div>
</blockquote>
<div>
	由 libm 可见，这是因为数学库没有被包含在编译命令中，于是我们编译&nbsp;<span style="color:#b22222;">build_all.sh</span>，为所有编译命令添加上&nbsp;<span style="color: rgb(255, 0, 0); ">-lm</span>&nbsp;编译参数：<br />
	<span style="color:#0000ff;">The &quot;libm&quot; told me that the math library was not included in the&nbsp;compiling command, so I edited&nbsp;</span><span style="color:#b22222;">build_all.sh</span><span style="color:#0000ff;">&nbsp;and add </span><span style="color:#b22222;">-lm</span><span style="color:#0000ff;"> to all compiling command:&nbsp;</span></div>
<div>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
#!/bin/sh                           

if [ $# -gt 0 ] ; then
        base=`basename $1 .c`
        echo &quot;compiling $base&quot;
        gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base -lm
else
        for i in *.c; do
            echo &quot;compiling $i&quot;
            gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv` -lm;
        done
        for i in *.cpp; do
            echo &quot;compiling $i&quot;
            g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv` -lm;
        done
fi
</pre>
</div>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
还忘了说一句，由于上面的脚本在编译时使用了pkg-config，所以在编译前，我们还需要先安装 pkg-config：<br />
<span style="color:#0000ff;">Sorry, I forget to mention that because of using pkg-config, we need to install pkg-config before compiling the sample:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
pacman -S pkg-config
</pre>
<p>然后再编译，成功。<br />
<span style="color:#0000ff;">Then the compiling will succeed.</span><br />
那么下面，我们再接着尝试把编译出的sample运行起来：<br />
<span style="color:#0000ff;">Then run the executable program we just compiled:</span></p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
[root@alarmpi c]# ./contours 

This program creates an image to demonstrate the use of the &quot;c&quot; contour
functions: cvFindContours() and cvApproxPoly() along with the storage
functions cvCreateMemStorage() and cvDrawContours().
It also shows the use of a trackbar to control contour retrieval.
 
Usage :
./contours
 
(image:460): Gtk-WARNING **: cannot open display:
</pre>
<p>很明显，运行不起来。<br />
看样子是跟gtk相关，并且我在网上搜到这跟X server什么的可能有关系，于是安装gtk和X server：<br />
<span style="color: rgb(0, 0, 255); ">It failed,&nbsp;</span><span style="color:#0000ff;">unfortunately</span><span style="color: rgb(0, 0, 255); ">.</span><br />
<span style="color:#0000ff;">And Google told me that the error is related to X server, too, so I installed gtk &amp; X server:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
pacman -S gtk xorg-server
</pre>
<p>再修改配置文件&nbsp;/etc/ssh/sshd_config ：<br />
<span style="color:#0000ff;">Modify the config file /etc/ssh/sshd_config :</span></p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
#AllowTcpForwarding yes
AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
X11UseLocalhost yes
</pre>
<p>注意，没有注释的那三行是我添加的。<br />
<span style="color:#0000ff;">Note that the 3&nbsp;uncommented lines are added by me.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
重启Pi的系统，运行X server：<br />
<span style="color:#0000ff;">Reboot Pi &amp; run X server:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
X
</pre>
<p>没错，命令就是这么简单。然后又出错了：<br />
<span style="color:#0000ff;">Yes, the command is just so simple, but it failed to start:</span></p>
<blockquote>
<div>
		[root@alarmpi c]# X &nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>
		&nbsp;</div>
<div>
		&nbsp;X.Org X Server 1.13.0</div>
<div>
		&nbsp;Release Date: 2012-09-05</div>
<div>
		&nbsp;X Protocol Version 11, Revision 0</div>
<div>
		&nbsp;Build Operating System: Linux 3.0.15-1-ARCH+ armv6l&nbsp;</div>
<div>
		&nbsp;Current Operating System: Linux alarmpi 3.2.27-11-ARCH+ #1 PREEMPT Sat Oct 13 22:46:16 UTC 2012 armv6l</div>
<div>
		&nbsp;Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1080 bcm2708.boardrev=0x3 bcm2708.serial=0x398ca41f smsc95xx.macaddr=B8:27:EB:8C:A4:1F vc_mem.mem_base=0xc000000 vc_mem.mem_size=0x10000000 &nbsp;sdhci-bcm2708.enable_llm=1 sdhci-bcm2708.sync_after_dma=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 loglevel=2 root=/dev/mmcblk0p2 init=/bin/systemd rootfstype=ext4 rootwait</div>
<div>
		&nbsp;Build Date: 14 October 2012 &nbsp;10:05:22PM</div>
<div>
		&nbsp;&nbsp;</div>
<div>
		&nbsp;Current version of pixman: 0.26.2</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>Before reporting problems, check http://wiki.x.org</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>to make sure that you have the latest version.</div>
<div>
		&nbsp;Markers: (--) probed, (**) from config file, (==) default setting,</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>(++) from command line, (!!) notice, (II) informational,</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>(WW) warning, (EE) error, (NI) not implemented, (??) unknown.</div>
<div>
		&nbsp;(==) Log file: &quot;/var/log/Xorg.0.log&quot;, Time: Mon Oct 15 14:30:03 2012</div>
<div>
		&nbsp;(==) Using config directory: &quot;/etc/X11/xorg.conf.d&quot;</div>
<div>
		&nbsp;Initializing built-in extension Generic Event Extension</div>
<div>
		&nbsp;Initializing built-in extension SHAPE</div>
<div>
		&nbsp;Initializing built-in extension MIT-SHM</div>
<div>
		&nbsp;Initializing built-in extension XInputExtension</div>
<div>
		&nbsp;Initializing built-in extension XTEST</div>
<div>
		&nbsp;Initializing built-in extension BIG-REQUESTS</div>
<div>
		&nbsp;Initializing built-in extension SYNC</div>
<div>
		&nbsp;Initializing built-in extension XKEYBOARD</div>
<div>
		&nbsp;Initializing built-in extension XC-MISC</div>
<div>
		&nbsp;Initializing built-in extension SECURITY</div>
<div>
		&nbsp;Initializing built-in extension XINERAMA</div>
<div>
		&nbsp;Initializing built-in extension XFIXES</div>
<div>
		&nbsp;Initializing built-in extension RENDER</div>
<div>
		&nbsp;Initializing built-in extension RANDR</div>
<div>
		&nbsp;Initializing built-in extension COMPOSITE</div>
<div>
		&nbsp;Initializing built-in extension DAMAGE</div>
<div>
		&nbsp;Initializing built-in extension MIT-SCREEN-SAVER</div>
<div>
		&nbsp;Initializing built-in extension DOUBLE-BUFFER</div>
<div>
		&nbsp;Initializing built-in extension RECORD</div>
<div>
		&nbsp;Initializing built-in extension DPMS</div>
<div>
		&nbsp;Initializing built-in extension X-Resource</div>
<div>
		&nbsp;Initializing built-in extension XVideo</div>
<div>
		&nbsp;Initializing built-in extension XVideo-MotionCompensation</div>
<div>
		&nbsp;Initializing built-in extension XFree86-VidModeExtension</div>
<div>
		&nbsp;Initializing built-in extension XFree86-DGA</div>
<div>
		&nbsp;Initializing built-in extension XFree86-DRI</div>
<div>
		&nbsp;Initializing built-in extension DRI2</div>
<div>
		&nbsp;Loading extension GLX</div>
<div>
		&nbsp;</div>
<div>
		&nbsp;Fatal server error:</div>
<div>
		&nbsp;no screens found</div>
<div>
		&nbsp;(EE)&nbsp;</div>
<div>
		&nbsp;Please consult the The X.Org Foundation support&nbsp;</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>&nbsp;at http://wiki.x.org</div>
<div>
		&nbsp; for help.&nbsp;</div>
<div>
		&nbsp;(EE) Please also check the log file at &quot;/var/log/Xorg.0.log&quot; for additional information.</div>
<div>
		&nbsp;(EE)&nbsp;</div>
<div>
		&nbsp;Server terminated with error (1). Closing log file.</div>
</blockquote>
<p>既然它让我看日志文件&nbsp;/var/log/Xorg.0.log，那我就看。在日志文件的最后，发现提示找不到 fbdev 模块/库，于是翻遍Google，找到一个答案：应该安装&nbsp;xf86-video-fbdev 包：<br />
<span style="color:#0000ff;">Since it told me to check log file&nbsp;/var/log/Xorg.0.log, then I did. At the last few lines of the log file, I found an error message which indicated a fbdev module/lib missing, so I ask Google again for a while, and I realized that I should install package&nbsp;xf86-video-fbdev:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
pacman -S xf86-video-fbdev
</pre>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
再用&ldquo;X&rdquo;命令启动X server，成功了：<br />
<span style="color:#0000ff;">Then run &quot;X&quot; again, it succeeded:</span></p>
<blockquote>
<div>
		[root@alarmpi ~]# X</div>
<div>
		&nbsp;</div>
<div>
		&nbsp;X.Org X Server 1.13.0</div>
<div>
		&nbsp;Release Date: 2012-09-05</div>
<div>
		&nbsp;X Protocol Version 11, Revision 0</div>
<div>
		&nbsp;Build Operating System: Linux 3.0.15-1-ARCH+ armv6l&nbsp;</div>
<div>
		&nbsp;Current Operating System: Linux alarmpi 3.2.27-11-ARCH+ #1 PREEMPT Sat Oct 13 22:46:16 UTC 2012 armv6l</div>
<div>
		&nbsp;Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1080 bcm2708.boardrev=0x3 bcm2708.serial=0x398ca41f smsc95xx.macaddr=B8:27:EB:8C:A4:1F vc_mem.mem_base=0xc000000 vc_mem.mem_size=0x10000000 &nbsp;sdhci-bcm2708.enable_llm=1 sdhci-bcm2708.sync_after_dma=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 loglevel=2 root=/dev/mmcblk0p2 init=/bin/systemd rootfstype=ext4 rootwait</div>
<div>
		&nbsp;Build Date: 14 October 2012 &nbsp;10:05:22PM</div>
<div>
		&nbsp;&nbsp;</div>
<div>
		&nbsp;Current version of pixman: 0.26.2</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>Before reporting problems, check http://wiki.x.org</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>to make sure that you have the latest version.</div>
<div>
		&nbsp;Markers: (--) probed, (**) from config file, (==) default setting,</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>(++) from command line, (!!) notice, (II) informational,</div>
<div>
		&nbsp;<span class="Apple-tab-span" style="white-space: pre; "> </span>(WW) warning, (EE) error, (NI) not implemented, (??) unknown.</div>
<div>
		&nbsp;(==) Log file: &quot;/var/log/Xorg.0.log&quot;, Time: Mon Oct 15 14:32:34 2012</div>
<div>
		&nbsp;(==) Using config directory: &quot;/etc/X11/xorg.conf.d&quot;</div>
<div>
		&nbsp;Initializing built-in extension Generic Event Extension</div>
<div>
		&nbsp;Initializing built-in extension SHAPE</div>
<div>
		&nbsp;Initializing built-in extension MIT-SHM</div>
<div>
		&nbsp;Initializing built-in extension XInputExtension</div>
<div>
		&nbsp;Initializing built-in extension XTEST</div>
<div>
		&nbsp;Initializing built-in extension BIG-REQUESTS</div>
<div>
		&nbsp;Initializing built-in extension SYNC</div>
<div>
		&nbsp;Initializing built-in extension XKEYBOARD</div>
<div>
		&nbsp;Initializing built-in extension XC-MISC</div>
<div>
		&nbsp;Initializing built-in extension SECURITY</div>
<div>
		&nbsp;Initializing built-in extension XINERAMA</div>
<div>
		&nbsp;Initializing built-in extension XFIXES</div>
<div>
		&nbsp;Initializing built-in extension RENDER</div>
<div>
		&nbsp;Initializing built-in extension RANDR</div>
<div>
		&nbsp;Initializing built-in extension COMPOSITE</div>
<div>
		&nbsp;Initializing built-in extension DAMAGE</div>
<div>
		&nbsp;Initializing built-in extension MIT-SCREEN-SAVER</div>
<div>
		&nbsp;Initializing built-in extension DOUBLE-BUFFER</div>
<div>
		&nbsp;Initializing built-in extension RECORD</div>
<div>
		&nbsp;Initializing built-in extension DPMS</div>
<div>
		&nbsp;Initializing built-in extension X-Resource</div>
<div>
		&nbsp;Initializing built-in extension XVideo</div>
<div>
		&nbsp;Initializing built-in extension XVideo-MotionCompensation</div>
<div>
		&nbsp;Initializing built-in extension XFree86-VidModeExtension</div>
<div>
		&nbsp;Initializing built-in extension XFree86-DGA</div>
<div>
		&nbsp;Initializing built-in extension XFree86-DRI</div>
<div>
		&nbsp;Initializing built-in extension DRI2</div>
<div>
		&nbsp;Loading extension GLX</div>
</blockquote>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
再试着运行OpenCV的sample，依然不行，Google搜索到一篇<a href="http://homebrew.jp/show?page=1440" target="_blank" rel="noopener noreferrer">在Pi上运行OpenCV的文章</a>，作者做了这样一件事情：<br />
<span style="color:#0000ff;">Then I tried to run the OpenCV sample again, still the same error(&quot;cannot open display&quot;), so I Googled </span><a href="http://homebrew.jp/show?page=1440" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">another article about using OpenCV on Pi</span></span></a><span style="color:#0000ff;">&nbsp;and found that the author did one thing:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;" style="width: 729px; ">
export DISPLAY=192.168.3.65:0.0
</pre>
<p>其中，192.168.3.65是Pi的IP地址。这样设置之后，再运行，程序不再报错了！再一看相同的目录下，生成了一个&nbsp;contours.xml 文件，说明程序执行成功了。<br />
<span style="color:#0000ff;">In which the &quot;192.168.3.65&quot; is your Pi&#39;s IP address. After setting this, the sample could run without any error&nbsp;occurred, and a contours.xml file was generated under the same directory, which indicated that we succeeded.</span></p>
<p><span style="background-color:#00ff00;">【4】</span>写一个简单的OpenCV C程序 / Write a simple OpenCV C program<br />
现在该写一个简单的OpenCV C程序来控制摄像头了。<br />
<span style="color:#0000ff;">Now we should write a simple C program to control the webcam by using OpenCV.</span></p>
<p>直接看程序：<br />
<span style="color:#0000ff;">Let&#39;s check the C code:</span></p>
<pre class="brush:cpp;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &quot;highgui.h&quot;
#include &quot;opencv.hpp&quot;

int main(int argc, char **argv) {
	/* init camera */
	CvCapture* pCapture = cvCreateCameraCapture(0);
	cvSetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_WIDTH, 320); 
	cvSetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_HEIGHT, 240);
	//cvSetCaptureProperty(pCapture, CV_CAP_PROP_FPS, 5);

	IplImage *pFrame = 0;

	if (NULL == pCapture) {
		fprintf(stderr, &quot;Can&#39;t initialize webcam!\n&quot;);
		return 1;
	}

	pFrame = cvQueryFrame(pCapture);	// query a frame 

	if(NULL == pFrame) {
		fprintf(stderr, &quot;Can&#39;t get a frame!\n&quot; );
		return 1;
	}

	const char *pImageFileName = &quot;webcam.jpg&quot;;
	cvSaveImage(pImageFileName, pFrame);

	cvReleaseCapture(&amp;pCapture);	// free memory

	return 0;
}
</pre>
<p>此程序做的事情非常简单：初始化摄像头，抓取一帧，然后保存为名为&ldquo;webcam.jpg&rdquo;的图片。<br />
<span style="color:#0000ff;">This program does a very simple job: initialize the camera, capture a frame &amp; save it to a image file named &quot;webcam.jpg&quot;.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
编译自己的webcam程序：<br />
<span style="color:#0000ff;">Then compile the webcam program:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
g++ -I/usr/include/opencv/ -I/usr/include/opencv2/  `pkg-config --cflags opencv --libs opencv` webcam.c -o webcam
</pre>
<p>会生成一个可执行程序&ldquo;webcam&rdquo;，运行它：<br />
<span style="color:#0000ff;">This will generate an executable bin &quot;webcam&quot;, just run it:</span></p>
<pre class="brush:shell;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
./webcam
</pre>
<p>然后在相同目录下，会看到生成了一个&ldquo;webcam.jpg&rdquo;图片，正是摄像头拍的照。<br />
<span style="color:#0000ff;">Then we&#39;ll get a &quot;webcam.jpg&quot; image file under the same directory, which is just the photo took by the camera.</span></p>
<p>这样，本文的主要目的就达成了。可以在此基础上继续开发其他的程序，来实现更为有用的功能，例如像<a href="http://www.codelast.com/?p=4341" target="_blank" rel="noopener noreferrer">摄像头娘</a>一样的运动检测功能。<br />
<span style="color:#0000ff;">So the main&nbsp;purpose of this article has been reached. We can develop more useful programs base on it, e.g. a program similar to the </span><a href="http://www.codelast.com/?p=4341" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">Camera Girl</span></span></a><span style="color:#0000ff;">, which implements the motion detection&nbsp;functionality.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">【5】</span>遗留问题 <span style="color:#ff0000;">/</span>&nbsp;<span style="color:#0000ff;">Unsolved problems</span><br />
在上述过程中，其实我还遇到了一些未解决的问题，暂时没有时间深究，在此先记录如下。<br />
<span style="color:#0000ff;">In the above process I met some unsolved problems and have no time to explore them yet, so I just write them down here for further study.</span></p>
<p><span style="background-color:#ee82ee;">①</span>拍照时使用稍高的分辨率就导致程序崩溃 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Use a little high resolution will cause the program crash</span><br />
在上面的程序中，如下两句是用于设置分辨率的（宽*高）：<br />
<span style="color:#0000ff;">In the above codes, the two lines below are used to set the resolution:</span></p>
<pre class="brush:cpp;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
cvSetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_WIDTH, 320); 
cvSetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_HEIGHT, 240);
</pre>
<p>根据我的试验，160*120的低分辨率比较少出问题，尽管320*240的分辨率对摄像头来说也根本不算高的，但是就算是使用320*240的分辨率，程序还是偶尔会崩溃的，报错如下：<br />
<span style="color:#0000ff;">According to my experiments, the 160*120 low resolution cause less crashes than higher resolutions. Even 320*240 is not a high resolution for a webcam nowadays, it still made the program crashed some times, and the error messages are:</span></p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
[root@alarmpi c]# ./webcam 
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_REQBUFS: Cannot allocate memory
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
HIGHGUI ERROR: V4L: Initial Capture Error: Unable to load initial memory buffers.
Can&#39;t get a frame!
</pre>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
或者：<br />
<span style="color:#0000ff;">Or:</span></p>
<pre class="brush:plain;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;">
VIDIOC_REQBUFS: Cannot allocate memory
HIGHGUI ERROR: V4L/V4L2: Could not obtain specifics of capture window.

Unable to stop the stream.: Bad file descriptor
VIDIOC_QBUF: Bad file descriptor
Can&#39;t get a frame!
</pre>
<p>我不确定这是跟Pi的CPU计算能力较弱有关呢，还是跟Pi的RAM太小有关呢，还是跟摄像头的供电不足有关呢（我没有使用带电源的USB HUB来接摄像头），或者是跟摄像头的驱动有关呢？<br />
如果你知道解决办法，请赐教，非常感谢。<br />
<span style="color:#0000ff;">I&#39;m not sure whether the problem is caused by the weak computation capability of Pi&#39;s CPU, or the too-small RAM on Pi, or the&nbsp;insufficient current supply of the webcam(I didn&#39;t use a powered USB HUB to connect the webcam to Pi), or the webcam&#39;s Linux driver...<br />
If you know something, please tell me and thank you&nbsp;in advance.</span></p>
<p><span style="background-color: rgb(238, 130, 238);">2015-02-19更新：</span><br />
在树莓派model B+上，使用OpenCV 2.4.10版的上述程序，已经没有了上面所说的问题，经我测试，每隔2秒一次，连续抓取了将近30分钟的图像，一次都没有问题。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
<div id="KSFIND_MASK" style="background-color: rgb(0, 0, 0); opacity: 0.22; position: absolute !important; left: 0px !important; top: 0px !important; border: 0px none !important; padding: 0px !important; z-index: 1000000 !important; height: 0px; width: 0px; display: none; ">
	&nbsp;</div>

			<!--[syntaxhighlighter]-->
			<!--代码高亮，请勿编辑-->
			<script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shCore.js"></script><script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushShell.js"></script>
<script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/scripts/shBrushCpp.js"></script>

			<link type="text/css" rel="stylesheet" href="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shCoreCk.css" />
			<link type="text/css" rel="stylesheet" href="https://www.codelast.com/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shThemeCk.css" />
			<script type="text/javascript">
			SyntaxHighlighter.defaults['class-name']	= '';
			SyntaxHighlighter.defaults['smart-tabs']	= true;
			SyntaxHighlighter.defaults['tab-size']		= 2;
			SyntaxHighlighter.defaults['gutter']		= true;
			SyntaxHighlighter.defaults['quick-code']	= true;
			SyntaxHighlighter.defaults['collapse'] 		= false;
			SyntaxHighlighter.defaults['auto-links']	= true;
			SyntaxHighlighter.defaults['toolbar']		= true;
			SyntaxHighlighter.all();
			</script>
			<!--[/syntaxhighlighter]-->]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b%e5%9c%a8raspberry-pi%e4%b8%8a%e7%94%a8opencv%e6%9d%a5%e6%93%8d%e7%ba%b5%e6%91%84%e5%83%8f%e5%a4%b4%e6%8b%8d%e7%85%a7use-opencv-on-raspberry-pi-to-controll-a-webcam-to-take-photos/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>[原创]Raspberry Pi(树莓派)配置记录/Configure the Arch Linux ARM on Raspberry Pi</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9braspberry-pi%e6%a0%91%e8%8e%93%e6%b4%be%e9%85%8d%e7%bd%ae%e8%ae%b0%e5%bd%95configure-the-arch-linux-arm-on-raspberry-pi/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9braspberry-pi%e6%a0%91%e8%8e%93%e6%b4%be%e9%85%8d%e7%bd%ae%e8%ae%b0%e5%bd%95configure-the-arch-linux-arm-on-raspberry-pi/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Thu, 18 Oct 2012 07:38:36 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Raspberry Pi/树莓派]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Arch Linux ARM]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[教程]]></category>
		<category><![CDATA[树莓派]]></category>
		<category><![CDATA[配置]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=4945</guid>

					<description><![CDATA[<p>
<span style="background-color: rgb(0, 255, 0); ">For non-Chinese readers:</span><br />
<span style="color: rgb(0, 0, 255); ">I&#39;m a software engineer in Shanghai, China, and since I bought a Raspberry Pi, I spent some spare time on it and I&#39;m glad to share something with Pi users all over the world, so this article has two languages: Chinese &#38; English, and I try to translate the Chinese to English as&#160;accurately as possible, but, there might be some translation mistakes, so if you don&#39;t know what I mean in the article, just leave a comment, and I&#39;ll reply when I get an answer.</span>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9braspberry-pi%e6%a0%91%e8%8e%93%e6%b4%be%e9%85%8d%e7%bd%ae%e8%ae%b0%e5%bd%95configure-the-arch-linux-arm-on-raspberry-pi/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
<span style="background-color: rgb(0, 255, 0); ">For non-Chinese readers:</span><br />
<span style="color: rgb(0, 0, 255); ">I&#39;m a software engineer in Shanghai, China, and since I bought a Raspberry Pi, I spent some spare time on it and I&#39;m glad to share something with Pi users all over the world, so this article has two languages: Chinese &amp; English, and I try to translate the Chinese to English as&nbsp;accurately as possible, but, there might be some translation mistakes, so if you don&#39;t know what I mean in the article, just leave a comment, and I&#39;ll reply when I get an answer. Also welcome to contact me via&nbsp;<a href="http://www.codelast.com/?page_id=2" target="_blank" rel="noopener noreferrer">Email</a>.</span><br />
<a href="http://www.raspberrypi.org/" target="_blank" rel="noopener noreferrer"><br />
Raspberry Pi</a>是什么？<br />
引用维基百科的一句话：</p>
<blockquote>
<p>
		The Raspberry Pi is a credit card sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools.</p>
</blockquote>
<p>简单地说，它就是一个基于ARM CPU的、信用卡那么大的迷你计算机。<br />
<span style="color: rgb(0, 0, 255); ">In short, Pi is an ARM-based mini computer which has a credit card size.</span><br />
<span id="more-4945"></span></p>
<div style="text-align: center; ">
	<img decoding="async" alt="Raspberry Pi" src="https://www.codelast.com/wp-content/uploads/2012/10/raspberry_pi.jpg" style="width: 367px; height: 248px; " /></div>
<p>
这货能拿来干嘛？由于它是一台计算机，并且它有着很迷你的体积，最关键的，它还很便宜，因此，用处实在太多了。有人拿它来<a href="http://v.youku.com/v_show/id_XNDMwMTQ2MTQw.html" target="_blank" rel="noopener noreferrer">控制玩具</a>，<a href="http://brewpi.com/" target="_blank" rel="noopener noreferrer">有人拿它来酿酒</a>，甚至还<a href="http://www.ifanr.com/158379" target="_blank" rel="noopener noreferrer">有人拿它来做超级计算机</a>！<br />
是的，这帮人确实太能玩了...<br />
<span style="color:#0000ff;">What can you use it for? Because it&#39;s a computer which has a very mini size, and most importantly, it&#39;s cheap enough, so it&#39;s really useful. Someone use it to </span><a href="http://v.youku.com/v_show/id_XNDMwMTQ2MTQw.html" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">control a toy</span></span></a><span style="color:#0000ff;">(people outside China mainland may not able to visit this video link due to copyright reason), someone use it to </span><a href="http://brewpi.com/" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">brew beer</span></span></a><span style="color:#0000ff;">, and someone even </span><a href="http://www.engadget.com/2012/09/13/supercomputer-built-from-raspberry-pi-and-lego/" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">used Pis to build a supercomputer</span></span></a><span style="color:#0000ff;">!</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
我在Raspberry Pi上安装的系统是官方推荐的几个系统之一：Arch Linux ARM（这不是第一推荐的那个Raspbian）。<br />
<span style="color:#0000ff;">What I installed on Pi is one of the&nbsp;official recommended Operation Systems: Arch Linux ARM(but this is not the most recommended Raspbian).</span></p>
<p>一开始我也是先尝试使用官方推荐的Raspbian，但是由于在刷好系统之后，进入系统之前进行配置的时候，对键盘布局的配置无论如何都无法保存，一直有一个error，导致无法正常使用键盘，所以我最终只能放弃了它，转而使用Arch Linux ARM，这就意味着自己需要做很多的配置工作了。<br />
下面各项，就是我在折腾的过程中遇到的各种问题以及解决办法。<br />
<span style="color:#0000ff;">At first I was trying to use the most official recommended OS - Raspbian, but after writing the OS image to my SD card, and before logging into the system, I met an keyboard layout configuration error in the configuration step, no matter how many times I tried, it&#39;s always the same, so I had to turn to Arch Linux ARM, which means that I need to do lots of configuration work myself.</span><br />
<span style="color:#0000ff;">Below notes, are the problems I met in the process of configuring Pi and the solutions.</span></p>
<p><span style="background-color:#00ff00;">【1】</span>关于分区 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">About the partitions</span><br />
如果你是在Windows下刷的Arch Linux ARM系统，那么，你可能是用官方推荐的<a href="https://launchpad.net/win32-image-writer/+download" target="_blank" rel="noopener noreferrer">Win32DiskImager</a>软件来刷的。Arch Linux ARM的镜像文件（一个.img文件）有约1.8G大，用Win32DiskImager将其刷到SD卡上之后，会发现根目录&ldquo;/&rdquo;所在的分区只有1点几G大，并且没有交换空间（swap），这很麻烦，因为我们随便装几个软件就会占满根目录所在分区，例如一个emacs就有几百M大。<br />
<span style="color:#0000ff;">If you wrote the OS image to SD card on Windows, you might use the official recommended&nbsp;</span><a href="https://launchpad.net/win32-image-writer/+download" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">Win32DiskImager</span></span></a><span style="color:#0000ff;">&nbsp;to do the work. The Arch Linux ARM OS image file(an .img file) has a size about 1.8GB, after you use&nbsp;Win32DiskImager to write it to a SD card, you&#39;ll find that the partition which contains the root directory &quot;/&quot; has a space of 1.X GB, and there is no swap partition - this is a trouble because the partition space will be used up soon, e.g. installing emacs related packages will use more than 200 MB space.</span></p>
<p>所以，我们要让根目录几乎使用全部的SD卡空间。例如，我的SD卡是16G的，我想把1G空间拿来做swap，其余的就给根目录了。<br />
<span style="color:#0000ff;">So, I need to let the root directory partition use almost the whole SD card space. For example, I have a 16GB SD card, then I want 1GB to be the swap, and the left space to be the root directory partition.</span><br />
<a href="http://www.youtube.com/watch?v=DztSRaFyaVE" target="_blank" rel="noopener noreferrer">Youtube上有教程</a>说明如何用<a href="http://gparted.sourceforge.net/" target="_blank" rel="noopener noreferrer">GParted</a>（一款开源软件）来操作SD卡，从而将更改系统分区的大小，我也曾尝试，不幸的是我在调整好空间大小之后，一点击&ldquo;Apply&rdquo;应用我的修改就出错，无法继续下去。所以我最后是采取了一个最简单，也成功了的办法，那就是：使用Ubuntu系统自带的磁盘管理工具来重新分区，听我慢慢道来：<br />
<span style="color:#0000ff;">There is </span><a href="http://www.youtube.com/watch?v=DztSRaFyaVE" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;"><span style="background-color:#ffa07a;">a video tutorial</span></span></a><span style="color:#0000ff;"> on Youtube teaching you how to resize the partition to full SD card capacity by using <a href="http://gparted.sourceforge.net/" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">GParted</span></a>(an open-source software). I tried that, but failed all the times, whenever I clicked the &quot;Apply&quot; button I got an error and couldn&#39;t continue, so at last I used a very simple way to do the same work, and it worked, that is, I used the disk management tool in Ubuntu to &quot;resize&quot; the SD card partition, as following:</span><br />
<span style="background-color:#ffff00;">（1）</span>进入Ubuntu系统，将SD卡上1点几G的那个分区（也就是根目录所在的分区）里的文件备份成tar包：<br />
<span style="color:#0000ff;">Logging into Ubuntu and backup the files in the SD card root partition with a size of 1.X GB to a tar package:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
tar cf os.tar XXX/<span style="color: rgb(255, 157, 0);">*</span></pre>
<p>其中，XXX是指你的SD卡目录。<br />
这个备份出来的tar包在后面我们修改完分区大小之后，恢复系统的时候要用。<br />
<span style="color:#0000ff;">The XXX refers to you SD card directory and the tar package will be used to restore your OS after resizing the partition.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color:#ffff00;">（2）</span>用Ubuntu系统自带的图形化磁盘管理工具（具体名字记不得了），删除掉1点几G的那个SD卡分区，同时你会发现，有一个十几G的未分配的空间，这就是我们要利用的宝贵空间。然后划分出一个13G的ext4分区（Pi官方推荐的那个Arch Linux ARM镜像刷出来的系统用的就是ext4文件系统），这将作为新的系统所在分区。<br />
<span style="color:#0000ff;">Use the graphical disk management tool(I forget the software name, sorry) to delete the SD card partition with the size of 1.X GB, and you&#39;ll find that there is an &quot;unallocated&quot; partition which has a size of &gt; 10GB(</span><span style="color:#000080;">NOTE: my SD card is a 16GB card</span><span style="color:#0000ff;">) - it&#39;s just the free space we want to use. Then create a 13GB partition with ext4 format, which will be used as the new OS partition.</span><br />
<span style="background-color:#ffff00;">（3）</span>将剩下的空间划分为一个交换空间（swap），如果你觉得此空间太大有点浪费，那么你可以在上一步里把空间设大一点，那么这里剩下的swap空间就会小一点，总之，自己衡量。<br />
<span style="color:#0000ff;">Use the left space to create a swap partition. If you think that it&#39;s a waste to allocate so much space to swap, you can allocate more space to OS partition in the previous step. Anyway, judge it by yourself.</span><br />
<span style="background-color:#ffff00;">（4）</span>待Ubuntu操作完成，把SD卡挂载上去，现在，你就有了一个十几G的系统分区和一个1G的swap分区。但是，由于重新分区，系统已经没了，我们怎么恢复？用刚才备份的tar文件就可以恢复。将其中的文件解压到十几G的系统分区里，你原来的设置、安装的软件都不会丢。但是要注意，可能你解压文件的时候，用的不是root用户，而是其他用户，那么你要保证解压出来之后，要修改所有文件的权限为root：<br />
<span style="color:#0000ff;">After the partition operation finished, just mount the SD card, then you&#39;ll find that you have a &gt; 10GB OS partition and a swap partition, but you lost the OS on the partition, so, how to restore the OS? Remember the tar file we backup before? Yes, unpack the files in the tar package to the OS partition, you&#39;ll get your previous OS back! But note that, when unpacking the tar file, you may use a non-root Ubuntu account, so after the unpacking done, we should change the ownership of all files/directories:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
chown -R root:root XXX/</pre>
<p>其中，XXX为你的SD卡的挂载目录。这是因为刚刷到Pi上的Arch Linux ARM只有一个root用户，我没有添加其他用户，所有文件owner均为root。<br />
<span style="color:#0000ff;">The XXX refers to your SD card mounted directory. I do this because I didn&#39;t add any other user for my Arch Linux ARM, except the root user.</span><br />
<span style="background-color:#ffff00;">（5）</span>把SD卡umount下来，插入Pi的卡槽中，启动系统，发现一切正常，成功了！<br />
<span style="color:#0000ff;">Then umount the SD card from Ubuntu, plug it into Pi, and boot Pi, everything is OK, it works with no problem.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">【2】</span>添加开机启动的程序 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Run your program on OS startup</span><br />
要让Pi开机启动一个脚本/执行一个命令怎么办？<br />
我们知道，RedHat有 /etc/rc.local 文件，在里面写上要执行的命令就可以开机执行了，这是最简单的办法，而Arch Linux ARM没有这个东西，它是按下面的方法设置的：<br />
假设我要开机执行一句shell命令，把它写在文件 /etc/rc.local 中（在Arch Linux中，此文件一开始是不存在的）：<br />
<span style="color:#0000ff;">How to execute a shell script/a command on Pi startup?<br />
For RedHat it&#39;s very easy, it has a /etc/rc.local file, we just add the commands to the file, while Arch Linux ARM doesn&#39;t have such thing, and I&#39;m a beginner of Arch, so after asking Google for many times, I find a way to do that - suppose I need to execute a shell command, so I create the /etc/rc.local file &amp; write the shell command to it:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
<span style="color: rgb(0, 136, 255); font-style: italic;"><span style="color: rgb(225, 239, 255);">#</span>!/bin/bash</span>
<span style="color: rgb(0, 136, 255); font-style: italic;"><span style="color: rgb(225, 239, 255);">#</span> this file defines the commands that will be executed at system startup</span>

<span style="color: rgb(255, 176, 84);">echo</span> <span style="color: rgb(58, 217, 0);">&quot;</span>abc<span style="color: rgb(58, 217, 0);">&quot;</span> <span style="color: rgb(255, 157, 0);">&gt;</span> /root/test.txt</pre>
<p>为此文件赋予可执行权限：<br />
<span style="color:#0000ff;">Give the file the executable permission:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
chmod +x /etc/rc.<span style="color: rgb(255, 238, 128);">local</span></pre>
<p>然后创建一个文件&nbsp;<span style="color:#b22222;">/usr/lib/systemd/system/rc-local.service</span>&nbsp;，内容为：<br />
<span style="color:#0000ff;">Then create a file&nbsp;</span><span style="color:#b22222;">/usr/lib/systemd/system/rc-local.service</span><span style="color:#0000ff;">&nbsp;, with the content of:</span></p>
<blockquote>
<div>
		[Unit]</div>
<div>
		Description=/etc/rc.local Compatibility</div>
<div>
		ConditionPathExists=/etc/rc.local</div>
<div>
		&nbsp;</div>
<div>
		[Service]</div>
<div>
		Type=forking</div>
<div>
		ExecStart=/etc/rc.local start</div>
<div>
		TimeoutSec=0</div>
<div>
		StandardOutput=tty</div>
<div>
		RemainAfterExit=yes</div>
<div>
		SysVStartPriority=99</div>
<div>
		&nbsp;</div>
<div>
		[Install]</div>
<div>
		WantedBy=multi-user.target</div>
</blockquote>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
创建一个软链接：<br />
<span style="color:#0000ff;">Create a symbol link:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
<span style="color: rgb(255, 176, 84);">cd</span> /etc/systemd/system/multi-user.target.wants
ln -s /usr/lib/systemd/system/rc-local.service rc-local.service</pre>
<p>启用服务：<br />
<span style="color:#0000ff;">Enable the service:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
systemctl <span style="color: rgb(255, 176, 84);">enable</span> rc-local.service</pre>
<p>重启系统，然后就可以开机执行你的shell命令了。如果要立即启用，则执行以下命令：<br />
<span style="color:#0000ff;">Restart Pi, then you&#39;ll be able to execute the shell command on OS startup. If you want to execute it without restarting Pi, just execute the following command:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
systemctl start rc-local.service</pre>
<p>这是使用systemd的启动方式，非常麻烦。<br />
如果你只是简单地要设置一个命令的别名，可以把命令写在 /etc/profile 中，ssh登录Pi的时候就自动会执行。<br />
<span style="color:#0000ff;">This seems to be the so-called &quot;systemd&quot; way to start something, and I think the setup process is very tedious.</span><br />
<span style="color:#0000ff;">You can also add the shell command to /etc/profile, and it will be executed when you logging into Pi using ssh.</span></p>
<p><span style="background-color:#00ff00;">【3】</span>安装软件 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Install packages</span><br />
在Arch Linux上安装软件使用pacman很方便，它相当于Ubuntu中的apt-get。例如，要安装gcc，可以这样：<br />
<span style="color:#0000ff;">It&#39;s very convenient to use </span><span style="color:#b22222;">pacman</span><span style="color:#0000ff;"> to install something on Arch Linux, and it&#39;s the&nbsp;equivalent of apt-get on Ubuntu. For example, you can install gcc by typing:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -S gcc</pre>
<p>然后Arch Linux ARM会提示你要下载的软件包的情况，以及向你确认是否要进行安装。<br />
在下载软件包的过程中，我的Pi一直提示下载不到某一个软件包的错误，重试无数遍都一样，于是我就只能尝试升级pacman以及系统了，执行：<br />
<span style="color:#0000ff;">Then Arch Linux will prompt you the info of the packages which will be downloaded/installed, and ask you to confirm the installation.<br />
In the process of downloading a gcc related package, I met an URL not found error and I tried many times but solved nothing, so at last I tried to update pacman and the OS:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -Syu</pre>
<p>升级时间较长（大约小于10分钟），之后再安装gcc，就成功了。<br />
<span style="color:#0000ff;">This consumes a bit long time(but &lt; 10 min, depends on your Internet connection speed), and after this I tried to install gcc again, it succeeded.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="color:#000000;"><span style="background-color:#00ff00;">【4】</span>配置静态IP地址 </span><span style="color:#ff0000;">/ </span><span style="color:#0000ff;">Set up a static IP address</span><br />
<span style="color:#000000;"> 相比设置一个静态的IP地址，我更愿意采取另一种简单的办法来让Pi每次都得到一个固定的IP地址，即：在路由器里为Pi所对应的Mac地址保留一个固定的IP地址。<br />
由于我对Pi所接入的网络的路由器有完全的控制权，所以我可以这样做。由于每种路由器的管理界面是不相同的，所以在此我就不把路由器管理界面的图贴上来了，大家自己看看你路由器的说明书就会弄了。</span><br />
<span style="color:#0000ff;">Comparing to setting up a static IP for Pi, I would like more to take another simple way to let Pi get a fixed IP everytime it accesses to the same network, that is, let the router to allocate(reserve) a fixed IP for Pi&#39;s Mac address.<br />
This can be done only because I have full control over the router which Pi accesses. Because different routers have different admin interfaces, so I post no sample images here and you can check the instruction book of your router to figure out how to set it.</span></p>
<p><span style="background-color: rgb(0, 255, 0); ">【5】</span>设置系统时区 &amp; 时间 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">System timezone &amp; time setup</span><br />
以上海为例，先编辑文件&nbsp;/etc/rc.conf，添加上如下内容：<br />
<span style="color:#0000ff;">Use Shanghai as an example, first we should edit file /etc/rc.conf and add the following content:</span></p>
<blockquote>
<div>
		LOCALE=&quot;en_US.UTF-8&quot;</div>
<div>
		DAEMON_LOCALE=&quot;no&quot;</div>
<div>
		HARDWARECLOCK=&quot;localtime&quot;</div>
<div>
		TIMEZONE=&quot;Asia/Shanghai&quot;</div>
</blockquote>
<p>然后做软链接：<br />
<span style="color:#0000ff;">Then make a symbolic link:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime</pre>
<p>/etc/localtime 原来是指向&nbsp;/usr/share/zoneinfo/Europe/London，在做这外软链接之后，就指向了&nbsp;/usr/share/zoneinfo/Asia/Shanghai。<br />
<span style="color:#0000ff;">The /etc/localtime was initially pointed to&nbsp;/usr/share/zoneinfo/Europe/London and after we made a new link, it will points to&nbsp;/usr/share/zoneinfo/Asia/Shanghai.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
这样就算设置好了时区了。下面该设置系统时间了。由于树莓派没有实时时钟，因此，最好利用网络来对时，所以使用<a href="http://www.openntpd.org/" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">OpenNTPD</span></a>是个非常好的选择。<br />
<span style="color:#0000ff;">So the timezone setup is done. Then we should setup the system time. Because Pi doesn&#39;t has a real-time clock built in, we better use the network to synchronize the system time, so using the <a href="http://www.openntpd.org/" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">OpenNTPD</span></a> is a good choice.</span><br />
我系统中安装的OpenNTPD（我不记得是系统自带的还是我安装的了）：<br />
<span style="color:#0000ff;">The OpenNTPD in my Arch Linux ARM(I forget whether it&#39;s installed by me or not):</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
[root@alarmpi <span style="color: rgb(255, 157, 0);">~</span>]# pacman -Q <span style="color: rgb(255, 157, 0);">|</span> grep ntp
openntpd 3.9p1-19</pre>
<p>确保 /etc/rc.conf 中有OpenNTPD的启动项：<br />
<span style="color:#0000ff;">Make sure that the OpenNTPD is in the auto startup list in /etc/rc.conf :</span></p>
<blockquote>
<p>
		DAEMONS=(syslog-ng network netfs crond openntpd sshd)</p>
</blockquote>
<p>然后重启系统，会发现时间自动同步正确了。<br />
<span style="color:#0000ff;">Then reboot the system and you&#39;ll find that the time is correct.</span><br />
如果你发现时间无法同步，那么请执行一下ntpd命令，该命令会加载ntpd配置文件 /etc/ntpd.conf，如果配置文件内容有错，它会提示出来。就算配置文件是正确的，有其他错误也会打印出来。<br />
例如，我升级了如下版本的系统：<br />
<span style="color:#0000ff;">If you find that the time cannot be&nbsp;synchronized, then you should execute the ntpd command to see what the problem is. The ntpd command will load configuration file /etc/ntpd.conf and if there is any problem in it, the command will tell you. Even the content of the conf file is correct, the ntpd command will print other error messages out.<br />
E.g. I upgraded my OS to following version:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
[root@alarmpi <span style="color: rgb(255, 157, 0);">~</span>]# cat /proc/version 
Linux version 3.2.27-14-ARCH+ <span style="color: rgb(225, 239, 255);">(</span>nobody@nitrogen<span style="color: rgb(225, 239, 255);">)</span> <span style="color: rgb(225, 239, 255);">(</span>gcc version 4.7.2 <span style="color: rgb(225, 239, 255);">(</span>GCC<span style="color: rgb(225, 239, 255);">)</span> <span style="color: rgb(225, 239, 255);">)</span> <span style="color: rgb(0, 136, 255); font-style: italic;"><span style="color: rgb(225, 239, 255);">#</span>1 PREEMPT Tue Nov 20 23:58:09 UTC 2012</span></pre>
<p>然后就遇到了无法同步时间的问题。执行ntpd命令会提示&ldquo;ntpd: unknown user ntp&rdquo;。网上Google了一堆文章，找到最后唯一一个可行的解决办法就是：为系统添加一个&ldquo;ntp&rdquo;用户：<br />
<span style="color:#0000ff;">Then I couldn&#39;t&nbsp;synchronized the time. When executing ntpd command it prompted &quot;ntpd: unknown user ntp&quot;. After Googling a lot of solutions I found the only one which can solve the problem, that is, add a &quot;ntp&quot; user for the OS:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
useradd ntp</pre>
<p>然后查看 /etc/passwd 文件，会看到已经添加了该用户。<br />
<span style="color:#0000ff;">Then check /etc/passwd to make sure the user has been added.</span><br />
为安全，编辑 /etc/passwd 文件，将此用户设置为无法ssh登录系统：<br />
<span style="color:#0000ff;">For security reason, edit /etc/passwd to forbid the user to login the OS:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
ntp:x:1000:1000::/home/ntp:/sbin/nologin</pre>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
另外，你也可以用ntpdate（现在已经被官方<a href="http://support.ntp.org/bin/view/Dev/DeprecatingNtpdate" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">弃用</span></a>了）来对时，但首先你必须安装ntp包：<br />
<span style="color:#0000ff;">You can also use ntpdate(which is now <a href="http://support.ntp.org/bin/view/Dev/DeprecatingNtpdate" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">deprecated</span></a>) to sync the time, but you have to install package ntp first:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -S ntp</pre>
<p>然后，找一个可用的时间服务器来同步时间：<br />
<span style="color:#0000ff;">And then find an available time server to sync the time:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
ntpdate  <span style="color: rgb(255, 157, 0);">time</span>.buptnet.edu.cn</pre>
<p>
<span style="background-color: rgb(0, 255, 0); ">【6】</span>配置Emacs编辑C++代码的自动补全功能 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Configure the auto-complete for editing C++ source in Emacs</span><br />
如果要在树莓派上用Emacs开发C++程序，那么配置好代码自动补全/自动完成功能大有帮助。<br />
<span style="color:#0000ff;">If you want to use Emacs to write C++ code on Pi, then the auto-completion should be a big help to you.</span><br />
<a href="http://cedet.sourceforge.net/" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">CEDET</span></a>实现了该功能，用的人也比较多，不过，由于树莓派的性能较低，并且CEDET很慢（很多文章都这么说，我没试），所以就不要考虑在树莓派上用这玩意了。<br />
<span style="color:#0000ff;">Many people use&nbsp;</span><span style="background-color: rgb(255, 160, 122); "><a href="http://cedet.sourceforge.net/" target="_blank" rel="noopener noreferrer"><span style="color:#0000ff;">CEDET</span></a></span><span style="color:#0000ff;">&nbsp;to do the auto-completion job, but because of the low performance of Pi, and the CEDET is very slow(many articles said that, but I didn&#39;t try it), so just choose something else but not CEDET on Pi.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
那么应该选择什么Emacs插件来实现呢？<a href="https://github.com/brianjcj/auto-complete-clang" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">auto-complete-clang</span></a>是一个很好的选择。<br />
<span style="color:#0000ff;">So what Emacs plugin we should use? the&nbsp;</span><a href="https://github.com/brianjcj/auto-complete-clang" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122); ">auto-complete-clang</span></a><span style="color:#0000ff;">&nbsp;is a good choice.</span><br />
下面，就介绍一下如何配置该插件，让自动完成功能在Emacs中用起来。<br />
<span style="color:#0000ff;">Then I&#39;ll tell you how to configure the plugin to get the auto-completion work.</span><br />
为了安装auto-complete-clang，你需要先安装两个东西：<a href="http://cx4a.org/pub/auto-complete/" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">auto-complete</span></a>&nbsp;和&nbsp;<a href="http://clang.llvm.org/" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">clang</span></a>。<br />
<span style="color:#0000ff;">Before installing&nbsp;auto-complete-clang, you must install another two software first:</span><a href="http://cx4a.org/pub/auto-complete/" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122); ">auto-complete</span></a><span style="color:#0000ff;">&nbsp;and&nbsp;</span><a href="http://clang.llvm.org/" target="_blank" rel="noopener noreferrer"><span style="background-color: rgb(255, 160, 122); ">clang</span></a><span style="color:#0000ff;">.</span><br />
<span style="background-color:#00ffff;">①</span>安装auto-complete <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Install auto-complete</span><br />
首先你要下载auto-complete的源码包，解压之后编译，安装（安装的过程中会询问你安装到哪个目录）：<br />
<span style="color:#0000ff;">Download the source package, unpack it, compile it &amp; install it(you&#39;ll be asked to type an installation directory in the process):</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
make
make install
Install to: /root/.emacs.d/auto-complete</pre>
<p>注意，我把它安装到了一个自己创建的目录下，后面要用到这个目录里的文件。<br />
<span style="color:#0000ff;">Note that I installed it to a directory created by me and we&#39;ll use the directory later.</span><br />
在Emacs配置文件.emacs中添加如下四行：<br />
<span style="color:#0000ff;">Add the following 4 lines in the Emacs configuration file .emacs:</span></p>
<blockquote>
<div>
		(add-to-list &#39;load-path &quot;/root/.emacs.d/auto-complete&quot;)</div>
<div>
		(require &#39;auto-complete-config)</div>
<div>
		(add-to-list &#39;ac-dictionary-directories &quot;/root/.emacs.d/auto-complete/ac-dict&quot;)</div>
<div>
		(ac-config-default)</div>
</blockquote>
<p>上面的路径就是和刚才的安装路径，如果你和我安装的路径不一样，请把它改成你自己的路径。<br />
<span style="color:#0000ff;">The paths above are just the installation directory, if yours are different from mine, change them.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ffff;">②</span>安装clang <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Install clang</span><br />
用pacman安装clang是最方便的：<br />
<span style="color:#0000ff;">Using pacman to install clang is the most&nbsp;convenient way:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -S clang</pre>
<p>如果你不幸遇到了下面的错误：<br />
<span style="color:#0000ff;">If you get the following errors&nbsp;unfortunately:</span></p>
<blockquote>
<div>
		error: failed retrieving file &#39;llvm-3.1-4-armv6h.pkg.tar.xz&#39; from mirror.archlinuxarm.org : The requested URL returned error: 404</div>
<div>
		warning: failed to retrieve some files from extra</div>
<div>
		error: failed retrieving file &#39;clang-3.1-4-armv6h.pkg.tar.xz&#39; from mirror.archlinuxarm.org : The requested URL returned error: 404</div>
<div>
		warning: failed to retrieve some files from extra</div>
<div>
		error: failed to commit transaction (download library error)</div>
</blockquote>
<div>
	那么你可以选择升级系统：<br />
	<span style="color:#0000ff;">Then you can choose to update the system:</span></div>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -Syu</pre>
<p>然后再用pacman安装clang，应该就没有上面的问题了。<br />
<span style="color:#0000ff;">Then install clang again, and the errors should not occur.</span><br />
<span style="background-color:#00ffff;">③</span>安装auto-complete-clang <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Install&nbsp;auto-complete-clang</span><br />
其实这一步所谓的安装，不过是下载+配置，并没有像上面一样的编译过程。<br />
<span style="color:#0000ff;">Actually the so-called installation in this step is just a process of downloading &amp; configuration, there is no compilation as previous steps.</span><br />
下载配置文件auto-complete-clang.el，我把它放到了 .emacs.d/auto-complete-clang 目录下。<br />
<span style="color:#0000ff;">Download the configuration file&nbsp;auto-complete-clang.el and I put it to directory&nbsp;.emacs.d/auto-complete-clang .</span><br />
在.emacs中添加下面一句：<br />
<span style="color:#0000ff;">Add the following line in Emacs configuration file .emacs:</span></p>
<blockquote>
<p>
		(add-to-list &#39;load-path &quot;~/.emacs.d/auto-complete-clang&quot;)</p>
</blockquote>
<p>该目录就是你放置&nbsp;auto-complete-clang.el 文件的目录。<br />
<span style="color:#0000ff;">The directory is just where you put file&nbsp;auto-complete-clang.el into.</span><br />
然后再继续添加如下内容（从网上抄来的）：<br />
<span style="color:#0000ff;">Then continue to add following content(I got this from the Internet):</span></p>
<blockquote>
<div>
		(require &#39;auto-complete-clang)</div>
<div>
		(setq ac-auto-start t)</div>
<div>
		(setq ac-quick-help-delay 0.5)</div>
<div>
		;; (ac-set-trigger-key &quot;TAB&quot;)</div>
<div>
		;; (define-key ac-mode-map&nbsp; [(control tab)] &#39;auto-complete)</div>
<div>
		(define-key ac-mode-map&nbsp; [(control tab)] &#39;auto-complete)</div>
<div>
		(defun my-ac-config ()</div>
<div>
		&nbsp; (setq ac-clang-flags</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; (mapcar(lambda (item)(concat &quot;-I&quot; item))</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(split-string</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;</div>
<div>
		&nbsp;/usr/lib/gcc/armv6l-unknown-linux-gnueabihf/4.7.2/../../../../include/c++/4.7.2</div>
<div>
		&nbsp;/usr/lib/gcc/armv6l-unknown-linux-gnueabihf/4.7.2/../../../../include/c++/4.7.2/armv6l-unknown-linux-gnueabihf</div>
<div>
		&nbsp;/usr/lib/gcc/armv6l-unknown-linux-gnueabihf/4.7.2/../../../../include/c++/4.7.2/backward</div>
<div>
		&nbsp;/usr/lib/gcc/armv6l-unknown-linux-gnueabihf/4.7.2/include</div>
<div>
		&nbsp;/usr/local/include</div>
<div>
		&nbsp;/usr/lib/gcc/armv6l-unknown-linux-gnueabihf/4.7.2/include-fixed</div>
<div>
		&nbsp;/usr/include</div>
<div>
		&quot;)))</div>
<div>
		&nbsp; (setq-default ac-sources &#39;(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))</div>
<div>
		&nbsp; (add-hook &#39;emacs-lisp-mode-hook &#39;ac-emacs-lisp-mode-setup)</div>
<div>
		&nbsp; ;; (add-hook &#39;c-mode-common-hook &#39;ac-cc-mode-setup)</div>
<div>
		&nbsp; (add-hook &#39;ruby-mode-hook &#39;ac-ruby-mode-setup)</div>
<div>
		&nbsp; (add-hook &#39;css-mode-hook &#39;ac-css-mode-setup)</div>
<div>
		&nbsp; (add-hook &#39;auto-complete-mode-hook &#39;ac-common-setup)</div>
<div>
		&nbsp; (global-auto-complete-mode t))</div>
<div>
		(defun my-ac-cc-mode-setup ()</div>
<div>
		&nbsp; (setq ac-sources (append &#39;(ac-source-clang ac-source-yasnippet) ac-sources)))</div>
<div>
		(add-hook &#39;c-mode-common-hook &#39;my-ac-cc-mode-setup)</div>
<div>
		;; ac-source-gtags</div>
<div>
		(my-ac-config)</div>
</blockquote>
<div>
	其中，那些类似于 <span style="color:#0000ff;">/usr/XXX</span> 的路径因环境不同而不同，它是通过如下命令得知的：<br />
	<span style="color:#0000ff;">The directories like&nbsp;</span><span style="color:#ff0000;">/usr/XXX</span><span style="color:#0000ff;"> are vary from&nbsp;environment to&nbsp;environment, they can be obtained via following command:</span></div>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
<span style="color: rgb(255, 176, 84);">echo</span> <span style="color: rgb(58, 217, 0);">&quot;</span><span style="color: rgb(58, 217, 0);">&quot;</span> <span style="color: rgb(255, 157, 0);">|</span> g++ -v -x c++ -E -</pre>
<div>
	从输出的一大堆信息中，找到那些 /usr/XXX 的路径填上就可以了。<br />
	<span style="color:#0000ff;">You can find the /usr/XXX paths from the messages outputted by the command.</span></div>
<div>
	配置好之后，再用Emacs打开一个C++代码文件，看看自动完成是不是生效了？<br />
	<span style="color:#0000ff;">After all these are done, open a C++ source file with Emacs to check whether the auto-completion has been available for you.</span></div>
<p><span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0); ">【7】</span>设置终端文字颜色 <span style="color:#ff0000;">/</span> <span style="color:#0000ff;">Setup the terminal text color</span><br />
Arch Linux ARM默认情况下终端文字是黑白的，对于文件和目录类型不方便区分，为提高工作效率，需要其显示不同颜色。<br />
<span style="color:#0000ff;">By default the Arch Linux ARM terminal text colors are just black and white and it&#39;s not&nbsp;convenient to identify directories &amp; files. So in order to improve the work efficiency we should setup the text color.</span><br />
修改&nbsp;<span style="color:#0000ff;">/etc/profile</span>，在最后添加一行：<br />
<span style="color:#0000ff;">Edit </span><span style="color:#ff0000;">/etc/profile</span><span style="color:#0000ff;"> and add the following line:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
<span style="color: rgb(255, 176, 84);">alias</span> ls=<span style="color: rgb(58, 217, 0);">&quot;</span>ls --color=auto<span style="color: rgb(58, 217, 0);">&quot;</span></pre>
<p>这样，ls命令显示出来的文字就有不同颜色了。<br />
<span style="color:#0000ff;">Then the &quot;ls&quot; command will display the colorful text.</span></p>
<p><span style="background-color: rgb(0, 255, 0); ">【8】</span>Arch Linux ARM的rontab文件在哪里 / Where the crontab file is<br />
使用 <span style="color:#b22222;">crontab -e</span> 命令可以编辑当前用户的crontab配置文件，但这个文件是位于何处？我更喜欢直接编辑它，因为我可以用我习惯的Emacs来操作。它是在&nbsp;<span style="color:#b22222;">/var/spool/cron/</span> 目录下，用户名即为文件名，例如，root用户的 <span style="color:#b22222;">crontab -e</span> 命令编辑的就是&nbsp;<span style="color:#b22222;">/var/spool/cron/root</span> 文件。<br />
<span style="color:#0000ff;">We can use command </span><span style="color:#b22222;">crontab -e</span><span style="color:#0000ff;"> to edit the crontab configuration file of current user, so where the corresponding file is? I like more to edit the file directly, because I can use my favourite editor Emacs to edit it. The crontab file is under the directory </span><span style="color:#b22222;">/var/spool/cron/</span><span style="color:#0000ff;"> , and with the same name as the Linux user, for example, the command </span><span style="color:#b22222;">crontab -e</span><span style="color:#0000ff;"> ran by root user will edit the file </span><span style="color:#b22222;">/var/spool/cron/root</span><span style="color:#0000ff;"> .</span></p>
<p><span style="background-color: rgb(0, 255, 0); ">【9】</span>安装dig，nslookup程序 / <span style="color:#0000ff;">Install command dig &amp; nslookup</span><br />
dig和nslookup程序包含在dnsutils包中，所以这样安装：<br />
<span style="color:#0000ff;">dig &amp; nslookup are contained in package&nbsp;dnsutils, so you can install them by:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -S dnsutils</pre>
<p>如果你用 pacman -S dig 或 pacman -S nslookup 来找，是找死也找不到的。<br />
<span style="color:#0000ff;">If you use pacman -S dig or pacmsn -S nslookup to install them, you&#39;ll never get what you want.</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0); ">【10】</span>备份SD卡上的系统 / <span style="color:#0000ff;">Backup the OS on SD card</span><br />
万一SD卡损坏，你辛辛苦苦配置了很久的系统就没了，所以必须要备份。直接拷贝SD卡里的数据到另一张SD卡上是行不通的，可以通过Linux的dd命令来复制SD卡，非常方便。<br />
<span style="color:#0000ff;">If the SD card broken, you&#39;ll lose the OS that you&#39;ve spent weeks on it, so it&#39;s very necessary to backup it. It&#39;s impossible to backup the OS by simply copying the SD card files to another card, you can do this by Linux command dd.</span><br />
<span style="background-color:#dda0dd;">（A）</span>查看SD卡的设备名 / <span style="color:#0000ff;">Check the device name of the SD card</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
[codelast@ <span style="color: rgb(255, 157, 0);">~</span>]$ dmesg <span style="color: rgb(255, 157, 0);">|</span> tail
[487324.668042] sd 7:0:0:0: [sdb] Mode Sense: 03 00 00 00
[487324.668916] sd 7:0:0:0: [sdb] No Caching mode page present
[487324.668922] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[487324.672481] sd 7:0:0:0: [sdb] No Caching mode page present
[487324.672487] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[487324.674866]  sdb: sdb1 sdb2 sdb3
[487324.679206] sd 7:0:0:0: [sdb] No Caching mode page present
[487324.679213] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[487324.679218] sd 7:0:0:0: [sdb] Attached SCSI removable disk
[487325.617680] pool[9188]: segfault at 0 ip 000000000042e62d sp 00007f88ff2c4520 error 4 <span style="color: rgb(255, 157, 0);">in</span> udisksd[400000+45000]</pre>
<p>可见我的SD卡设备名是sdb。<br />
<span style="color:#0000ff;">You can see that my SD card device name is sdb.</span><br />
<span style="background-color:#dda0dd;">（B）</span>备份SD卡上的OS到一个磁盘文件里 / <span style="color:#0000ff;">Backup the OS on SD card to a disk file</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
[codelast@ <span style="color: rgb(255, 157, 0);">~</span>]$ sudo dd <span style="color: rgb(255, 157, 0);">if</span>=/dev/sdb of=<span style="color: rgb(255, 157, 0);">~</span>/raspberry_pi_os_backup
31537152+0 records <span style="color: rgb(255, 157, 0);">in</span>
31537152+0 records out
16147021824 bytes <span style="color: rgb(225, 239, 255);">(</span>16 GB<span style="color: rgb(225, 239, 255);">)</span> copied, 942.766 s, 17.1 MB/s</pre>
<p>在这里，/dev/sdb是我的SD卡，OS被备份到了~/raspberry_pi_os_backup文件中。整个过程花了约15分钟完成（16G的SD卡）。<br />
<span style="color:#0000ff;">So /dev/sdb is my SD card and the OS was backuped to file ~/raspberry_pi_os_backup. The whole process took me about 15 minutes(16GB SD card).</span><br />
<span style="color: rgb(255, 255, 255); ">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255); ">http://www.codelast.com/</span></a><br />
<span style="background-color: rgb(221, 160, 221); ">（C）</span>将格式化新的SD卡为ext4 / <span style="color:#0000ff;">Format the new SD card to ext4</span><br />
由于我原来的SD卡是ext4格式，所以我利用Ubuntu的磁盘管理工具将新的SD卡也格式化成了ext4格式。至于这一步是否有必要，我没有试验，但是可以肯定的是：这样做一定能成功。<br />
<span style="color:#0000ff;">Because my old SD card has a format of ext4, so I used the Ubuntu disk management tool to format the new SD card to ext4, too. I&#39;m not sure whether this step is a must, but I&#39;m sure that it&#39;s no problem to do this and can lead you to success.</span><br />
<span style="background-color:#dda0dd;">（D）</span>将备份的磁盘文件恢复到新的SD卡上 / <span style="color:#0000ff;">Restore the disk file to the new SD card</span><br />
<span style="color:#ff0000;">拔下旧的SD卡，插上新的SD卡</span>，用 dmesg | tail&nbsp;命令查看一下，新的SD卡的设备名仍然是sdb，因此恢复OS的命令为：<br />
<span style="color:#0000ff;">Unplug the old SD card, plug the new SD card into your computer, and use dmesg | tail command to check the device name(it&#39;s still sdb), so the command to restore the OS is:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
[codelast@ <span style="color: rgb(255, 157, 0);">~</span>]$ sudo dd <span style="color: rgb(255, 157, 0);">if</span>=<span style="color: rgb(255, 157, 0);">~</span>/raspberry_pi_os_backup of=/dev/sdb
31537152+0 records <span style="color: rgb(255, 157, 0);">in</span>
31537152+0 records out
16147021824 bytes <span style="color: rgb(225, 239, 255);">(</span>16 GB<span style="color: rgb(225, 239, 255);">)</span> copied, 5459.12 s, 3.0 MB/s</pre>
<p>这个操作时间更长，耐心等待完成即可。<br />
<span style="color:#0000ff;">This process takes even more time, just be patient and wait it to finish.</span><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">【11】</span>用pacman -Syu升级系统时提示&ldquo;error: failed to commit transaction (conflicting files)&rdquo;的解决办法 / <span style="color:#0000ff;">How to fix the &quot;error: failed to commit transaction (conflicting files)&quot; problem when using [pacman -Syu] to upgrade your OS</span><br />
我在用pacman -Syu升级系统时，提示如下错误：<br />
<span style="color:#0000ff;">When I used &quot;pacman -Syu&quot; to upgrade my OS, I got these error messages:</span></p>
<blockquote>
<div>
		error: failed to commit transaction (conflicting files)</div>
<div>
		filesystem: /bin exists in filesystem</div>
<div>
		filesystem: /sbin exists in filesystem</div>
<div>
		filesystem: /usr/sbin exists in filesystem</div>
<div>
		Errors occurred, no packages were upgraded.</div>
</blockquote>
<p>这个问题可以通过依次执行以下几条命令来解决，经测试可用：<br />
<span style="color:#0000ff;">To solve the problem, you can execute following commands one by one and they worked for me:</span></p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
pacman -R localepurge
pacman -Syu --ignore filesystem,bash
pacman -S bash
pacman -Su</pre>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">【12】</span>清空pacman安装包缓存<br />
某天我用 pacman -Syu 升级OS的时候，提示空间不足，我当时觉得不可思议，因为我在SD卡上存储的东西并不多，于是我用 du -sh 把系统目录挨个看了一下，发现占用空间最大的是&nbsp;<span style="color:#0000ff;">/var/cache/pacman/pkg</span> 这个目录，足足占了我3.5GB！从名字上看，它应该是用 pacman 安装软件时留下的缓存，应该是可以清掉的，于是Google了一下，找到答案：可以用下面的命令清除掉一些旧的缓存：</p>
<blockquote>
<p>
		pacman -Sc</p>
</blockquote>
<p>如果要清除全部缓存，则可以用下面的命令：</p>
<blockquote>
<p>
		pacman -Scc</p>
</blockquote>
<p>我使用的是前者，执行完后释放了2.8GB的空间，又可以愉快地玩耍了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color: rgb(0, 255, 0);">【13】</span>创建用户 &amp; 免密码切换到root<br />
新装好的系统创建用户：</p>
<blockquote>
<p>
		useradd -m codelast</p>
</blockquote>
<p>这就创建了一个codelast用户。-m表示在 /home/ 目录下创建一个 codelast 目录，如果不加此参加则不创建。<br />
之后紧接着就修改codelast用户的密码：</p>
<blockquote>
<p>
		passwd codelast</p>
</blockquote>
<p>再之后，为这个用户设置免密码切换到root的权限：</p>
<blockquote>
<p>
		visudo</p>
</blockquote>
<p>这会自动用一个编辑器打开 /etc/sudoers 文件（注意不能用其他的编辑器来编辑此文件，但这个默认的编辑器太难用了）。<br />
在文件中加上这一句：</p>
<pre style="user-select: text; position: absolute; top: -99px;">
codelast ALL=(ALL) NOPASSWD: ALL
</pre>
<blockquote>
<p>
		codelast ALL=(ALL) NOPASSWD: ALL</p>
</blockquote>
<p>表示允许codelast用户免密码执行任何命令。无需重启，保存文件之后用 codelast 用户试一下：</p>
<blockquote>
<p>
		sudo su -</p>
</blockquote>
<p>应该就能免密码切换到root了</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
<div id="KSFIND_MASK" style="background-color: rgb(0, 0, 0); opacity: 0.22; position: absolute !important; left: 0px !important; top: 0px !important; border: 0px none !important; padding: 0px !important; z-index: 1000000 !important; height: 0px; width: 0px; display: none; cursor: auto; ">
	&nbsp;</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9braspberry-pi%e6%a0%91%e8%8e%93%e6%b4%be%e9%85%8d%e7%bd%ae%e8%ae%b0%e5%bd%95configure-the-arch-linux-arm-on-raspberry-pi/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
