非必要不建议缩减分区,避免数据丢失。
[root@kvm ~]# umount /data
[root@kvm ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 16.0GB 16.0GB ext4
(parted) resizepart 1 10G
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?
Yes/No? y
(parted)p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 10.0GB 9999MB ext4
(parted) quit
Information: You may need to update /etc/fstab.
[root@kvm ~]# e2fsck -f /dev/sdc1
e2fsck 1.42.9 (28-Dec-2013)
The filesystem size (according to the superblock) is 3905994 blocks
The physical size of the device is 2441150 blocks
Either the superblock or the partition table is likely to be corrupt!
原文件系统/dev/sdc1大小与新的物理分区/dev/sdc1大小不一致,比物理分区/dev/sdc1大小更大,所以存在报错。
解决办法:将原来分区大小恢复,先e2fsck、resiz2fs缩小文件系统,再使用parted 中resizpart调整分区大小,最后resize2fs 、e2fsck,再执行mount挂载。
1、恢复原来分区大小
[root@kvm ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 10.0GB 9999MB ext4
(parted) rm1
(parted) rescue 1049kB 16G
searching for file systems... 3% (time left 00:33)Information: A ext4 primary partition was found at 1049kB -> 16.0GB. Do you want to add it to the partition table?
Yes/No/Cancel? y
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 16.0GB 16.0GB ext4
(parted) quit
Information: You may need to update /etc/fstab.
2、e2fsck、resiz2fs缩小文件系统
[root@kvm ~]#e2fsck -f /dev/sdc1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdc1: 12/602400 files (0.0% non-contiguous), 75948/2441150 blocks
[root@kvm ~]#resize2fs /dev/sdc1 5G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sdc1 to 1310720 (4k) blocks.
The filesystem on /dev/sdc1 is now 1310720 blocks long.
3、使用parted 中resizpart调整分区大小
[root@kvm ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 10.0GB 9999MB ext4
(parted) resizepart 1 5G
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?
Yes/No? y
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 5000MB 4999MB ext4
(parted) quit
Information: You may need to update /etc/fstab.
4、通过resize2fs 、e2fsck调整检测文件系统
[root@kvm ~]# resize2fs /dev/sdc1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sdc1 to 1220447 (4k) blocks.
The filesystem on /dev/sdc1 is now 1220447 blocks long.
[root@kvm ~]# e2fsck -f /dev/sdc1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdc1: 12/305216 files (0.0% non-contiguous), 56703/1220447 blocks
[root@kvm ~]# mount /dev/sdc1 /data
[root@kvm ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 919724 0 919724 0% /dev
tmpfs 931520 0 931520 0% /dev/shm
tmpfs 931520 9716 921804 2% /run
tmpfs 931520 0 931520 0% /sys/fs/cgroup
/dev/mapper/centos-root 9349120 2135468 7213652 23% /
/dev/sda1 1038336 191268 847068 19% /boot
tmpfs 186304 0 186304 0% /run/user/0
/dev/sdc1 4674044 19068 4394516 1% /data