个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/RenameUSBDrive}}
 
{{From|https://help.ubuntu.com/community/RenameUSBDrive}}
 
{{Languages|UbuntuHelp:RenameUSBDrive}}
 
{{Languages|UbuntuHelp:RenameUSBDrive}}
== Editing ext2/ext3/JFS/ReiserFS/XFS/FAT32/NTFS Partition Labels ==
+
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconDisks.png%7D%7D  This guide is for editing FAT16/FAT32, NTFS, ext2/ext3, JFS, ReiserFS, and XFS filesystem partition labels.
There are 6 programs you use to label a drive. The program used depends on the partition type.
+
== Basics ==
*For '''FAT32''' Partitions you use '''Mtools'''.
+
There are 6 programs used to label a partition - the program used depends on the partition's [[UbuntuHelp:LinuxFilesystemsExplained| filesystem]] type:
*For '''NTFS''' Partitions you use '''ntfsprogs'''.
+
* For '''FAT16''' and '''FAT32''' partitions, use '''mtools'''.
*For '''ext2''' or '''ext3''' Partitions you use '''e2label'''.
+
* For '''NTFS''' partitions, use '''ntfsprogs'''.
*For '''JFS''' partitions you use '''jfs_tune'''.
+
* For '''ext2''' or '''ext3''' partitions, use '''e2label'''.
*For '''ReiserFS''' (v3) partitions you can use '''reiserfstune'''.
+
* For '''JFS''' partitions, use '''jfs_tune'''.
*For '''XFS''' partitions you use '''xfs_admin'''
+
* For '''ReiserFS''' (v3) partitions, use '''reiserfstune'''.
Instructions for all are given below.
+
* For '''XFS''' partitions, use '''xfs_admin'''
=== Identify your partition ===
+
By default, external drives automount at <code><nowiki>/media/disk</nowiki></code> then <code><nowiki>/media/disk-1</nowiki></code> and so on.  This is not very helpful when trying to find the drive you are looking for, especially if you have multiple devices plugged in.
Plug in your USB device and list your partitions with :
+
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png%7D%7D Labeled devices that automount will be mounted in the ''/media'' directory using their label as the mount point, <code><nowiki>/media/<label></nowiki></code>.  ex: <code><nowiki>/media/my_external</nowiki></code> .
 +
<<BR>>{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=warning.png%7D%7D When creating labels, be sure that the new mount point (based on the label) does not already exist since hal's automount function creates the directory when it mounts the device.
 +
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=important.png%7D%7D This guide is primarily for '''external drives''' such as USB hard drives, USB flash drives, and flash memory cards.  You can label internal disks, but to change their mount points, use [[UbuntuHelp:MoveMountpointHowto]] which uses the file called [[UbuntuHelp:Fstab]].
 +
== Identify your Partition ==
 +
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png%7D%7D For help with the terminal, see [[UbuntuHelp:UsingTheTerminal]].
 +
Plug in your USB device and list your partitions with:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo fdisk -l
 
sudo fdisk -l
 
</nowiki></pre>
 
</nowiki></pre>
Alternately, list your mounted devices with :
+
You can also list your mounted devices and their descriptions with:
 
<pre><nowiki>
 
<pre><nowiki>
 
mount
 
mount
 
</nowiki></pre>
 
</nowiki></pre>
Devices that auto mount will be mounted in /media using their label as a mount point (name).
+
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D For the rest of this tutorial we will use the following:
=== Editing FAT32 Partition Labels using mtools ===
+
* <device> = your device /dev/sdxy, ex: ''/dev/sdb1''
I wanted to rename the fat32 partitions that get automounted when they are plugged in to the USB drive. Two were exactly similar external hard disk drives, and one was an iPod. The exactly similar hard disk drives (one each at home and work) were both getting mounted at /media/sda1 or sda2 etc, and it was impossible to distinguish one from the other easily. Also, I found that it wasn’t that easy to edit the partition labels for FAT32 partitions. So I thought I would summarize how I named my fat32 partitions to have consistent names. This has the benefit that when these drives are automounted, they will be at the location /media/partition-label, where partition-label is the label that you give the partition.
+
* <label> = your desired (new) label, ex: ''my_external''
Step by step instructions to re-label FAT partitions follow:
+
== Install the Labeling Program ==
<device> = your device /dev/sdxy (Identified as above).
+
Based on the package names listed above for each filesystem type, install the correct package for your partition:
<Label> = your desired (new) Label.
+
==== Instructions: ====
+
==== 1) Install mtools: ====
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo apt-get install mtools
+
sudo apt-get install <package>
 
</nowiki></pre>
 
</nowiki></pre>
==== 2) After the usb drive is automounted after plugging in, find out the device descriptor using: ====
+
Here are all the different ones:
 
<pre><nowiki>
 
<pre><nowiki>
mount
+
sudo apt-get install mtools
</nowiki></pre>
+
sudo apt-get install ntfsprogs
and Note down where it says “sda2″ or similar
+
sudo apt-get install e2fsprogs
==== 3) Check what the label for the drive is currently: ====
+
sudo apt-get install jfsutils
 +
