openwrt(lede)默认磁盘大小就300多M,打日志监控打开,没多久就满了,因此需要做硬盘扩容,但更确切的说,应该是新磁盘挂载!
proxmox部署openwrt(lede)在网上已经有一大堆的教程,这里就不再说明了,直接进入硬盘扩容操作方法!
1 现象说明
pve自带的硬盘扩大,相信大家都已经会操作了,这里就不多说了;
Disk /dev/sda: 40.34 GiB,我在pve上面扩容了40G,但实际上/overlay,还是只有170MB

root@OpenWrt:~# fdisk -l
Disk /dev/loop0: 172.83 MiB, 181207040 bytes, 353920 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


GPT PMBR size mismatch (689214 != 84582399) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 40.34 GiB, 43306188800 bytes, 84582400 sectors
Disk model: QEMU HARDDISK
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: gpt
Disk identifier: D2255BC7-A8A7-FBE0-565F-0F2EB9A09D00

Device      Start    End Sectors  Size Type
/dev/sda1     512  33279   32768   16M EFI System
/dev/sda2   33792 689151  655360  320M Microsoft basic data
/dev/sda128    34    511     478  239K BIOS boot

Partition table entries are not in disk order.

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               147.3M    147.3M         0 100% /rom
tmpfs                   996.0M      8.7M    987.3M   1% /tmp
/dev/loop0              170.8M     79.7M     91.1M  47% /overlay
overlayfs:/overlay      170.8M     79.7M     91.1M  47% /
/dev/sda1                16.0M      5.4M     10.5M  34% /boot
/dev/sda1                16.0M      5.4M     10.5M  34% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
cgroup                  996.0M         0    996.0M   0% /sys/fs/cgroup
overlayfs:/overlay      170.8M     79.7M     91.1M  47% /opt/docker

2 新建磁盘分区

进入对应硬盘创建分区

root@OpenWrt:~# fdisk /dev/sda

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

GPT PMBR size mismatch (689214 != 84582399) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.

Command (m for help): m #查看各命令所代表的意思

Help:

  GPT
   M   enter protective/hybrid MBR

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table
   
Command (m for help): n #新建分区
Partition number (3-127, default 3): #回车,默认
First sector (33280-84582366, default 690176):#回车,默认
Last sector, +/-sectors or +/-size{K,M,G,T,P} (690176-84582366, default 84582366):#回车,默认

Created a new partition 3 of type 'Linux filesystem' and of size 40 GiB.
Command (m for help): w #保存退出
The partition table has been altered.
Syncing disks.

校验分区是否创建成功

root@OpenWrt:~# fdisk -l
Disk /dev/loop0: 172.83 MiB, 181207040 bytes, 353920 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 /dev/sda: 40.34 GiB, 43306188800 bytes, 84582400 sectors
Disk model: QEMU HARDDISK
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: gpt
Disk identifier: D2255BC7-A8A7-FBE0-565F-0F2EB9A09D00

Device       Start      End  Sectors  Size Type
/dev/sda1      512    33279    32768   16M EFI System
/dev/sda2    33792   689151   655360  320M Microsoft basic data
/dev/sda3   690176 84582366 83892191   40G Linux filesystem  #为新建分区
/dev/sda128     34      511      478  239K BIOS boot

Partition table entries are not in disk order.

格式化新建分区,将新创建的分区格式化为ext4格式

root@OpenWrt:~# mkfs.ext4 /dev/sda3
mke2fs 1.45.6 (20-Mar-2020)
Discarding device blocks: done
Creating filesystem with 10486523 4k blocks and 2624496 inodes
Filesystem UUID: 29bce85b-1de1-4b63-880e-45c318c50086
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624

Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done

3 替换/overlay分区

临时挂载新建分区

root@OpenWrt:~# mount -t ext4 /dev/sda3 /mnt/sda3
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               147.3M    147.3M         0 100% /rom
tmpfs                   996.0M      8.9M    987.1M   1% /tmp
/dev/loop0              170.8M     79.7M     91.1M  47% /overlay
overlayfs:/overlay      170.8M     79.7M     91.1M  47% /
/dev/sda1                16.0M      5.4M     10.5M  34% /boot
/dev/sda1                16.0M      5.4M     10.5M  34% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
cgroup                  996.0M         0    996.0M   0% /sys/fs/cgroup
overlayfs:/overlay      170.8M     79.7M     91.1M  47% /opt/docker
/dev/sda3                39.1G     48.0M     37.1G   0% /mnt/sda3



复制overlay数据进/dev/sda3

root@OpenWrt:~# cp -r /overlay/* /mnt/sda3
root@OpenWrt:~#

设置开机自动挂载/dev/sda3,不会的参考以下截图

vi /etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
#添加以下这句挂载命令
mount /dev/sda3 /overlay 
exit 0

使用TTYD终端进行编辑文件

设置完成后,重启openwrt验证

root@OpenWrt:~# reboot

4 校验是否替换成功

查看磁盘分区已生效

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               147.3M    147.3M         0 100% /rom
tmpfs                   996.0M      7.9M    988.1M   1% /tmp
/dev/loop0               39.1G     54.4M     37.1G   0% /overlay #已变化
overlayfs:/overlay      170.8M     79.7M     91.1M  47% /
/dev/sda1                16.0M      5.4M     10.5M  34% /boot
/dev/sda1                16.0M      5.4M     10.5M  34% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
cgroup                  996.0M         0    996.0M   0% /sys/fs/cgroup
/dev/sda3                39.1G     54.4M     37.1G   0% /mnt/sda3
/dev/sda3                39.1G     54.4M     37.1G   0% /overlay
overlayfs:/overlay      170.8M     79.7M     91.1M  47% /opt/docker

查看openwrt

Last modification:December 29, 2021
If you think my article is useful to you, please feel free to appreciate