說明:此操做在centos7下進行,若是是centos6發行版,須要注意格式化LV的文件系統類型(centos7.0開始默認文件系統是xfs,centos6是ext4)、最後一步寫入系統的類型node
[root@fsddxtclgj9vm900419 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 44G 3.7G 41G 9% / devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs tmpfs 7.8G 777M 7.0G 10% /run tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/vda1 xfs 1014M 179M 836M 18% /boot tmpfs tmpfs 1.6G 36K 1.6G 1% /run/user/0 tmpfs tmpfs 1.6G 40K 1.6G 1% /run/user/1001
[root@fsddxtclgj9vm900419 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] vdb 252:16 0 974G 0 disk
能夠看到 /dev/vdb 爲新增的磁盤centos
[root@fsddxtclgj9vm900419 ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Error: /dev/vdb: unrecognised disk label Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1046GB Sector size (logical/physical): 512B/512B Partition Table: unknown Disk Flags: (parted) mklabel gpt (parted) mkpart primary 0 1045GB Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? i (parted) print Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1046GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 1045GB 1045GB primary (parted) set 1 lvm on (parted) print Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1046GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 1045GB 1045GB primary lvm (parted) quit Information: You may need to update /etc/fstab
以上 (parted) 開頭的表明輸入的命令,具體功能能夠經過 help 查看app
partprobe /dev/vdb
[root@fsddxtclgj9vm900419 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] vdb 252:16 0 974G 0 disk └─vdb1 252:17 0 973.2G 0 part
能夠看到vdb下多了vdb1,這個用來建立pvdom
[root@fsddxtclgj9vm900419 ~]# pvcreate -v /dev/vdb1 Wiping internal VG cache Wiping cache of LVM-capable devices Wiping signatures on new PV /dev/vdb1. Set up physical volume for "/dev/vdb1" with 2041015592 available sectors. Zeroing start of device /dev/vdb1. Writing physical volume data to disk "/dev/vdb1". Physical volume "/dev/vdb1" successfully created.
PV建立好以後,到這一步能夠選擇擴展或者新建掛載點,擴容的前提條件是擴容掛載點的磁盤格式是LVM格式,這裏先演示新建掛載點而後刪除掛載點並擴容ide
[root@fsddxtclgj9vm900419 ~]# pvdisplay --- Physical volume --- PV Name /dev/vda2 VG Name centos PV Size <49.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 12543 Free PE 0 Allocated PE 12543 PV UUID CCUeq0-ZnG9-iUY8-dPOj-fVOa-XC10-ooGyle "/dev/vdb1" is a new physical volume of "973.23 GiB" --- NEW Physical volume --- PV Name /dev/vdb1 VG Name PV Size 973.23 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID vUoC7C-MIP2-iwXr-0SWu-c2Wz-yb6o-qFrfo1
注意看 VG Name,前面的是系統安裝時選擇LVM格式的,後面的尚未建立,因此 VG Name 爲空測試
[root@fsddxtclgj9vm900419 ~]# vgcreate -s 4M vg01 /dev/vdb1 Volume group "vg01" successfully created
[root@fsddxtclgj9vm900419 ~]# vgdisplay --- Volume group --- VG Name vg01 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 973.23 GiB PE Size 4.00 MiB Total PE 249147 Alloc PE / Size 0 / 0 Free PE / Size 249147 / 973.23 GiB VG UUID hb8zoy-kKjU-VXD5-EjCN-8hS2-MOzf-lq3O5j --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <49.00 GiB PE Size 4.00 MiB Total PE 12543 Alloc PE / Size 12543 / <49.00 GiB Free PE / Size 0 / 0 VG UUID kSwsMj-4FKB-zwFq-7MBq-EfOD-rccg-HC59x9
能夠看到 vg01 爲新建的VGui
[root@fsddxtclgj9vm900419 ~]# lvcreate -l 100%FREE -n lv01 vg01 Logical volume "lv01" created
格式化文件系統類型有xfs,ext4,這裏測試使用ext4格式,默認centos7下使用xfs格式,centos6爲ext4格式centos7
[root@fsddxtclgj9vm900419 ~]# mkfs.ext4 /dev/vg01/lv01 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 63782912 inodes, 255126528 blocks 12756326 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2403336192 7786 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
mkdir /app mount /dev/vg01/lv01 /app # 永久寫入掛載點 # echo '/dev/vg01/lv01 /app xfs defaults 0 0' >> /etc/fstab
[root@fsddxtclgj9vm900419 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] vdb 252:16 0 974G 0 disk └─vdb1 252:17 0 973.2G 0 part └─vg01-lv01 253:2 0 973.2G 0 lvm /app
能夠看到新增磁盤以LVM格式掛載在 /app 下code
[root@fsddxtclgj9vm900419 ~]# umount -v /dev/vg01/lv01 umount: /app (/dev/mapper/vg01-lv01) unmounted
[root@fsddxtclgj9vm900419 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] vdb 252:16 0 974G 0 disk └─vdb1 252:17 0 973.2G 0 part └─vg01-lv01 253:2 0 973.2G 0 lvm
能夠看到 /app 掛載點刪除了,刪除 /app 目錄orm
rm -rf /app
參數爲 LV Path
[root@fsddxtclgj9vm900419 ~]# lvremove /dev/vg01/lv01 Do you really want to remove active logical volume vg01/lv01? [y/n]: y Logical volume "lv01" successfully removed
參數爲 VG Name
[root@fsddxtclgj9vm900419 ~]# vgremove vg01 Volume group "vg01" successfully removed
參數爲 VG Name 和 PV Name
[root@fsddxtclgj9vm900419 ~]# vgextend centos /dev/vdb1 Volume group "centos" successfully extended
此時 PV /dev/vdb1 所有擴展到 VG centos下
[root@fsddxtclgj9vm900419 ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID PCx0yU-o9JZ-R92O-lI01-f8EU-DKyM-etst0H LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-12-24 16:46:31 +0800 LV Status available # open 2 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID Idf9IO-AxkA-tS1C-FTgN-FsLT-d3Zk-7o1W5E LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-12-24 16:46:31 +0800 LV Status available # open 1 LV Size <44.00 GiB Current LE 11263 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
經過查看,系統安裝時選擇的磁盤格式是LVM而且有兩個分區,接下來擴展根分區
參數爲 LV Path
[root@fsddxtclgj9vm900419 ~]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from <44.00 GiB (11263 extents) to <1017.23 GiB (260410 extents). Logical volume centos/root successfully resized
若是發現誤操做,須要還原,能夠經過如下命令縮小LV分區
lvreduce -L 1017.2G /dev/centos/root
此時查看系統能夠看到已經擴容,但沒有加載到文件系統
[root@fsddxtclgj9vm900419 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 49G 0 part ├─centos-root 253:0 0 1017.2G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] vdb 252:16 0 974G 0 disk └─vdb1 252:17 0 973.2G 0 part └─centos-root 253:0 0 1017.2G 0 lvm / [root@fsddxtclgj9vm900419 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 44G 3.7G 41G 9% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 777M 7.0G 10% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/vda1 1014M 179M 836M 18% /boot tmpfs 1.6G 36K 1.6G 1% /run/user/0 tmpfs 1.6G 40K 1.6G 1% /run/user/1001
加載擴容到系統
參數爲 LV path,被擴容的掛載點必定是LVM格式
[root@fsddxtclgj9vm900419 ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2883328 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=11533312, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5631, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 11533312 to 266659840
說明:若使用ext4文件格式(centos6),是使用resize2fs命令來生效
查看磁盤
[root@fsddxtclgj9vm900419 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 1018G 3.7G 1014G 1% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 777M 7.0G 10% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/vda1 1014M 179M 836M 18% /boot tmpfs 1.6G 36K 1.6G 1% /run/user/0 tmpfs 1.6G 40K 1.6G 1% /run/user/1001