AWS 上服务器centos 重新建源

AWS服务器的CENTOS 提示

rpm -qa |grep yum

rpm -e yum-plugin-fastestmirror-1.1.31-50.el7.noarch –nodeps

rpm -e yum-3.4.3-161.el7.centos.noarch –nodeps

rpm -e yum-metadata-parser-1.1.4-10.el7.x86_64 –nodeps

yum-utils-1.1.31-54.el7_8.noarch

移动除些源

下载新源
cd /var/www/setup

wget https://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm

wget https://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm

wget https://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget https://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

重新编辑REPO

curl http://mirrors.163.com/.help/CentOS7-Base-163.repo -o /etc/yum.repos.d/CentOS6-Base-163.repo
vim /etc/yum.repo/CentOS7-Base-163.repo

如果网络允许,baseurl可以使用外网地址,并使用全文替换:
:1,$s/$releasever/7
否则,可以本地挂载iso系统光盘

修改yum的代码,vi /bin/yun 第一行python 改成python2

同样修改yum 命令使用到的python

vi /usr/libexec/urlgrabber-ext-down

修改报错文件,将头行”#!/usr/bin/python” 改为 “#!/usr/bin/python2″即可。

重建缓存并使用yum install 来进行测试是否yum源重建成功

清除缓存

[root@localhost yum.repos.d]# yum clean all
重建缓存,以提高搜索安装软件的速度

[root@localhost yum.repos.d]# yum makecache
更新系统(可选)

[root@localhost yum.repos.d]# yum update
测试yum安装:

[root@localhost yum.repos.d]# yum install vsftp


docker 青龙面板安装依赖

docker exec -it qinglong pip3 install requests
docker exec -it qinglong pip3 install canvas
docker exec -it qinglong pip3 install ping3
docker exec -it qinglong pip3 install jieba
docker exec -it qinglong pip3 install dailycheckin

docker exec -it qinglong pip3 install bizCode
docker exec -it qinglong pip3 install bizMsg
docker exec -it qinglong pip3 install lxml


NodeJs下

docker exec -it qinglong bash -c “npm install png-js”

docker exec -it qinglong pnpm install crypto-js
docker exec -it qinglong pnpm install
prettytable
dotenv
docker exec -it qinglong pnpm install jsdom

docker exec -it qinglong pnpm install date-fns
docker exec -it qinglong pnpm install
tough-cookie
docker exec -it qinglong pnpm install
tslib
ws@7.4.3
docker exec -it qinglong pnpm install
ts-md5

docker exec -it qinglong pnpm install jsdom -g

docker exec -it qinglong pnpm install jieba
docker exec -it qinglong pnpm install
fs
form-data

docker exec -it qinglong pnpm install json5
docker exec -it qinglong pnpm install
global-agent
docker exec -it qinglong pnpm install
png-js

docker exec -it qinglong pnpm install @types/node
docker exec -it qinglong pnpm install
require
docker exec -it qinglong pnpm install
typescript

docker exec -it qinglong pnpm install js-base64

树莓派4全新安装系统 安装

(系统版本:CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-4-2009-sda.raw)

