Add a new hard disk and expand the original partition

Expanding the original partition first is invalid only for physical volumes formatted with logical volumes

Query the added disk first and partition and format it

[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

Format the partition to specify the ext4 format:

[root @localhost ~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.41.12 (17-May-2010)
filesystem label=
OS:Linux
block size=4096 (log=2)
block size=4096 (log= 2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620595 blocks
....


Writing inode table: Done                            
Creating journal (32768 blocks): Done
Writing superblocks and filesystem accounting information: Done

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 ##Display physical volume as above
  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]

 Expansion VG Add the created pv to the volume group where the system root partition is located /dev/mapper/VolGroup-lv_root 36G 7.4G 26G 23% / viewed through df -h

The group name is VolGroup-lv

The logical volume is named lv_root

[root@localhost /]# vgextend VolGroup /dev/sdb1 ###Add /dev/sdb1/ to the logical volume group 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 ##At this time VG size and change
  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
   

At this point, it is expanding lv, that is, the root partition

[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 

##The error is because there are only 2558 pe blocks available at this time 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
 

But df -h did not take effect 

[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.

At this point the root partition has changed 

[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
 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070743&siteId=291194637