134 lines
4.7 KiB
Markdown
134 lines
4.7 KiB
Markdown
### 登入
|
||
- 帳號:`pi`
|
||
- 密碼:`<你自己設的密碼>`
|
||
|
||
### 設定固定IP
|
||
#### Ethernet
|
||
打開`/etc/dhcpcd.conf`,設定如下:
|
||
```
|
||
interface eth0
|
||
static ip_address=192.168.1.20/24
|
||
static routers=192.168.1.1
|
||
static domain_name_servers=168.95.1.1 1.1.1.1
|
||
```
|
||
|
||
#### WIFI
|
||
打開`/etc/dhcpcd.conf`,設定如下:
|
||
```
|
||
interface wlan0
|
||
static ip_address=192.168.1.21/24
|
||
static routers=192.168.1.1
|
||
static domain_name_servers=168.95.1.1 1.1.1.1
|
||
```
|
||
|
||
確定`dhcpcd`與`networking`是enabled,不確定可以直接用下面的命令來啟動。
|
||
```shell
|
||
systemctl enable dhcpcd ;\
|
||
systemctl enable networking
|
||
```
|
||
|
||
### 更新記憶卡容量
|
||
- [Taiwan-RaspberryPi | 台灣樹莓派 - (1)更新記憶卡容量](https://www.taiwan-raspberrypi.com/start/setting/1%E6%9B%B4%E6%96%B0%E8%A8%98%E6%86%B6%E5%8D%A1%E5%AE%B9%E9%87%8F/)
|
||
|
||
### 設定免密碼登入
|
||
1. 將自己的public key copy到RaspberryPi上:
|
||
```
|
||
scp ~/.ssh/rpi.pub pi@<IP_ADDR>:~/.ssh/
|
||
```
|
||
2. 登入到RaspberryPi,這一次要輸入密碼:
|
||
```shell
|
||
ssh pi@<IP_ADDR>
|
||
```
|
||
3. (現在是在RaspberryPi上操作)把剛剛的public key加到`authorized_keys`裡面:
|
||
```bash
|
||
cd ~/.ssh ;\
|
||
cat id_rsa.pub >> authorized_keys
|
||
```
|
||
|
||
## 安裝
|
||
### Python3
|
||
```shell
|
||
sudo apt install python3
|
||
```
|
||
|
||
### Docker
|
||
#### Install
|
||
```shell
|
||
# Install some required packages first
|
||
sudo apt update ; sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
|
||
|
||
# Get the Docker signing key for packages
|
||
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
|
||
|
||
# Add the Docker official repos
|
||
echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
|
||
$(lsb_release -cs) stable" | \
|
||
sudo tee /etc/apt/sources.list.d/docker.list
|
||
|
||
# Install Docker
|
||
sudo apt update ; sudo apt install -y --no-install-recommends docker-ce cgroupfs-mount
|
||
```
|
||
|
||
#### Confirm installation
|
||
```shell
|
||
sudo docker run --rm hello-world
|
||
```
|
||
如果成功,會有如下的訊息:
|
||
![[Pasted image 20210125183754.png]]
|
||
|
||
### docker-compose
|
||
```shell
|
||
# Install required packages
|
||
sudo apt update ; sudo apt install -y python3-pip libffi-dev
|
||
|
||
# Install Docker Compose from pip (using Python3)
|
||
# This might take a while
|
||
sudo pip3 install docker-compose
|
||
```
|
||
|
||
#### Confirm installation
|
||
```shell
|
||
docker-compose -version
|
||
```
|
||
會輸出docker-compose的版本,類似下面:
|
||
```
|
||
docker-compose version 1.28.0, build unknown
|
||
```
|
||
|
||
## 更新
|
||
```shell
|
||
sudo apt-get update `# 1. 更新 /etc/apt/sources.list 底下的套件清單。` ;\
|
||
sudo apt-get upgrade `# 2. 比對套件清單決定是否需要更新,但如果要更新的套件有相依性問題,則放棄更新。` ;\
|
||
sudo apt-get dist-upgrade `# 3. 會處理新版本套件與相依性套件的衝突,並試著安裝/移除有問題的套件來完成更新。` ;\
|
||
sudo apt-get autoremove `# 4. 刪除之前因為有相依性而安裝,但現在已經不再使用的套件(非必要)。` ;\
|
||
sudo apt-get autoclean `# 5. 清除下載到 /var/cache/apt/archives 的 .deb 套件檔(非必要)` ;\
|
||
sudo rpi-update `# 6. 更新核心和韌體到最新版本(可能不穩定),因此更新前一定要先備份重要資料`
|
||
```
|
||
|
||
## 備份
|
||
1. 下載必須的工具
|
||
```
|
||
wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
|
||
sudo chmod +x pishrink.sh
|
||
sudo mv pishrink.sh /usr/local/bin
|
||
```
|
||
1. 插入隨身碟,並將隨身碟mount起來。記住mount的路徑,這邊假設是`/mnt/usb0`。
|
||
2. 用`lsblk`確認SD卡的device node,這邊假設SD卡是`/dev/mmcblk0`。
|
||
3. 輸入以下指令,將整片microSD卡備份到USB隨身碟
|
||
```
|
||
sudo dd if=/dev/mmcblk0 of=/mnt/usb0/PiBackup_20220513.img bs=1M
|
||
```
|
||
這個命令會將整張SD卡dummp到隨身碟,SD卡有多大,產生的img檔就會有多大。
|
||
這個命令會花上好一點時間。
|
||
> `dd`命令並不會顯示任何進度或是訊息,若是希望在執行過程中看到一些訊息,可以加入`status=progress`,將可以看到速度的訊息。
|
||
> 但是`progress`這個小工具是需要另外安裝的,可以用`sudo apt install progress`來安裝。
|
||
> 例:`sudo dd if=/dev/mmcblk0 of=/mnt/usb0/PiBackup_20220513.img bs=1M status=progress`
|
||
5. 切換到隨身碟的目錄:`cd /mnt/usb0`。
|
||
6. 用以下命令來把img變小:
|
||
```
|
||
sudo pishrink.sh -z PiBackup_20220513.img
|
||
```
|
||
這個命令也會花上好一點時間。
|
||
|
||
### 參考
|
||
- [[Raspberry Pi] 備份樹莓派系統Micro SD卡的最佳做法_PiShrink @ skybow](https://skybow.pixnet.net/blog/post/121176894-%5Braspberry-pi%5D-%E5%82%99%E4%BB%BD%E6%A8%B9%E8%8E%93%E6%B4%BEsd%E5%8D%A1%E7%9A%84%E6%9C%80%E4%BD%B3%E5%81%9A%E6%B3%95) |