分区格式化
查看分区信息
fdisk -l
[root@www application]# fdisk -lWARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.Disk /dev/sda: 6001.2 GB, 6001175126016 bytes, 11721045168 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk label type: gptDisk identifier: B408EEC8-6FC3-4F9B-B726-EB390EF3469D# Start End Size Type Name 1 2048 4095 1M BIOS boot 2 4096 2101247 1G Microsoft basic 3 2101248 11721043967 5.5T Linux LVM WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.Disk /dev/sdc: 6001.2 GB, 6001175126016 bytes, 11721045168 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk label type: gptDisk identifier: 44D5CA56-C9DA-437F-916D-F043BD79B458# Start End Size Type NameDisk /dev/sdb: 6001.2 GB, 6001175126016 bytes, 11721045168 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/vg-root: 5986.3 GB, 5986332966912 bytes, 11692056576 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/vg-swap: 12.7 GB, 12683575296 bytes, 24772608 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/vg-tmp: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytes
查看已分区信息
[root@www application]# df -HFilesystem Size Used Avail Use% Mounted ondevtmpfs 13G 0 13G 0% /devtmpfs 13G 0 13G 0% /dev/shmtmpfs 13G 9.4M 13G 1% /runtmpfs 13G 0 13G 0% /sys/fs/cgroup/dev/mapper/vg-root 6.0T 1.6G 5.7T 1% / /dev/sda2 1.1G 125M 880M 13% /boot/dev/mapper/vg-tmp 1.1G 2.7M 951M 1% /tmptmpfs
格式化分区
# 格式化为xfs格局mkfs.xfs /dev/sdb
如果格式化成ext4模式, 执行以下命令
# 格式化为ext4格局mkfs -t ext4 /dev/sdb
挂载分区
挂载分区
mount /dev/sdb /home/sdb
开机主动挂载
如果是ext4格局, 将上面的xfs 改成 ext4
vim /etc/fstab/* 增加如下信息 *//dev/sdb /home/sdb xfs defaults 0 0
增加分区到卷组
分区除了挂载到指定目录外, 还能够增加到卷组, 这样能够将不同分区挂载到同一目录
pv、vg、lv的意思
物理卷(Physical Volume,PV):就是指硬盘分区,也能够是整个硬盘或已创立的软RAID,是LVM的根本存储设备。
卷组(Volume Group,VG):是由一个或多个物理卷所组成的存储池,在卷组上能创立一个或多个逻辑卷。
逻辑卷(Logical Volume,LV):相似于非LVM零碎中的硬盘分区,它建设在卷组之上,是一个规范的块设施,在逻辑卷之上能够建设文件系统。
1. 创立PV(Physical Volume)
pvcreate /dev/sdb
[root@www application]# pvcreate /dev/sdbWARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdb. Physical volume "/dev/sdb" successfully created.
2. 把PV退出VG(Volume Group)中
相当于裁减VG的大小,
应用vgs查看vg组:
[root@www application]# vgs VG #PV #LV #SN Attr VSize VFree vg 1 3 0 wz--n- <5.46t 4.00m
能够看到有一个名称为"vg"的卷组, PV物理卷1个, LV逻辑卷3个, 可用空间5.46T
pvs查看这1个物理卷
[root@www application]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 vg lvm2 a-- <5.46t 4.00m /dev/sdb lvm2 --- <5.46t <5.46t
能够发现曾经退出卷组的/dev/sda3物理卷, 未退出卷组的/dev/sdb物理卷
lvs查看这3个逻辑卷:
[root@www application]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root vg -wi-ao---- 5.44t swap vg -wi-ao---- 11.81g tmp vg -wi-ao---- 1.00g
将/dev/sdb退出VG
vgextend vg(卷组名称) /dev/sdb(PV,物理卷)[root@www application]# vgextend vg /dev/sdb Volume group "vg" successfully extended# 删除PV卷能够用命令# vgreduce vg /dev/sdc
查看vgs、lvs、pvs的变动
[root@www application]# vgs VG #PV #LV #SN Attr VSize VFree vg 2 3 0 wz--n- <10.92t <5.46t /* sdb的容量增加进来的 */[root@www application]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root vg -wi-ao---- 5.44t swap vg -wi-ao---- 11.81g tmp vg -wi-ao---- 1.00g [root@www application]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 vg lvm2 a-- <5.46t 4.00m /dev/sdb vg lvm2 a-- <5.46t <5.46t /* 胜利退出了vg */
除了lvs, vgs、pvs都有sdb退出后的变动
LV(Logicl Volume)扩容
将sdb的容量增加到LV中lvextend -l +100%FREE /dev/mapper/vg-root# 扩大全副空间到lv中去,前面的/dev/mapper/vg-root是指定扩大的文件地位,可在df -hT中看见# 也能够加指定容量# lvextend -L +20G /dev/mapper/centos-root# 缩小容量:# lvreduce -L -3G /dev/mapper/vg-root
再查看lvs, 容量曾经减少了
[root@www application]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root vg -wi-ao---- 10.90t # 减少了sdb的容量 swap vg -wi-ao---- 11.81g tmp vg -wi-ao---- 1.00g
从新读取VG大小
此时查看df -hT[root@www application]# df -hTFilesystem Size Used Avail Use% Mounted ondevtmpfs 13G 0 13G 0% /devtmpfs 13G 0 13G 0% /dev/shmtmpfs 13G 9.4M 13G 1% /runtmpfs 13G 0 13G 0% /sys/fs/cgroup/dev/mapper/vg-root 6.0T 1.6G 5.7T 1% / # 没有减少sdb的容量/dev/sda2 1.1G 125M 880M 13% /boot/dev/mapper/vg-tmp 1.1G 2.7M 951M 1% /tmptmpfs 2.6G 0 2.6G 0% /run/user/0
如果是ext文件系统, 应用 resize2fs /dev/mapper/vg-root 命令
如果是xfs文件系统, 应用 xfs_growfs /dev/mapper/vg-root 命令[root@www application]# resize2fs /dev/mapper/vg-rootresize2fs 1.42.9 (28-Dec-2013)Filesystem at /dev/mapper/vg-root is mounted on /; on-line resizing requiredold_desc_blocks = 697, new_desc_blocks = 1396The filesystem on /dev/mapper/vg-root is now 2926638080 blocks long.
再次用df -hT查看已分区信息
[root@www application]# df -hTFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 12G 0 12G 0% /devtmpfs tmpfs 12G 0 12G 0% /dev/shmtmpfs tmpfs 12G 9.0M 12G 1% /runtmpfs tmpfs 12G 0 12G 0% /sys/fs/cgroup/dev/mapper/vg-root ext4 11T 1.4G 11T 1% / # sdb的容量曾经增加进来了/dev/sda2 ext2 1008M 119M 839M 13% /boot/dev/mapper/vg-tmp ext4 976M 2.6M 907M 1% /tmptmpfs tmpfs 2.4G 0 2.4G 0% /run/user/0
完