sudo apt-get install reiserfsprogs
 +
sudo apt-get install xfsprogs</nowiki></pre>
 +
or install the appropriate package from [[UbuntuHelp:SynapticHowto| Synaptic]].
 +
== Unmount the Partition ==
 +
Partitions generally need to be unmounted before you can fiddle with them, so unmount the partition of the device you want to change the label for:
 
<pre><nowiki>
 
<pre><nowiki>
sudo mlabel -i /dev/sda2 -s ::
+
sudo umount <device>
 
</nowiki></pre>
 
</nowiki></pre>
You may have to change sda2 to something else depending on what you got in step 2 above.
+
ex:
Note that we're using the special "::" drive which allows us to specify the device descriptor on the command line; otherwise we'd have to edit ~/.mtoolsrc to assign a drive letter.
+
==== 4) Change the label to something pretty: ====
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo mlabel -i /dev/sda2 ::my-ipod
+
sudo umount /dev/sdb1</nowiki></pre>
</nowiki></pre>
+
If it was automounted, you can also unmount the drive by right clicking the desktop icon and clicking '''Unmount''' (or '''Eject''' in some cases).
replace my-ipod with what you would like to name the usb drive
+
== Changing the Label ==
Note:  You may need to create a file named ".mtoolsrc" in your home directory that has the fallowing line in it:
+
=== FAT16 and FAT32 ===
mtools_skip_check=1
+
These filesystems are most often found on USB thumb drives, flash cards (like for a camera or cell phone), and older external USB hard drives.
 +
==== Check the current label ====
 
<pre><nowiki>
 
<pre><nowiki>
gedit ~/.mtoolsrc
+
sudo mlabel -i <device> -s ::
 
</nowiki></pre>
 
</nowiki></pre>
==== 5) Check if the label has changed: ====
+
ex:
 
<pre><nowiki>
 
<pre><nowiki>
sudo mlabel -i /dev/sda2 -s ::
+
sudo mlabel -i /dev/sdb1 -s ::</nowiki></pre>
</nowiki></pre>
+
Note that we're using the special "::" drive which allows us to specify the device descriptor on the command line; otherwise we'd have to edit <code><nowiki>~/.mtoolsrc</nowiki></code> to assign a drive letter.
I got the following output –
+
If you get a message like this:
Volume label is MY-IPOD
+
You’re all set!! The next time that partition gets automounted, it will be at /media/MY-IPOD
+
=== Editing NTFS Partition Labels using ntfsprogs ===
+
==== Instructions: ====
+
==== 1) Install ntfsprogs: ====
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo apt-get install ntfsprogs
+
Total number of sectors (7831520) not a multiple of sectors per track (63)!
 
</nowiki></pre>
 
</nowiki></pre>
==== 2) After the drive is automounted after plugging in, find out the device descriptor using: ====
+
You can easily ignore the check by running this command:
 
<pre><nowiki>
 
<pre><nowiki>
mount
+
echo mtools_skip_check=1 >> ~/.mtoolsrc
 
</nowiki></pre>
 
</nowiki></pre>
and Note down where it says “sda1″ or similar
+
==== Change the label ====
==== 3) Change the label to something pretty: ====
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo ntfslabel /dev/sda1 newlabel
+
sudo mlabel -i <device> ::<label>
 
