next up previous contents
Next: 邏輯捲軸管理 Up: 邏輯捲軸管理員 Previous: 邏輯捲軸管理員   Contents

產生邏輯捲軸

  1. 何謂LVM?
    • LVM (Logical Volume Manager):邏輯捲軸管理員。
    • LVM 目的為彈性進行 filesystem 的擴充或縮小。
  2. PV, PE, VG, LV 的意義
    • Physical Volume, PV, 實體捲軸:partition 時需要調整系統識別碼 (system ID) 成為 8e (LVM 的識別碼)。
    • Volume Group, VG, 捲軸群組:將許多 PV 整合而成。
    • Physical Extend, PE, 實體延伸區塊:LVM 最小的儲存區塊。
    • Logical Volume, LV, 邏輯捲軸:從 VG 切割而成,為最後可被格式化使用之格式,LV 的裝置檔名通常指定為『 /dev/vgname/lvname 』的樣式。

    \begin{picture}(300,150)
\put(0,0){\dashbox{3}(330,140)[tr]{\Large VG}}
\multipu...
...120)[b]{\Large PV}}
\put(15,87){\dashbox{2}(150,45)[c]{\Large LV}}
\end{picture}
  3. 建立 LVM partitions
    [root@instructor ~]# fdisk -c /dev/sda
    
    Command (m for help): p
    
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x2bd2c32a
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          17      131072   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              17        4096    32768000   8e  Linux LVM
    /dev/sda3            4096        6646    20480000   8e  Linux LVM
    /dev/sda4            6646       60802   435006464    5  Extended
    /dev/sda5            6646        7952    10485760   83  Linux
    /dev/sda6            7952       10563    20979362   8e  Linux LVM
    /dev/sda7           10564       11869    10490413+  8e  Linux LVM
    
    Command (m for help): n
    First cylinder (11870-60802, default 11870): 
    Using default value 11870
    Last cylinder, +cylinders or +size{K,M,G} (11870-60802, default 60802): +1G
    
    Command (m for help): n
    First cylinder (12002-60802, default 12002): 
    Using default value 12002
    Last cylinder, +cylinders or +size{K,M,G} (12002-60802, default 60802): +1G
    
    Command (m for help): p
    
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x2bd2c32a
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          17      131072   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              17        4096    32768000   8e  Linux LVM
    /dev/sda3            4096        6646    20480000   8e  Linux LVM
    /dev/sda4            6646       60802   435006464    5  Extended
    /dev/sda5            6646        7952    10485760   83  Linux
    /dev/sda6            7952       10563    20979362   8e  Linux LVM
    /dev/sda7           10564       11869    10490413+  8e  Linux LVM
    /dev/sda8           11870       12001     1060258+  83  Linux
    /dev/sda9           12002       12133     1060258+  83  Linux
    
    Command (m for help): t
    Partition number (1-10): 8
    Hex code (type L to list codes): 8e
    Changed system type of partition 8 to 8e (Linux LVM)
    
    Command (m for help): t
    Partition number (1-10): 9
    Hex code (type L to list codes): 8e
    Changed system type of partition 9 to 8e (Linux LVM)
    
    Command (m for help): p
    
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x2bd2c32a
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          17      131072   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              17        4096    32768000   8e  Linux LVM
    /dev/sda3            4096        6646    20480000   8e  Linux LVM
    /dev/sda4            6646       60802   435006464    5  Extended
    /dev/sda5            6646        7952    10485760   83  Linux
    /dev/sda6            7952       10563    20979362   8e  Linux LVM
    /dev/sda7           10564       11869    10490413+  8e  Linux LVM
    /dev/sda8           11870       12001     1060258+  8e  Linux LVM
    /dev/sda9           12002       12133     1060258+  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 or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    [root@instructor ~]# partprobe 
    Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
    device-mapper: remove ioctl failed: Device or resource busy
    device-mapper: remove ioctl failed: Device or resource busy
    Warning: parted was unable to re-read the partition table on /dev/mapper/GLSguest-demo-real (Device or resource busy).  This means Linux won't know anything about the modifications you made. 
    [root@instructor ~]# reboot
    [root@instructor ~]# fdisk -l /dev/sda
    
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x2bd2c32a
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          17      131072   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              17        4096    32768000   8e  Linux LVM
    /dev/sda3            4096        6646    20480000   8e  Linux LVM
    /dev/sda4            6646       60802   435006464    5  Extended
    /dev/sda5            6646        7952    10485760   83  Linux
    /dev/sda6            7952       10563    20979362   8e  Linux LVM
    /dev/sda7           10564       11869    10490413+  8e  Linux LVM
    /dev/sda8           11870       12001     1060258+  8e  Linux LVM
    /dev/sda9           12002       12133     1060258+  8e  Linux LVM
    

  4. 產生 PV
    [root@instructor ~]# pvscan 
      PV /dev/sda3   VG GLSguest   lvm2 [19.50 GiB / 5.00 GiB free]
      PV /dev/sda2   VG GLSvg      lvm2 [31.22 GiB / 0    free]
      PV /dev/sda6   VG GLSvg      lvm2 [20.00 GiB / 6.44 GiB free]
      PV /dev/sda7   VG GLSvg      lvm2 [10.00 GiB / 10.00 GiB free]
      Total: 4 [80.72 GiB] / in use: 4 [80.72 GiB] / in no VG: 0 [0   ]
    [root@instructor ~]# pvcreate /dev/sda{8,9,10}
      Physical volume "/dev/sda8" successfully created
      Physical volume "/dev/sda9" successfully created
      Physical volume "/dev/sda10" successfully created
    [root@instructor ~]# pvscan 
      PV /dev/sda3    VG GLSguest        lvm2 [19.50 GiB / 5.00 GiB free]
      PV /dev/sda2    VG GLSvg           lvm2 [31.22 GiB / 0    free]
      PV /dev/sda6    VG GLSvg           lvm2 [20.00 GiB / 6.44 GiB free]
      PV /dev/sda7    VG GLSvg           lvm2 [10.00 GiB / 10.00 GiB free]
      PV /dev/sda8                       lvm2 [1.01 GiB]
      PV /dev/sda9                       lvm2 [1.01 GiB]
      PV /dev/sda10                      lvm2 [2.01 GiB]
      Total: 7 [84.75 GiB] / in use: 4 [80.72 GiB] / in no VG: 3 [4.03 GiB]
    
    [root@instructor ~]# pvdisplay 
      "/dev/sda8" is a new physical volume of "1.01 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sda8
      VG Name               
      PV Size               1.01 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               oaj98p-1kMw-LdJh-57yS-zxEf-MX1m-31XoZr
       
      "/dev/sda9" is a new physical volume of "1.01 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sda9
      VG Name               
      PV Size               1.01 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               iugncx-zGZr-CDt9-PIU3-jq5n-54ec-2KJjQR
       
      "/dev/sda10" is a new physical volume of "2.01 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sda10
      VG Name               
      PV Size               2.01 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               Ko6qem-n1mm-YMLd-pDMl-Ee0z-PClw-DcEI9b
    

  5. 產生 VG
    [root@instructor ~]# vgcreate -s 32M dywvg /dev/sda{8,9}
      Volume group "dywvg" successfully created
    [root@instructor ~]# vgscan
      Reading all physical volumes.  This may take a while...
      Found volume group "dywvg" using metadata type lvm2
      Found volume group "GLSguest" using metadata type lvm2
      Found volume group "GLSvg" using metadata type lvm2
    [root@instructor ~]# pvscan 
      PV /dev/sda8    VG dywvg           lvm2 [1.00 GiB / 0    free]
      PV /dev/sda9    VG dywvg           lvm2 [1.00 GiB / 736.00 MiB free]
      PV /dev/sda3    VG GLSguest        lvm2 [19.50 GiB / 5.00 GiB free]
      PV /dev/sda2    VG GLSvg           lvm2 [31.22 GiB / 0    free]
      PV /dev/sda6    VG GLSvg           lvm2 [20.00 GiB / 6.44 GiB free]
      PV /dev/sda7    VG GLSvg           lvm2 [10.00 GiB / 10.00 GiB free]
      PV /dev/sda10                      lvm2 [2.01 GiB]
      Total: 7 [84.73 GiB] / in use: 6 [82.72 GiB] / in no VG: 1 [2.01 GiB]
    [root@instructor ~]# vgdisplay dywvg 
      --- Volume group ---
      VG Name               dywvg
      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               0
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               2.00 GiB
      PE Size               32.00 MiB
      Total PE              64
      Alloc PE / Size       50 / 1.56 GiB
      Free  PE / Size       14 / 448.00 MiB
      VG UUID               NK9GXl-AVxX-g5Vj-Xx0n-HtRD-a9YW-F5mu0W
    
  6. 產生 LV
    [root@instructor ~]# lvcreate -l 50 -n dywlv dywvg
      Logical volume "dywlv" created
    [root@instructor ~]# ll /dev/dywvg/dywlv 
    lrwxrwxrwx. 1 root root 8 Jul 10 19:26 /dev/dywvg/dywlv -> ../dm-20
    [root@instructor ~]# lvdisplay /dev/dywvg/dywlv
      --- Logical volume ---
      LV Name                /dev/dywvg/dywlv
      VG Name                dywvg
      LV UUID                0U1tft-9dii-XLEp-fNv4-kf1d-Vu5J-m2ZMYo
      LV Write Access        read/write
      LV Status              available
      # open                 0
      LV Size                1.56 GiB
      Current LE             50
      Segments               2
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:20
    

  7. 建立檔案系統
    [root@instructor ~]# mkfs.ext3 /dev/dywvg/dywlv 
    mke2fs 1.41.12 (17-May-2010)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    102544 inodes, 409600 blocks
    20480 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=419430400
    13 block groups
    32768 blocks per group, 32768 fragments per group
    7888 inodes per group
    Superblock backups stored on blocks: 
    	32768, 98304, 163840, 229376, 294912
    
    Writing inode tables: done                            
    Creating journal (8192 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 26 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    
    [root@instructor ~]# mkdir /mnt/dywlvm
    [root@instructor ~]# mount /dev/dywvg/dywlv /mnt/dywlvm
    [root@instructor ~]# df -h /mnt/dywlvm
    Filesystem               1K-blocks   Used Available Use% Mounted on
    /dev/mapper/dywvg-dywlv  1.6G        35M   1.5G      3%   /mnt/dywlvm
    



2015-04-13