Linux自动挂载文件系统详解


Linux磁盘自动挂载必须,而且必要,不然每次重启后都要挂载就太麻烦啦。


1. 查看系统中磁盘信息,并确定是否需要分区
首先,为了需要,新添加一块磁盘到linux主机中,
目的是让这个新添加的磁盘分区格式化并可以随系统启动自动挂载。

[root@localhost ~]# fdisk -l
【此处是sda的磁盘信息】
Disk /dev/sda: 299.4 GB, 299439751168 bytes
255 heads, 63 sectors/track, 36404 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 36404 292310707+ 8e Linux LVM


【此处是sdb的磁盘信息】
Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table 【此处显示磁盘dev/sdb尚未格式化】

如上所示,系统中有两块磁盘sda、sdb,并提示sdb未含有分区表,需要将其进行分区操作。


2.对磁盘进行分区操作
磁盘容量与主分区、扩展分区、逻辑分区的关系:


硬盘的容量=主分区的容量+扩展分区的容量
扩展分区的容量=各个逻辑分区的容量之和

一块物理硬盘只能有:
一到四个主分区(但其中只能有一个是活动的主分区),
或一到三个主分区,和一个扩展分区。分别对应hda1,hda2,hda3,hda4.

Linux 中规定,每一个硬盘设备最多能有 4 个主分区(其中包含扩展分区)构成,
任何一个扩展分区都要占用一个主分区号码,也就是在一个硬盘中,主分区和扩展分区一共最多是 4 个。

一块硬盘可以只设主分区,这时主分区可设置4个分区号。


也可以设置成主分区+逻辑分区,这时也是最多4个分区号码,但是变成了4 = 3 + 1.
. 其中4是主分区和扩展分区加起来最多4个;
. 3是主分区,可以小于或等于3;
. 1是扩展分区号,占用了一个主分区号。


[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 182024.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


Command (m for help): p 【显示磁盘基本信息】
Disk /dev/sdb: 1497.1 GB, 1497198755840 bytes
255 heads, 63 sectors/track, 182024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System


【此处可以看出,尚未对磁盘进行分区】
Command (m for help):n    【n:add a new partition】
Command action
e extended      【选择主分区还是扩展分区】
p primary partition (1-4)
p
Partition number (1-4): 1  【选择分区数】
First cylinder (1-182024, default 1): 【设置分区大小。此处选择默认值,直接回车
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-182024, default 182024):
Using default value 182024
Command (m for help):w    【如无误输入w保存配置信息,如不保存输入q退出】
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks


【再检查一下分区成功与否】
$ fdisk /dev/sdb
The number of cylinders for this disk is set to 182024.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): p   【如下查看分区之后的磁盘信息】
Disk /dev/sdb: 1497.1 GB, 1497198755840 bytes
255 heads, 63 sectors/track, 182024 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System
/dev/sdb1 1 182024 1462107748+ 5 Extended


Command (m for help): q
  • 1
  • 2
  • 下一页

相关内容