扩展硬盘

 

 

对硬盘进行分区

(1) 查看现有的硬盘分区情况
[mysql@china ~]$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/vg_china-lv_root   18G  5.2G   12G  32% /
tmpfs                         931M   72K  931M   1% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot

(2).对新增的硬盘空间做新增分区(硬盘数没有增加,增加的是空间)

 sudo    fdisk     /dev/sda

出现如下提示:Command (m for help): 
 n   说明:新增分区
继续提示:Command action
   e   extended
   p   primary partition (1-4)
p 说明:打印分区表    
3 说明:Partition number (1-4):此时fdisk会让你选择主分区的编号,如果已经有了主分区sda1,sda2,那么编号就选3,即要创建的该分区为sda3.
First cylinder (2611-16632, default 2611): 默认回车(最小)
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-16632, default 16632):默认回车(最大)
Using default value 16632
Command (m for help):   t 说明:修改分区类型
Partition number (1-4):   3 说明:修改分区类型对应的分区号
Hex code (type L to list codes):    8e说明:8e是lvm磁盘类型
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help):    p 说明:打印分区表

Command (m for help):    w 说明:保存退出
The partition table has been altered!
(3)重新启动系统
    reboot
(4) 输入一下命令
     sudo fdisk -l /dev/sda

 (5).执行
    sudo  pvcreate /dev/sda3       为这个新分区创建一个物理卷Volume;
 (6).现在要做的是把物理卷(volume)扩展到新的物理卷上,先执行命令
   sudo vgdisplay          来查看已有的系统Volume Group的情况,输出如下:
   [root@china ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_china
  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               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               SCI2oR-nhr6-89fG-AfDW-CzsM-HxqL-QpS3jr
  
(7)执行命令
     vgextend vg_china   /dev/sda3    ,   扩展以后的Volume Group到新的物理磁盘卷Volume上。

(8)下一步是扩展逻辑卷(Logic Volume)到新的卷上,先用命令
     vgdisplay     看看目前已有的逻辑卷(Logic Volume)的情况
    [root@china ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_china
  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               99.50 GiB
  PE Size               4.00 MiB
  Total PE              25473
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       20479 / 80.00 GiB
  VG UUID               SCI2oR-nhr6-89fG-AfDW-CzsM-HxqL-QpS3jr

 (9)执行命令 扩展逻辑分区
    [root@china ~]# lvextend -L +79.99G /dev/vg_china/lv_root /dev/sda3 
  Rounding size to boundary between physical extents: 79.99 GiB
  Extending logical volume lv_root to 97.50 GiB
  Logical volume lv_root successfully resized

(10)最后将文件系统resize到新的逻辑卷上来,执行命令
[root@china ~]# resize2fs /dev/vg_china/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_china/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 7
Performing an on-line resize of /dev/vg_china/lv_root to 25559040 (4k) blocks.
The filesystem on /dev/vg_china/lv_root is now 25559040 blocks long.

(11)用命令看到扩展的分区

[root@china ~]# fdisk -l /dev/sda

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0007243f

   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        2611    20458496   8e  Linux LVM
/dev/sda3            2611       13054    83884735   8e  Linux LVM

[root@china ~]# df -hl
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/vg_china-lv_root   96G  5.2G   86G   6% /
tmpfs                         931M   72K  931M   1% /dev/shm
/dev/sda1                     485M   39M  421M   9% /boot

 

版权声明:本文为xiao-apple36原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xiao-apple36/p/9003089.html