歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> 記一次創建LVM的日志記錄,創建LVM日志記錄

記一次創建LVM的日志記錄,創建LVM日志記錄

日期:2017/3/6 8:55:29   编辑:學習Linux

記一次創建LVM的日志記錄,創建LVM日志記錄

記一次創建LVM的日志記錄,創建LVM日志記錄


先上一張鳥哥LVM的圖.感覺這張最清楚了.

#以下以Xshell的日志記錄系統直接記錄.上面添加了一些個人理解的注釋 
[BEGIN] 2016/9/13 9:22:24
#先查看下硬盤的情況.
[root@iZ23h637rtdZ ~]# fdisk -l

Disk /dev/vda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x00078f9c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1        7833    62912512   83  Linux

Disk /dev/vdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       65270   524281243+  8e  Linux LVM
#上面這裡顯示已經有LVM.但是為了方便演示. 下面先將這個刪除掉了
[root@iZ23h637rtdZ ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/vdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       65270   524281243+  8e  Linux LVM

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/vdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-65270, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-65270, default 65270): 
Using default value 65270

Command (m for help): p

Disk /dev/vdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       65270   524281243+  83  Linux
#此處使用t來修改格式.由於是需要LVM.所以需要改為8e的格式.
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       65270   524281243+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZ23h637rtdZ ~]# partprobe 
Warning: WARNING: the kernel failed to re-read the partition table on /dev/vda (Device or resource busy).  
As a result, it may not reflect all of your changes until after reboot. [root@iZ23h637rtdZ ~]# fdisk -l Disk /dev/vda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x00078f9c Device Boot Start End Blocks Id System /dev/vda1 * 1 7833 62912512 83 Linux Disk /dev/vdb: 536.9 GB, 536870912000 bytes 255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb Device Boot Start End Blocks Id System /dev/vdb1 1 65270 524281243+ 8e Linux LVM [root@iZ23h637rtdZ ~]# pvscan No matching physical volumes found #先建pv.後面接具體的劃分的路徑. [root@iZ23h637rtdZ ~]# pvcreate /dev/vdb1 Physical volume "/dev/vdb1" successfully created [root@iZ23h637rtdZ ~]# pvscan PV /dev/vdb1 lvm2 [499.99 GiB] Total: 1 [499.99 GiB] / in use: 0 [0 ] / in no VG: 1 [499.99 GiB] [root@iZ23h637rtdZ ~]# pvdisplay "/dev/vdb1" is a new physical volume of "499.99 GiB" --- NEW Physical volume --- PV Name /dev/vdb1 VG Name PV Size 499.99 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID GOeBQF-iCCD-n7i7-Y4DT-U5PE-tjHK-B9Z3CL #再建VG.由於是直接使用整個劃分的區塊,所以直接跟區塊名 /dev/vdb1,前面接的是vg名稱,這個隨便命名的. [root@iZ23h637rtdZ ~]# vgcreate mailbox_vg /dev/vdb1 Volume group "mailbox_vg" successfully created [root@iZ23h637rtdZ ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "mailbox_vg" using metadata type lvm2 [root@iZ23h637rtdZ ~]# pvscan PV /dev/vdb1 VG mailbox_vg lvm2 [499.99 GiB / 499.99 GiB free] Total: 1 [499.99 GiB] / in use: 1 [499.99 GiB] / in no VG: 0 [0 ] [root@iZ23h637rtdZ ~]# vgdisplay --- Volume group --- VG Name mailbox_vg 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 499.99 GiB PE Size 4.00 MiB Total PE 127998 Alloc PE / Size 0 / 0 Free PE / Size 127998 / 499.99 GiB VG UUID JjdDER-Y1OK-ICwZ-3FgC-cry2-bZYl-SqD3RP #下面需要創建LV.-l後面接的是pe的數量.這個可使用上面的vgdisplay的命令來查看. #然後後面接lv的名稱.也是可以隨便命名,但是個人建議這裡寫個可以區分的.要不到時難分清楚. [root@iZ23h637rtdZ ~]# lvcreate -l 127998 -n mailbox_lv mailbox_vg Logical volume "mailbox_lv" created [root@iZ23h637rtdZ ~]# lvdisplay --- Logical volume --- LV Path /dev/mailbox_vg/mailbox_lv LV Name mailbox_lv VG Name mailbox_vg LV UUID VPA4HE-22B4-gZc0-Qo8V-TO1C-tKaF-AT8s5T LV Write Access read/write LV Creation host, time iZ23h637rtdZ, 2016-09-13 09:25:34 +0800 LV Status available # open 0 LV Size 499.99 GiB Current LE 127998 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@iZ23h637rtdZ ~]# fdisk -l Disk /dev/vda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x00078f9c Device Boot Start End Blocks Id System /dev/vda1 * 1 7833 62912512 83 Linux Disk /dev/vdb: 536.9 GB, 536870912000 bytes 255 heads, 63 sectors/track, 65270 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: 0x3a7be7cb Device Boot Start End Blocks Id System /dev/vdb1 1 65270 524281243+ 8e Linux LVM Disk /dev/mapper/mailbox_vg-mailbox_lv: 536.9 GB, 536862523392 bytes 255 heads, 63 sectors/track, 65269 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: 0x00000000 #建好了.進行格式化 [root@iZ23h637rtdZ ~]# mkfs -t ext4 /dev/mailbox_vg/mailbox_lv 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 32768000 inodes, 131069952 blocks 6553497 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 4000 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 34 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. #創建掛載目錄,進行掛載. [root@iZ23h637rtdZ ~]# mkdir /mail_mailbox [root@iZ23h637rtdZ ~]# mount /dev/ Display all 179 possibilities? (y or n) [root@iZ23h637rtdZ ~]# mount /dev/mailbox_vg/mailbox_lv /mail_mailbox/ [root@iZ23h637rtdZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 59G 1.9G 55G 4% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/mapper/mailbox_vg-mailbox_lv 493G 70M 467G 1% /mail_mailbox #使用vim修改fstab的文件.讓其開機自動的掛載 . 以下是後面cat /etc/fstab的內容補上,這裡vim沒有記錄 -------------------------------------------------------------------------------------- [root@iZ23h637rtdZ ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Aug 14 21:16:42 2014 # # 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=94e4e384-0ace-437f-bc96-057dd64f42ee / ext4 defaults,barrier=0 1 1 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/mailbox_vg/mailbox_lv /mail_mailbox ext4 defaults 1 2 [root@iZ23h637rtdZ ~]# -------------------------------------------------------------------------------------- [root@iZ23h637rtdZ ~]# vim /etc/fstab #下面進行umount然後再mount -a測試一下fstab是否正常寫 [root@iZ23h637rtdZ ~]# umount /mail_mailbox/ [root@iZ23h637rtdZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 59G 1.9G 55G 4% / tmpfs 3.9G 0 3.9G 0% /dev/shm [root@iZ23h637rtdZ ~]# mount -a [root@iZ23h637rtdZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 59G 1.9G 55G 4% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/mapper/mailbox_vg-mailbox_lv 493G 70M 467G 1% /mail_mailbox [END] 2016/9/13 9:32:31

這裡到此就結束的.整合一下相關的一些步驟:

#fdisk /dev/vdb 
#pvcreate /dev/vdb1
#vgcreate mailbox_vg /dev/vdb1
#lvcreate -l 127998 -n mailbox_lv mailbox_vg
#mkfs -t ext4 /dev/mailbox_vg/mailbox_lv 
#mkdir /mail_mailbox
#mount /dev/mailbox_vg/mailbox_lv /mail_mailbox/

http://xxx/Linuxjc/1157900.html TechArticle

Copyright © Linux教程網 All Rights Reserved