可以把Raspberry Pi當成一台學習Linux的小電腦
http://ithelp.ithome.com.tw/question/10130317
上一篇: Linux Pi的奇幻旅程(2)-檔案結構與開機程序
http://ithelp.ithome.com.tw/question/10129477
下一篇: Linux Pi的奇幻旅程(4)-Windows篇
http://ithelp.ithome.com.tw/question/10130317
全部: http://ithelp.ithome.com.tw/ironman6/player/bizpro/alll/1
aspberry Pi開機了, 如果是用HDMI或S-Video接電視或電腦螢幕, 可以直接查找到IP或設定IP, 另一個方法是掃描DHCP的範圍, 不然就是找router中的連線紀錄, 不管什麼方法, 把IP找出來後, 就可以用ssh連線到Raspberry Pi了. 在Windows系統中, 可以用putty(http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe).
$ ssh pi@192.168.1.112
pi@192.168.1.112's password:
Linux raspberrypi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Sep 1 13:29:16 2013 from 192.168.1.102
Raspbian的內定帳號是pi, 而密碼就是raspberry了, 進入raspbian的第一步當然是改密碼和做重要的設定了. 在Linux中, 修改密碼很簡單, 就用指令passwd:
pi@raspberrypi ~ $ passwd pi
Changing password for pi.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
上面的pi@raspberrypi是什麼意思? 先看看下面的指令:
pi@raspberrypi ~ $ hostname
raspberrypi
pi@raspberrypi ~ $ whoami
pi
當然是使用者pi在(at, @)主機名稱(hostname)為raspberrypi的Raspberry Pi小電腦上的意思了. 這些都是可以修改的, 要修改主機名稱, 就直接修改檔案/etc/hostname:
pi@raspberrypi ~ $ sudo nano /etc/hostname
我習慣用文字編輯器nano, 許多人習慣用vi, 習慣就好了.
進入Raspberry Pi之後, 檢查一下檔案結構:
pi@raspberrypi ~ $ ls -ls /
total 88
4 drwxr-xr-x 2 root root 4096 Jul 26 12:19 bin
16 drwxr-xr-x 3 root root 16384 Jan 1 1970 boot
0 drwxr-xr-x 12 root root 3060 Sep 1 15:37 dev
4 drwxr-xr-x 96 root root 4096 Sep 24 15:19 etc
4 drwxr-xr-x 3 root root 4096 Jul 26 11:47 home
4 drwxr-xr-x 12 root root 4096 Jul 26 12:08 lib
16 drwx------ 2 root root 16384 Jul 26 11:22 lost+found
4 drwxr-xr-x 2 root root 4096 Jul 26 11:24 media
4 drwxr-xr-x 2 root root 4096 Jun 15 15:44 mnt
4 drwxr-xr-x 3 root root 4096 Jul 26 11:49 opt
0 dr-xr-xr-x 71 root root 0 Jan 1 1970 proc
4 drwx------ 8 root root 4096 Sep 1 15:37 root
0 drwxr-xr-x 11 root root 500 Sep 24 15:10 run
4 drwxr-xr-x 2 root root 4096 Jul 26 12:19 sbin
4 drwxr-xr-x 2 root root 4096 Jun 20 2012 selinux
4 drwxr-xr-x 2 root root 4096 Jul 26 11:24 srv
0 dr-xr-xr-x 12 root root 0 Jan 1 1970 sys
4 drwxrwxrwt 4 root root 4096 Sep 24 15:22 tmp
4 drwxr-xr-x 10 root root 4096 Jul 26 11:24 usr
4 drwxr-xr-x 11 root root 4096 Jul 26 13:43 var
可以看到, 原本在SD卡中的兩個子目錄, 9c7e2035-df9b-490b-977b-d60f2170889d
和boot都被重新設置了, 9c7e2035-df9b-490b-977b-d60f21708896成了根目錄, 而SD卡中的boot子目錄則被掛載到根目錄之下:
pi@raspberrypi ~ $ cat /etc/fstab
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
/etc/fstab是Linux開機時要主動掛載系統的設定檔. /dev/mmcblk0p1和/dev/mmcblk0p2是甚麼?由指令fdisk可以知道, SD卡中有兩個分割區(partition), 也就是/dev/mmcblk0p1和/dev/mmcblk0p2.
pi@raspberrypi ~ $ sudo fdisk -l
Disk /dev/mmcblk0: 3980 MB, 3980394496 bytes
4 heads, 16 sectors/track, 121472 cylinders, total 7774208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00047c7a
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 7774207 3825664 83 Linux
而在/etc/fstab中/dev/mmcblk0p1被掛在成/boot, 檔案格式是vfat
/dev/mmcblk0p1 /boot vfat defaults 0 2
而/dev/mmcblk0p1被掛載成根目錄/, 檔案格式是ext4.
對於熟悉Linux系統的使用者, 這些都是基礎的指令, 這是一台跑Debian的電腦, 可以使用一般的Linux指令, 例如查查系統版本:
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 armv6l GNU/Linux
pi@raspberrypi ~ $ cat /etc/issue
Raspbian GNU/Linux 7 \n \l
檢查記憶體使用情形, 共有438MB可用記憶體, 只用了126MB.
pi@raspberrypi ~ $ free -m
total used free shared buffers cached
Mem: 438 126 311 0 9 95
-/+ buffers/cache: 22 415
Swap: 99 0 99
檢查CPU, 記憶體和運行的程序的狀態:
pi@raspberrypi ~ $ top
top - 15:46:51 up 39 min, 1 user, load average: 0.06, 0.13, 0.12
Tasks: 58 total, 1 running, 57 sleeping, 0 stopped, 0 zombie
%Cpu0 : 0.3 us, 0.7 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 448776 total, 129680 used, 319096 free, 9272 buffers
KiB Swap: 102396 total, 0 used, 102396 free, 97524 cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2245 pi 20 0 4640 1288 936 R 0.7 0.3 0:00.21 top
1 root 20 0 2144 728 620 S 0.0 0.2 0:01.68 init
..........
編輯網路設定檔/etc/network/interfaces, 如
pi@raspberrypi ~ $ sudo nano /etc/network/interfaces
原本的設定是採用dhcp的.
pi@raspberrypi ~ $ sudo cat /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
接著更新系統吧:
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get upgrade
...........
Setting up libraspberrypi0 (1.20130902-1) ...
Setting up libraspberrypi-dev (1.20130902-1) ...
Setting up libraspberrypi-doc (1.20130902-1) ...
Setting up libraspberrypi-bin (1.20130902-1) ...
Setting up raspi-config (20130910-1) ...
Setting up perl-modules (5.14.2-21+rpi2) ...
Setting up perl (5.14.2-21+rpi2) ..
這樣, 又有一台效能不錯的Linux電腦了. 又省電. 玩壞了, 再重裝SD卡, 重新來過.