树莓派4 U盘加载系统

树莓派4 U盘引导启动

一、硬件镜像准备

1、准备Micro SD卡(8 or 16GB) 和 USB3.0 U盘1个(大于8G)
2、准备镜像
树莓派官方Raspbian系统,官网免费下载:点这里

树莓派镜像

3、准备烧录工具
目前balenaEtcher支持各个平台,推荐使用给这个烧录(下载地址:点这里)

烧录工具

4、烧录
解压树莓派镜像得到2020-02-13-raspbian-buster.img文件,打开烧录工具选择image、分别选择2个存储设备进行2次烧录,完成后得到2个启动盘。

二、树莓派4设置

1、将sd卡和U盘分别接到设备上如图


15882969324743.jpg
15882969256677.jpg

2、用SSH连接 或者 树莓派终端登陆
3、运行blkid查看设备信息,如下面,可以看到新版树莓派4 SD卡和外置存储器PARTUUID相同,所以不需要修改cmdline.txt文件

pi@raspberrypi:~ $ sudo lsblk -o name,label,partuuid
NAME        LABEL  PARTUUID
sda
├─sda1      boot   ea7d04d6-01
└─sda2      rootfs ea7d04d6-02
mmcblk0
├─mmcblk0p1 boot   ea7d04d6-01
└─mmcblk0p2 rootfs ea7d04d6-02

4、运行如下命令删除sd卡中rootfs分区

pi@raspberrypi:~ $ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): w
The partition table has been altered.
Failed to remove partition 2 from system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.

pi@raspberrypi:~ $ sudo reboot

然后输入‘d’,再选择2,删除第二分区之后,输入‘w’。保存退出之后重启树莓派
5、删除U盘中boot分区(也可以调过
当系统启动之后执行以下命令:

pi@raspberrypi:~ $ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2, default 2): 1

Partition 1 has been deleted.

Command (m for help): w
The partition table has been altered.
Failed to remove partition 1 from system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.

pi@raspberrypi:~ $ sudo reboot

然后输入‘d’,再选择1,删除第一分区之后,输入‘w’。保存退出之后重启树莓派

pi@raspberrypi:~ $ sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="6341-C9E5" TYPE="vfat" PARTUUID="ea7d04d6-01"
/dev/sda2: LABEL="rootfs" UUID="80571af6-21c9-48a0-9df5-cffb60cf79af" TYPE="ext4" PARTUUID="ea7d04d6-02"
/dev/mmcblk0: PTUUID="ea7d04d6" PTTYPE="dos"

此时内存卡中只有个启动分区,外置储存设备中只有rootfs系统分区了。

6、调整文件系统大小

pi@raspberrypi:~ $ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.33.1).
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/sda: 28.7 GiB, 30765219840 bytes, 60088320 sectors
Disk model: Ultra Fit
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xea7d04d6

Device     Boot  Start     End Sectors  Size Id Type
/dev/sda2       532480 7397375 6864896  3.3G 83 Linux

Command (m for help): q

记录下 532480 起始 sector 后面resize时候使用。
接下来调整分区大小,步骤如下:

pi@raspberrypi:~ $ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Selected partition 2
Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 2
First sector (2048-60088319, default 2048): 532480
Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-60088319, default 60088319):

Created a new partition 2 of type 'Linux' and of size 28.4 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): w

The partition table has been altered.
Syncing disks.

pi@raspberrypi:~ $ sudo reboot

重启后连接设备,查看分区大小

pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.2G  2.9G   98M  97% /
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G  8.6M  1.9G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   54M  199M  22% /boot
tmpfs           391M     0  391M   0% /run/user/1000

看到/dev/root分区大小还没有重新调整,接下来使用resize2fs 命令来调整

pi@raspberrypi:~ $ sudo resize2fs /dev/sda2
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/sda2 is now 7444480 (4k) blocks long.

pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        28G  2.9G   24G  11% /
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G  8.6M  1.9G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   54M  199M  22% /boot
tmpfs           391M     0  391M   0% /run/user/1000

经过上面的步骤 可以看到/dev/root分区大小已经调整过来了。
到此树莓派4可以通过usb的rootfs启动,速度大大提升!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。