服務器環境:
[root@ws-cdp04 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 63G 0 63G 0% /dev tmpfs tmpfs 63G 0 63G 0% /dev/shm tmpfs tmpfs 63G 20M 63G 1% /run tmpfs tmpfs 63G 0 63G 0% /sys/fs/cgroup /dev/mapper/Centos7--vGroup001-root xfs 44G 2.5G 42G 6% / /dev/sda1 xfs 1014M 232M 783M 23% /boot tmpfs tmpfs 13G 0 13G 0% /run/user/0 [root@ws-cdp04 ~]# fdisk -l Disk /dev/sdb: 3221.2 GB, 3221225472000 bytes, 6291456000 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 /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009b07b Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 104857599 51379200 8e Linux LVM Disk /dev/sdc: 3221.2 GB, 3221225472000 bytes, 6291456000 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 /dev/mapper/Centos7--vGroup001-root: 47.2 GB, 47240445952 bytes, 92266496 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 /dev/mapper/Centos7--vGroup001-swap: 5368 MB, 5368709120 bytes, 10485760 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@ws-cdp04 ~]# vgs VG #PV #LV #SN Attr VSize VFree Centos7-vGroup001 1 2 0 wz--n- <49.00g 0 [root@ws-cdp04 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 Centos7-vGroup001 lvm2 a-- <49.00g 0 [root@ws-cdp04 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root Centos7-vGroup001 -wi-ao---- <44.00g swap Centos7-vGroup001 -wi-ao---- 5.00g
場景一:
sdb sdc 兩塊磁盤通過 lvm 擴容掛載到 /data 同一個目錄的方法
# 對sdb 的處理
pvcreate /dev/sdb vgcreate centos7_vGroup002 /dev/sdb lvcreate -l 100%VG -n lv_data centos7_vGroup002 mkfs.xfs -f /dev/centos7_vGroup002/lv_data mkdir /data mount /dev/mapper/centos7_vGroup002-lv_data /data
# sdc 的處理
pvcreate /dev/sdc vgextend centos7_vGroup002 /dev/sdc lvextend -l +100%FREE /dev/mapper/centos7_vGroup002-lv_data xfs_growfs /dev/mapper/centos7_vGroup002-lv_data
# 開機自動掛載
echo "/dev/mapper/centos7_vGroup002-lv_data /data xfs defaults 0 0" >> /etc/fstab
場景二:
添加單塊磁盤掛載到 /data 目錄的方法
pvcreate /dev/sdb vgcreate centos7_vGroup002 /dev/sdb lvcreate -l 100%VG -n lv_data centos7_vGroup002 mkfs.xfs -f /dev/centos7_vGroup002/lv_data mount /dev/mapper/centos7_vGroup002-lv_data /data # 開機自動掛載 # vim /etc/fstab /dev/mapper/centos7_vGroup002-lv_data /data xfs defaults 0 0
場景三:
# 擴容系統盤
在vcenter界面中直接把50G修改為100G,然后重啟操作系統
fdisk -l 可以看到 sda 變成了 100G
# 通過fdisk 操作刪除已經存在的 sda2 分區
fdisk /dev/sda 刪除 sda2 然后重新創建 sda2並且把剩余空間全部分配給 sda2
[root@ws-cdp04 ~]# fdisk /dev/sda 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/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009b07b Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 104857599 51379200 8e Linux LVM Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 is deleted Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009b07b Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (2099200-209715199, default 2099200): Using default value 2099200 Last sector, +sectors or +size{K,M,G} (2099200-209715199, default 209715199): Using default value 209715199 Partition 2 of type Linux and of size 99 GiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' 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@ws-cdp03 ~]# partprobe [root@ws-cdp03 ~]# partprobe /dev/sda2 [root@ws-cdp04 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 Centos7-vGroup001 lvm2 a-- <49.00g 0
# 擴容pv
[root@ws-cdp03 ~]# pvresize -v /dev/sda2 [root@ws-cdp04 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 Centos7-vGroup001 lvm2 a-- <99.00g 50.00g # 擴容lv lvextend -l +100%FREE /dev/mapper/Centos7--vGroup001-root # 擴容 xfs_growfs /dev/mapper/Centos7--vGroup001-root
場景四:
擴容非系統盤,比如 /dev/sdb,由100G擴容到3T,直接在 vcenter 中修改磁盤大小為3000G,然后在操作系統中執行如下命令,不會影響已有數據
# 擴容pv pvresize -v /dev/sdb # 擴容lv lvextend -l +100%FREE /dev/mapper/centos7_vGroup002-lv_data xfs_growfs /dev/mapper/centos7_vGroup002-lv_data
此時再添加一塊磁盤並且綁定在 /data/中
# sdc 的處理
pvcreate /dev/sdc vgextend centos7_vGroup002 /dev/sdc lvextend -l +100%FREE /dev/mapper/centos7_vGroup002-lv_data xfs_growfs /dev/mapper/centos7_vGroup002-lv_data
場景五:
# ext4 的擴容方法,掛載新的 磁盤到根目錄(擴容) # 在控制台添加300G磁盤 pvcreate /dev/sdc vgextend VolGroup /dev/sdc lvextend -l +100%FREE /dev/mapper/VolGroup-root resize2fs /dev/VolGroup/root
場景六:
添加磁盤以后找不到磁盤的處理
# 磁盤使用率已經達到了 94%,剩余空間不到 200G,新增加了磁盤,系統識別不了
[root@sz_sjzx_cbslog01_10_207 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 2.8T 2.6T 186G 94% / devtmpfs devtmpfs 16G 0 16G 0% /dev tmpfs tmpfs 16G 0 16G 0% /dev/shm tmpfs tmpfs 16G 1.7G 15G 11% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 220M 795M 22% /boot tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1001 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1002 [root@sz_sjzx_cbslog01_10_207 ~]# fdisk -l Disk /dev/sdc: 322.1 GB, 322122547200 bytes, 629145600 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 /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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 /dev/sda: 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: 0x000d5bd2 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 104857599 51379200 8e Linux LVM Disk /dev/mapper/centos-root: 3050.5 GB, 3050483744768 bytes, 5957976064 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 /dev/mapper/centos-swap: 8589 MB, 8589934592 bytes, 16777216 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 /dev/sdd: 536.9 GB, 536870912000 bytes, 1048576000 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@sz_sjzx_cbslog01_10_207 ~]# cd /sys/class/scsi_host [root@sz_sjzx_cbslog01_10_207 scsi_host]# cat host0/scan cat: host0/scan: Permission denied [root@sz_sjzx_cbslog01_10_207 scsi_host]# echo "- - -" > host0/scan
# 再次查看發現有了新的磁盤 /dev/sde
[root@sz_sjzx_cbslog01_10_207 scsi_host]# fdisk -l Disk /dev/sdc: 322.1 GB, 322122547200 bytes, 629145600 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 /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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 /dev/sda: 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: 0x000d5bd2 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 104857599 51379200 8e Linux LVM Disk /dev/mapper/centos-root: 3050.5 GB, 3050483744768 bytes, 5957976064 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 /dev/mapper/centos-swap: 8589 MB, 8589934592 bytes, 16777216 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 /dev/sdd: 536.9 GB, 536870912000 bytes, 1048576000 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 /dev/sde: 1073.7 GB, 1073741824000 bytes, 2097152000 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
# 創建pvs
[root@sz_sjzx_cbslog01_10_207 ~]# pvcreate /dev/sde Physical volume "/dev/sde" successfully created. [root@sz_sjzx_cbslog01_10_207 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 4 2 0 wz--n- 2.78t 0
# 擴容vg
[root@sz_sjzx_cbslog01_10_207 ~]# vgextend centos /dev/sde Volume group "centos" successfully extended [root@sz_sjzx_cbslog01_10_207 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 5 2 0 wz--n- <3.76t <1000.00g [root@sz_sjzx_cbslog01_10_207 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 2.77t swap centos -wi-ao---- 8.00g
# lvs 擴容
[root@sz_sjzx_cbslog01_10_207 ~]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 2.77 TiB (727292 extents) to 3.75 TiB (983291 extents). Logical volume centos/root successfully resized. [root@sz_sjzx_cbslog01_10_207 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 3.75t swap centos -wi-ao---- 8.00g [root@sz_sjzx_cbslog01_10_207 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 2.8T 2.7T 175G 94% / devtmpfs devtmpfs 16G 0 16G 0% /dev tmpfs tmpfs 16G 0 16G 0% /dev/shm tmpfs tmpfs 16G 1.7G 15G 11% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 220M 795M 22% /boot tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1001 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1002
# 磁盤擴容
[root@sz_sjzx_cbslog01_10_207 ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=278, agsize=2686720 blks = sectsz=512 attr=2, projid32bit=1 Size of logical volume centos/root changed from 2.77 TiB (727292 extents) to 3.75 TiB (983291 extents). Logical volume centos/root successfully resized. [root@sz_sjzx_cbslog01_10_207 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 3.75t swap centos -wi-ao---- 8.00g [root@sz_sjzx_cbslog01_10_207 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 2.8T 2.7T 175G 94% / devtmpfs devtmpfs 16G 0 16G 0% /dev tmpfs tmpfs 16G 0 16G 0% /dev/shm tmpfs tmpfs 16G 1.7G 15G 11% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 220M 795M 22% /boot tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1001 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1002 # 磁盤擴容 [root@sz_sjzx_cbslog01_10_207 ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=278, agsize=2686720 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=744747008, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5247, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 744747008 to 1006889984 [root@sz_sjzx_cbslog01_10_207 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 3.8T 2.7T 1.2T 70% / devtmpfs devtmpfs 16G 0 16G 0% /dev tmpfs tmpfs 16G 0 16G 0% /dev/shm tmpfs tmpfs 16G 1.7G 15G 11% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 220M 795M 22% /boot tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1001 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/1002