1. 硬件准备
- 某东购买Raspberry 3B+,性能参数如下:
- 网线一条;
- DHCP服务器,用于给树莓派分配地址(家用路由器即可,高端玩家可以在自己电脑搭DHCP服务器)
- 安卓充电器给树莓派供电;
- SD卡,推荐64G;
- SD卡读卡器;
- 如果有条件可以准备一台linux电脑(虚拟机也可),用于直接修改Raspberry网络配置文件。当然这一步也可以通过其他方式实现。
2. 软件准备
-
去官网下载Centos7
-
格式化工具SD Card Formatter下载
-
系统烧录软件balenaEtcher下载
3. 烧录系统
- 用SD card Formatter格式化SD卡;
- 用BalenaEtcher写入系统
4. 接入网络
系统烧录完成后就可以上线了。上线之前需要解决联网问题。联网方式有两种:
- 将格式化好后的SD卡插入Linux系统,然后修改配置文件如下:
在SD卡路径/etc/sysconfig/network-scripts下新建ifcfg-eth0文本文件(如果涉及权限问题,先设置为777,编辑保存后在修改为644):
在刚新建的ifcfg-eth0文本中粘贴如下内容
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
UUID="f3ab18d3-eeda-3a23-aa45-be5e3ff82c3d"
DEVICE="eth0"
ONBOOT="yes"
IPADDR=192.168.1.7 #根据自己网络情况填写
GATEWAY=192.168.1.1 #根据自己网络情况填写
NETMASK=255.255.255.0 #根据自己网络情况填写
DNS1=8.8.8.8 #根据自己网络情况填写
- 另一种方法是通过DHCP服务器自动分配IP地址,但是这种方式并不知道树莓派拿到的IP地址是多少,不方便ssh登录树莓派。
- 完成上面操作后就可以给树莓派上电了。将树莓派接到路由器上,然后PC ping刚才配置的IP地址,显示通了。
- 此时通过SSH终端 连接树莓派,本人使用SecureCRT,默认用户名和密码root centos
- 接下来配置wifi
通过命令nmcli d wifi
查看可用wifi SSID:
连接wifi:
nmcli d wifi connect PLDTHOMEDSLFHFH0 password '********'
#***是密码
通过nmcli d show wlan0
查看无线网卡Wlan0状态:
成功连接无线,并获取到192.168.1.9地址,接下来,我们将固定无线地址:
查看/etc/sysconfig/network-scripts
文件夹发现多出来了名为ifcfg-PLDTHOMEDSLFHFH0
的文件,
现在同理编辑该文件,增加固定IP为192.168.1.8 ,配置如下:
KEY_MGMT=WPA-PSK
SECURITYMODE=open
MAC_ADDRESS_RANDOMIZATION=default
TYPE=Wireless
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=PLDTHOMEDSLFHFH0
UUID=e1f62658-fb51-414e-95f4-b2e9cb00609f
ONBOOT=yes
GATEWAY=192.168.1.1 #新增部分
IPADDR=192.168.1.8 #新增部分
NETMASK=255.255.255.0 #新增部分
DNS1=8.8.8.8 #新增部分
重启网络服务,使之生效;
如果无线静态地址配置了不生效,记得使用命令:ifconfig wlan0 down
和ifconfig wlan0 up
使接口手动UP/Down一下。
5. 根目录扩容
Centos 默认使用到4G,但是DS卡远远不止4G,那么需要扩容。步骤如下:
df -h
查看当前空间情况:
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 3.7G 2.9G 757M 80% / #发现总空间3.7G,只利用到了2.9G
devtmpfs 459M 0 459M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 13M 451M 3% /run
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 286M 55M 232M 20% /boot
tmpfs 93M 0 93M 0% /run/user/0
tmpfs 93M 8.0K 93M 1% /run/user/992
fdisk -l
查看是否有可用空间
Disk /dev/ram15: 4 MB, 4194304 bytes, 8192 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mmcblk0: 63.9 GB, 63864569856 bytes, 124735488 sectors ##发现有63G总空间
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 label type: dos
Disk identifier: 0x00097f72
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 8192 593919 292864 c W95 FAT32 (LBA)
/dev/mmcblk0p2 593920 1593343 499712 82 Linux swap / Solaris
/dev/mmcblk0p3 1593344 9406463 3906560 83 Linux
- 用
fdisk /dev/mmcblk0
开始扩容
[root@localhost ~]# fdisk /dev/mmcblk0 ##对mmcblk0进行操作
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p #查看当前分区情况
Disk /dev/mmcblk0: 63.9 GB, 63864569856 bytes, 124735488 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 label type: dos
Disk identifier: 0x00097f72
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 8192 593919 292864 c W95 FAT32 (LBA)
/dev/mmcblk0p2 593920 1593343 499712 82 Linux swap / Solaris
/dev/mmcblk0p3 1593344 9406463 3906560 83 Linux #计划删除该分区,一定要记住Start值,后面有用
Command (m for help): d #输入d
Partition number (1-3, default 3): 3 #输入3,完成删除3分区
Partition 3 is deleted
Command (m for help): p #再查看,发现3号分区已经删除
Disk /dev/mmcblk0: 63.9 GB, 63864569856 bytes, 124735488 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 label type: dos
Disk identifier: 0x00097f72
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 8192 593919 292864 c W95 FAT32 (LBA)
/dev/mmcblk0p2 593920 1593343 499712 82 Linux swap / Solaris
Command (m for help): n #输入n新建分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p #输入p 新建primary分区
Partition number (3,4, default 3): 3 #输入分区编号3
First sector (2048-124735487, default 2048): 1593344 #输入刚才start记录的值,否则系统会崩溃
Last sector, +sectors or +size{K,M,G} (1593344-124735487, default 124735487): #默认最大
Using default value 124735487
Partition 3 of type Linux and of size 58.7 GiB is set
Command (m for help): p #再查看分区情况,发现已经新增完成
Disk /dev/mmcblk0: 63.9 GB, 63864569856 bytes, 124735488 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 label type: dos
Disk identifier: 0x00097f72
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 8192 593919 292864 c W95 FAT32 (LBA)
/dev/mmcblk0p2 593920 1593343 499712 82 Linux swap / Solaris
/dev/mmcblk0p3 1593344 124735487 61571072 83 Linux
Command (m for help): w #保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# reboot #重启
Last login: Mon Dec 30 09:31:28 2019 from 192.168.1.3
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 3.7G 2.9G 756M 80% /
devtmpfs 459M 0 459M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 13M 451M 3% /run
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 286M 55M 232M 20% /boot
tmpfs 93M 8.0K 93M 1% /run/user/992
tmpfs 93M 0 93M 0% /run/user/0
[root@localhost ~]# resize2fs /dev/mmcblk0p
mmcblk0p1 mmcblk0p2 mmcblk0p3
[root@localhost ~]# resize2fs /dev/mmcblk0p3 #重载分区3
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mmcblk0p3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 8
The filesystem on /dev/mmcblk0p3 is now 15392768 blocks long.
[root@localhost ~]# df -h #查看,已经扩容到58G了
Filesystem Size Used Avail Use% Mounted on
/dev/root 58G 2.9G 55G 5% /
devtmpfs 459M 0 459M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 13M 451M 3% /run
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 286M 55M 232M 20% /boot
tmpfs 93M 8.0K 93M 1% /run/user/992
tmpfs 93M 0 93M 0% /run/user/0
【完】