增加一块新硬盘,扩大原有分区

首先扩大原有分区只针对与逻辑卷格式 物理卷无效

先查询 增加的磁盘 并且对其进行分区 格式化

[root@localhost ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b2e43

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@localhost ~]# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xdd2a01a6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):   ## 划分最大空间 
Using default value 1305

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: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b2e43

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdd2a01a6

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   83  Linux

格式化分区 指定 ext4格式:

[root@localhost ~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620595 blocks
....


正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost /]# pvdisplay  ##显示物理卷
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               39.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10114
  Free PE               0
  Allocated PE          10114
  PV UUID               6LL9QX-ULqY-RHs8-NyWS-P5Vf-g5qi-eqZMKh
   
  "/dev/sdb1" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               iF8Gno-3nEP-cp24-hcCZ-dQz8-SjGf-Cjj9ad
 

[root@localhost /]# pvscan  ##显示物理卷 作用同上
  PV /dev/sda2   VG VolGroup        lvm2 [39.51 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [10.00 GiB]
  Total: 2 [49.50 GiB] / in use: 1 [39.51 GiB] / in no VG: 1 [10.00 GiB]

扩容 VG 将刚才创建好的pv 添加到系统根分区所在的卷组中 通过df -h 查看到的 /dev/mapper/VolGroup-lv_root   36G  7.4G   26G  23% /

组名为 VolGroup-lv

逻辑卷名为 lv_root

[root@localhost /]# vgextend VolGroup /dev/sdb1   ###将/dev/sdb1/ 添加到逻辑卷组  VolGroup中
  Volume group "VolGroup" successfully extended
[root@localhost /]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               49.50 GiB   ##此时VG的大小以及改变
  PE Size               4.00 MiB
  Total PE              12672
  Alloc PE / Size       10114 / 39.51 GiB
  Free  PE / Size       2558 / 9.99 GiB
  VG UUID               XhRR19-HGRS-ObYb-NLfd-vM41-XgS4-ZiD0o4
   

此时在将其扩展lv 即根分区

[root@localhost /]# lvextend -L +10G /dev/mapper/VolGroup-lv_root 
  Extending logical volume lv_root to 45.65 GiB
  Insufficient free space: 2560 extents needed, but only 2558 available 

##报错 是因为此时可用pe块只有2558个 2558*4/1024=9.992G


[root@localhost /]# lvextend -L +9.992G /dev/mapper/VolGroup-lv_root 
  Rounding size to boundary between physical extents: 9.99 GiB
  Extending logical volume lv_root to 45.64 GiB
  Logical volume lv_root successfully resized     ###成功

[root@localhost /]# lvdisplay  
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                obpkNc-TjiE-YTln-23wo-c6KS-lofw-BRm50Y
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-09-13 21:56:39 +0800
  LV Status              available
  # open                 1
  LV Size                45.64 GiB
  Current LE             11684
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
 

但是 df -h 并未生效 

[root@localhost /]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   36G  7.4G   26G  23% /
tmpfs                         996M   72K  996M   1% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot
  

[root@localhost /]# resize2fs  /dev/mapper/VolGroup-lv_root  ## 使扩容马上生效
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 3
Performing an on-line resize of /dev/VolGroup/lv_root to 11964416 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 11964416 blocks long.

此时 根分区已经改变 

[root@localhost /]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   45G  7.4G   36G  18% /
tmpfs                         996M   72K  996M   1% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot
 

猜你喜欢

转载自my.oschina.net/u/3652215/blog/1571104