一、安装系统
1、烧录系统
这里用到树莓派官方(https://www.raspberrypi.com/software/)的烧录软件
Raspberry Pi Imager

2.下载安装包,本次使用没有UI的系统,华为云下载相应镜像

(注:此系统不含 GNOME,只是命令行)

https://mirrors.huaweicloud.com/centos-altarch/7.9.2009/isos/armhfp/CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-4-2009-sda.raw.xz

3烧录完成

二、登陆系统,.

把烧录好的SD卡插入树莓派,通上电并接上路由器,通过路由器的管理页面观察树莓派的ip地址。

跟Raspberry Pi OS不同,centOS是默认开启ssh的。

默认帐号密码登陆 root 密码centos

默认用户名:root
默认密码:centos

2.修改密码

passwd root

3. 到目前为止我们已经成功安装centos并通过局域网连接树莓派。
如果想让树莓派连接Wi-Fi,可以输入

nmtui
#设置有线IP为10.8.0.188
#连接wifi casey

选 active connection连接wifi

三、硬盘扩容

fd -h

命令查看,发现32G的tf卡只用了2G,光是系统就基本用满了,装不了什么东西,所以得把剩下30G(29724664)也用上。这里暂时只使用16G,(约14862332)

fdisk /dev/mmcblk0
p——查看旧分区情况
d——删除分区,并按照提示删除第三个分区
n——添加一个分区,空间起始位置按照系统默认
p——查看新分区情况
w——写入分区信息并退出软件

先p查看分区,抄下第三分区的开始start (1593344)

【d】删除第三分区,

【n】新建第三分区【p】,使用16G,所以end长度29724664

[w] 保存,

重启

reboot

重启后,刷新分区

resize2fs /dev/mmcblk0p3

四、安装软件vim,vi

1.安装vim

yum install -y vim

2、换源

清理旧仓库

# 清除缓存
yum clean all
sudo rm -rf /var/cache/yum
# 卸载epel仓库
yum remove epel-release
# 删除所有旧仓库文件
# 注意,如有其它仓库文件请自行重装或选择性删除
rm -rf /etc/yum.repos.d/*

建立仓库

vim /etc/yum.repos.d/CentOS-Base.repo

内容

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
 
#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/updates/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/extras/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32


sudo vi /etc/yum.repos.d/epel.repo
[epel]
name=Epel rebuild for armhfp
baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/
enabled=1
gpgcheck=0

重新缓存

yum makecache
yum update -y
yum upgrade -y

安装wget

yum install -y wget

安装gcc

yum install -y gcc

5、安装python3并配置pip

安装python3

下载python

#下载
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
#解压
tar -zxvf  Python-3.8.3.tgz

先安装make

yum install make -y

安装zlib,由于直接安装失败,我是通过源码安装的

yum -y install zlib -y
cd /var
mkdir www
cd www
mkdir setup
cd setup
wget  http://www.im.com.cn/source/armhf/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install

安装openssl

yum install -y openssl 

编择python3

mkdir /usr/local/python3 #创建编译安装目录
cd Python-3.8.3
./configure  --prefix=/opt/python-3.7.1 --with-openssl=/opt/openssl-1.0.2q
make && make install

最后成功会出现那列语句

Successfully installed pip-19.2.3 setuptools-41.2.0

创建软件连接

ll /usr/bin/ |grep python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

现在同时保留了原版python2.7 和新的python3

同样链接pip

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

给pip也换个源

mkdir  ~/.pip/
 vim ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

五、建立用户,授予权限

. 修改文 件 /etc/rc.d/rc.local 与/etc/rc.local
setterm -powersave off -blank 0
这种方式在启动时再次设置。

adduser mee
passwd mee
chmod -v u+w /etc/sudoers
vim /etc/sudoers
找到root ALL=(ALL) ALL
然后添加temp_user ALL=(ALL) NOPASSWD:ALL
如需新用户使用sudo时不用输密码,把最后一个ALL改为NOPASSWD:ALL即可。
chmod -v u-w /etc/sudoers

六、安装小软件

1.安装iw管理wireless

#安装wifi管理软件
yum install -y iw
#安装USB管理软件
yum install -y usbutils 
#安装v4l软件
yum install -y v4l-utils 
#安装 NTFS 软件
yum install -y ntfs-3g
#unzip
yum install -y zip unzip 

#用于安装git的前备软件
yum install -y install zlib-devel
yum install -y openssl-devel
yum install -y cpio
yum install -y expat-devel 
yum install -y gettext-devel 
yum install -y curl-devel 
yum install -y perl-ExtUtils-CBuilder 
yum install -y perl-ExtUtils-MakeMaker

yum install -y automake
#用于管理ipv6
yum install -y haveged 



systemctl enable haveged
systemctl start haveged

2. 安装wire less tools

cd /var/www/setup
wget https://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz
wget http://www.inhhh.com/download/wireless_tools.29.tar.gz
tar -zxvf wireless_tools.29.tar.gz 
cd /var/www/setup/wireless_tools.29
make
make install
reboot
#关闭power_save
sudo iw wlan0 set power_save off
查看 power_save
iw waln0 get power_save

Don’t forget to add /usr/local/lib/ to /etc/ld.so.conf, and run ldconfig as root
意思就是编辑
/etc/ld.so.conf, 文件,加上一行

vi /etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/lib/

使生效

sudo ldconfig

测试命令

iwlist
iwconfig

七,重装git 2.25.1

wget https://github.com/git/git/archive/v2.25.1.zip
git --version
yum remove git  -y
unzip v2.25.1.zip
cd git-2.25.1
make prefix=/usr/local all
make prefix=/usr/local install

vi /etc/profile
增加一行
PATH=/usr/local/bin:$PATH

source /etc/profile
echo $PATH
git --version

CentOS7取消服务器自动休眠
CentOS作为服务器操作系统,默认会自动休眠的设定有点匪夷所思。

手动关闭自动休眠的方法如下:

[root@CentOS ~]

# vi /etc/X11/xorg.conf
复制代码
Section “ServerFlags”
Option “BlankTime” “0” #关闭黑屏
Option “StandbyTime” “0” #关闭待机
Option “SuspendTime” “0” #关闭睡眠
Option “OffTime” “0”
EndSection

Section “Monitor”
Option “DPMS” “false”
EndSection
复制代码

[root@CentOS ~]

# reboot

八、安装wiringpi

cd /var/www/setup
mkdir WiringPi
cd WiringPi
#克隆库
git clone https://github.com/WiringPi/WiringPi.git
#进入文件夹
cd WiringPi
#编译安装
./build
gpio -v

九、安装opencv

安装pkg-config

cd /var/www/setup 
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
tar -zxvf pkg-config-0.29.2.tar.gz 
cd pkg-config-0.29.2
./configure --prefix=/usr/local/pkg-config --with-internal-glib 
make
make install
yum install -y ffmpeg ffmpeg-devel
ffmpeg --version
#准备软件
yum install -y gcc 
yum install -y gcc-c++ 
yum install -y gtk2-devel 
yum install -y gimp-devel 
yum install -y gimp-devel-tools 
#yum install -y gimp-help-browser 
#yum install -y zlib-devel 
yum install -y libtiff-devel 
yum install -y libjpeg-devel 
yum install -y libpng-devel 
yum install -y gstreamer-devel 
yum install -y libavc1394-devel 
yum install -y libraw1394-devel 
yum install -y libdc1394-devel 
yum install -y jasper-devel 
yum install -y jasper-utils 
yum install -y swig 
yum install -y python 
yum install -y libtool 
yum install -y nasm 
yum install -y numpy


yum install -y autoconf 
yum install -y automake 
yum install -y freetype-devel 
yum install -y git 
yum install -y make 
yum install -y mercurial 
yum install -y pkgconfig 
yum install -y gstreamer-plugins-base-devel
yum install -y cmake
#下载opencv-3.4.14
cd /var/www/setup
mkdir opencv
cd opencv
wget http://www.im.com.cn/source/armhf/opencv-3.4.14.tar.gz
tar -zxvf opencv-3.4.14.tar.gz
cd opencv-3.4.14
mkdir release
cd release
#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_PYTHON_SUPPORT=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_OPENGL=ON -D WITH_GTK=ON ..
make 
make install


export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}
pkg-config --modversion opencv





#添加库路径(创建opencv.conf文件)
输入命令:
vi /etc/ld.so.conf.d/opencv.conf
输入/usr/local/lib,并保存退出

#添加环境变量
输入命令:vi /etc/profile

在末尾加入:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

更新环境变量:source /etc/profile

#、设置另外环境变量

输入命令:vi /etc/bashrc

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

更新环境变量:source /etc/profile

#更新系统库缓存

输入命令:ldconfig
#、查看opencv是否安装成功
输入命令:pkg-config—cflags opencv
          pkg-config—libs opencv

如果没有出错,说明安装成功。
#测试
输入命令:cd ..../OpenCV-2.4.0/samples/cpp
g++ `pkg-config --cflags --libs opencv` drawing.cpp -o drawing
./drawing

十、安装ffmpeg rtmp视频推流

1.安装准备软件

yum install -y yasm

2.源码编译安装 x264

cd /var/www/setup
mkdir x264
cd x264
# wget https://codeload.github.com/qupai/x264/zip/master
wget http://www.ingridmillet.com.cn/source/armhf/x264-master.zip
#tar -zxvf x264-master
unzip x264-master
cd x264-master
#查看帮助信息
./configure --help
#我们需要的是x264以.so or .a的形式来支援ffmpeg,所以一般就关注shared和static关键词就可以了, --disable-cli一定要填,不然make出错
./configure --prefix=/usr/local/x264 --enable-shared --enable-static  --disable-cli --enable-strip --enable-yasm 
make
make install


vim /etc/profile
末尾加入内容export PKG_CONFIG_PATH=/usr/local/x264/lib/pkgconfig,具体看各位自己x264的安装路径
source /etc/profile

3.源码编译安装 FFMPEG

在FFmpeg官网获取源码 http://ffmpeg.org/download.html ,当前版本为 ffmpeg-4.2.tar.bz2 ,配置完成后编译并安装

cd /var/www/setup
mkdir ffmpeg
cd ffmpeg
# wget https://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2
# tar -jxvf ffmpeg-4.1.tar.bz2
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib --disable-x86asm
make
make install

如果遇到错误,把相关lib目录添加到lib

find / -name libavdevice.so.58
#find / -name libx264.so.*
vim /etc/ld.so.conf 
#将上述目录添加到最后一行并保存退出;
/sbin/ldconfig

#执行 ldconfig -v 命令,更新 ld.so.cache,使修改立即生效:
ldconfig -v

4. 创建软连接

#相当于 windows 中的创建快捷方式:
ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/
ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/
ln -s /usr/local/ffmpeg/bin/ffserver /usr/local/bin/

5. 头文件拷贝

#路径 /usr/local/ffmpeg/include/ 包含的文件信息如下:
cd /usr/local/ffmpeg/include/
ls
#/usr/local/ffmpeg/include 目录下创建 ffmpeg 目录:
mkdir ffmpeg
#将 /usr/local/ffmpeg/include 路径下所有目录复制到 ffmpeg 目录中:
复制代码
cp -r libswscale/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libswresample/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libpostproc/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavutil/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavformat/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavfilter/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavcodec/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavdevice/ /usr/local/ffmpeg/include/ffmpeg/
#将 /usr/local/ffmpeg/include 路径下 ffmpeg/ 目录复制到 /usr/include/:
cp -r ffmpeg/ /usr/include/

6.PKG_CONFIG_PATH 变量设置

ffmpeg 安装程序会在 /usr/local/ffmpeg/lib/pkgconfig 目录下提供 libavcodec.pc libswscale.pc 等5个.pc文件,分别对应安装的五个库文件。必须要让 pkg-config 能找到 ffmpeg 的 *.pc 文件,通过 PKG_CONFIG_PATH 来设置 pkg-config 来更新。

cd /usr/local/ffmpeg/lib/pkgconfig/
vim /etc/profile
#添加如下配置:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/ffmpeg/lib/pkgconfig
export FFMPEG_HOME=/usr/local/ffmpeg
export PATH=$PATH:$FFMPEG_HOME
#使配置立即生效:
source /etc/profile

4.测试推流

ffmpeg -version

ffmpeg -ss 0 -t 100 -pix_fmt yuv420p -i /dev/video0 -c:v h264_omx -f flv rtmp://10.8.0.188:8884/live

ffmpeg -ss 0 -t 100 -pix_fmt yuv420p -i /dev/video0 -c:v h264_v4l2m2 -f flv rtmp://10.8.0.188:8884/live

新玩树莓派4B

1.下载系统,
下载32位就可以了。

下载网址
https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit
选择系统可以有很多种,这里选 带桌面 与各种常用软件的。

Raspberry Pi OS with desktop and recommended software
实际下载路径是
https://downloads.raspberrypi.org/raspios_full_armhf/images/raspios_full_armhf-2021-03-25/2021-03-04-raspios-buster-armhf-full.zip

2. 解压系统
解压后是一个8.4G的img文 件。


3.写入TF卡
使用常用软件
Win32DiskImager.exe
即可

4. 修改系统设置

树莓派禁止休眠、屏幕常亮
打开lightdm.conf
sudo vi /etc/lightdm/lightdm.conf
xserver-command=X

修改为
[Seat:*]
xserver-command=X -s 0 -dpms
-s # –设置屏幕保护不启用
dpms 关闭电源节能管理


5.更新wiringpi到 2.52版本

cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.de

6. 安装 libncurses5-dev
apt-get install -y libncurses5-dev

7.源码安装mysql

参考

第十章:源代码编译安装MySQL
https://www.bilibili.com/video/BV1Py4y1B7Az
(注意原文 件中mysql/sql/sql_acl.cc 文 件中 .str == ‘\0’ 需要修改为 .str == “\0”)

树莓派(Centos) 第九章:建立共享文件夹,NAS)

yum install -y samba

groupadd smbgroups -g 6000

useradd smbuser1 -u 6000 -g 6000 -s /sbin/nologin -d /dev/null

smbpasswd -a smbuser1

gedit /etc/samba/smb.conf

[varwww]
comment = test resource
path = /var/www
writeable = yes
browseable = yes
write list = smbuser1
public = no

在windows 清除网络连接
net use * /del /y

树莓派(Centos) 第三章:增加磁盘空间

此处主要使用linux自带的命令fdisk

【1】查看当前磁盘大小,总大小只有3.9GB

$df -h

【2】查看第二分区的起始地址,把这个地址记下来

$cat /sys/block/mmcblk0/mmcblk0p3/start
1593344

【3】进入fdisk模式

$sudo fdisk /dev/mmcblk0

【4】按下d键,删除分区

Command(m for help):d

【5】选择删除的分区

Partition number(1-3,default 3):3

【6】按 n 键,重新创建Linux主分区

Command(m for help):n

【7】Partition Type(分类类型) 选 P (Primary)

Select(default p):p

【8】Partition Number (分区号) 选 3

Partition number(3-4,default 3):3

【9】First Sector(起始Sector) 一定要输入刚才记下来的Start Sector号(我的是122880)

First Sector(2048-31116287,default 2048):1593344回车

【10】Last sector,回车默认

Last Sector,+sectors or +size{K,M,G,T,P}(122880-31116287,default 31116287):回车

【11】按w保存操作并退出

Command(m for help):w

【12】接下来,立即重启,不要做任何其它事情

$sudo reboot

【13】重启并登录后,立即用以下命令

$sudo resize2fs /dev/mmcblk0p3

该命令将把第二个分区扩展到新的空间中

命令解释:
① 查看当前磁盘大小,总大小只有2.9GB
② 查看第二分区的起始地址,后面会用到
③ 使用fdisk操作磁盘
④ d,删除分区
⑤ 2,删除第二分区
⑥ 创建一个新分区
⑦ 创建主分区
⑧ 分区2
⑨ 输入第一次得到的第二分区起始扇区
⑩ 最后一个sector,默认即可
⑪ 将上面的操作写入分区表

等待一会儿操作完成,再次使用df -h查看发现空间已变大成30GB。