linux 磁盘扩容实验
linux 磁盘扩容实验
实验前环境准备和思路
环境:
以下虚拟机做测试为例子(测试环境:虚拟机Oracle VM VirtualBox 6.1 ,虚拟机系统centos7.6 (最小化安装) ), 查看我的虚拟机磁盘配置。
思路:
1.lvm下增加磁盘,扩容当前分区,或增加新的分区用于扩容。
2.非lvm下编辑磁盘大小,扩容分区。
我的实验环境磁盘配置如下操作:
[root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 47G 1008M 46G 3% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 47G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sr0 11:0 1 1024M 0 rom [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <49.00g 4.00m [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <49.00g 4.00m [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 46.99g swap centos -wi-ao---- 2.00g [root@localhost ~]#
我有一块磁盘sda为50G ,创建了一个物理卷,全部属于卷组VG centos 大小为49G,逻辑卷root,划分了47G,挂载到根分区。逻辑卷swap 为2G。
这里添加两块磁盘用于编辑和测试,虚拟机界面增加磁盘如下:
操作演示1
增加sdb20G磁盘,扩展根分区, 登陆系统,可看到新增两块未分区的磁盘,分别为sdb,sdc
Last login: Thu Jul 7 02:59:07 2022 from gateway [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 47G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk sdc 8:32 0 20G 0 disk sr0 11:0 1 1024M 0 rom [root@localhost ~]#
将磁盘sdb,扩展到根分区,
脚本解释:
pvcreate /dev/sdb 将磁盘加入物理卷
vgextend centos /dev/sdb 将磁盘加入卷组centos
lvextend -L +1g /dev/mapper/centos-root 扩展root卷,容量为1G 可看帮助命令 L后跟容量单位为G,M,
lvextend -l +100%free /dev/mapper/centos-root 扩展剩余全部空闲容量,l后跟百分比
xfs_growfs /dev/mapper/centos-root 扩展分区
操作步骤如下 :
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 47G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk sdc 8:32 0 20G 0 disk sr0 11:0 1 1024M 0 rom [root@localhost ~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created. [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <49.00g 4.00m [root@localhost ~]# vgextend centos /dev/sdb Volume group "centos" successfully extended [root@localhost ~]# lvextend -L +1g /dev/mapper/centos-root Size of logical volume centos/root changed from 46.99 GiB (12030 extents) to 47.99 GiB (12286 extents). Logical volume centos/root successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3079680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=12318720, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6015, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 12318720 to 12580864 [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 48G 1007M 47G 3% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 48G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk └─centos-root 253:0 0 48G 0 lvm / sdc 8:32 0 20G 0 disk sr0 11:0 1 1024M 0 rom [root@localhost ~]# lvextend -l +100%free /dev/mapper/centos-root Size of logical volume centos/root changed from 47.99 GiB (12286 extents) to 66.99 GiB (17150 extents). Logical volume centos/root successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=5, agsize=3079680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=12580864, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6015, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 12580864 to 17561600 [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 67G 1007M 66G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 [root@localhost ~]#
扩容完毕。
操作演示2
编辑sdb为40G,剩余容量扩展到根分区
(编辑磁盘大小后,执行pvresize 可看到vg中有空闲容量,执行lvextend扩展全部容量即可) 操作步骤如下
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 67G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 40G 0 disk └─centos-root 253:0 0 67G 0 lvm / sdc 8:32 0 40G 0 disk └─data-lv0--data 253:2 0 20G 0 lvm sr0 11:0 1 1024M 0 rom [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <49.00g 0 /dev/sdb centos lvm2 a-- <20.00g 0 /dev/sdc data lvm2 a-- <20.00g 0 [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 68.99g 0 data 1 1 0 wz--n- <20.00g 0 [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 66.99g swap centos -wi-ao---- 2.00g lv0-data data -wi-a----- <20.00g [root@localhost ~]# pvresize /dev/sdb Physical volume "/dev/sdb" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <49.00g 0 /dev/sdb centos lvm2 a-- <40.00g 20.00g /dev/sdc data lvm2 a-- <20.00g 0 [root@localhost ~]# [root@localhost ~]# lvextend -l +100%free /dev/mapper/centos-root Size of logical volume centos/root changed from 66.99 GiB (17150 extents) to 86.99 GiB (22270 extents). Logical volume centos/root successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=6, agsize=3079680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=17561600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6015, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 17561600 to 22804480 [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 [root@localhost ~]#
操作演示3
增加sdc20G磁盘,,扩展到/data分区,划分lvm操作脚本如下
[root@localhost ~]# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created. [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 68.99g 0 [root@localhost ~]# vgcreate data /dev/sdc Volume group "data" successfully created [root@localhost ~]# lvcreate -l 100%free -n lv0-data data Logical volume "lv0-data" created. [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 66.99g swap centos -wi-ao---- 2.00g lv0-data data -wi-a----- <20.00g [root@localhost ~]# mkfs.xfs /dev/mapper/data-lv0--data meta-data=/dev/mapper/data-lv0--data isize=512 agcount=4, agsize=1310464 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=5241856, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mount /dev/mapper/data-lv0--data /data [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 67G 1007M 66G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/mapper/data-lv0--data xfs 20G 33M 20G 1% /data [root@localhost ~]#
不划分lvm操作如下,(直接fdisk 进行分区,mkfs创建文件系统,创建目录进行挂载即可)
[root@localhost ~]# fdisk -l /dev/sdc Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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 [root@localhost ~]# fdisk /dev/sdc Welcome to fdisk (util-linux 2.23.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 Building a new DOS disklabel with disk identifier 0x2102e59f. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Partition 1 of type Linux and of size 20 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# mkfs. mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs [root@localhost ~]# mkfs.xfs /dev/sdc sdc sdc1 [root@localhost ~]# mkfs.xfs /dev/sdc1 meta-data=/dev/sdc1 isize=512 agcount=4, agsize=1310656 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=5242624, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mkdir /data [root@localhost ~]# mount /dev/sdc1 /data [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 67G 1007M 66G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/sdc1 xfs 20G 33M 20G 1% /data [root@localhost ~]#
操作演示4
编辑sdc为40G,剩余容量扩展到/data分区,(先对pv进行resize ,后看到vg中有空闲容量,执行lvextend进行扩容)
脚本演示如下
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 87G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 40G 0 disk └─centos-root 253:0 0 87G 0 lvm / sdc 8:32 0 40G 0 disk └─data-lv0--data 253:2 0 20G 0 lvm sr0 11:0 1 1024M 0 rom [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <49.00g 0 /dev/sdb centos lvm2 a-- <40.00g 0 /dev/sdc data lvm2 a-- <20.00g 0 [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 88.99g 0 data 1 1 0 wz--n- <20.00g 0 [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 86.99g swap centos -wi-ao---- 2.00g lv0-data data -wi-a----- <20.00g [root@localhost ~]# pvresize /dev/sdc Physical volume "/dev/sdc" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <49.00g 0 /dev/sdb centos lvm2 a-- <40.00g 0 /dev/sdc data lvm2 a-- <40.00g 20.00g [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 88.99g 0 data 1 1 0 wz--n- <40.00g 20.00g [root@localhost ~]# lvextend -l +100%free /dev/mapper/data-lv0--data Size of logical volume data/lv0-data changed from <20.00 GiB (5119 extents) to <40.00 GiB (10239 extents). Logical volume data/lv0-data successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/data-lv0--data xfs_growfs: /dev/mapper/data-lv0--data is not a mounted XFS filesystem [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 [root@localhost ~]# mount /dev/mapper/data-lv0--data /data [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/mapper/data-lv0--data xfs 20G 33M 20G 1% /data [root@localhost ~]# xfs_growfs /dev/mapper/data-lv0--data meta-data=/dev/mapper/data-lv0--data isize=512 agcount=4, agsize=1310464 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=5241856, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 5241856 to 10484736 [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/mapper/data-lv0--data xfs 40G 33M 40G 1% /data [root@localhost ~]#
扩容完毕。
操作演示5
增加一块20G磁盘,不使用lvm,直接分区挂载到/backup ,编辑磁盘大小为50G,进行扩容/backup 分区,(我这里基于上次磁盘新增,新增磁盘后盘符发生了改变,之前的sdc变成了sdd,新增的磁盘为sdc,直接将磁盘分区,创建文件系统,创建目录进行挂载即可)。
操作如下:
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 87G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 40G 0 disk └─centos-root 253:0 0 87G 0 lvm / sdc 8:32 0 20G 0 disk sdd 8:48 0 40G 0 disk └─data-lv0--data 253:2 0 40G 0 lvm [root@localhost ~]# fdisk /dev/sdc Welcome to fdisk (util-linux 2.23.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 Building a new DOS disklabel with disk identifier 0x0fec34e6. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Partition 1 of type Linux and of size 20 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# mkfs.xfs /dev/sdc1 meta-data=/dev/sdc1 isize=512 agcount=4, agsize=1310656 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=5242624, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mkdir /backup [root@localhost ~]# mount /dev/sdc1 /backup/ [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/sdc1 xfs 20G 33M 20G 1% /backup [root@localhost ~]#
新增磁盘已经被挂载到/backup , 调整磁盘大小为50G,对分区进行扩容,(操作步骤,创建测试文件在backup目录下,使用fdisk 对磁盘进行删除原有分区,切记此时不要保存写入,在进行创建分区,此时的分区容量为50G,创建完毕写入即可,后执行partprobe , xfs_growfs 即可)(虚拟机平台测试原有创建的数据都无问题)。
操作脚本如下
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 87G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 40G 0 disk └─centos-root 253:0 0 87G 0 lvm / sdc 8:32 0 50G 0 disk └─sdc1 8:33 0 20G 0 part /backup sdd 8:48 0 40G 0 disk └─data-lv0--data 253:2 0 40G 0 lvm [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/sdc1 xfs 20G 33M 20G 1% /backup [root@localhost ~]# [root@localhost ~]# touch /backup/000 [root@localhost ~]# touch /backup/111 [root@localhost ~]# touch /backup/222 [root@localhost ~]# echo "file is test" >> /backup/000 [root@localhost ~]# echo "file is test" >> /backup/111 [root@localhost ~]# echo "file is test" >> /backup/222 [root@localhost ~]# ls /backup/ 000 111 222 [root@localhost ~]# ls /backup/ -l total 12 -rw-r--r--. 1 root root 13 Jul 27 22:37 000 -rw-r--r--. 1 root root 13 Jul 27 22:37 111 -rw-r--r--. 1 root root 13 Jul 27 22:37 222 [root@localhost ~]# cat /backup/000 file is test [root@localhost ~]# [root@localhost ~]# fdisk /dev/sdc Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 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 Disk label type: dos Disk identifier: 0x0fec34e6 Device Boot Start End Blocks Id System /dev/sdc1 2048 41945087 20971520 83 Linux Command (m for help): d Selected partition 1 Partition 1 is deleted Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-104857599, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): Using default value 104857599 Partition 1 of type Linux and of size 50 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@localhost ~]# partprobe [root@localhost ~]# xfs_growfs /dev/sdc1 meta-data=/dev/sdc1 isize=512 agcount=4, agsize=1310720 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=5242880, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 5242880 to 13106944 [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 87G 1007M 86G 2% / devtmpfs devtmpfs 484M 0 484M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.8M 489M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 133M 882M 14% /boot tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/sdc1 xfs 50G 33M 50G 1% /backup [root@localhost ~]# ls /backup/ 000 111 222 [root@localhost ~]# cat /backup/000 file is test [root@localhost ~]# cat /backup/111 file is test [root@localhost ~]# cat /backup/222 file is test [root@localhost ~]#
此时非 lvm方式扩容完毕。