文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用label而不是设备名来挂载文件系统

使用label而不是设备名来挂载文件系统

时间:2007-05-10  来源:ypxing

When you're dealing with multiple drives, both fixed and removable, it can get hard to remember which is which. Remembering to mount /dev/sda1 in one place and /dev/sdc5 in another. The solution to this problem is to use labels instead of partition names when referring to them, and here we'll show how that can be done.

There are two things you need to do to start using labels:

  • Add the label to your filesystem(s), or more properly partitions.
  • Use the names rather than anything else to refer to your partitions.

To add a label you must use the tune2fs command, specifying the partition to modify and the label to add.

Upon my home system I have only a single disk /dev/sda which has three partitions:

 Name Flags Size (MB)
-------------------------------------------
sda1 Linux ext3 20003.89
sda2 swap 3002.23
sda3 Linux LVM 297064.22

To add the label "root" to my root partition, /dev/sda1, I'd run:

root@mine:~# tune2fs -Lroot /dev/sda1

Once I've got a label in place it becomes visible in my partition list when I run "cfdisk /dev/sda", so I know it has worked.

Once the label has been put into place there are now two places which I need to update the system in order to use it:

  • /etc/fstab
    • This file lists the partitions/file-systems which should be mounted at boot-time
  • /boot/grub/menu.lst
    • This file configures my boot-loader so that the system will boot.

In both cases the change is the same, instead of specifying /dev/sda1 I specify LABEL=root.

My /etc/fstab file now looks like this:

#
# /etc/fstab - static file system information.
#
LABEL=root / ext3 defaults,errors=remount-ro 0 1
/dev/sda2 none swap sw 0 0
...
...

The grub configuration file was updated to change:

# kopt=root=/dev/sda1 ro acpi=off noapic

into this:

# kopt=root=LABEL=root ro acpi=off noapic

Once this was done the kernel(s) can be updated by running update-grub. This updated my Xen kernels and my Debian kernels to include the new root - for example:

title Xen 3.0.3-1-amd64 / Debian GNU/Linux, kernel 2.6.18-4-xen-amd64
root (hd0,0)
kernel /boot/xen-3.0.3-1-amd64.gz
module /boot/vmlinuz-2.6.18-4-xen-amd64 root=LABEL=root ro acpi=off noapic console=tty0
module /boot/initrd.img-2.6.18-4-xen-amd64
savedefault

The advantage of doing this is that I can now use identical configuration files upon each of my hosts, and rely upon the labels to make sure the correct partition is used as my root filesystem. This is very useful when you're configuring your systems via CFEngine, or similar.

相关阅读 更多 +
排行榜 更多 +
拉力竞速2

拉力竞速2

体育竞技 下载
文字乱舞水浒

文字乱舞水浒

角色扮演 下载
蓝图公考

蓝图公考

学习教育 下载