最近树莓派2到手了, 开始折腾
环境设备: ubuntu虚拟机 树莓派2
###选择系统
从官网上下来 NOOBS 安装试了 RASPBIAN。过程很简单,
解压复制到TF卡根目录插到树莓派开机即可。但是有时一不小心碰到电源,
树莓派突然断电系统就损坏了…开始以为是系统原因,就换成ArchLinux了
###archlinux | arm 安装
需要一个Linux环境来进行下面操作
Start fdisk to partition the SD card:
fdisk /dev/sdX
At the fdisk prompt, delete old partitions and create a new one:
Type o. This will clear out any partitions on the drive.
Type p to list partitions. There should be no partitions left.
Type n, then p for primary, 1 for the first partition on the drive,
press ENTER to accept the default first sector,
then type +100M for the last sector.
Type t, then c to set the first partition to type W95 FAT32 (LBA).
Type n, then p for primary, 2 for the second partition on the drive,
and then press ENTER twice to accept the default first and last sector.
Write the partition table and exit by typing w.
Create and mount the FAT filesystem:
1 | mkfs.vfat /dev/sdX1 |
Create and mount the ext4 filesystem:
1 | mkfs.ext4 /dev/sdX2 |
Download and extract the root filesystem (as root, not via sudo):1
2
3wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root
sync
Move boot files to the first partition:
1 | mv root/boot/* boot |
Unmount the two partitions:
1 | umount boot root |
Insert the SD card into the Raspberry Pi, connect ethernet, and apply 5V power.
Use the serial console or SSH to the IP address given to the board by your router. The default root password is ‘root’.
###基本配置
更换源地址
1
2
3
4
5
6#养成备份好习惯
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
nano /etc/pacman.d/mirrorlist
#将下面这行加进去
Server = http://mirrors.ustc.edu.cn/archlinuxarm/armv7h/$repo
添加普通用户
useradd -m user
安装 sudo
pacman -S sudo
使用
visudo
命令来配置用户权限,将刚创建的用户加入到配置中(文件中有root用户为示例)配置DNS
最近网络有些异常,要配置下 DNS 才能正常上网。 arch 的 wiki 里有写
nano /etc/resolv.conf
需要设置下 resolv.conf 文件的权限来防止被其他进程修改
1
2
3
4
5
6#需要root权限
cd /etc
cp resolv.conf resolv.conf.bak
chattr +i resolv.conf.bak
rm resolv.conf
cp resolv.conf.bak resolv.conf按照这个步骤来应该不会出现异常了
设置时间同步
不知道是网络的原因还是怎么回事,openntpd 和 ntpdate 都没成功
在网上查到一篇文章 树莓派上使用htpdate同步时间 准备试下
系统修复和备份
系统坏了时可以尝试运行这条命令来修复,注意替换为正确的磁盘
fsck.ext4 -y /dev/sdb2
修复成功的几率不大,最好还是做好备份:
可以使用 win32DiskImager 把 tf 卡 read 出来, 恢复备份时重新写入就好
也可以使用以下命令
1
2
3
4
5#备份和恢复
sudo dd bs=4M if=/dev/sdb of=raspbian.img
sudo dd bs=4M if=raspbian.img of=/dev/sdb