1. 登录
ssh root@192.168.5.18
2. 返回到根目录
cd ..
3. 查看硬盘添加前的情况
df -h
输出
Filesystem Size Used Available Use% Mounted on
/dev/root 98.3M 66.6M 29.7M 69% /
tmpfs 352.5M 272.0K 352.2M 0% /tmp
/dev/sda1 16.0M 6.2M 9.7M 39% /boot
/dev/sda1 16.0M 6.2M 9.7M 39% /boot
tmpfs 512.0K 0 512.0K 0% /dev
fdisk -l
输出
Disk /dev/sda: 120.28 MiB, 126123520 bytes, 246335 sectors
Disk model: VMware Virtual S
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: 11458228-0839-40E2-FE5C-7D7FC0445100
Device Start End Sectors Size Type
/dev/sda1 512 33279 32768 16M Linux filesystem
/dev/sda2 33280 246271 212992 104M Linux filesystem
/dev/sda128 34 511 478 239K BIOS boot
4. 虚拟机设置里面添加一个8GB的硬盘
是添加另一个硬盘,不是扩容原来的
fdisk -l
输出
Disk /dev/sda: 120.28 MiB, 126123520 bytes, 246335 sectors
Disk model: VMware Virtual S
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: 11458228-0839-40E2-FE5C-7D7FC0445100
Device Start End Sectors Size Type
/dev/sda1 512 33279 32768 16M Linux filesystem
/dev/sda2 33280 246271 212992 104M Linux filesystem
/dev/sda128 34 511 478 239K BIOS boot
Partition table entries are not in disk order.
Disk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
ls /dev/sd*
输出
/dev/sda /dev/sda1 /dev/sda128 /dev/sda2 /dev/sdb
5. 在这个设备分区
fdisk /dev/sdb
输出
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0xc2f9fad7.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-16777215, default 16777215):
Created a new partition 1 of type ‘Linux’ and of size 8 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
6. 格式化/dev/sdb1为ext4格式
mkfs.ext4 /dev/sdb1
输出
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 2096896 4k blocks and 524288 inodes
Filesystem UUID: d57470c8-8542-48be-9e50-24565944bb38
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
7. 创建/mnt/data目录
mkdir /mnt/data
8. 将/dev/sdb1挂载到/mnt/data目录
mount /dev/sdb1 /mnt/data
9. 用vi修改fstab内容
vi /etc/config/fstab
增加以下内容
config ‘mount’
option target ‘/mnt/data’
option device ‘/dev/sdb1’
option fstype ‘ext4’
option options ‘rw,sync’
option enabled ‘1’
config ‘mount’
option target ‘/overlay’
option device ‘/dev/sdb1’
option fstype ‘ext4’
option options ‘rw,sync’
option enabled ‘1’
10. 重启服务
/etc/init.d/fstab restart
11. 卸载现有的 overlay(如果已经挂载)
umount /overlay
12. 安装rsync
opkg update
opkg install rsync
13. 将现有的 /overlay 目录内容移动到新硬盘上
rsync -aAXv /overlay/ /mnt/data/
14. 手动挂载 overlay
mount /dev/sdb1 /overlay
15. 检查 overlay 是否成功挂载到新硬盘
df -h
输出
Filesystem Size Used Available Use% Mounted on
/dev/root 98.3M 68.4M 27.8M 71% /
tmpfs 352.5M 236.0K 352.2M 0% /tmp
/dev/sda1 16.0M 6.2M 9.7M 39% /boot
/dev/sda1 16.0M 6.2M 9.7M 39% /boot
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sdb1 7.8G 2.0M 7.4G 0% /mnt/data
/dev/sdb1 7.8G 2.0M 7.4G 0% /overlay
16. 重启
reboot
其他
如果是硬路由升级到openwrt
root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 4.8M 4.8M 0 100% /rom
tmpfs 242.9M 1.2M 241.7M 1% /tmp
/dev/ubi0_2 44.6M 1.1M 41.1M 3% /overlay
overlayfs:/overlay 44.6M 1.1M 41.1M 3% /
tmpfs 512.0K 0 512.0K 0% /dev
看到的是根目录 / 下挂载了/overlay
安装工具
opkg update #每次更新和安装软件都需要执行
opkg install kmod-usb-core #usb驱动
opkg install kmod-scsi-core #SCSI总线驱动
opkg install kmod-scsi-generic
opkg install kmod-usb-uhci #USB OHCI controllers
opkg install kmod-usb-ohci #USB UHCI controllers
opkg install kmod-usb2 #usb2.0驱动
opkg install kmod-usb3 #usb3.0驱动
opkg install kmod-usb-storage #usb存储设备驱动
opkg install kmod-usb-storage-extras #其他USB读卡器设备驱动
opkg install kmod-fs-ext2 #安装ext2分区支持
opkg install kmod-fs-ext3 #安装ext3分区格式支持组件
opkg install kmod-fs-ext4 #安装ext4分区格式支持组件
opkg install kmod-fs-ntfs #ntfs内核驱动
opkg install kmod-fs-vfat #挂载FAT
opkg install block-mount #在web页面里显示mount points
opkg install e2fsprogs #ext4格式化工具
执行完这些以后,就可以用 fdisk -l 看到插入的U盘
一样的给硬盘格式化、做分区
Web进到 system –> mount points
Mount points 下点击 add
UUID 1ad87fa0-7a87-4d32-a7f3-9e4c4472fec4 (/dev/sda1, 58.59 GiB)
Mount point Use as external overlay (/overlay)
保存以后别忘记点整个页面的Save & Apply
Reboot
ssh登录时提示错误
PS C:\Users\xyah> ssh root@192.168.1.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:hGAb7k4v4OML2EdNP2Uu80GoYr8L1/zrTRbEDDhQJm4.
Please contact your system administrator.
Add correct host key in C:\\Users\\xyah/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in C:\\Users\\xyah/.ssh/known_hosts:3
Host key for 192.168.1.1 has changed and you have requested strict checking.
Host key verification failed.
执行ssh-keygen -R 192.168.1.1后再次登录
执行df -h,可以看到新的挂载情况
root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 4.8M 4.8M 0 100% /rom
tmpfs 242.9M 256.0K 242.7M 0% /tmp
/dev/sda1 57.4G 2.4M 54.4G 0% /overlay
overlayfs:/overlay 57.4G 2.4M 54.4G 0% /
tmpfs 512.0K 0 512.0K 0% /dev
迎得一钩月到,送得三更月去,莺燕不相猜。