我正在从 250GB SSD 迁移到 1TB SSD,但在克隆和调整根分区大小后,卷仍然只显示原始分区大小。以下是我采取的步骤:
首先,克隆驱动器:
sudo dd if=/dev/sdb of=/dev/sdc bs=64M conv=sync,noerror status=progress
接下来,我用来parted
调整分区大小:
$ sudo parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) select /dev/sdc
Using /dev/sdc
(parted) unit B
(parted) resizepart 4 1000204869119
(parted) print
Model: ATA WDC WDBNCE0010P (scsi)
Disk /dev/sdc: 1000204886016B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1048576B 3145727B 2097152B grub bios_grub
2 3145728B 137363455B 134217728B ext2 boot boot, esp
3 137363456B 674234367B 536870912B linux-swap(v1) swap
4 674234368B 1000204869119B 999530634752B ext4 rootfs
(parted) quit
Information: You may need to update /etc/fstab.
启动新驱动器并运行,df -h
结果令人失望,根文件系统 (/dev/sda4) 的卷大小仍然仅显示 228G:
$ sudo df -h
Filesystem Size Used Avail Use% Mounted on
udev 10M 4.0K 10M 1% /dev
/dev/sda4 228G 228G 0 100% /
tmpfs 789M 2.3M 787M 1% /run
cgroup_root 10M 0 10M 0% /sys/fs/cgroup
shm 3.9G 0 3.9G 0% /dev/shm
/dev/sda2 124M 70M 49M 59% /boot
运行lshw
验证驱动器:
*-scsi:0
physical id: 0
logical name: scsi0
capabilities: emulated
*-disk
description: ATA Disk
product: WDC WDBNCE0010P
vendor: Western Digital
physical id: 0.0.0
bus info: scsi@0:0.0.0
logical name: /dev/sda
version: 00WD
serial: 19243F448513
size: 931GiB (1TB)
capabilities: gpt-1.00 partitioned partitioned:gpt
configuration: ansiversion=5 guid=054e688b-70a8-4ffd-8226-1bc6b75b2a28 logicalsectorsize=512 sectorsize=512
*-volume:0
description: BIOS Boot partition
vendor: EFI
physical id: 1
bus info: scsi@0:0.0.0,1
logical name: /dev/sda1
serial: 468b2294-12d4-441f-8c64-d256156a2de3
capacity: 2047KiB
capabilities: nofs
configuration: name=grub
*-volume:1
description: System partition
vendor: Linux
physical id: 2
bus info: scsi@0:0.0.0,2
logical name: /dev/sda2
logical name: /boot
version: 1.0
serial: cd85570b-2031-47e9-87f8-d4c940a40945
size: 128MiB
capabilities: boot extended_attributes large_files ext2 initialized
configuration: filesystem=ext2 modified=2019-07-31 09:37:36 mount.fstype=ext2 mount.options=rw,relatime,errors=continue,user_xattr,acl name=boot state=mounted
*-volume:2
description: Linux swap volume
physical id: 3
bus info: scsi@0:0.0.0,3
logical name: /dev/sda3
version: 1
serial: cb02e96e-b1ae-4b38-b86d-bd79034b5ced
size: 511MiB
capacity: 511MiB
capabilities: swap initialized
configuration: filesystem=swap name=swap pagesize=4095
*-volume:3
description: EXT4 volume
vendor: Linux
physical id: 4
bus info: scsi@0:0.0.0,4
logical name: /dev/sda4
logical name: /
logical name: /var/lib/docker
version: 1.0
serial: ed921b41-8b1a-4199-b6cb-d062e2b0eb13
size: 232GiB
capacity: 930GiB
capabilities: journaled extended_attributes large_files huge_files dir_nlink recover 64bit extents ext4 ext2 initialized
configuration: created=2007-02-01 07:27:38 filesystem=ext4 lastmountpoint=/ modified=2017-08-19 23:06:44 mount.fstype=ext4 mount.options=rw,noatime,data=ordered mounted=2019-07-31 09:37:35 name=rootfs state=mounted
我注意到第 3 卷列出了以下内容:
size: 232GiB
capacity: 930GiB
接下来,我运行e2fsck
,但我不确定我还能做什么(sdc
现在删除了原始驱动器sdb
)。
$ sudo e2fsck -vf /dev/sdb4
e2fsck 1.44.1 (24-Mar-2018)
Pass 1: Checking inodes, blocks, and sizes
Inode 991031 extent tree (at level 1) could be narrower. Fix<y>? yes
Inode 11797848 extent tree (at level 2) could be narrower. Fix<y>? yes
Pass 1E: Optimizing extent trees
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb4: ***** FILE SYSTEM WAS MODIFIED *****
5025939 inodes used (33.00%, out of 15228928)
30101 non-contiguous files (0.6%)
1926 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 4828038/4154/9
60848819 blocks used (99.94%, out of 60884782)
0 bad blocks
4 large files
4354526 regular files
465207 directories
1080 character device files
523 block device files
22 fifos
22888 links
204492 symbolic links (192025 fast symbolic links)
80 sockets
------------
5048818 files
检查lsblk
:
$ sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 931.5G 0 disk
├─sdb1 8:17 0 2M 0 part
├─sdb2 8:18 0 128M 0 part
├─sdb3 8:19 0 512M 0 part
└─sdb4 8:20 0 930.9G 0 part
答案1
您错过了最后一步(也是最令人满意的一步)——扩大文件系统。这可以通过 resize2fs /dev/sdb4 之类的命令在线完成(一些发行版使用 resize4fs 作为同一工具)