Centos7.5磁盘扩容XFS格式
2019-10-28 本文已影响0人
胸口砕大石
虚拟机上增加磁盘容量50G,然后重启系统reboot
VM操作查看磁盘格式
$ df -T
只可以查看已经挂载的分区和文件系统类型。
[root@dockerRepository ~]# df -T
文件系统 类型 1K-块 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1927152 0 1927152 0% /dev
tmpfs tmpfs 1938928 0 1938928 0% /dev/shm
tmpfs tmpfs 1938928 9052 1929876 1% /run
tmpfs tmpfs 1938928 0 1938928 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 52403200 1770988 50632212 4% /
/dev/mapper/centos-home xfs 257000900 33856 256967044 1% /home
/dev/sda1 xfs 1038336 192308 846028 19% /boot
tmpfs tmpfs 387788 0 387788 0% /run/user/0
查看磁盘格式
$ fdisk -l
可以显示出所有挂载和未挂载的分区,但不显示文件系统类型。
磁盘 /dev/sda:322.1 GB, 322122547200 字节,629145600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b6894
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 209715199 103808000 8e Linux LVM
/dev/sda3 209715200 629145599 209715200 8e Linux LVM
磁盘 /dev/mapper/centos-root:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:263.2 GB, 263192576000 字节,514048000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
$ parted -l
可以查看未挂载的文件系统类型,以及哪些分区尚未格式化。
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1049kB 1075MB 1074MB primary xfs 启动
2 1075MB 107GB 106GB primary lvm
3 107GB 322GB 215GB primary lvm
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-home: 263GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 263GB 263GB xfs
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4161MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 4161MB 4161MB linux-swap(v1)
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 53.7GB 53.7GB xfs
警告: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
Model: NECVMWar VMware IDE CDR10 (scsi)
Disk /dev/sr0: 4589MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
2 4907kB 40.6MB 35.7MB primary
$ lsblk -f
可以查看未挂载的文件系统类型。
NAME FSTYPE LABEL UUID MOUNTPOINT
fd0
sda
├─sda1 xfs 24dc261f-1dd1-4b5d-b213-f2321c35a52e /boot
├─sda2 LVM2_member 1tGdhn-71TX-2CqF-IRrw-tj81-WaY3-E2J94O
│ ├─centos-root xfs ce0cef69-01ff-4ea5-8066-d80cd046e24e /
│ ├─centos-swap swap a30b5456-dc32-4e64-ba3b-ea4d603d87bf [SWAP]
│ └─centos-home xfs d4aeedb6-182f-42b2-81fb-3a901356fb9e /home
└─sda3 LVM2_member DzgDhI-1iCe-iukT-GEiA-jjN2-y5sQ-fPhqy4
└─centos-home xfs d4aeedb6-182f-42b2-81fb-3a901356fb9e /home
sr0 iso9660 CentOS 7 x86_64 2018-11-25-23-54-16-00
开始扩容
$ fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):
输入m
命令(输入 m 获取帮助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
命令(输入 m 获取帮助):
输入n,新建
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
输入p,新建
已选择分区 4
起始 扇区 (629145600-734003199,默认为 629145600):
起始扇区与结束扇区 默认回车 获取最大值
起始 扇区 (629145600-734003199,默认为 629145600):
将使用默认值 629145600
Last 扇区, +扇区 or +size{K,M,G} (629145600-734003199,默认为 734003199):
将使用默认值 734003199
分区 4 已设置为 Linux 类型,大小设为 50 GiB
设置分区格式 t - 4 - L
分区号 (1-4,默认 4):4
Hex 代码(输入 L 列出所有代码):L
0 空 24 NEC DOS 81 Minix / 旧 Linu bf Solaris
1 FAT12 27 隐藏的 NTFS Win 82 Linux 交换 / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 隐藏的 C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux 扩展 c7 Syrinx
5 扩展 41 PPC PReP Boot 86 NTFS 卷集 da 非文件系统数据
6 FAT16 42 SFS 87 NTFS 卷集 db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux 纯文本 de Dell 工具
8 AIX 4e QNX4.x 第2部分 8e Linux LVM df BootIt
9 AIX 可启动 4f QNX4.x 第3部分 93 Amoeba e1 DOS 访问
a OS/2 启动管理器 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad 休 eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 扩展 (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC
11 隐藏的 FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq 诊断 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 隐藏的 FAT16 <3 61 SpeedStor ab Darwin 启动 f2 DOS 次要
16 隐藏的 FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 隐藏的 HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST 智能睡眠 65 Novell Netware b8 BSDI swap fd Linux raid 自动
1b 隐藏的 W95 FAT3 70 DiskSecure 多启 bb Boot Wizard 隐 fe LANstep
1c 隐藏的 W95 FAT3 75 PC/IX be Solaris 启动 ff BBT
1e 隐藏的 W95 FAT1 80 旧 Minix
Hex 代码(输入 L 列出所有代码):
设置为 8e lvm格式
已将分区“Linux”的类型更改为“Linux LVM”
输入p 查询
磁盘 /dev/sda:375.8 GB, 375809638400 字节,734003200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b6894
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 209715199 103808000 8e Linux LVM
/dev/sda3 209715200 629145599 209715200 8e Linux LVM
/dev/sda4 629145600 734003199 52428800 8e Linux LVM
磁盘已经扩充过1次 sda3,本次为第二次扩充sda4
退出fdisk ctrl c
输入w写入分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
重启reboot!
创建物理卷
$ pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
查看物理卷
$ pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25343
Free PE 0
Allocated PE 25343
PV UUID 1tGdhn-71TX-2CqF-IRrw-tj81-WaY3-E2J94O
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 200.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 51199
Free PE 0
Allocated PE 51199
PV UUID DzgDhI-1iCe-iukT-GEiA-jjN2-y5sQ-fPhqy4
"/dev/sda4" is a new physical volume of "50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda4
VG Name
PV Size 50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID CVOCOi-4dK2-tlh9-zjSC-m6Rh-BYbq-flqtQe
sda4 50gb为心扩充磁盘
$ vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 298.99 GiB
PE Size 4.00 MiB
Total PE 76542
Alloc PE / Size 76542 / 298.99 GiB
Free PE / Size 0 / 0
VG UUID gPWtPa-dR7U-43HL-KkAq-PTLK-l7GF-pF1Ekf
这时候还看不到扩充的磁盘,free空间为0
将新增的分区加入/dev/sda4加入到根目录分区centos中,名字为上面结果中的VG name
$ vgextend centos /dev/sda4
Volume group "centos" successfully extended
重新查看卷组信息
$ vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 3
Act PV 3
VG Size <348.99 GiB
PE Size 4.00 MiB
Total PE 89341
Alloc PE / Size 76542 / 298.99 GiB
Free PE / Size 12799 / <50.00 GiB
VG UUID gPWtPa-dR7U-43HL-KkAq-PTLK-l7GF-pF1Ekf
free PE 为50GB
进行卷扩容,名字在df -T结果中
文件系统 类型 1K-块 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1927144 0 1927144 0% /dev
tmpfs tmpfs 1938920 0 1938920 0% /dev/shm
tmpfs tmpfs 1938920 9056 1929864 1% /run
tmpfs tmpfs 1938920 0 1938920 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 52403200 1771032 50632168 4% /
/dev/mapper/centos-home xfs 257000900 33856 256967044 1% /home
/dev/sda1 xfs 1038336 192308 846028 19% /boot
tmpfs tmpfs 387788 0 387788 0% /run/user/0
$ lvextend -l +100%FREE /dev/mapper/centos-home
Size of logical volume centos/home changed from <245.12 GiB (62750 extents) to 295.11 GiB (75549 extents).
Logical volume centos/home successfully resized.
调整卷分区大小
$ xfs_growfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512 agcount=22, agsize=2956800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=64256000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5775, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 64256000 to 77362176
df -h查看扩容成功
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 1.7G 49G 4% /
/dev/mapper/centos-home 296G 34M 296G 1% /home
/dev/sda1 1014M 188M 827M 19% /boot
tmpfs 379M 0 379M 0% /run/user/0