个人工具

“UbuntuHelp:UsingUUID”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/UsingUUID}} {{Languages|UbuntuHelp:UsingUUID}} Since Edgy, Ubuntu requires the use of '''UUID''' or '''LABEL''' (for filesystems including swap),...)
 
 
(未显示同一用户的7个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/UsingUUID}}
 
{{From|https://help.ubuntu.com/community/UsingUUID}}
 
{{Languages|UbuntuHelp:UsingUUID}}
 
{{Languages|UbuntuHelp:UsingUUID}}
 
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconDisks.png Linux now prefers to use '''UUID''' (Universally Unique Identifier), '''LABEL''', or symlinks to identify media storage devices on a system.  Directly using <code><nowiki>/dev/hd*#</nowiki></code> or <code><nowiki>/dev/sd*#</nowiki></code> is no longer preferred since these device assignments can change between system boots:
Since Edgy, Ubuntu requires the use of '''UUID''' or '''LABEL''' (for filesystems including swap), or udev-created symlinks (for removable media like CDROMs and USB drives).  Directly using <code><nowiki>/dev/hd*</nowiki></code> or <code><nowiki>/dev/sd*</nowiki></code> is no longer supported (since these device assignments can change from boot to boot):
+
* all filesystems should be specified by <code><nowiki>UUID=<id></nowiki></code> or <code><nowiki>LABEL=<name></nowiki></code> for each partition.
 
+
* all physical devices should be specified by a symlink, like <code><nowiki>/dev/cdrom</nowiki></code> for a cd drive and <code><nowiki>/dev/disk/by-id/...</nowiki></code> for each physical hard drive.
* all filesystems should be specified by <code><nowiki>UUID=</nowiki></code> or <code><nowiki>LABEL=</nowiki></code>
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=PicDocs.png The files for which UUID is most critical:
* all physical devices should be specified by a symlink (e.g. <code><nowiki>/dev/cdrom</nowiki></code>, <code><nowiki>/dev/disk/by-id/...</nowiki></code>, etc.)
+
 
+
The files for which this is most critical are:
+
 
* <code><nowiki>/boot/grub/menu.lst</nowiki></code>
 
* <code><nowiki>/boot/grub/menu.lst</nowiki></code>
 
* <code><nowiki>/etc/fstab</nowiki></code>
 
* <code><nowiki>/etc/fstab</nowiki></code>
 
* <code><nowiki>/etc/initramfs-tools/conf.d/resume</nowiki></code>
 
* <code><nowiki>/etc/initramfs-tools/conf.d/resume</nowiki></code>
 
+
This page uses the terminal a lot, so if you are new to this, see [[UbuntuHelp:UsingTheTerminal|UsingTheTerminal]].
==== Finding ====
+
== Finding UUIDs ==
 
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=eyes.png UUIDs can be determined using the <code><nowiki>vol_id</nowiki></code> or <code><nowiki>blkid</nowiki></code> commands.  The first command is used on individual partitions, the second command lists for all attached devices (mounted or not).
UUIDs can be determined using the <code><nowiki>vol_id</nowiki></code> command.  For example, to find the UUID for the filesystem on <code><nowiki>/dev/sda1</nowiki></code>:
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png Here are examples (your output will be different, but similarly formatted).  The command:
 
+
 
<pre><nowiki>
 
<pre><nowiki>
$ sudo /sbin/vol_id -u /dev/sda1
+
sudo vol_id -u /dev/sda2
79415992-7093-4a0e-a2e5-4574ed702d05
+
 
</nowiki></pre>
 
</nowiki></pre>
 
+
Note:  The utility vol_id doesn't exist in Karmic.
Symlinks created by udev can be found by searching for the target device in <code><nowiki>/dev</nowiki></code>. For example, to find <code><nowiki>/dev/sda1</nowiki></code>:
+
(for an ext3 filesystem) produces an output similar to:
 
+
 
<pre><nowiki>
 
<pre><nowiki>
$ ls -la /dev/disk/by-id | grep /sda1$
+
30fcb748-ad1e-4228-af2f-951e8e7b56df</nowiki></pre>
lrwxrwxrwx 1 root root  10 8207-06-10 02:46 ata-ST2250823AS_3ND277BL-part1 -> ../../sda1
+
and the command:
lrwxrwxrwx 1 root root  10 8207-06-10 02:46 scsi-1ATA_ST2250823AS_3ND277BL-part1 -> ../../sda1
+
<pre><nowiki>
 +
sudo blkid
 
</nowiki></pre>
 
</nowiki></pre>
 
+
produces an output similar to:
==== Converting ====
+
 
+
To perform these UUID lookups and corrections automatically (which should have already happened during the Dapper to Edgy upgrade) please use:
+
 
+
* For <code><nowiki>/boot/grub/menu.lst</nowiki></code>:
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo update-grub
+
/dev/sda1: TYPE="ntfs" UUID="72C0DE8EC0DE57C5" LABEL="windows"
 +
/dev/sda2: UUID="30fcb748-ad1e-4228-af2f-951e8e7b56df" SEC_TYPE="ext2" TYPE="ext3"
 +
/dev/sda5: TYPE="swap" UUID="8c4e69f8-5074-42c0-8134-0b2429c4c02c"
 +
/dev/sdb1: SEC_TYPE="msdos" UUID="4848-E35A" TYPE="vfat" </nowiki></pre>
 +
Alternatively you can list them from their listing in your root filesystem:
 +
<pre><nowiki>
 +
ls -l /dev/disk/by-uuid/
 
</nowiki></pre>
 
</nowiki></pre>
* For <code><nowiki>/etc/fstab</nowiki></code>:
+
produces an output similar to:
 
<pre><nowiki>
 
<pre><nowiki>
sudo rm -f /etc/fstab.pre-uuid
+
total 0
 +
lrwxrwxrwx 1 root root 10 2008-06-04 03:10 30fcb748-ad1e-4228-af2f- 951e8e7b56df -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 2008-06-07 16:51 4848-E35A -> ../../sdb1
 +
lrwxrwxrwx 1 root root 10 2008-06-04 03:10 72C0DE8EC0DE57C5 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 2008-06-04 03:10 8c4e69f8-5074-42c0-8134-0b2429c4c02c -> ../../sda5</nowiki></pre>
 +
== Converting to UUIDs ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconNote.png If you are using Ubuntu 6.06 [[UbuntuHelp:DapperDrake| Dapper Drake]] LTS, you can use these commands to "upgrade" to UUIDs.  '''All other supported versions of Ubuntu automatically use UUIDs, so this is not necessary.'''  You may be interested in having a look, anyway.
 +
=== Fstab ===
 +
For <code><nowiki>/etc/fstab</nowiki></code>:
 +
<pre><nowiki>
 +
sudo rm /etc/fstab.pre-uuid
 
sudo /var/lib/dpkg/info/volumeid.postinst configure
 
sudo /var/lib/dpkg/info/volumeid.postinst configure
 
</nowiki></pre>
 
</nowiki></pre>
* For <code><nowiki>/etc/initramfs-tools/conf.d/resume</nowiki></code>, there is no automatic procedure:
+
=== Grub ===
** Verify that <code><nowiki>RESUME=</nowiki></code> matches your <code><nowiki>swap</nowiki></code> line in <code><nowiki>/etc/fstab</nowiki></code>
+
For <code><nowiki>/boot/grub/menu.lst</nowiki></code>:
** After any adjustment, run <code><nowiki>sudo update-initramfs -u</nowiki></code>
+
<pre><nowiki>
 +
sudo update-grub
 +
</nowiki></pre>
 +
=== Resuming from Hibernation ===
 +
For <code><nowiki>/etc/initramfs-tools/conf.d/resume</nowiki></code>, there is no automatic procedure.  You must manually verify that <code><nowiki>RESUME=UUID=<some_UUID></nowiki></code> where <code><nowiki><some_UUID></nowiki></code> matches the UUID for the <code><nowiki>swap</nowiki></code> line in your <code><nowiki>/etc/fstab</nowiki></code> file.
 +
First check the contents of the files:
 +
<pre><nowiki>
 +
cat /etc/initramfs-tools/conf.d/resume
 +
cat /etc/fstab | grep swap
 +
</nowiki></pre>
 +
If the UUIDs do not match or do not exist in the <code><nowiki>resume</nowiki></code> file, open it for editing one of the following:
 +
<pre><nowiki>
 +
gksudo gedit /etc/initramfs-tools/conf.d/resume
 +
sudo nano -Bw /etc/initramfs-tools/conf.d/resume
 +
</nowiki></pre>
 +
Now add the correct UUID to the <code><nowiki>resume</nowiki></code> file in the format
 +
<pre><nowiki>
 +
RESUME=UUID=<swap_UUID></nowiki></pre>
 +
Save and close.
 +
'''After any adjustment, run:'''
 +
<pre><nowiki>
 +
sudo update-initramfs -u
 +
</nowiki></pre>
 +
== Using LABEL ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconNotes.png Labels can be very useful for external media, like flash drives and USB hard drives since these are generally automounted by <code><nowiki>hal</nowiki></code> (Hardware Abstraction Layer).  If a device has a label, it will be mounted at the <code><nowiki>/media/<label></nowiki></code> location and appear with the label on the desktop. 
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png For help with labeling devices, see [[UbuntuHelp:RenameUSBDrive|RenameUSBDrive]].
 +
== Symlinks ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconHandPointing.png Symlinks (symbolic links) are used to make it easier to identify a device.  For example <code><nowiki>/dev/cdrom</nowiki></code> can link to <code><nowiki>/dev/scd0</nowiki></code>.  These are normally created by '''udev''' which is the device manager program used in the Linux 2.6 kernel series.  We will not cover creating your own symlinks here (may be added later).
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconExample48.png Other examples of symlinks include <code><nowiki>/dev/floppy</nowiki></code> to <code><nowiki>/dev/fd0</nowiki></code> or <code><nowiki>/dev/dvd</nowiki></code> to <code><nowiki>/dev/scd1</nowiki></code> .
 +
You can view the linked device on a symlink with the <code><nowiki>ls</nowiki></code> command, like so:
 +
<pre><nowiki>
 +
ls -l /dev/cdrom
 +
</nowiki></pre>
 +
produces an output similar to:
 +
<pre><nowiki>
 +
lrwxrwxrwx 1 root root 4 2008-06-22 17:31 /dev/cdrom -> scd0</nowiki></pre>
 +
This tell us that <code><nowiki>/dev/cdrom</nowiki></code> is a symlink to the device <code><nowiki>/dev/scd0</nowiki></code> .
 +
To view the physical device identifiers (like for a hard drive, not to be confused with a disk's partitions), the command:
 +
<pre><nowiki>
 +
ls -l /dev/disk/by-id/
 +
</nowiki></pre>
 +
produces an output similar to:
 +
<pre><nowiki>
 +
total 0
 +
lrwxrwxrwx 1 root root  9 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5
 +
lrwxrwxrwx 1 root root  9 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb
 +
lrwxrwxrwx 1 root root 10 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1
 +
lrwxrwxrwx 1 root root  9 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5
 +
lrwxrwxrwx 1 root root  9 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb
 +
lrwxrwxrwx 1 root root 10 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1</nowiki></pre>
 +
Note that each partition (called ''part#'') identifies with their parent device - this is because they exist on that physical piece of hardware.  You will also notice that the drives and partitions appear twice, the first time as '''ata''' and the second time as '''scsi'''.  I am unclear as to why this is, but I believe it is related to IDE hard drives being identified to the system as SCSI drives (because of ide-scsi emulation?).
 +
== Other Resources  ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png Here are some other useful and related pages.
 +
* [[UbuntuHelp:Fstab|Fstab]]
 +
* [[UbuntuHelp:RenameUSBDrive|RenameUSBDrive]] - help with adding LABELs to partitions
 +
* [[UbuntuHelp:LinuxFilesystemsExplained|LinuxFilesystemsExplained]]
 +
* [http://ubuntu.wordpress.com/2006/03/01/editing-fat32-partition-labels-using-mtools/ Editing FAT32 Partition Labels using mtools].
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月20日 (四) 00:44的最新版本


IconsPage?action=AttachFile&do=get&target=IconDisks.png Linux now prefers to use UUID (Universally Unique Identifier), LABEL, or symlinks to identify media storage devices on a system. Directly using /dev/hd*# or /dev/sd*# is no longer preferred since these device assignments can change between system boots:

  • all filesystems should be specified by UUID=<id> or LABEL=<name> for each partition.
  • all physical devices should be specified by a symlink, like /dev/cdrom for a cd drive and /dev/disk/by-id/... for each physical hard drive.

IconsPage?action=AttachFile&do=get&target=PicDocs.png The files for which UUID is most critical:

  • /boot/grub/menu.lst
  • /etc/fstab
  • /etc/initramfs-tools/conf.d/resume

This page uses the terminal a lot, so if you are new to this, see UsingTheTerminal.

Finding UUIDs

IconsPage?action=AttachFile&do=get&target=eyes.png UUIDs can be determined using the vol_id or blkid commands. The first command is used on individual partitions, the second command lists for all attached devices (mounted or not). IconsPage?action=AttachFile&do=get&target=example.png Here are examples (your output will be different, but similarly formatted). The command:

sudo vol_id -u /dev/sda2

Note: The utility vol_id doesn't exist in Karmic. (for an ext3 filesystem) produces an output similar to:

 30fcb748-ad1e-4228-af2f-951e8e7b56df

and the command:

sudo blkid

produces an output similar to:

 /dev/sda1: TYPE="ntfs" UUID="72C0DE8EC0DE57C5" LABEL="windows" 
 /dev/sda2: UUID="30fcb748-ad1e-4228-af2f-951e8e7b56df" SEC_TYPE="ext2" TYPE="ext3" 
 /dev/sda5: TYPE="swap" UUID="8c4e69f8-5074-42c0-8134-0b2429c4c02c" 
 /dev/sdb1: SEC_TYPE="msdos" UUID="4848-E35A" TYPE="vfat" 

Alternatively you can list them from their listing in your root filesystem:

ls -l /dev/disk/by-uuid/

produces an output similar to:

 total 0
 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 30fcb748-ad1e-4228-af2f- 951e8e7b56df -> ../../sda2
 lrwxrwxrwx 1 root root 10 2008-06-07 16:51 4848-E35A -> ../../sdb1
 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 72C0DE8EC0DE57C5 -> ../../sda1
 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 8c4e69f8-5074-42c0-8134-0b2429c4c02c -> ../../sda5

Converting to UUIDs

IconsPage?action=AttachFile&do=get&target=info.png IconsPage?action=AttachFile&do=get&target=IconNote.png If you are using Ubuntu 6.06 Dapper Drake LTS, you can use these commands to "upgrade" to UUIDs. All other supported versions of Ubuntu automatically use UUIDs, so this is not necessary. You may be interested in having a look, anyway.

Fstab

For /etc/fstab:

sudo rm /etc/fstab.pre-uuid
sudo /var/lib/dpkg/info/volumeid.postinst configure

Grub

For /boot/grub/menu.lst:

sudo update-grub

Resuming from Hibernation

For /etc/initramfs-tools/conf.d/resume, there is no automatic procedure. You must manually verify that RESUME=UUID=<some_UUID> where <some_UUID> matches the UUID for the swap line in your /etc/fstab file. First check the contents of the files:

cat /etc/initramfs-tools/conf.d/resume
cat /etc/fstab | grep swap

If the UUIDs do not match or do not exist in the resume file, open it for editing one of the following:

gksudo gedit /etc/initramfs-tools/conf.d/resume
sudo nano -Bw /etc/initramfs-tools/conf.d/resume

Now add the correct UUID to the resume file in the format

 RESUME=UUID=<swap_UUID>

Save and close. After any adjustment, run:

sudo update-initramfs -u

Using LABEL

IconsPage?action=AttachFile&do=get&target=IconNotes.png Labels can be very useful for external media, like flash drives and USB hard drives since these are generally automounted by hal (Hardware Abstraction Layer). If a device has a label, it will be mounted at the /media/<label> location and appear with the label on the desktop. IconsPage?action=AttachFile&do=get&target=IconTip.png For help with labeling devices, see RenameUSBDrive.

Symlinks

IconsPage?action=AttachFile&do=get&target=IconHandPointing.png Symlinks (symbolic links) are used to make it easier to identify a device. For example /dev/cdrom can link to /dev/scd0. These are normally created by udev which is the device manager program used in the Linux 2.6 kernel series. We will not cover creating your own symlinks here (may be added later). IconsPage?action=AttachFile&do=get&target=IconExample48.png Other examples of symlinks include /dev/floppy to /dev/fd0 or /dev/dvd to /dev/scd1 . You can view the linked device on a symlink with the ls command, like so:

ls -l /dev/cdrom

produces an output similar to:

 lrwxrwxrwx 1 root root 4 2008-06-22 17:31 /dev/cdrom -> scd0

This tell us that /dev/cdrom is a symlink to the device /dev/scd0 . To view the physical device identifiers (like for a hard drive, not to be confused with a disk's partitions), the command:

ls -l /dev/disk/by-id/

produces an output similar to:

 total 0
 lrwxrwxrwx 1 root root  9 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5
 lrwxrwxrwx 1 root root  9 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb
 lrwxrwxrwx 1 root root 10 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1
 lrwxrwxrwx 1 root root  9 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3
 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5
 lrwxrwxrwx 1 root root  9 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb
 lrwxrwxrwx 1 root root 10 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1

Note that each partition (called part#) identifies with their parent device - this is because they exist on that physical piece of hardware. You will also notice that the drives and partitions appear twice, the first time as ata and the second time as scsi. I am unclear as to why this is, but I believe it is related to IDE hard drives being identified to the system as SCSI drives (because of ide-scsi emulation?).

Other Resources

IconsPage?action=AttachFile&do=get&target=IconBook-small.png Here are some other useful and related pages.