码迷,mamicode.com
首页 > 系统相关 > 详细

不损坏数据的情况下 linux磁盘如何扩展 LVM格式

时间:2015-05-04 15:46:28      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

方式:LVM方式

第一步 增加分区:
 1、VM—>编辑设置—>硬盘 下扩大磁盘(菜单操作不再赘复)。
 2、使用fdisk 命令
 fdisk  /dev/sda
 #用n命令建个P类型的磁盘,然后用t命令更改ID为8e(LVM类别)。
  #  p查看一下:
 Disk /dev/sda: 17.1 GB, 17179869184 bytes
 255 heads, 63 sectors/track, 2088 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          13      104391   83  Linux
 /dev/sda2              14        1044     8281507+  8e  Linux LVM
 /dev/sda3            1045        1545     4024282+  8e  Linux LVM
 最后w保存
 3、重启一下服务器,不然挂载不上新建的sda3、sda4,

第二步 加入VLM:
 root#mkfs.ext3 /dev/sda3                   ##格式化新增的分区)

root#lvm
 lvm>pvcreate /dev/sda3                     ##创建LVM硬分区
   Physical volume "/dev/sda3" successfully created
 lvm> vgextend VolGroup00 /dev/sda3          ##加入与/目录同一个LVM组
   Volume group "VolGroup00" successfully extended
 查看一下:
 lvm>pvdisplay
   --- Physical volume ---
   PV Name               /dev/sda2
   VG Name               VolGroup00
   PV Size               7.90 GB / not usable 23.41 MB
   Allocatable           yes (but full)
   PE Size (KByte)       32768
   Total PE              252
   Free PE               0
   Allocated PE          252
   PV UUID               ua5FJN-jSLL-bGkp-w0XO-N8JG-MBR0-1yDzGW

  --- Physical volume ---
   PV Name               /dev/sda3
   VG Name               VolGroup00
   PV Size               3.84 GB / not usable 25.96 MB
   Allocatable           yes
   PE Size (KByte)       32768
   Total PE              122
   Free PE               122
   Allocated PE          0
   PV UUID               mHKWzk-mQ1o-jkQB-0DZC-PVqW-w2R9-14y19G
 把sda3变为LVM的虚拟磁盘(增加容量的关键)
 lvm>vgextend /dev/VolGroup00/LogVol102 /dev/sda3
 第三步 增加 /目录容量
 lvm> lvextend -L +3.8G /dev/VolGroup00/LogVol00
   Rounding up size to full physical extent 3.81 GB
   Extending logical volume LogVol00 to 9.69 GB
   Logical volume LogVol00 successfully resized
 # resize2fs /dev/VolGroup00/LogVol00        ##还要重新一下识别磁盘容量
 resize2fs 1.39 (29-May-2006)
 Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
 Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2539520 (4k) blocks.
 The filesystem on /dev/VolGroup00/LogVol00 is now 2539520 blocks long.

最终确认结果:
 lvm> lvdisplay
   --- Logical volume ---
   LV Name                /dev/VolGroup00/LogVol00
   VG Name                VolGroup00
   LV UUID                r9eG4x-njBD-z2HT-lmL2-2l81-P3XV-KVd0e4
   LV Write Access        read/write
   LV Status              available
   # open                 1
   LV Size                9.69 GB
   Current LE             310
   Segments               2
   Allocation             inherit
   Read ahead sectors     auto
   - currently set to     256
   Block device           253:0

增加一块新硬盘

1。增加前先关闭VM,然后编辑VM属性,增加一个vritual disk(scsi),其实是增加一个虚拟磁盘文件。

hard disk2就是我新增加的

2。查看目前的磁盘结构

[root@mail ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
 255 heads, 63 sectors/track, 1305 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          13      104391   83  Linux
 /dev/sda2              14         905     7164990   83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
 255 heads, 63 sectors/track, 130 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn‘t contain a valid partition table
 //说明磁盘/dev/sdb还没有被系统识别

3。分区

[root@mail ~]# fdisk /dev/sbd

Command (m for help): n  //输入m获得帮助信息,n创建分区
 Command action
    e   extended
    p   primary partition (1-4)
 p //创建主分区
 Partition number (1-4): 1 //指定分区的起始柱面
 First cylinder (1-130, default 1):
Using default value 1
 Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):  //设置分区容量,直接回车表示全部
 Using default value 130

Command (m for help): t //改变一个分区的系统ID
 Selected partition 1
 Hex code (type L to list codes): L //查看文件类型对应的Hex

 85  Linux extended //linux  ext3的hex是85

Hex code (type L to list codes): 85
 You cannot change a partition into an extended one or vice versa
 Delete it first.

Command (m for help): p //列出当前硬盘的分区

Disk /dev/sdb: 1073 MB, 1073741824 bytes
 255 heads, 63 sectors/track, 130 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
 /dev/sdb1               1         130     1044193+  83  Linux

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

Calling ioctl() to re-read partition table.
 Syncing disks.

4。查看现在的分区

[root@mail ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
 255 heads, 63 sectors/track, 1305 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          13      104391   83  Linux
 /dev/sda2              14         905     7164990   83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
 255 heads, 63 sectors/track, 130 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
 /dev/sdb1               1         130     1044193+  83  Linux

5。格式化分区

[root@mail ~]# mkfs.ext3 /dev/sdb1  //格式化成ext3格式

6。挂载分区

[root@mail ~]# mount /dev/sdb1 /tmp
 [root@mail ~]# df -h  /tmp
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sdb1            1004M  1.3M  952M   1% /tmp

7。自动挂载

修改/etc/fstab

增加一行

/dev/sdb1               /sdb1                   ext3    defaults        0 0
 重起

本文出自 “技术成就梦想” 博客,请务必保留此出处http://pizibaidu.blog.51cto.com/1361909/1641695

不损坏数据的情况下 linux磁盘如何扩展 LVM格式

标签:

原文地址:http://pizibaidu.blog.51cto.com/1361909/1641695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!