系統重啓後 sda sdb順序變化 pv vg lv dm

在Linux下往往會碰到這樣的問題,磁盤的設備文件,比如/dev/sda, sdb, sdc等等在某些情況下會混亂掉,比如sda變成了sdb或者sdc變成了sdb等等,這樣無形中會導致磁盤
在Linux下往往會碰到這樣的問題,磁盤的設備文件,比如/dev/sda, sdb, sdc等等在某些情況下會混亂掉,比如sda變成了sdb或者sdc變成了sdb等等,這樣無形中會導致磁盤設備管理的混亂,最常見的比如Linux文件 系統的啓動問題。很多人在遇到這種問題的時候都去找磁盤、陣列廠家,懷疑是他們的問題,其實這種底層的磁盤(單個磁盤或者RAID陣列)和Linux下磁 盤設備文件的映射並不是磁盤、陣列廠家來決定的,而是Linux內核自身的原因。

目前Linux內核對於這種磁盤設備的映射基本上取決於三個順序,
一是磁盤驅動程序的加載;
二是主機PCI插槽的監測;
三是磁盤本身的監測,先來的當然是a,以此類推。所以,在出現熱插拔了某些設備、重啓等特殊情況下,實際磁盤在Linux下映射的設備文件可能由於這種“排隊”的原因而發生改變,而這種底層“偷偷的”變化有時候會讓管理員犯一些低級錯誤。

這是Linux Kernel的限制,所以目前還沒辦法來正面的克服應對,但有兩個“迂迴戰術”的辦法來減少可能出現的問題,一個是採用UUID設備唯一識別的方法,另一個是採用對設備卷做Label標識的辦法。

一、 UUID (globally unique identifier),唯一的身份識別,是採用SCSI Inquiry命令的Page 83信息來映射磁盤設備的。例如我們可以在Linux下查詢一些磁盤設備的UUID標識代碼。

引用

bash# ls -la /dev/disk/by-id
total 0
drwxr-xr-x 2 root root 280 Mar 11 12:29 .
drwxr-xr-x 5 root root 100 Mar 11 12:28 ..
lrwxrwxrwx 1 root root 9 Mar 11 12:29 edd-int13_dev80 -> ../../sda
lrwxrwxrwx 1 root root 10 Mar 11 12:29 edd-int13_dev80-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Mar 11 12:29 edd-int13_dev80-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Mar 11 12:29 edd-int13_dev80-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Mar 11 12:29 edd-int13_dev80-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Mar 11 12:29 edd-int13_dev80-part6 -> ../../sda6
lrwxrwxrwx 1 root root 9 Mar 11 12:28 scsi-3600050e03d7c67007bf400009f890000 -
> ../../sda
lrwxrwxrwx 1 root root 10 Mar 11 12:28 scsi-3600050e03d7c67007bf400009f890000-p
art1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Mar 11 12:28 scsi-3600050e03d7c67007bf400009f890000-p
art3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Mar 11 12:28 scsi-3600050e03d7c67007bf400009f890000-p
art4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Mar 11 12:28 scsi-3600050e03d7c67007bf400009f890000-p
art5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Mar 11 12:28 scsi-3600050e03d7c67007bf400009f890000-p
art6 -> ../../sda6

找到了磁盤設備唯一的UUID代碼後,就可以加到/etc/grub.conf和/etc/fstab中,這樣即使初始的系統盤sda變成了sdb,但Linux和文件系統的啓動加載都是按照UUID來的,所以上層也不會受到影響,例如,
在 /etc/grub.conf系統啓動入口中做以下更改:

引用

kernel /boot/vmlinuz-2.6.27.7 root=/dev/disk/by-id/scsi-3600050e03d7c67007bf400009f890000-part1


在 /etc/fstab文件系統啓動入口中做以下更改:

引用

/dev/disk/by-id/scsi-3600050e03d7c67007bf400009f890000-part1 / ext3 1 1
/dev/disk/by-id/scsi-234892819987c8f828473829becf38289-part2 /home ext3 1 1



二、 第二種算是比較老式的解決方法,即對磁盤卷設置Label標籤,同樣的道理,系統啓動的時候只看標籤,不看底層的sda/sdb等設備號,所以也不會影響到系統、文件系統的啓動。例如,
使用e2label命令對sda1和sdb1設置標籤:

引用

/sbin/e2label /dev/sda1 myroot
/sbin/e2label /dev/sdb1 myhome

之後在 /etc/grub.conf 系統啓動入口中做以下更改:
kernel /boot/vmlinuz-2.6.29 ro root=LABEL=myroot
在 /etc/fstab文件系統啓動入口中做以下更改:

引用

LABEL=myroot / ext3 defaults 1 1
LABEL=myhome /home ext3 defaults 1 1



