UbuntuWiki:UdevLvm
文章出处: |
{{#if: | {{{2}}} | https://wiki.ubuntu.com/UdevLvm }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/af | • {{#if: UbuntuWiki:UdevLvm|Afrikaans| [[::UbuntuWiki:UdevLvm/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ar | • {{#if: UbuntuWiki:UdevLvm|العربية| [[::UbuntuWiki:UdevLvm/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/az | • {{#if: UbuntuWiki:UdevLvm|azərbaycanca| [[::UbuntuWiki:UdevLvm/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/bcc | • {{#if: UbuntuWiki:UdevLvm|جهلسری بلوچی| [[::UbuntuWiki:UdevLvm/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/bg | • {{#if: UbuntuWiki:UdevLvm|български| [[::UbuntuWiki:UdevLvm/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/br | • {{#if: UbuntuWiki:UdevLvm|brezhoneg| [[::UbuntuWiki:UdevLvm/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ca | • {{#if: UbuntuWiki:UdevLvm|català| [[::UbuntuWiki:UdevLvm/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/cs | • {{#if: UbuntuWiki:UdevLvm|čeština| [[::UbuntuWiki:UdevLvm/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/de | • {{#if: UbuntuWiki:UdevLvm|Deutsch| [[::UbuntuWiki:UdevLvm/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/el | • {{#if: UbuntuWiki:UdevLvm|Ελληνικά| [[::UbuntuWiki:UdevLvm/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/es | • {{#if: UbuntuWiki:UdevLvm|español| [[::UbuntuWiki:UdevLvm/es|español]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/fa | • {{#if: UbuntuWiki:UdevLvm|فارسی| [[::UbuntuWiki:UdevLvm/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/fi | • {{#if: UbuntuWiki:UdevLvm|suomi| [[::UbuntuWiki:UdevLvm/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/fr | • {{#if: UbuntuWiki:UdevLvm|français| [[::UbuntuWiki:UdevLvm/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/gu | • {{#if: UbuntuWiki:UdevLvm|ગુજરાતી| [[::UbuntuWiki:UdevLvm/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/he | • {{#if: UbuntuWiki:UdevLvm|עברית| [[::UbuntuWiki:UdevLvm/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/hu | • {{#if: UbuntuWiki:UdevLvm|magyar| [[::UbuntuWiki:UdevLvm/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/id | • {{#if: UbuntuWiki:UdevLvm|Bahasa Indonesia| [[::UbuntuWiki:UdevLvm/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/it | • {{#if: UbuntuWiki:UdevLvm|italiano| [[::UbuntuWiki:UdevLvm/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ja | • {{#if: UbuntuWiki:UdevLvm|日本語| [[::UbuntuWiki:UdevLvm/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ko | • {{#if: UbuntuWiki:UdevLvm|한국어| [[::UbuntuWiki:UdevLvm/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ksh | • {{#if: UbuntuWiki:UdevLvm|Ripoarisch| [[::UbuntuWiki:UdevLvm/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/mr | • {{#if: UbuntuWiki:UdevLvm|मराठी| [[::UbuntuWiki:UdevLvm/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ms | • {{#if: UbuntuWiki:UdevLvm|Bahasa Melayu| [[::UbuntuWiki:UdevLvm/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/nl | • {{#if: UbuntuWiki:UdevLvm|Nederlands| [[::UbuntuWiki:UdevLvm/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/no | • {{#if: UbuntuWiki:UdevLvm|norsk| [[::UbuntuWiki:UdevLvm/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/oc | • {{#if: UbuntuWiki:UdevLvm|occitan| [[::UbuntuWiki:UdevLvm/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/pl | • {{#if: UbuntuWiki:UdevLvm|polski| [[::UbuntuWiki:UdevLvm/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/pt | • {{#if: UbuntuWiki:UdevLvm|português| [[::UbuntuWiki:UdevLvm/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ro | • {{#if: UbuntuWiki:UdevLvm|română| [[::UbuntuWiki:UdevLvm/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/ru | • {{#if: UbuntuWiki:UdevLvm|русский| [[::UbuntuWiki:UdevLvm/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/si | • {{#if: UbuntuWiki:UdevLvm|සිංහල| [[::UbuntuWiki:UdevLvm/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/sq | • {{#if: UbuntuWiki:UdevLvm|shqip| [[::UbuntuWiki:UdevLvm/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/sr | • {{#if: UbuntuWiki:UdevLvm|српски / srpski| [[::UbuntuWiki:UdevLvm/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/sv | • {{#if: UbuntuWiki:UdevLvm|svenska| [[::UbuntuWiki:UdevLvm/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/th | • {{#if: UbuntuWiki:UdevLvm|ไทย| [[::UbuntuWiki:UdevLvm/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/tr | • {{#if: UbuntuWiki:UdevLvm|Türkçe| [[::UbuntuWiki:UdevLvm/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/vi | • {{#if: UbuntuWiki:UdevLvm|Tiếng Việt| [[::UbuntuWiki:UdevLvm/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/yue | • {{#if: UbuntuWiki:UdevLvm|粵語| [[::UbuntuWiki:UdevLvm/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/zh | • {{#if: UbuntuWiki:UdevLvm|中文| [[::UbuntuWiki:UdevLvm/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/zh-hans | • {{#if: UbuntuWiki:UdevLvm|中文(简体)| [[::UbuntuWiki:UdevLvm/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuWiki:UdevLvm | UbuntuWiki:UdevLvm | {{#if: | :}}UbuntuWiki:UdevLvm}}/zh-hant | • {{#if: UbuntuWiki:UdevLvm|中文(繁體)| [[::UbuntuWiki:UdevLvm/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuWiki:UdevLvm|:UbuntuWiki:UdevLvm|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :UbuntuWiki:UdevLvm/zh | | {{#ifexist: UbuntuWiki:UdevLvm/zh | | {{#ifeq: {{#titleparts:UbuntuWiki:UdevLvm|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:UbuntuWiki:UdevLvm|1|-1|}} | zh | | }}
Please check the status of this specification in Launchpad before editing it. If it is Approved, contact the Assignee or another knowledgeable person before making changes.
- Launchpad entry: udev-lvm
- Packages affected: udev, lvm2
Summary
This specification details how to make udev and LVM play nicely together, in particular ensuring that udev events are issued for LVM volumes and that UUIDs are correctly exported and do not conflict.
Rationale
LVM is used by system administrators to collect block devices together into Volume Groups and then split them into Logical Volumes which can be readily resized and adjusted within the group without needing complicated work. In order to support event-based mounting of these filesystems, we need reliable events from the block subsystem and no race conditions.
Use cases
- Fabio uses a combination of LVM and RAID for his root filesystem, he would like this to continue to be supported.
Scope
The scope of this specification is limited to the interaction between udev and LVM2; other specifications address similar concerns with device-mapper (on which LVM is based), RAID, etc.
Design
`vgchange -ay` is the command run to iterate all block devices on the system (filtered by CD-ROM, etc. devices) and combine them into volume groups, and activate logical volumes. If the necessary components of a group cannot be found, it is not activated.
This can be run directly from a udev rule whenever an LVM block device is added to the system. `vol_id` can be used to determine whether a block device is an LVM Physical Volume or not.
As LVM builds Logical Volumes using device-mapper, a further block event will be issued when the logical volume has been activated.
There is a race between `vgchange` creating the `/dev/VGNAME/LVNAME` symlinks and udev receiving the device-mapper block event for the device that those should point to. For this reason, `vgchange` will be instructed not to create these symlinks and instead `vgmknodes` will be called from a udev rule for device-mapper block devices.
When mirroring is involved, it's possible for a logical volume to be mounted even though it's not yet complete. We will offer the option of forcing a partial volume group mount after a timeout if it has not yet been activated.
As with device-mapper, the Volume Group and Logical Volume name, and thus the device path, consitutes a unique identifier; there is no need for UUID or LABEL support for these block devices. We will continue to ignore them.
Implementation
- Patch `vgchange` to accept an option to inhibit device symlink creation.
- Add a udev rule to call vgchange when block devices are added:
SUBSYSTEM=="block", RUN+="watershed /sbin/vgchange -ay --no-symlinks"
- Add a udev rule to call vgmknodes when device-mapper block devices are added:
SUBSYSTEM=="block", KERNEL=="dm-[0-9]*", RUN+="watershed /sbin/vgmknodes"
- Modify the mountroot script to give the option of attempting `vgchange -P` after a timeout.
The `watershed` command used in the rules above is a tool to ensure that `vgchange` is run as many times as are necessary to process the incoming events. It works by locking a known filename, clearing a state file, and then running the command. If it cannot lock, it writes to the state file, and exits. When the command finishes, it checks the state file, and if it exists it loops and runs the command again.
This means that if two events come in hours apart, it is run twice. If one hundred come in in rapid sequence, it will be run at least twice, but usually not 100 times.
Notes from the actual implementation
The "race between vgchange creating the /dev/VGNAME/LVNAME symlinks and udev receiving the device-mapper block event" is that the udev rules for processing the dm device for the lv might run before the symlinks are created.
In fact, this is addressed as follows: the new rule for running vgchange as a result new block devices will apply both to the pv device and to the lv dm device (set up by vgchange run as a result of the pv vgchange). In both cases, vgchange will take out the vg lock. This means that the second vgchange (which does nothing very much) cannot exit until the first has finished (ie, the symlink is present). Putting the vgchange udev rule earlier in the sequence than other rules is sufficient to avoid the race.
Limitation: The system, as designed above, will not cope at all with device removal events.
-- IanJackson 8.12.2006
Implementation status
The changes to lvm2 have been uploaded, but proper testing must wait until integration test: both (i) the udev "watershed" feature and (ii) proper handling of dm devices by higher layers are missing. The specified change to "the mountroot script" has not yet been made either.
-- IanJackson 8.12.2006