歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux自動掛載文件系統詳解

Linux自動掛載文件系統詳解

日期:2017/2/28 14:37:31   编辑: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
Copyright © Linux教程網 All Rights Reserved