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

linux LVM

时间:2014-12-12 19:27:20      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:lvm

[root@qing ~]# fdisk -l                                                                    #查看磁盘信息

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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        5221    41833260   8e  Linux LVM

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
[root@qing ~]#
[root@qing ~]#
[root@qing ~]#
[root@qing ~]# fdisk /dev/sdb                       #进入分区管理

Command (m for help): n                 #创建新分区
Command action
   e   extended
   p   primary partition (1-4)
p                               #分区类型为主分区
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): +5368M      #分区大小为5368M
Value out of range.
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652):
Using default value 652

Command (m for help): p                      #查看分区信息

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  83  Linux

Command (m for help): t            #修改分区类型
Selected partition 1               #指定分区,26行中"Partition number (1-4): 1" 指定的分区
Hex code (type L to list codes): 8e             #类型为8e   为LVM类型
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  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: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@qing ~]#
[root@qing ~]#
[root@qing ~]#
[root@qing ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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        5221    41833260   8e  Linux LVM

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  8e  Linux LVM         #已经创建了一个LVM分区
[root@qing ~]#
[root@qing ~]# pvcreate /dev/sdb1                    #使用pvcreate创建pv
  Writing physical volume data to disk "/dev/sdb1"     
  Physical volume "/dev/sdb1" successfully created
[root@qing ~]#
[root@qing ~]# pvdisplay               #查看已经存在的PV
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               39.90 GB / not usable 20.79 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              1276
  Free PE               0
  Allocated PE          1276
  PV UUID               XUeOGK-U3Xu-I8AD-NdZn-tISP-G7iH-C9yRTI
   
  "/dev/sdb1" is a new physical volume of "4.99 GB"            #刚创建的PV
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               4.99 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               RyVVY8-teMl-wHSq-oEcM-fEYu-axDK-pw7liR
   
[root@qing ~]#
[root@qing ~]# vgcreate volGroup00 /dev/sdb1            #创建VG ,可以使用VG名volGroup00或者使用新的,volGroup01
  Volume group "volGroup00" successfully created
[root@qing ~]#
[root@qing ~]# vgdisplay               #查看已经创建好的VG
  --- Volume group ---
  VG Name               volGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  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               4.99 GB
  PE Size               4.00 MB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / 4.99 GB                            # 新创建的VG,可使用的容量为4.99G
  VG UUID               pBeCkt-D5bU-avY6-0mkd-DgGd-BcX5-qvj6q0
   
  --- Volume group ---
  VG Name               VolGroup00
  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               39.88 GB
  PE Size               32.00 MB
  Total PE              1276
  Alloc PE / Size       1276 / 39.88 GB
  Free  PE / Size       0 / 0   
  VG UUID               4WRogY-DsNe-ZtCq-gQKm-HmZX-UxwD-GxNwHA
   
[root@qing ~]#
[root@qing ~]# lvcreate -L 4.99G -n lvData2 volGroup00         #创建LV ,-L指定大小,-n指定LV名称 ,vo1Group00:表示从这个VG中划分LV
  Rounding up size to full physical extent 4.99 GB
  Logical volume "lvData2" created
[root@qing ~]#
[root@qing ~]# mkfs -t ext3 /dev/volGroup00/lvData2          #格式化LV,以便存储资料
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 1308672 blocks
65433 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@qing ~]#
[root@qing ~]# df -h                                     #挂载前磁盘信息
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                       37G  6.0G   29G  18% /
/dev/sda1              99M   13M   81M  14% /boot
tmpfs                 500M     0  500M   0% /dev/shm
[root@qing ~]#
[root@qing ~]#
[root@qing ~]# mount /dev/volGroup00/lvData2 /boot          #挂载LV
[root@qing ~]# df -h                                           #挂载后磁盘信息
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                       37G  6.0G   29G  18% /
/dev/sda1             5.0G  139M  4.6G   3% /boot
tmpfs                 500M     0  500M   0% /dev/shm
/dev/mapper/volGroup00-lvData2
                      5.0G  139M  4.6G   3% /boot
[root@qing ~]#
[root@qing ~]# lvremove /dev/volGroup00/lvData2             #移除创建的LV
Do you really want to remove active logical volume lvData2? [y/n]: y
  Logical volume "lvData2" successfully removed
[root@qing ~]# vgremove /dev/volGroup00                 #移除创建的VG
  Volume group "volGroup00" successfully removed
[root@qing ~]#
[root@qing ~]# blkid              #查看所有分区的label以及UUID
/dev/mapper/VolGroup00-LogVol01: TYPE="swap"
/dev/mapper/VolGroup00-LogVol00: UUID="e24e83e0-9d0c-468a-9dae-93e2a0113ec2" TYPE="ext3"
/dev/sda1: LABEL="/boot" UUID="9c46230d-c5f4-4039-9822-23ee1089f2f7" TYPE="ext3"
/dev/hdc: LABEL="CentOS_5.8_Final" TYPE="iso9660"
/dev/VolGroup00/LogVol00: UUID="e24e83e0-9d0c-468a-9dae-93e2a0113ec2" TYPE="ext3"
/dev/VolGroup00/LogVol01: TYPE="swap"
/dev/cdrw: LABEL="CentOS_5.8_Final" TYPE="iso9660"
/dev/volGroup01/vlg01_1: UUID="e73b79aa-d95f-422a-b021-7c50ac402117" SEC_TYPE="ext2" TYPE="ext3"
/dev/mapper/volGroup01-vlg01_1: UUID="e73b79aa-d95f-422a-b021-7c50ac402117" SEC_TYPE="ext2" TYPE="ext3"
[root@qing ~]#
[root@qing ~]# vi /etc/fstab         #配置系统在启动的时候挂载LV

/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
UUID=e73b79aa-d95f-422a-b021-7c50ac402117 /boot  ext3   defaults        1 2

本文出自 “小白的小窝” 博客,请务必保留此出处http://qing429.blog.51cto.com/5781009/1589356

linux LVM

标签:lvm

原文地址:http://qing429.blog.51cto.com/5781009/1589356

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