centos7添加硬盘扩展根分区

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   42G   30G   13G  71% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  9.3M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  162M  335M  33% /boot
tmpfs                    380M     0  380M   0% /run/user/0
[root@localhost ~]# fdisk -l 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: 0x000b61b6 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 104857599 51915776 8e Linux LVM Disk /dev/sdb: 161.1 GB, 161061273600 bytes, 314572800 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-root: 44.6 GB, 44568674304 bytes, 87048192 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 [root@localhost ~]# fdisk /dev/sdb 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. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xdb6e91f6. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-314572799, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-314572799, default 314572799): Using default value 314572799 Partition 1 of type Linux and of size 150 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# fdisk -l 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: 0x000b61b6 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 104857599 51915776 8e Linux LVM Disk /dev/sdb: 161.1 GB, 161061273600 bytes, 314572800 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: 0xdb6e91f6 Device Boot Start End Blocks Id System /dev/sdb1 2048 314572799 157285376 83 Linux Disk /dev/mapper/centos-root: 44.6 GB, 44568674304 bytes, 87048192 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 [root@localhost ~]# vgdisplay -v --- 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.51 GiB PE Size 4.00 MiB Total PE 12674 Alloc PE / Size 12674 / <49.51 GiB Free PE / Size 0 / 0 VG UUID HJh1E8-mSbo-0XcD-fEhA-x6ed-ukCx-cjJjcC --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID dRprxJ-xwgg-s2yE-Xqz6-PrcQ-wzGq-T73G6p LV Write Access read/write LV Creation host, time localhost, 2019-06-27 15:15:53 +0800 LV Status available # open 2 LV Size 8.00 GiB Current LE 2048 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 UqLucs-x3Jc-cGqT-5O8l-KinU-fQQL-6Xt9T9 LV Write Access read/write LV Creation host, time localhost, 2019-06-27 15:15:53 +0800 LV Status available # open 1 LV Size <41.51 GiB Current LE 10626 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Physical volumes --- PV Name /dev/sda2 PV UUID ZwHY1c-KNJv-i0f1-km9S-6KoW-XylU-Qap1UA PV Status allocatable Total PE / Free PE 12674 / 0 [root@localhost ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 49.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 12674 Free PE 0 Allocated PE 12674 PV UUID ZwHY1c-KNJv-i0f1-km9S-6KoW-XylU-Qap1UA "/dev/sdb1" is a new physical volume of "<150.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size <150.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID VdMwcf-RAfk-7Jbw-GfnS-A622-wnkM-PzTNfH [root@localhost ~]# vgextend centos /dev/sdb1 Volume group "centos" successfully extended [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID dRprxJ-xwgg-s2yE-Xqz6-PrcQ-wzGq-T73G6p LV Write Access read/write LV Creation host, time localhost, 2019-06-27 15:15:53 +0800 LV Status available # open 2 LV Size 8.00 GiB Current LE 2048 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 UqLucs-x3Jc-cGqT-5O8l-KinU-fQQL-6Xt9T9 LV Write Access read/write LV Creation host, time localhost, 2019-06-27 15:15:53 +0800 LV Status available # open 1 LV Size <41.51 GiB Current LE 10626 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@localhost ~]# lvextend -l +100%Free /dev/centos/root Size of logical volume centos/root changed from <41.51 GiB (10626 extents) to 191.50 GiB (49025 extents). Logical volume centos/root successfully resized. [root@localhost ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2720256 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=10881024, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5313, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 10881024 to 50201600 [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 192G 30G 163G 16% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.3M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 497M 162M 335M 33% /boot tmpfs 380M 0 380M 0% /run/user/0

  

原文地址:https://www.cnblogs.com/taihao/p/15396883.html