Linux存储实验二:LVM操作


Linux存储实验二:LVM操作
 
Linux存储实验二:RAID操作
http://www.2cto.com/os/201303/195811.html
 
 (1) 创建LVM
 
       步骤一:再新建5块10MB SCSI的硬盘
               这一步和上一步制作raid的操作是一样的,请参见上一篇
 
       步骤二:用4块硬盘做raid5+1hostspare
               mdadm --create --auto=yes /dev/md1 --level=5 --raid-devices=4 --spare-device=1 /dev/sdc{5,6,7,8,9}
               注意:这次我们创建raid起名为/dev/md1(上次为/dev/md0)
 
       步骤三:查看RAID组成情况  
    
[root@compute-0 mnt]# mdadm --detail /dev/md*
mdadm: /dev/md does not appear to be an md device
/dev/md0:  # 上次RAID实验创建的
        Version : 1.2
  Creation Time : Fri Mar 22 04:41:39 2013
     Raid Level : raid5
     Array Size : 480768 (469.58 MiB 492.31 MB)
  Used Dev Size : 160256 (156.53 MiB 164.10 MB)
   Raid Devices : 4
  Total Devices : 5
    Persistence : Superblock is persistent
    Update Time : Fri Mar 22 05:44:28 2013
          State : clean 
 Active Devices : 4
Working Devices : 5
 Failed Devices : 0
  Spare Devices : 1
         Layout : left-symmetric
     Chunk Size : 512K
           Name : compute-0:0  (local to host compute-0)
           UUID : d81cdfce:03d33c89:ffe54067:44e19b55
         Events : 18
    Number   Major   Minor   RaidDevice State
       0       8       21        0      active sync   /dev/sdb5
       1       8       22        1      active sync   /dev/sdb6
       2       8       23        2      active sync   /dev/sdb7
       5       8       24        3      active sync   /dev/sdb8
       4       8       25        -      spare   /dev/sdb9
/dev/md1:   #这次我们新创建的
        Version : 1.2
  Creation Time : Fri Mar 22 04:42:44 2013
     Raid Level : raid5
     Array Size : 480768 (469.58 MiB 492.31 MB)
  Used Dev Size : 160256 (156.53 MiB 164.10 MB)
   Raid Devices : 4
  Total Devices : 5
    Persistence : Superblock is persistent
    Update Time : Fri Mar 22 05:44:31 2013
          State : clean 
 Active Devices : 4
Working Devices : 5
 Failed Devices : 0
  Spare Devices : 1
         Layout : left-symmetric
     Chunk Size : 512K
           Name : compute-0:1  (local to host compute-0)
           UUID : da3b02e6:b77652b6:3688ad25:9c34dabc
         Events : 18
    Number   Major   Minor   RaidDevice State
       0       8       37        0      active sync   /dev/sdc5
       1       8       38        1      active sync   /dev/sdc6
       2       8       39        2      active sync   /dev/sdc7
       5       8       40        3      active sync   /dev/sdc8
       4       8       41        -      spare   /dev/sdc9
        
      步骤四:将RAID转换为物理卷(即:PV)  
 
[root@compute-0 mnt]# pvscan     # 先扫描一下是否有现存的物理卷
  No matching physical volumes found
[root@compute-0 mnt]# pvcreate /dev/md1    # 创建物理卷
  Writing physical volume data to disk "/dev/md1"
  Physical volume "/dev/md1" successfully created
[root@compute-0 mnt]# pvscan     # 查看一下
  PV /dev/md1                      lvm2 [469.50 MiB]
  Total: 1 [469.50 MiB] / in use: 0 [0   ] / in no VG: 1 [469.50 MiB]
[root@compute-0 mnt]# 
      
       步骤五:新建一个逻辑卷组(即:VG)
 
[root@compute-0 mnt]# vgscan 
  Reading all physical volumes.  This may take a while...
  No volume groups found
[root@compute-0 mnt]# vgcreate -s 16M houqdvg /dev/md1 
       # 注:-s 表示PE的大小 houqdvg表示创建的逻辑卷组的名称 
  Volume group "houqdvg" successfully created
[root@compute-0 mnt]# vgscan 
  Reading all physical volumes.  This may take a while...
  Found volume group "houqdvg" using metadata type lvm2
[root@compute-0 mnt]# vgdisplay 
  --- Volume group ---
  VG Name               houqdvg
  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               464.00 MiB
  PE Size               16.00 MiB   # PE的大小
  Total PE              29          # 该逻辑卷组里面PE的总量
  Alloc PE / Size       0 / 0   
  Free  PE / Size       29 / 464.00 MiB
  VG UUID               vBlcd2-qt6Y-Bt1D-v63K-oIJv-a3Hm-tPzoue
   
[root@compute-0 mnt]# 
         
        步骤六:建立逻辑卷(即:LV),并建立文件系统
 
[root@compute-0 mnt]# lvcreate -l 29 -n houqdlv houqdvg
     注: -l 后面指定的是PE的个数   
          -L 后面指定的是按照大小来建
          -n 后面指定创建的逻辑卷的名字
  Logical volume "houqdlv" created
