next up previous contents
Next: 開機自動掛載 Up: 邏輯捲軸管理員 Previous: 單一指令放大縮小 LV   Contents

產生邏輯捲冊

  1. 檢查硬碟分割區,確認硬碟編號為 /dev/vda。
    [root@kvm7 ~]# lsblk 
    NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda                 252:0    0    4G  0 disk 
    ├─vda1              252:1    0  200M  0 part /boot
    ├─vda2              252:2    0  3.4G  0 part 
    │ ├─vg_kvm7usb-swap 253:0    0  124M  0 lvm  [SWAP]
    │ └─vg_kvm7usb-root 253:1    0  3.1G  0 lvm  /
    ├─vda3              252:3    0  130M  0 part 
    │ └─vg_kvm7home-vo  253:2    0   30M  0 lvm  /home
    ├─vda4              252:4    0    1K  0 part 
    └─vda5              252:5    0   10M  0 part [SWAP]
    
  2. fdisk /dev/vda 建立 LVM partitions。
    [root@kvm7 ~]# fdisk /dev/vda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000cd485
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    /dev/vda4         7845888     8388607      271360    5  Extended
    /dev/vda5         7847936     7868415       10240   82  Linux swap / Solaris
    
    Command (m for help): n
    All primary partitions are in use
    Adding logical partition 6
    First sector (7870464-8388607, default 7870464): 
    Using default value 7870464
    Last sector, +sectors or +size{K,M,G} (7870464-8388607, default 8388607): 
    Using default value 8388607
    Partition 6 of type Linux and of size 253 MiB is set
    
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000cd485
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    /dev/vda4         7845888     8388607      271360    5  Extended
    /dev/vda5         7847936     7868415       10240   82  Linux swap / Solaris
    /dev/vda6         7870464     8388607      259072   83  Linux
    Command (m for help): t
    Partition number (1-6, default 6): 
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000cd485
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    /dev/vda4         7845888     8388607      271360    5  Extended
    /dev/vda5         7847936     7868415       10240   82  Linux swap / Solaris
    /dev/vda6         7870464     8388607      259072   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.
    
  3. 載入新的硬碟分割表。
    [root@kvm7 ~]# partprobe /dev/vda
    [root@kvm7 ~]# kpartx /dev/vda
    vda1 : 0 409600 /dev/vda 2048
    vda2 : 0 7168000 /dev/vda 411648
    vda3 : 0 266240 /dev/vda 7579648
    vda4 : 0 2 /dev/vda 7845888
    vda5 : 0 20480 /dev/vda 7847936
    vda6 : 0 518144 /dev/vda 7870464
    
  4. 檢查硬碟分割區,確認硬碟 /dev/vda 分割區出現 vda6。
    [root@kvm7 ~]# lsblk 
    NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda                 252:0    0    4G  0 disk 
    ├─vda1              252:1    0  200M  0 part /boot
    ├─vda2              252:2    0  3.4G  0 part 
    │ ├─vg_kvm7usb-swap 253:0    0  124M  0 lvm  [SWAP]
    │ └─vg_kvm7usb-root 253:1    0  3.1G  0 lvm  /
    ├─vda3              252:3    0  130M  0 part 
    │ └─vg_kvm7home-vo  253:2    0   30M  0 lvm  /home
    ├─vda4              252:4    0    1K  0 part 
    ├─vda5              252:5    0   10M  0 part [SWAP]
    └─vda6              252:6    0  253M  0 part
    
  5. 查看 pv 可用指令。
    [root@kvm7 ~]# pv [TAB}{TAB]
    pvchange   pvcreate   pvmove     pvresize   pvscan     
    pvck       pvdisplay  pvremove   pvs
    
  6. 查看目前只有兩個 PV。
    [root@kvm7 ~]# pvscan 
      PV /dev/vda2   VG vg_kvm7usb    lvm2 [3.41 GiB / 172.00 MiB free]
      PV /dev/vda3   VG vg_kvm7home   lvm2 [128.00 MiB / 98.00 MiB free]
      Total: 2 [3.54 GiB] / in use: 2 [3.54 GiB] / in no VG: 0 [0   ]
    
  7. 將 /dev/vda6 建立為 PV。
    [root@kvm7 ~]# pvcreate /dev/vda6
      Physical volume "/dev/vda6" successfully created
    
  8. 再查看 /dev/vda6 是新建立的 PV,但還沒有 VG。
    [root@kvm7 ~]# pvscan 
      PV /dev/vda2   VG vg_kvm7usb    lvm2 [3.41 GiB / 172.00 MiB free]
      PV /dev/vda3   VG vg_kvm7home   lvm2 [128.00 MiB / 98.00 MiB free]
      PV /dev/vda6                    lvm2 [253.00 MiB]
      Total: 3 [3.79 GiB] / in use: 2 [3.54 GiB] / in no VG: 1 [253.00 MiB]
    
  9. 查看 vg 可用指令。
    [root@kvm7 ~]# vg [TAB][TAB]
    vgcfgbackup    vgconvert      vgextend       vgmknodes      vgs
    vgcfgrestore   vgcreate       vgimport       vgreduce       vgscan
    vgchange       vgdisplay      vgimportclone  vgremove       vgsplit
    vgck           vgexport       vgmerge        vgrename
    
  10. 查看 vgcreate 輔助說明。
    [root@kvm7 ~]# vgcreate --help
      vgcreate: Create a volume group
    
    vgcreate
    	[-A|--autobackup {y|n}]
    	[--addtag Tag]
    	[--alloc AllocationPolicy]
    	[-c|--clustered {y|n}]
    	[--commandprofile ProfileName]
    	[-d|--debug]
    	[-h|--help]
    	[-l|--maxlogicalvolumes MaxLogicalVolumes]
    	[--metadataprofile ProfileName]
    	[-M|--metadatatype 1|2]
    	[--[vg]metadatacopies #copies]
    	[-p|--maxphysicalvolumes MaxPhysicalVolumes]
    	[-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]]
    	[-t|--test]
    	[-v|--verbose]
    	[--version]
    	[-y|--yes]
    	[ PHYSICAL DEVICE OPTIONS ]
    	VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
    
  11. 在 PV /dev/vda6 上建立名為 vg_mnt PE size 2M 的 VG。
    [root@kvm7 ~]# vgcreate -s 2M vg_mnt /dev/vda6
      Volume group "vg_mnt" successfully created
    
  12. 查看 lv 可用指令。
    [root@kvm7 ~]# lv [TAB][TAB]
    lvchange     lvextend     lvmdiskscan  lvmsar       lvresize     
    lvconvert    lvm          lvmdump      lvreduce     lvs          
    lvcreate     lvmchange    lvmetad      lvremove     lvscan       
    lvdisplay    lvmconf      lvmsadc      lvrename
    
  13. 查看 lv 輔助說明。
    [root@kvm7 ~]# lvcreate --help
      lvcreate: Create a logical volume
    
    lvcreate
    	[-A|--autobackup {y|n}]
    	[-a|--activate [a|e|l]{y|n}]
    	[--addtag Tag]
    	[--alloc AllocationPolicy]
    	[-H|--cache
    	  [--cachemode {writeback|writethrough}]
    	[--cachepool CachePoolLogicalVolume{Name|Path}]
    	[-c|--chunksize ChunkSize]
    	[-C|--contiguous {y|n}]
    	[--commandprofile ProfileName]
    	[-d|--debug]
    	[-h|-?|--help]
    	[--errorwhenfull {y|n}]
    	[--ignoremonitoring]
    	[--monitor {y|n}]
    	[-i|--stripes Stripes [-I|--stripesize StripeSize]]
    	[-k|--setactivationskip {y|n}]
    	[-K|--ignoreactivationskip]
    	{-l|--extents LogicalExtentsNumber[%{VG|PVS|FREE}] |
    	 -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
    	[-M|--persistent {y|n}] [-j|--major major] [--minor minor]
    	[--metadataprofile ProfileName]
    	[-m|--mirrors Mirrors [--nosync]
    	  [{--mirrorlog {disk|core|mirrored}|--corelog}]]
    	[-n|--name LogicalVolumeName]
    	[--noudevsync]
    	[-p|--permission {r|rw}]
    	[--poolmetadatasize MetadataSize[bBsSkKmMgG]]
    	[--poolmetadataspare {y|n}]]
    	[--[raid]minrecoveryrate Rate]
    	[--[raid]maxrecoveryrate Rate]
    	[-r|--readahead {ReadAheadSectors|auto|none}]
    	[-R|--regionsize MirrorLogRegionSize]
    	[-T|--thin
    	  [--discards {ignore|nopassdown|passdown}]
    	[--thinpool ThinPoolLogicalVolume{Name|Path}]
    	[-t|--test]
    	[--type VolumeType]
    	[-v|--verbose]
    	[-W|--wipesignatures {y|n}]
    	[-Z|--zero {y|n}]
    	[--version]
    	VolumeGroupName [PhysicalVolumePath...]
    
  14. vg_mnt 上建立名為 pub,大小為 12 個 PE 的 LV。
    [root@kvm7 ~]# lvcreate -l 12 -n pub vg_mnt
      Logical volume "pub" created.
    
  15. 依照要求 (此例為 vfat )格式化 vg_mnt-pub
    [root@kvm7 ~]# mkfs.vfat /dev/vg_mnt/pub 
    mkfs.fat 3.0.20 (12 Jun 2013)
    unable to get drive geometry, using default 255/63
    



2017-07-10