ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 使用LVM来增大文件系统

使用LVM来增大文件系统

原创 Linux操作系统 作者:hl_fen 时间:2011-12-12 15:16:40 0 删除 编辑
初始环境:
一块盘,sda
[root@test-han ~]# fdisk -l /dev/sda
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        1305    10377990   8e  Linux LVM
目前已经分配了10G,现在想把剩下的10G通过lv的方式也加上
 
 
[root@test-han ~]# fdisk /dev/sda
Command (m for help): p 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        1305    10377990   8e  Linux LVM
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p                                    --这里只能选p,如果选e,则不能更改分区类型
Partition number (1-4): 3
First cylinder (1306-2610, default 1306):
Using default value 1306
Last cylinder or +size or +sizeM or +sizeK (1306-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        1305    10377990   8e  Linux LVM
/dev/sda3            1306        2610    10482412+  83  Linux
Command (m for help): t       --更改分区类型
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        1305    10377990   8e  Linux LVM
/dev/sda3            1306        2610    10482412+  8e  Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@test-han ~]# ls /dev/sda
sda   sda1  sda2  sda3 
 
[root@test-han ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        1305    10377990   8e  Linux LVM
/dev/sda3            1306        2610    10482412+  8e  Linux LVM
[root@test-han ~]# pvcreate /dev/sda3   --将这个分区建成pv
  Physical volume "/dev/sda3" successfully created
 
[root@test-han ~]# vgextend VolGroup00 /dev/sda3  --将它加入vg
  Volume group "VolGroup00" successfully extended
 
[root@test-han ~]# lvextend -L +10200M /dev/VolGroup00/LogVol00 --扩展VG下的LV
  Rounding up size to full physical extent 9.97 GB
  Extending logical volume LogVol00 to 17.84 GB
  Logical volume LogVol00 successfully resized

[root@test-han ~]# vgdisplay -v /dev/VolGroup00
    Using volume group(s) on command line
    Finding volume group "VolGroup00"
  --- Volume group ---
  VG Name               VolGroup00
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               19.84 GB
  PE Size               32.00 MB
  Total PE              635
  Alloc PE / Size       635 / 19.84 GB
  Free  PE / Size       0 / 0  
  VG UUID               6D8hK4-oGeF-ejBb-lTEi-jUzy-Z5HQ-JWxWlv
  
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                VPJRDV-GO3j-24OG-1w7J-Gn8C-A7TB-pV1fLT
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                17.84 GB
  Current LE             571
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                tqE5XC-dD6d-kDQR-CCgA-ux8V-0Zw0-A1GGsI
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             64
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
  --- Physical volumes ---
  PV Name               /dev/sda2    
  PV UUID               ZRUh1g-oEb0-YFX1-Hcby-YkzZ-Q2BY-AVkmH3
  PV Status             allocatable
  Total PE / Free PE    316 / 0
  
  PV Name               /dev/sda3    
  PV UUID               5khAb7-f72J-HYBD-VOBA-r7uR-dr9J-QwlqAX
  PV Status             allocatable
  Total PE / Free PE    319 / 0
 
可以看到已经加入这个VG,但是df -h 还看不出来
 
[root@test-han ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      7.7G  7.1G  212M  98% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
 
接下来需要增大文件系统
 
[root@test-han ~]# resize2fs -p /dev/mapper/VolGroup00-LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol00 to 4677632 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol00 is now 4677632 blocks long.
[root@test-han ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       18G  7.1G  9.4G  43% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
 
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/76790/viewspace-713168/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: mysql更改datadir
请登录后发表评论 登录
全部评论

注册时间:2011-12-07

  • 博文量
    4
  • 访问量
    5617