通过 Linux 中 fdisk 命令进行分区,并为 openwrt 挂载。
1. 添加磁盘
首先我们需要添加磁盘,我这里使用的 Hyper-V 添加了 64G 虚拟磁盘。这里根据情况来进行操作。
2. fdisk -l
接下来我们使用 fdisk -l
命令来查看添加的磁盘空间。
[root@OpenWrt:03:17 PM ~] # fdisk -l
Disk /dev/loop0: 827.88 MiB, 868089856 bytes, 1695488 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 (2091039 != 134217727) will be corrected by write.
The backup GPT table is corrupt, but the primary appears OK, so that will be used.
The backup GPT table is not on the end of the device.
Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 08417A16-6787-D51A-5685-CA7813760600
Device Start End Sectors Size Type
/dev/sda1 2048 34815 32768 16M Linux filesystem
/dev/sda2 34816 2091007 2056192 1004M Linux filesystem
/dev/sda128 34 2047 2014 1007K BIOS boot
Partition 128 does not start on physical sector boundary.
Partition table entries are not in disk order.
Disk /dev/zram0: 662 MiB, 694157312 bytes, 169472 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
可以看到 /dev/sda ,我这边有 64 GB 可用。
3. fdisk /dev/sda
使用命令 fdisk /dev/sda
对 /dev/sda 进行操作。
[root@OpenWrt:03:17 PM ~] # fdisk /dev/sda
Welcome to fdisk (util-linux 2.39).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (2091039 != 134217727) will be corrected by write.
The backup GPT table is corrupt, but the primary appears OK, so that will be used.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help):
我们输入 n 然后 enter 键,创建分区。
使用默认数值即可(直接回车),我这边创建的就是 /dev/sda3
(对应 3)
Command (m for help): n
Partition number (3-127, default 3):
然后选择 first sector,默认回车即可。
Command (m for help): n
Partition number (3-127, default 3):
First sector (2091008-134217694, default 2091008):
接下来输入 +50GB
以为 /dev/sda3 分区 50 GB,根据自己分区情况来即可。
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2091008-134217694, default 134215679): +50GB
Created a new partition 3 of type 'Linux filesystem' and of size 46.6 GiB.
Command (m for help):
最后我们输入 command W
即 W for writing table to disk and exit
Command (m for help): w
The partition table has been altered.
Syncing disks.
4. 挂载
接下来我们还需要将分区挂载路径。我这里挂载到 /mnt/sda3
。
注意,如果你使用和我一样是 Openwrt, 如果 Openwrt 有 docker,记得先关闭,不然会不生效,
我们这里再输入 fdisk -l,可以看到分的 /dev/sda3 分区。
Device Start End Sectors Size Type
/dev/sda1 2048 34815 32768 16M Linux filesystem
/dev/sda2 34816 2091007 2056192 1004M Linux filesystem
/dev/sda3 2091008 99747839 97656832 46.6G Linux filesystem
/dev/sda128 34 2047 2014 1007K BIOS boot
接下来将 /dev/sda3 格式化为 ext4
mkfs.ext4 /dev/sda3
如果是普通 Linux 流程,接下来我们使用 mount 命令挂载即可。
这里因为使用的是 Openwrt,我们选择更合适的方法,用 OpenWRT 的挂载点功能来挂载。
进入 openwrt 后台,来到 挂载点
,点击 生成配置
。
接下来在挂载点即可看到 /dev/sda3 ,我们点击编辑并启用,挂载路径为 /mnt/sda3。
最后点击保存并应用,即可看到在上方已经成功挂载到 /mnt/sda3
我们在命令行中输入 df -h
,可以看到挂载到路径的 /mnt/sda3。
[root@OpenWrt:04:12 PM ~] # df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 176.3M 176.3M 0 100% /rom
tmpfs 993.8M 3.8M 990.0M 0% /tmp
/dev/loop0 825.9M 70.9M 755.0M 9% /overlay
overlayfs:/overlay 825.9M 70.9M 755.0M 9% /
/dev/sda1 16.0M 7.2M 8.8M 45% /boot
/dev/sda1 16.0M 7.2M 8.8M 45% /boot
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda1 16.0M 7.2M 8.8M 45% /mnt/sda1
cgroup 993.8M 0 993.8M 0% /sys/fs/cgroup
/dev/sda3 45.5G 2.0M 43.2G 0% /mnt/sda3
最后就可以将 openwrt 上 docker 及 adguard home dns,的存储内容放到扩展好的路径下了。