个人工具

UbuntuHelp:RenameUSBDrive

来自Ubuntu中文

跳转至: 导航, 搜索

IconsPage?action=AttachFile&do=get&target=IconDisks.png This guide is for editing partition labels (disk names) for FAT16/FAT32, NTFS, ext2/ext3, JFS, ReiserFS, and XFS filesystems.

Partition Editor

Nautilus currently does not support renaming partitions, but Gnome's Partition Editor (GParted) does. To change a partition's label, follow these directions. (Be careful using Partition Editor, as it's capable of making your computer completely unusable if you do the wrong thing.)

  1. Open the System > Administration menu and see if there's an entry for GParted (previously Partition Editor).
  2. If there is, launch it. If there isn't, install the "gparted" package and it should now appear in the menu. Enter your password when prompted.
  3. Disk drives are divided up into partitions. To find the partition you want to re-label, you first have to find the disk drive that contains it, using the drop-down menu in the upper right. It will show a device name like `/dev/sdb` and the drive's total size in parentheses. After selecting a drive, you will see a list of all partitions on that drive.
  4. If the partition is mounted (has a key icon next to it), right-click on the partition and select Unmount.
  5. With the key icon gone, right-click on the partition and select Label. If you can't select it, install the ntfsprogs package.
  6. Enter the new partition name and press Ok.
  7. The label change is now pending, but has not been completed. Press the Apply button near the top of the window. After confirming, it should say "All operations successfully completed". The drive now has a new label.

Command line

There are at least 6 separate command line tools 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, ext3, or ext4 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. IconsPage?action=AttachFile&do=get&target=IconTip.png Labeled devices that automount will be mounted in the /media directory using their label as the mount point, /media/<label>. ex: /media/my_external . <
>IconsPage?action=AttachFile&do=get&target=warning.png 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. IconsPage?action=AttachFile&do=get&target=important.png 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 MoveMountpointHowto which uses the file called Fstab.

Identify your Partition

IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png For help with the terminal, see 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

IconsPage?action=AttachFile&do=get&target=example.png 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

After you complete the appropriate porition for your filesystem, jump to the next section to verify the change.

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 (see Option 2 under "Change the label").

Change the label

Option 1

After unmounting and checking the current label (above), use

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

ex:

 sudo mlabel -i /dev/sdb1 ::my_external

Ignore the "Volume label is XYZ" output as this is the old label. Jump to the Verify the Change section below.

Option 2

For Ubuntu 8.10 and up, edit mtools.conf as sudo

sudo nano /etc/mtools.conf 

add something like for each drive:

 drive p: file="/dev/sdb1"
 drive q: file="/dev/sdb2"

etc. Then use

sudo mlabel p:new_label

ex:

 sudo mlabel p:30GB_FAT32

(note the underscore _ should be used, as spaces are not allowed) http://ubuntuforums.org/showpost.php?p=6356016&postcount=9

Error message

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

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, ext3, and ext4

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. Without unplugging and having the device remount, you can also just run:

sudo blkid

Other Resources

IconsPage?action=AttachFile&do=get&target=IconBook-small.png Some other related material: