前言 我的飞牛OS的某一块硬盘仅512G大小,并将全部容量设置为Basic存储模式,而最近我找了一块1T的新硬盘,希望能替代旧硬盘并扩容硬盘。以下是我的踩坑记录。
下文中设备的路径等请改成自己实际的路径,千万不要照抄!
复制数据 先关闭飞牛OS并取出硬盘,并在Windows系统下使用DiskGenius软件中的“克隆磁盘”功能将旧硬盘的所有数据拷贝到新硬盘中。我使用的是“复制所有扇区”。完成后,我将新硬盘放入飞牛OS所在的机器中,然后打开飞牛OS。
扩容分区 此时打开飞牛OS的设置界面,我们可以看到新硬盘已经成功代替了旧硬盘。不过此时只有新硬盘的前500G在使用,而剩余的500G则处于空闲状态。我们需要把剩余的500G也扩充到前面的存储分区去。
我在测试时,没有卸载掉这个硬盘,最终也成功了,但是个人不建议这么做。
首先,我们通过SSH连接我们的飞牛OS。然后使用sudo fdisk -l看一下此时的分区情况。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 denvo@denvosCenterm:~$ sudo fdisk -l [sudo ] password for denvo: Disk /dev/sda: 29.82 GiB, 32017047552 bytes, 62533296 sectors Disk model: SSD 32GB 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: 0x1372dc16 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 194559 192512 94M 83 Linux /dev/sda2 194560 52428799 52234240 24.9G 83 Linux /dev/sda3 52428800 62531583 10102784 4.8G 83 Linux Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Tech 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: F6C0FF81-599B-430E-A54F-8038DBB7030D Device Start End Sectors Size Type /dev/sdb1 2048 976773119 976771072 465.8G Linux RAID Disk /dev/md0: 465.63 GiB, 499971522560 bytes, 976506880 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0: 465.63 GiB, 499969425408 bytes, 976502784 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes denvo@denvosCenterm:~$
根据输出,我这里的实际内容应该是存储在/dev/sdb1里的,但是我们发现后面竟然有Linux RAID的标识。说实话我没有想到,毕竟我之前创建的存储分区使用的是Basic模式,并没有使用任何Raid。然后,输出中竟然还有一个/dev/md0的设备,为什么呢?我们输入sudo mdadm -D /dev/md0,得到如下结果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 denvo@denvosCenterm:~$ sudo mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Sun Mar 9 22:27:25 2025 Raid Level : raid1 Array Size : 488253440 (465.63 GiB 499.97 GB) Used Dev Size : 488253440 (465.63 GiB 499.97 GB) Raid Devices : 1 Total Devices : 1 Persistence : Superblock is persistent Intent Bitmap : Internal Update Time : Sun Jun 22 17:46:13 2025 State : clean Active Devices : 1 Working Devices : 1 Failed Devices : 0 Spare Devices : 0 Consistency Policy : bitmap Name : denvosCenterm:0 (local to host denvosCenterm) UUID : 6de584a8:dee738cb:aa33a826:be3fdf5d Events : 32 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 denvo@denvosCenterm:~$
竟然使用的是Raid1?好吧,看来大概的情况是飞牛OS把这个单块硬盘整了个Raid1,然后把这个Raid映射到了/dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0中并使用Brtfs文件系统。好了,既然如此,那就有大概的思路了。首先我们需要确保刚才sudo mdadm -D /dev/md0得到的结果中State一项对应的值为clean,然后我们继续操作。
我们首先来对新硬盘中的分区进行扩容。我这个硬盘是GPT格式的,所以这么扩容:
我们使用sudo parted /dev/sdb命令进入目标硬盘的设置,然后输入print all找到我们需要扩容的分区的序号。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 denvo@denvosCenterm:~$ sudo parted /dev/sdb GNU Parted 3.5 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print all Model: JMicron Tech (scsi) Disk /dev/sdb: 1000GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 500GB 500GB primary raid Model: ATA SSD 32GB (scsi) Disk /dev/sda: 32.0GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 99.6MB 98.6MB primary ext4 2 99.6MB 26.8GB 26.7GB primary ext4 3 26.8GB 32.0GB 5173MB primary Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0: 500GB Sector size (logical/physical): 512B/4096B Partition Table: loop Disk Flags: Number Start End Size File system Flags 1 0.00B 500GB 500GB btrfs Error: /dev/md0: unrecognised disk label Model: Linux Software RAID Array (md) Disk /dev/md0: 500GB Sector size (logical/physical): 512B/4096B Partition Table: unknown Disk Flags: (parted)
我这里对应的序号是1,所以我现在输入resizepart 1 100%,将硬盘内序号为1的分区大小调整至100%。然后输入quit退出。
1 2 3 4 5 (parted) resizepart 1 100% (parted) quit Information: You may need to update /etc/fstab. denvo@denvosCenterm:~$
对于MBR格式的硬盘,请使用sudo fdisk /dev/sdX来扩展分区。最后达到的效果需一样。
此时的分区状态像这样1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 denvo@denvosCenterm:~$ sudo fdisk -l Disk /dev/sda: 29.82 GiB, 32017047552 bytes, 62533296 sectors Disk model: SSD 32GB 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: 0x1372dc16 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 194559 192512 94M 83 Linux /dev/sda2 194560 52428799 52234240 24.9G 83 Linux /dev/sda3 52428800 62531583 10102784 4.8G 83 Linux Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Tech 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: F6C0FF81-599B-430E-A54F-8038DBB7030D Device Start End Sectors Size Type /dev/sdb1 2048 1953525134 1953523087 931.5G Linux RAID Disk /dev/md0: 465.63 GiB, 499971522560 bytes, 976506880 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0: 465.63 GiB, 499969425408 bytes, 976502784 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes denvo@denvosCenterm:~$
接下来我们需要扩展Raid上的记录,使用sudo mdadm --grow /dev/md0 --size=max。
1 2 3 denvo@denvosCenterm:~$ sudo mdadm --grow /dev/md0 --size=max mdadm: component size of /dev/md0 has been set to 976629447K denvo@denvosCenterm:~$
此时的分区状态像这样1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 denvo@denvosCenterm:~$ sudo fdisk -l Disk /dev/sda: 29.82 GiB, 32017047552 bytes, 62533296 sectors Disk model: SSD 32GB 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: 0x1372dc16 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 194559 192512 94M 83 Linux /dev/sda2 194560 52428799 52234240 24.9G 83 Linux /dev/sda3 52428800 62531583 10102784 4.8G 83 Linux Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Tech 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: F6C0FF81-599B-430E-A54F-8038DBB7030D Device Start End Sectors Size Type /dev/sdb1 2048 1953525134 1953523087 931.5G Linux RAID Disk /dev/md0: 931.39 GiB, 1000068554240 bytes, 1953258895 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0: 465.63 GiB, 499969425408 bytes, 976502784 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes denvo@denvosCenterm:~$
接下来更新物理卷和逻辑卷,然后扩展Brtfs文件系统。根据如下进行设置。
1 2 3 4 5 6 7 8 9 denvo@denvosCenterm:~$ sudo pvresize /dev/md0 Physical volume "/dev/md0" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized denvo@denvosCenterm:~$ sudo lvextend -l +100%FREE /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0 Size of logical volume trim_d014f486_5dff_41db_a333_eae448374f08/0 changed from 465.63 GiB (119202 extents) to 931.38 GiB (238434 extents). Logical volume trim_d014f486_5dff_41db_a333_eae448374f08/0 successfully resized. denvo@denvosCenterm:~$ sudo btrfs filesystem resize max /vol1 Resize device id 1 (/dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0) from 465.63GiB to max denvo@denvosCenterm:~$
第二条命令中,/dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0是Raid最终映射到的位置;第三条命令中,/vol1是实际挂载点。
扩充结果 完成后,现在我们来看看分区情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 denvo@denvosCenterm:~$ sudo fdisk -l Disk /dev/sda: 29.82 GiB, 32017047552 bytes, 62533296 sectors Disk model: SSD 32GB 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: 0x1372dc16 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 194559 192512 94M 83 Linux /dev/sda2 194560 52428799 52234240 24.9G 83 Linux /dev/sda3 52428800 62531583 10102784 4.8G 83 Linux Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Tech 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: F6C0FF81-599B-430E-A54F-8038DBB7030D Device Start End Sectors Size Type /dev/sdb1 2048 1953525134 1953523087 931.5G Linux RAID Disk /dev/md0: 931.39 GiB, 1000068554240 bytes, 1953258895 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0: 931.38 GiB, 1000064679936 bytes, 1953251328 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes denvo@denvosCenterm:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 383M 39M 344M 11% /run /dev/sda2 25G 11G 13G 44% / tmpfs 1.9G 1.4M 1.9G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock trimafs 932G 65G 866G 7% /fs /dev/mapper/trim_d014f486_5dff_41db_a333_eae448374f08-0 932G 65G 866G 7% /vol1 1000-1-8543a4d8{SYtpW}:cloud-storage/v1/dav 1.0P 0 1.0P 0% /vol02/1000-1-8543a4d8 1000-1-dba14728{2_a9I}:cloud-storage/v1/dav 1.0P 0 1.0P 0% /vol02/1000-1-dba14728 overlay 932G 65G 866G 7% /vol1/docker/overlay2/c931c52cd06181098eff1309a7e772abe2e4cd2979dc40613d8e96145f5b495f/merged tmpfs 383M 0 383M 0% /run/user/1000 denvo@denvosCenterm:~$
看样子已经成功了。此时我们重新打开飞牛OS的设置界面,刷新后发现我们的存储空间已经成功扩展。