</nowiki></pre>
 
</nowiki></pre>
replace '''newlabel''' with what you would like to name the usb drive / Harddisk
+
ex:
you may have to unmount the drive for this to work (system-> administration-> disks -> then under partitions for the hard disk hit disable).
+
==== 3) Check if the label has changed: ====
+
Restart your computer to see the label change if your harddrive is internal, and for usb just unplug/plug in USB again
+
=== Editing ext2 or ext3 Partition Labels using e2label ===
+
==== Instructions: ====
+
==== 1) After the drive is automounted after plugging in, find out the device descriptor using: ====
+
 
<pre><nowiki>
 
<pre><nowiki>
mount
+
sudo mlabel -i /dev/sdb1 ::my_external</nowiki></pre>
 +
=== NTFS ===
 +
This filesystem is most often found on external USB and firewire hard drives or other Windows formatted disks.
 +
==== Check the current label ====
 +
<pre><nowiki>
 +
sudo ntfslabel <device>
 
</nowiki></pre>
 
</nowiki></pre>
and Note down where it says “sda1″ or similar
+
ex:
==== 2) Change the label to something pretty: ====
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo e2label /dev/sda1 newlabel
+
sudo ntfslabel /dev/sdb1</nowiki></pre>
 +
==== Change the label ====
 +
Note: 128 characters maximum.
 +
<pre><nowiki>
 +
sudo ntfslabel <device> <label>
 
</nowiki></pre>
 
</nowiki></pre>
replace '''newlabel''' with what you would like to name the usb drive / Harddisk
+
ex:
you may have to unmount the drive for this to work (system-> administration-> disks -> then under partitions for the hard disk hit disable).
+
<pre><nowiki>
==== 3) Check if the label has changed: ====
+
sudo ntfslabel /dev/sdb1 my_external</nowiki></pre>
Restart your computer to see the label change if your harddrive is internal, and for usb just unplug/plug in USB again
+
Ubuntu caches the drive's label so to see full affects of the change it is not enough just to umount and mount it again, the you should umount, remove, put back, mount again.
=== Editing JFS partition labels using jfs_tune ===
+
=== ext2 and ext3 ===
==== Instructions: ====
+
These filesystems are most often found on linux formatted drives.
Show label :
+
==== Check the current label ====
 
<pre><nowiki>
 
<pre><nowiki>
jfs_tune -l <device>
+
sudo e2label <device>
 
</nowiki></pre>
 
</nowiki></pre>
Set a new label :
+
ex:
 
<pre><nowiki>
 
<pre><nowiki>
jfs_tune -L <Label> <device>
+
sudo e2label /dev/sdb1</nowiki></pre>
 +
==== Change the label ====
 +
Note: 16 characters maximum.
 +
<pre><nowiki>
 +
sudo e2label <device> <label>
 
</nowiki></pre>
 
</nowiki></pre>
<device> = your device /dev/sdxy
+
ex:
<Label>  = your desired (new) Label
+
=== Editing ReiserFS v3 partition labels using reiserfstune ===
+
Note: this could work with ReiserFS 4 too, I have not tried.
+
==== 1) After the drive is automounted after plugging in, find out the device descriptor using:  ====
+
 
<pre><nowiki>
 
<pre><nowiki>
mount
+
sudo e2label /dev/sdb1 my_external</nowiki></pre>
 +
=== JFS ===
 +
These filesystems are most often found on IBM and some linux formatted disks.
 +
==== Check the current label ====
 +
<pre><nowiki>
 +
sudo jfs_tune -l <device>
 
</nowiki></pre>
 
</nowiki></pre>
and Note down where it says “sda1″ or similar; Or you could simply open '''gnome-system-monitor''' and take note of the mount point of the partitions you want to label.
+
ex:
==== 2) Unmount the partitions you want to label ====
+
For example:
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo umount /dev/sda1
+
sudo jfs_tune /dev/sdb1</nowiki></pre>
 +
==== Change the label ====
 +
Note: 16 characters maximum.
 +
<pre><nowiki>
 +