當然,以上兩種都是爲了不影響系統和文件系統的啓動採用的變通方法,在實際的系統管理時還是要密切注意底層設備的變化,否則如果出現了磁盤分區誤刪除的事情罪過可就大了



====================================================

one disk or disk partition can be considerred a PV, like sda, or sda1, or sda2.

every PV is divided into PE. usually it is 4M byte.

one , or more than one PV form a VG.

For example, disk sda was divided 2 partition, sda1 and sda2.

sda1 was used to store boot loader, so we don't need to create lv on it.

sda2 was used to store data,so we need to create VG on it, and then create LV on VG.


df -lh

Filesystem                   1K-blocks     Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  51606140  8690444  40294256  18% /
tmpfs                          1820768      236   1820532   1% /dev/shm
/dev/sda1                       495844    69544    400700  15% /boot
/dev/mapper/VolGroup-lv_home  50395844  1084612  46751232   3% /home
/dev/mapper/VolGroup-lv_opt  100791728 16247552  79424176  17% /opt

from above output, there were not VG and LV on disk partition /dev/sda1


the LV, like lv_home,lv_root,lv_opt, shoul be create on sda2.

 vgdisplay --verbose
    Finding all volume groups
    Finding volume group "VolGroup"
  --- Volume group ---
  VG Name               VolGroup
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               465.27 GiB
  PE Size               4.00 MiB
  Total PE              119109
  Alloc PE / Size       50300 / 196.48 GiB
  Free  PE / Size       68809 / 268.79 GiB
  VG UUID               eiUY7U-YAne-xuce-o08D-ikv7-ue9Q-pK7whN
   
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                gR5yI0-OBRg-mSew-cXhm-LHRc-4IjE-u0af9s
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-05-24 21:04:09 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_opt
  LV Name                lv_opt
  VG Name                VolGroup
  LV UUID                FJJ5O0-N8ZV-0CBE-VbS6-bwhe-R3ft-tQ8Dem
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-05-24 21:04:19 +0800
  LV Status              available
  # open                 1
  LV Size                97.66 GiB
  Current LE             25000
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_home
  LV Name                lv_home
  VG Name                VolGroup
  LV UUID                YSulS6-YfCa-3fsP-YGt7-1Xy9-65Rc-aUOk2D
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-05-24 21:04:38 +0800
  LV Status              available
  # open                 1
  LV Size                48.83 GiB
  Current LE             12500
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               t05rhs-cX12-y03y-fZWk-BDoo-MEvc-BBAhLv
  PV Status             allocatable
  Total PE / Free PE    119109 / 68809

fdisk -l

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 / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xbb9abb9a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       60802   487873536   8e  Linux LVM

 from the above ouput, and considerring the previous output, sda1 was not used to lvm, sda2 was used to LVM, that means sda2 as a PV form a VG, and create some LV on VG.


Basically, the disk sda could be a local disk, or a local virtual disk which consist of RAID.


Furtherly, linux use device mapper(DM) .

# iostat -x
Linux 2.6.32-431.el6.x86_64 (15090279host)     06/19/2016     _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.85    0.00    0.43    0.27    0.00   97.45

Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.44    29.03    1.61    1.58    51.93   238.07    91.03     0.10   32.52   3.77   1.20
dm-0            0.00     0.00    1.89   22.98    49.19   183.65     9.37     7.66  308.28   0.24   0.59
dm-1              0.00     0.00    0.03    0.00     0.23     0.00     7.95     0.00    3.36   0.88   0.00
dm-2              0.00     0.00    0.09    6.44     1.47    52.25     8.23     0.51   78.08   1.00   0.65

[root@15090279host linux-2.6.32]# cd /dev/mapper/
[root@15090279host mapper]# ls -l
total 0
crw-rw---- 1 root root 10, 58 Jun 19 00:10 control
lrwxrwxrwx 1 root root      7 Jun 19 00:10 VolGroup-lv_home -> ../dm-2
lrwxrwxrwx 1 root root      7 Jun 19 00:10 VolGroup-lv_opt -> ../dm-1
lrwxrwxrwx 1 root root      7 Jun 19 00:10 VolGroup-lv_root -> ../dm-0


 ls -l
total 0
lrwxrwxrwx 1 root root 7 Jun 19 00:10 lv_home -> ../dm-2
lrwxrwxrwx 1 root root 7 Jun 19 00:10 lv_opt -> ../dm-1
lrwxrwxrwx 1 root root 7 Jun 19 00:10 lv_root -> ../dm-0
[root@15090279host VolGroup]# pwd
/dev/VolGroup

best practice:

VG shoud reserve a number of space for space extend(emergency, or normal).

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章