1. 程式人生 > >Centos/RHEL :How to add,delete and display LVM tags

Centos/RHEL :How to add,delete and display LVM tags

1. 什麼是LVM標籤?

  在你想開機啟動時讓邏輯卷被啟用可用時,新增lvm標籤是一個不錯的選擇。lvm標籤允許那些被預先標記的實現這樣的效果。

2. 配置檔案

  配置檔案/etc/lvm/lvm.conf中有這樣一段話:

# vim /etc/lvm/lvm.conf
    # If volume_list is defined, each LV is only activated if there is a
    # match against the list.
    #
    #   "vgname" and "vgname/lvname" are matched exactly.
    #   
"@tag" matches any tag set in the LV or VG. # "@*" matches if any tag defined on the host is also set in the LV or VG # # If any host tags exist but volume_list is not defined, a default # single-entry list containing "@*" is assumed. # # volume_list = [ "vg1", "vg2/lvol1", "
@tag1", "@*" ]

3. 新增LVM標籤

  1. vgchange 這個命令是用於新增或刪除一個標籤,請看下面的語法。在下面的例子中,標籤“lvm_test_tag”被新增到"vg_test"邏輯組裡。

# vgchange --addtag lvm_test_tag /dev/vg_test
        Volume group "vg_test" successfully changed

  2. 你可以確認上述操作是否正確

# vgs -o vg_tags /dev/vg_test
        VG Tags
        lvm_test_tag

  3. 修改配置檔案/etc/lvm/lvm.conf:在上面的配置檔案的相關部分下面新增一個與例子相同的volume_list:

# vim /etc/lvm/lvm.conf

    ...
    volume_list = ["vg_test","@lvm_test_tag"]
    ...

  這樣,帶有“lvm_test_tag”標籤的VGs就只會在開機啟動時被啟用

4. 刪除LVM標籤

  1. 想要刪除一個標籤的話,用 -deltag標誌,如下所示:

# vgchange --deltag lvm_test_tag /dev/vg_test
    Volume group "vg_test" successfully changed

  2. 確認一下是否刪除了標籤

# vgs -o vgtags /dev/vg_test
    VG Tags

  如果你僅僅是想為一個單一lv而不是整個邏輯組修改標籤的話,請用lvchange代替vgchange

5. 為邏輯卷新增、刪除LVM標籤

  如果遇到給個別邏輯卷而不是整個邏輯組新增標籤的情況時,借鑑上面的命令,只要把vgchange改為lvchange就可以,只是用於顯示LVM標籤的命令不一樣,如下所示:

# lvs -o lv_tags
    LV Tags