sudo jfs_tune -L <label> <device>
 
</nowiki></pre>
 
</nowiki></pre>
==== 3) Change the label to something pretty ====
+
ex:
(note: 16 characters maximum)
+
<pre><nowiki>
 +
sudo jfs_tune -L my_external /dev/sdb1</nowiki></pre>
 +
=== ReiserFS (v3) ===
 +
This filesystem is most often found on linux formatted disks.
 +
Note: this could work with ReiserFS 4 too, I have not tried.
 +
==== Change the label ====
 +
Note: 16 characters maximum.
 
<pre><nowiki>
 
<pre><nowiki>
sudo reiserfstune -l 'johnny' /dev/sda1
+
sudo reiserfstune -l <label> <device>
 
</nowiki></pre>
 
</nowiki></pre>
=== Editing XFS partition labels using xfs_admin ===
+
ex:
==== Instructions: ====
+
<pre><nowiki>
Show label :
+
sudo reiserfstune -l my_external /dev/sdb1</nowiki></pre>
 +
=== XFS ===
 +
This filesystem is most often found on UNIX formatted disks.
 +
==== Check the current label ====
 
<pre><nowiki>
 
<pre><nowiki>
 
xfs_admin -l <device>
 
xfs_admin -l <device>
 
</nowiki></pre>
 
</nowiki></pre>
Set a new label :
+
ex:
 
<pre><nowiki>
 
<pre><nowiki>
sudo xfs_admin -L <Label> <device>
+
xfs_admin -l /dev/sdb1</nowiki></pre>
 +
==== Change the label ====
 +
Note: 12 characters maximum.
 +
<pre><nowiki>
 +
sudo xfs_admin -L <label> <device>
 
</nowiki></pre>
 
</nowiki></pre>
<device> = your device /dev/sdxy
+
ex:
<Label> = your desired (new) Label
+
<pre><nowiki>
 +
xfs_admin -l my_external /dev/sdb1</nowiki></pre>
 +
== Verify the Change ==
 +
Now for the easiest part: unplug the drive, wait a second, then plug it back in.  It should appear on your desktop with the new label and have its new mount point.
 +
== Other Resources ==
 +
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png%7D%7D Some other related material:
 +
* [[UbuntuHelp:MoveMountpointHowto]]
 +
* [[UbuntuHelp:LinuxFilesystemsExplained]]
 +
* [[UbuntuHelp:Fstab]]
 +
* [[UbuntuHelp:MountingWindowsPartitions]]
 +
* [[UbuntuHelp:MountingWindowsPartitions/ThirdPartyNTFS3G]]
 
----
 
----
=== Credits ===
+
[[category:CategoryDocumentation]] [[category:CategoryUsb]]
The information on this page was originally copied from http://ubuntu.wordpress.com/, and i believe it deserves to be in the wiki because the wiki is where i looked  when i first had this problem.
+
==== ReiserFS part by Jeff ====
+
Just added this from my knowledge (which came from various forum posts and bug reports)
+
== Comments ==
+
* There's no GUI method (Nautilus?) to rename partitions?
+
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
+
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2008年10月19日 (日) 17:04的版本

