開始虛擬機安裝時咱們就選擇了lvm 進行磁盤分區的劃分。後期磁盤不夠時再加也很方便,因而就有了這個lvm的擴容。這臺內部虛擬機主要作共享和數據備份,須要的磁盤空間比較大。下面記錄lvm的擴容node
首先增長一塊新的磁盤,Centos 新增硬盤之後,系統不能自動進行識別linux
[root@samba]# fdisk -l 磁盤 /dev/sda:536.9 GB, 536870912000 字節,1048576000 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標籤類型:dos 磁盤標識符:0x0007efbe 設備 Boot Start End Blocks Id System /dev/sda1 * 2048 501759 249856 83 Linux /dev/sda2 501760 1048575999 524037120 8e Linux LVM 磁盤 /dev/mapper/vg-0:536.6 GB, 536610865152 字節,1048068096 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 [root@samba]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 500G 0 disk ├─sda1 8:1 0 244M 0 part /boot └─sda2 8:2 0 499.8G 0 part └─vg-0 253:0 0 499.8G 0 lvm / sr0 11:0 1 1024M 0 rom
lsblk命令的英文是「list block」,即用於列出全部可用塊設備的信息,並且還能顯示他們之間的依賴關係(我的很喜歡這個命令,樹狀列出)centos
因爲不知道新增硬盤掛載的位置,能夠先查看現有硬盤掛載的適配器。app
[root@samba]# ls -l /sys/block/sda lrwxrwxrwx 1 root root 0 5月 29 10:26 /sys/block/sda -> ../devices/pci0000:00/0000:00:10.0/host16/target16:0:0/16:0:0:0/block/sda
發現磁盤掛載到host16,能夠嘗試使用下邊命令,從新掃描host16信息tcp
[root@samba]# echo "- - -" > /sys/class/scsi_host/host16/scan [root@samba]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 500G 0 disk ├─sda1 8:1 0 244M 0 part /boot └─sda2 8:2 0 499.8G 0 part └─vg-0 253:0 0 499.8G 0 lvm / sdb 8:16 0 500G 0 disk sr0 11:0 1 1024M 0 rom
磁盤分區以及格式化ui
[root@samba]# fdisk /dev/sdb 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 Device does not contain a recognized partition table 使用磁盤標識符 0x7bfce339 建立新的 DOS 磁盤標籤。 命令(輸入 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 (0 primary, 0 extended, 4 free) e extended Select (default p): p 分區號 (1-4,默認 1):1 起始 扇區 (2048-1048575999,默認爲 2048): 將使用默認值 2048 Last 扇區, +扇區 or +size{K,M,G} (2048-1048575999,默認爲 1048575999): 將使用默認值 1048575999 分區 1 已設置爲 Linux 類型,大小設爲 500 GiB 命令(輸入 m 獲取幫助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盤。 [root@samba]# fdisk -l 磁盤 /dev/sda:536.9 GB, 536870912000 字節,1048576000 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標籤類型:dos 磁盤標識符:0x0007efbe 設備 Boot Start End Blocks Id System /dev/sda1 * 2048 501759 249856 83 Linux /dev/sda2 501760 1048575999 524037120 8e Linux LVM 磁盤 /dev/mapper/vg-0:536.6 GB, 536610865152 字節,1048068096 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤 /dev/sdb:536.9 GB, 536870912000 字節,1048576000 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標籤類型:dos 磁盤標識符:0x7bfce339 設備 Boot Start End Blocks Id System /dev/sdb1 2048 1048575999 524286976 83 Linux [root@samba]# mkfs -t xfs /dev/sdb mkfs.xfs: /dev/sdb appears to contain a partition table (dos). mkfs.xfs: Use the -f option to force overwrite. [root@samba]# mkfs.xfs /dev/sdb mkfs.xfs: /dev/sdb appears to contain a partition table (dos). mkfs.xfs: Use the -f option to force overwrite. [root@samba]# mkfs.xfs -f /dev/sdb meta-data=/dev/sdb isize=512 agcount=4, agsize=32768000 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=131072000, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=64000, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
查看vg邏輯卷組this
[root@samba]# vgdisplay --- Volume group --- VG Name vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size <499.76 GiB PE Size 4.00 MiB Total PE 127938 Alloc PE / Size 127938 / <499.76 GiB Free PE / Size 0 / 0 VG UUID kNi93D-daLZ-qYmt-hhzS-Kdm3-ZUHv-0eUYL3
擴容vgcentos7
[root@samba]# vgextend vg /dev/sdb WARNING: xfs signature detected on /dev/sdb at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sdb. Physical volume "/dev/sdb" successfully created. Volume group "vg" successfully extended [root@samba]# vgdisplay --- Volume group --- VG Name vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 999.75 GiB PE Size 4.00 MiB Total PE 255937 Alloc PE / Size 127938 / <499.76 GiB Free PE / Size 127999 / <500.00 GiB VG UUID kNi93D-daLZ-qYmt-hhzS-Kdm3-ZUHv-0eUYL3
查看lv,把lv擴容到vg的剩餘容量spa
[root@samba]# lv lvchange lvcreate lvextend lvmconf lvmdiskscan lvmetad lvmsadc lvreduce lvrename lvs lvconvert lvdisplay lvm lvmconfig lvmdump lvmpolld lvmsar lvremove lvresize lvscan [root@samba]# lvdisplay --- Logical volume --- LV Path /dev/vg/0 LV Name 0 VG Name vg LV UUID JQVovf-H4tM-kGNi-Nq9b-QRyE-QDIW-lAg2KP LV Write Access read/write LV Creation host, time samba, 2020-04-09 16:23:09 +0800 LV Status available # open 1 LV Size <499.76 GiB Current LE 127938 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@samba]# lvextend /dev/vg/0 /dev/sdb Size of logical volume vg/0 changed from <499.76 GiB (127938 extents) to 999.75 GiB (255937 extents). Logical volume vg/0 successfully resized. [root@samba]# lvdisplay --- Logical volume --- LV Path /dev/vg/0 LV Name 0 VG Name vg LV UUID JQVovf-H4tM-kGNi-Nq9b-QRyE-QDIW-lAg2KP LV Write Access read/write LV Creation host, time samba, 2020-04-09 16:23:09 +0800 LV Status available # open 1 LV Size 999.75 GiB Current LE 255937 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@samba]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 500G 0 disk ├─sda1 8:1 0 244M 0 part /boot └─sda2 8:2 0 499.8G 0 part └─vg-0 253:0 0 999.8G 0 lvm / sdb 8:16 0 500G 0 disk └─vg-0 253:0 0 999.8G 0 lvm / sr0 11:0 1 1024M 0 rom
最後,讓新增的空間在線生效.centos7 推薦用xfs文件格式。rest
[root@samba]# xfs_ xfs_admin xfs_copy xfs_estimate xfs_fsr xfs_info xfs_logprint xfs_metadump xfs_ncheck xfs_repair xfs_bmap xfs_db xfs_freeze xfs_growfs xfs_io xfs_mdrestore xfs_mkfile xfs_quota xfs_rtcp [root@samba]# xfs_growfs -h xfs_growfs:無效選項 -- h Usage: xfs_growfs [options] mountpoint Options: -d grow data/metadata section -l grow log section -r grow realtime section -n don't change anything, just show geometry -i convert log from external to internal format -t alternate location for mount table (/etc/mtab) -x convert log from internal to external format -D size grow data/metadata section to size blks -L size grow/shrink log section to size blks -R size grow realtime section to size blks -e size set realtime extent size to size blks -m imaxpct set inode max percent to imaxpct -V print version information [root@samba]# xfs_growfs / meta-data=/dev/mapper/vg-0 isize=512 agcount=4, agsize=32752128 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=131008512, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=63969, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 131008512 to 262079488
到此,lvm擴容完成,最後查看一下
[root@samba]# df -h 文件系統 容量 已用 可用 已用% 掛載點 devtmpfs 979M 0 979M 0% /dev tmpfs 991M 0 991M 0% /dev/shm tmpfs 991M 18M 973M 2% /run tmpfs 991M 0 991M 0% /sys/fs/cgroup /dev/mapper/vg-0 1000G 267G 734G 27% / /dev/sda1 241M 133M 109M 55% /boot tmpfs 199M 0 199M 0% /run/user/1000