lvm快速使用

作/译者:叶金荣(Email: ),来源:http://imysql.cn,转载请注明作/译者和出处,并且不能用于商业用途,违者必究。
1. fdisk -l 查看可用分区
[root@localhost ~]# fdisk -l
Disk /dev/cciss/c0d0: 146.7 GB, 146778685440 bytes
255 heads, 63 sectors/track, 17844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          16      128488+  83  Linux
/dev/cciss/c0d0p2              17         799     6289447+  83  Linux
/dev/cciss/c0d0p4            1322       17844   132720997+   5  Extended
/dev/cciss/c0d0p6            2105        2626     4192933+  82  Linux swap
Disk /dev/cciss/c0d1: 293.5 GB, 293564211200 bytes
255 heads, 32 sectors/track, 70265 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes
Disk /dev/cciss/c0d1 doesn't contain a valid partition table
 
2. 选取启用一个设备,来启用lvm
2.1 创建一个物理设备
[root@localhost ~]# pvcreate /dev/cciss/c0d1
  Physical volume "/dev/cciss/c0d1" successfully created
 
看看啥结果:
[root@localhost ~]# pvdisplay -v
    Scanning for physical volume names
  --- Physical volume ---
  PV Name               /dev/cciss/c0d1
  VG Name               data
  PV Size               273.40 GB / not usable 664.00 KB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              69991
  Free PE               46698
  Allocated PE          23293
  PV UUID               ElM1rp-UYEw-KlV8-JjGu-cO17-5BIo-plyXXq

2.2 创建一个卷组
[root@localhost ~]# vgcreate data /dev/cciss/c0d1
  Volume group "data" successfully created
 
看看结果:
[root@localhost ~]# vgdisplay -v
    Finding all volume groups
    Finding volume group "data"
  --- Volume group ---
  VG Name               data
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               272.24 GB
  PE Size               4.00 MB
  Total PE              69694
  Alloc PE / Size       0 / 0
  Free  PE / Size       69694 / 272.24 GB
  VG UUID               7UcyGl-TYPr-3c82-2oew-eJ3F-6Z1b-mVtM7G
  --- Physical volumes ---
  PV Name               /dev/cciss/c0d1
  PV UUID               7Y4Vze-WR95-uDDJ-exi8-IPVD-gEEW-Tqpuy2
  PV Status             allocatable
  Total PE / Free PE    69694 / 69694
 
2.3 创建一个lvm卷
[root@localhost ~]# lvcreate -L 60G -n mysql data
  Logical volume "mysql" created
 
看看:
[root@localhost ~]#lvdisplay -v
    Finding all logical volumes
  --- Logical volume ---
  LV Name                /dev/data/mysql
  VG Name                data
  LV UUID                bO5R6V-UVhX-yaJw-Ap0a-fQIe-AfYy-OJ0XyT
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                90.99 GB
  Current LE             23293
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
 
 
 

估计不够大,来给它加大一点,呵呵
[root@localhost ~]# lvresize -L +10G /dev/data/mysql
  Extending logical volume mysql to 70.00 GB
  Logical volume mysql successfully resized
 
2.4 创建文件系统
[root@localhost ~]# mkfs.ext3 -j /dev/data/mysql
......
......
然后挂载到你想要的地方。
在这里要注意了,想要使得加大的空间生效,必须再一次执行 ext2online 。
[root@localhost ~]# ext2online /dev/data/mysql
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
 
3. 简单测试一下
挂载
[root@localhost ~]# mount /dev/data/mysql /mysql
[root@localhost ~]# ls -l /mysql/
total 0
 
往目标目录下拷贝一个文件:
[root@localhost ~]# cp test.tgz /mysql
[root@localhost ~]# ls -l /mysql
total 1176
-rw-r--r--  1 root root 1196796 May  5 16:20 test.tgz
 
ok,现在创建一下快照:
[root@localhost ~]# lvcreate -L 10M -s -n snap /dev/data/mysql
  Rounding up size to full physical extent 12.00 MB
  Logical volume "snap" created
 
然后把快照挂载,看看都有啥咚咚:
[root@localhost ~]# mount /dev/data/snap /snap
[root@localhost ~]# ls -l /snap
total 1176
-rw-r--r--  1 root root 1196796 May  5 16:20 linux.tgz

呵呵,看到了吧,快照生效。这个时候,如果想要备份,只需要把里面的文件拷贝出来即可,然后尽快删除快照。
本文出自 “MySQL中文网”博客 http://www.imysql.cn/
 

本文出自 “爱MySQL” 博客,转载请与作者联系!

你可能感兴趣的:(职场,lvm,休闲)