{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconDisks.png%7D%7D This guide is for editing FAT16/FAT32, NTFS, ext2/ext3, JFS, ReiserFS, and XFS filesystem partition labels.

Basics

There are 6 programs used to label a partition - the program used depends on the partition's filesystem type:

  • For FAT16 and FAT32 partitions, use mtools.
  • For NTFS partitions, use ntfsprogs.
  • For ext2 or ext3 partitions, use e2label.
  • For JFS partitions, use jfs_tune.
  • For ReiserFS (v3) partitions, use reiserfstune.
  • For XFS partitions, use xfs_admin

By default, external drives automount at /media/disk then /media/disk-1 and so on. This is not very helpful when trying to find the drive you are looking for, especially if you have multiple devices plugged in. {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png%7D%7D Labeled devices that automount will be mounted in the /media directory using their label as the mount point, /media/<label>. ex: /media/my_external . <
>{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=warning.png%7D%7D When creating labels, be sure that the new mount point (based on the label) does not already exist since hal's automount function creates the directory when it mounts the device. {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=important.png%7D%7D This guide is primarily for external drives such as USB hard drives, USB flash drives, and flash memory cards. You can label internal disks, but to change their mount points, use UbuntuHelp:MoveMountpointHowto which uses the file called UbuntuHelp:Fstab.

Identify your Partition

{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png%7D%7D For help with the terminal, see UbuntuHelp:UsingTheTerminal. Plug in your USB device and list your partitions with:

sudo fdisk -l

You can also list your mounted devices and their descriptions with:

mount

{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D For the rest of this tutorial we will use the following:

  • <device> = your device /dev/sdxy, ex: /dev/sdb1
  • <label> = your desired (new) label, ex: my_external

Install the Labeling Program

Based on the package names listed above for each filesystem type, install the correct package for your partition:

sudo apt-get install <package>

Here are all the different ones:

 sudo apt-get install mtools
 sudo apt-get install ntfsprogs
 sudo apt-get install e2fsprogs
 sudo apt-get install jfsutils
 sudo apt-get install reiserfsprogs
 sudo apt-get install xfsprogs

or install the appropriate package from Synaptic.

Unmount the Partition

Partitions generally need to be unmounted before you can fiddle with them, so unmount the partition of the device you want to change the label for:

sudo umount <device>

ex:

 sudo umount /dev/sdb1

If it was automounted, you can also unmount the drive by right clicking the desktop icon and clicking Unmount (or Eject in some cases).

Changing the Label

FAT16 and FAT32

These filesystems are most often found on USB thumb drives, flash cards (like for a camera or cell phone), and older external USB hard drives.

Check the current label

sudo mlabel -i <device> -s ::

ex:

 sudo mlabel -i /dev/sdb1 -s ::

Note that we're using the special "::" drive which allows us to specify the device descriptor on the command line; otherwise we'd have to edit ~/.mtoolsrc to assign a drive letter. If you get a message like this:

Total number of sectors (7831520) not a multiple of sectors per track (63)!

You can easily ignore the check by running this command:

echo mtools_skip_check=1 >> ~/.mtoolsrc

Change the label

sudo mlabel -i <device> ::<label>

ex:

 sudo mlabel -i /dev/sdb1 ::my_external

NTFS

This filesystem is most often found on external USB and firewire hard drives or other Windows formatted disks.

Check the current label

sudo ntfslabel <device>

ex:

 sudo ntfslabel /dev/sdb1

Change the label

Note: 128 characters maximum.

sudo ntfslabel <device> <label>

ex:

 sudo ntfslabel /dev/sdb1 my_external

Ubuntu caches the drive's label so to see full affects of the change it is not enough just to umount and mount it again, the you should umount, remove, put back, mount again.

ext2 and ext3

These filesystems are most often found on linux formatted drives.

Check the current label

sudo e2label <device>

ex:

 sudo e2label /dev/sdb1

Change the label

Note: 16 characters maximum.

sudo e2label <device> <label>

ex:

 sudo e2label /dev/sdb1 my_external

JFS

These filesystems are most often found on IBM and some linux formatted disks.

Check the current label

sudo jfs_tune -l <device>

ex:

 sudo jfs_tune /dev/sdb1

Change the label

Note: 16 characters maximum.

sudo jfs_tune -L <label> <device>

ex:

 sudo jfs_tune -L my_external /dev/sdb1

ReiserFS (v3)

This filesystem is most often found on linux formatted disks. Note: this could work with ReiserFS 4 too, I have not tried.

Change the label

Note: 16 characters maximum.

sudo reiserfstune -l <label> <device>

ex:

 sudo reiserfstune -l my_external /dev/sdb1

XFS

This filesystem is most often found on UNIX formatted disks.

Check the current label

xfs_admin -l <device>

ex:

 xfs_admin -l /dev/sdb1

Change the label

Note: 12 characters maximum.

sudo xfs_admin -L <label> <device>

ex:

 xfs_admin -l my_external /dev/sdb1

Verify the Change

Now for the easiest part: unplug the drive, wait a second, then plug it back in. It should appear on your desktop with the new label and have its new mount point.

Other Resources

{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png%7D%7D Some other related material: