lvm扩容到根分区

[root@localhost ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0             2:0    1    4K  0 disk 
sda             8:0    0   61G  0 disk 
├─sda1          8:1    0  500M  0 part /boot
└─sda2          8:2    0 60.5G  0 part 
  ├─rhel-root 253:0    0 52.5G  0 lvm  /
  └─rhel-swap 253:1    0    8G  0 lvm  [SWAP]
sdb             8:16   0  100G  0 disk 
sr0            11:0    1 1024M  0 rom  
[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 0x2aebfa9e.

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): 1
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector, +sectors or +size{
    
    K,M,G} (2048-209715199, default 209715199): 
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 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: 0x2aebfa9e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe 
[root@localhost ~]# partx /dev/sdb
NR START       END   SECTORS SIZE NAME UUID
 1  2048 209715199 209713152 100G      
[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# vgextend rhel /dev/sdb1
  Volume group "rhel" successfully extended
[root@localhost ~]#   lvextend -l +100%FREE /dev/rhel/root 
  Size of logical volume rhel/root changed from <52.51 GiB (13442 extents) to 152.50 GiB (39041 extents).
  Logical volume rhel/root successfully resized.
[root@localhost ~]# resize2fs /dev/rhel/root 
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/rhel/root is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 20
The filesystem on /dev/rhel/root is now 39977984 blocks long.

[root@localhost ~]# lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
fd0             2:0    1     4K  0 disk 
sda             8:0    0    61G  0 disk 
├─sda1          8:1    0   500M  0 part /boot
└─sda2          8:2    0  60.5G  0 part 
  ├─rhel-root 253:0    0 152.5G  0 lvm  /
  └─rhel-swap 253:1    0     8G  0 lvm  [SWAP]
sdb             8:16   0   100G  0 disk 
└─sdb1          8:17   0   100G  0 part 
  └─rhel-root 253:0    0 152.5G  0 lvm  /
sr0            11:0    1  1024M  0 rom  
[root@localhost ~]# df -TH
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root ext4      162G  6.0G  148G   4% /
devtmpfs              devtmpfs   26G     0   26G   0% /dev
tmpfs                 tmpfs      26G     0   26G   0% /dev/shm
tmpfs                 tmpfs      26G   29M   26G   1% /run
tmpfs                 tmpfs      26G     0   26G   0% /sys/fs/cgroup
/dev/sda1             xfs       521M  145M  376M  28% /boot
tmpfs                 tmpfs     5.1G     0  5.1G   0% /run/user/1000

命令步骤:

fdisk /dev/sdb --> n --> p --> 1 --> 回车 --> 回车 --> t --> 8e --> p --> w
partprobe #同步分区表到硬盘  或者partx /dev/sdb
pvcreate /dev/sdb1
vgextend vg名字 /dev/sdb1
lvextend -l +100%FREE /dev/rhel/root    #或者全部空间加载给根目录    
xfs_growfs /dev/rhel/root   #xfs格式使用此命令
resize2fs  /dev/rhel/root   #ext2、ext3、ext4使用此命令

猜你喜欢

转载自blog.csdn.net/change_can/article/details/120419226
今日推荐