歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux存儲實驗二:LVM操作

Linux存儲實驗二:LVM操作

日期:2017/3/1 16:27:53   编辑:關於Linux
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,這周的實驗就先到這裡吧,下周有可能會根據這兩周做的實驗,講一下關於系統快照的知識,看情況再說吧。
Copyright © Linux教程網 All Rights Reserved