[root@compute-0 mnt]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/houqdvg/houqdlv    
         # 注:以后使用该逻辑卷一定要用这个/dev/houqdvg/houqdlv全名
  VG Name                houqdvg
  LV UUID                T0L4cu-dqNC-PRHz-QQ3u-0ubi-VAWe-YquY7t
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                464.00 MiB
  Current LE             29
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     6144
  Block device           253:0   
[root@compute-0 mnt]# mkfs -t ext3 /dev/houqdvg/houqdlv    # 创建文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=512 blocks, Stripe width=1536 blocks
118784 inodes, 475136 blocks
23756 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
58 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@compute-0 mnt]# 
        
       步骤七:挂载逻辑卷,先用mount命令挂载,然后定义在/etc/fstab中
 
[root@compute-0 mnt]# mkdir -p /mnt/lvm
[root@compute-0 mnt]# mount /dev/houqdvg/houqdlv /mnt/lvm/   # 挂载
[root@compute-0 mnt]# mount   # 查看所有挂载
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
/dev/mapper/houqdvg-houqdlv on /mnt/lvm type ext3 (rw)     # 我们挂载的
[root@compute-0 mnt]# vi /etc/fstab   # 设置每次开机自动挂载 
# /etc/fstab
# Created by anaconda on Wed Feb 27 13:44:14 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=4626a1a8-2485-4f14-a09a-6eef0a6c720e /                       ext4    defaults        1 1
UUID=74b536a0-9407-4214-98ed-11ba8b2d389c /boot                   ext4    defaults        1 2
UUID=a90215c9-be26-4884-bd0e-3799c7ddba7b swap                    swap    defaults        0 0
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/houqdvg/houqdlv    /mnt/lvm                ext3    defaults        1 2
 
(2) LVM扩容
 
步骤一:将第一个RAID转换为物理卷
 
[root@compute-0 mnt]# pvcreate /dev/md0
  Writing physical volume data to disk "/dev/md0"
  Physical volume "/dev/md0" successfully created
[root@compute-0 mnt]# 
 
步骤二:将物理卷加入到现有的逻辑卷组中
 
[root@compute-0 mnt]# vgextend houqdvg /dev/md0   
             # 将/dev/md0加入到houqdvg这个卷组中了
  Volume group "houqdvg" successfully extended
 
步骤三:查看逻辑卷组空间大小
 
[root@compute-0 mnt]# vgdisplay 
  --- Volume group ---
  VG Name               houqdvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               928.00 MiB
  PE Size               16.00 MiB
  Total PE              58    # 注:这里PE的总量增加了一倍,
  Alloc PE / Size       29 / 464.00 MiB
  Free  PE / Size       29 / 464.00 MiB    # 注:未分配的还有29个PE
  VG UUID               vBlcd2-qt6Y-Bt1D-v63K-oIJv-a3Hm-tPzoue
 
步骤四:将逻辑卷空间增加200M并查看逻辑卷空间大小
 
[root@compute-0 mnt]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/houqdvg/houqdlv
  VG Name                houqdvg
  LV UUID                T0L4cu-dqNC-PRHz-QQ3u-0ubi-VAWe-YquY7t
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                464.00 MiB    # 这是未增加之前的
  Current LE             29
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     6144
  Block device           253:0
   
[root@compute-0 mnt]# lvresize -L +200M /dev/houqdvg/houqdlv 
       # 注:-L 后面直接指定大小,或者也可以用 -l+PE的个数来指定 
  Rounding up size to full physical extent 208.00 MiB
  Extending logical volume houqdlv to 672.00 MiB
  Logical volume houqdlv successfully resized
[root@compute-0 mnt]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/houqdvg/houqdlv
  VG Name                houqdvg
  LV UUID                T0L4cu-dqNC-PRHz-QQ3u-0ubi-VAWe-YquY7t
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                672.00 MiB      # 可以看到该逻辑卷的确增加了200M
  Current LE             42
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     6144
  Block device           253:0
 
步骤五:将文件系统增加200M
 
[root@compute-0 mnt]# df /mnt/lvm/
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/houqdvg-houqdlv
                        460144     10543    425845   3% /mnt/lvm
    # 注:我们已经将逻辑卷/dev/houqdvg/houqdlv扩容了但是这里还是400多M
[root@compute-0 mnt]# resize2fs /dev/houqdvg/houqdlv 
    # 注:这里才是真正的对文件系统扩容,实际block块的大小是不会增加的,只是分组数增多了,响应的空间就大了
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/houqdvg/houqdlv is mounted on /mnt/lvm; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/houqdvg/houqdlv to 688128 (1k) blocks.
The filesystem on /dev/houqdvg/houqdlv is now 688128 blocks long.
[root@compute-0 mnt]# df /mnt/lvm/
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/houqdvg-houqdlv
                        666415     10789    621236   2% /mnt/lvm
    # 注:现在查看已经扩容
   
 OK,这周的实验就先到这里吧,下周有可能会根据这两周做的实验,讲一下关于系统快照的知识,看情况再说吧。

相关内容

    暂无相关文章