[分享] 在树莓派4上安装 openwrt

树莓派开发者   2023-6-7 11:34 楼主

openwrt

安装

At the PC:
#unzip the Image

gzip -d openwrt-21.02.0-bcm27xx-bcm2708-rpi-squashfs-factory.img.gz
# insert SD-card and check the name, alternatively check dmesg
lsblk
# copy the Image 1:1 to the SD-card
sudo dd if=openwrt-21.02.0-bcm27xx-bcm2708-rpi-squashfs-factory.img of=/dev/mmcblk0 bs=1M conv=fsync

扩展文件系统

SSH INTO THE RASPBERRY PI:

opkg install kmod-usb-storage kmod-usb-ohci kmod-usb-uhci e2fsprogs fdisk resize2fs
fdisk /dev/mmcblk0

(also see the less finicky way by @SemperEnim below):

To make it clear what I entered, here the complete session of fdisk. Please note how the first sector remains unaltered:
Welcome to fdisk (util-linux 2.36.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/mmcblk0: 14.99 GiB, 16096690176 bytes, 31438848 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
Disklabel type: dos
Disk identifier: 0x5452574f

Device         Boot  Start    End Sectors  Size Id Type
/dev/mmcblk0p1 *      8192 139263  131072   64M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      147456 360447  212992  104M 83 Linux

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

Partition 2 has been deleted.

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

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

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

Command (m for help): p

Disk /dev/mmcblk0: 14.99 GiB, 16096690176 bytes, 31438848 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
Disklabel type: dos
Disk identifier: 0x5452574f

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *      8192   139263   131072   64M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      147456 31438847 31291392 14.9G 83 Linux

Command (m for help): w
The partition table has been altered.
Syncing disks.

REBOOT AND LOG IN AGAIN

The device usage and sizes are now as follows (my SD-card is 16 GB in size). The size needs still needs to be adjusted:

df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.3M      4.3M         0 100% /rom
tmpfs                   217.9M     52.0K    217.9M   0% /tmp
/dev/loop0               92.7M      2.6M     83.1M   3% /overlay
overlayfs:/overlay       92.7M      2.6M     83.1M   3% /
/dev/mmcblk0p1           63.9M     17.3M     46.6M  27% /boot
tmpfs                   512.0K         0    512.0K   0% /dev

Actually this was easier than expected, simply use resize2fs:

opkg update && opkg install resize2fs

resize2fs /dev/loop0

resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/loop0 is mounted on /overlay; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 120
The filesystem on /dev/loop0 is now 15641408 (1k) blocks long.

AND NOW DF -H RETURNS THE ADJUSTED SIZE:

df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.3M      4.3M         0 100% /rom
tmpfs                   217.9M     56.0K    217.9M   0% /tmp
/dev/loop0               14.5G      3.1M     13.9G   0% /overlay
overlayfs:/overlay       14.5G      3.1M     13.9G   0% /
/dev/mmcblk0p1           63.9M     17.3M     46.6M  27% /boot
tmpfs                   512.0K         0    512.0K   0% /dev

在 Raspberry Pi 4上安装 openwrt

WX:上海晶珩电子科技

回复评论 (5)

这个openwrt是干甚么用的,把它装在树莓派上有啥用?
点赞  2023-6-7 15:11
这个好我俩pi,主力pi400用来joplin了
点赞  2023-6-7 18:38
pi3b 可以整个openwrt玩玩~
点赞  2023-6-7 18:39
引用: lkh747566933 发表于 2023-6-7 15:11 这个openwrt是干甚么用的,把它装在树莓派上有啥用?

OpenWrt是一个开源的系统,会不断出现新颖的插件,家用路由器一般只有上网等基本功能,而刷openwrt系统后,我们可以获得几千元价值的企业路由器功能,比如上网行为管理功能。可以参考这个:https://zhuanlan.zhihu.com/p/582871506

WX:上海晶珩电子科技
点赞  2023-6-8 09:43
引用: 吾妻思萌 发表于 2023-6-7 18:38 这个好我俩pi,主力pi400用来joplin了

可以的,你们都好会玩

WX:上海晶珩电子科技
点赞  2023-6-8 09:47
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复