先把須要掛載的硬盤正確鏈接到電腦上,查看 BIOS,確保開機自檢時,BIOS 可以檢測並識別出新鏈接的硬盤,而後再進行下面的操做。
[root@Linux ~]# fdisk -l //查看當前磁盤信息,就會發現最下面顯示新加入的硬盤不是有效分區,以下:
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10241406 83 Linux
/dev/sda2 1276 2349 8626905 83 Linux
/dev/sda3 2350 2610 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@Linux ~]# 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 2610.
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)
//這一步能夠不作,就是能夠經過輸入 h 查看幫助信息
Command (m for help): h
h: unknown command
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
//這一步是必須作的
Command (m for help): n //輸入 n,新建分區
Command action
e extended //新建邏輯分區
p primary partition (1-4) //新建主分區
p //輸入 p,創建主分區
Partition number (1-4): 1 //一共能夠分4個主分區,輸入 1,創建第一個主分區
First cylinder (1-2610, default 1): //選擇該分區的起始磁盤數,如無特殊需求強烈建議選擇默認,也就是默認用1 來分區(直接按回車)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): //定義該分區的大小,若是按默認(直接回車),就是使用所有可用存儲空間;若是要分紅一個 1G 的空間,輸入 +1024m 便可
Using default value 2610
Command (m for help): w //寫入分區信息,其實就是保存分區信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@Linux ~]# fdisk -l //查看剛剛分紅的分區,內容以下,注意最後一行的信息:
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10241406 83 Linux
/dev/sda2 1276 2349 8626905 83 Linux
/dev/sda3 2350 2610 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux //劃線部分,就是分區,格式化時要寫正確
[root@Linux ~]# mkfs -t ext3 -c /dev/sdb1 //對分區使用 ext3 格式化,若是創建了多個分區,顯示 /dev/sdb二、/dev/sdb3 等,以此類推,重複輸入這條命令,就能夠進行其它分區的格式化操做了。由於新硬盤加了-c參數,要先檢測磁盤壞道,所以,這個過程全有些長,須要耐心等待……
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Checking for bad blocks (read-only test): done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@Linux ~]# fdisk -l //再次查看硬盤信息
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10241406 83 Linux
/dev/sda2 1276 2349 8626905 83 Linux
/dev/sda3 2350 2610 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
[root@Linux ~]# mkdir /dir //新建掛載目錄
[root@Linux ~]# mount /dev/sdb1 /dir //掛載這塊新硬盤
[root@Linux ~]# df -hl //查看分區大小是否和咱們預約的同樣
Filesystem(文件系統) Size(容量) Used(已用) Avail(可用) Use%(已用%) Mounted on(掛載點)
/dev/sda1 9.5G 3.8G 5.2G 43% /
/dev/sda2 8.0G 361M 7.3G 5% /linux
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 20G 173M 19G 1% /dir //最後這一行是新硬盤的相關信息
[root@Linux ~]# vi /etc/fstab //編輯 /etc/fstab 文件,設置系統啓動後自動掛載硬盤,最後一行爲添加的相關內容
LABEL=/ / ext3 defaults 1 1
LABEL=/web /linux ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/sdb1 /dir ext3 defaults 1 2
"/etc/fstab" 8L, 571C written
[root@Linux ~]# df -h //再次查看硬盤信息,最後一行爲新添加的硬盤信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.5G 3.8G 5.2G 43% /
/dev/sda2 8.0G 361M 7.3G 5% /linux
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 20G 173M 19G 1% /dir
[root@Linux ~]# reboot //從新啓動系統
[root@Linux ~]# df -h //查看硬盤信息;同時,檢查咱們添加硬盤、掛載硬盤、系統啓動後自動掛載硬盤這一系列的操做是否正確,若是出現了最後一行,則咱們的操做就是正確的
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.5G 3.8G 5.2G 43% /
/dev/sda2 8.0G 361M 7.3G 5% /linux
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 20G 173M 19G 1% /dir
//================ 如下命令與註釋,是上面的精簡版 ================//
[root@Linux ~]# fdisk -l //查看當前磁盤信息,就會發現最下面顯示新加入的硬盤不是有效分區,以下:
[root@Linux ~]# fdisk /dev/sdb //根據提示,對新硬盤進行分區操做
//這一步能夠不作,就是能夠經過輸入 h 查看幫助信息
Command (m for help): h
//這一步是必須作的
Command (m for help): n //輸入 n,新建分區
Command action
e extended //新建邏輯分區
p primary partition (1-4) //新建主分區
p //輸入 p,創建主分區
Partition number (1-4): 1 //一共能夠分4個主分區,輸入 1,創建第一個主分區
First cylinder (1-2610, default 1): //選擇該分區的起始磁盤數,如無特殊需求強烈建議選擇默認,也就是默認用1 來分區(直接按回車)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): //定義該分區的大小,若是按默認(直接回車),就是使用所有可用存儲空間;若是要分紅一個 1G 的空間,輸入 +1024m 便可
Using default value 2610
Command (m for help): w //寫入分區信息,其實就是保存分區信息
[root@Linux ~]# fdisk -l //查看剛剛分紅的分區,內容以下,注意最後一行的信息:
/dev/sdb1 1 2610 20964793+ 83 Linux //劃線部分,就是分區,格式化時要寫正確
[root@Linux ~]# mkfs -t ext3 -c /dev/sdb1 //對分區使用 ext3 格式化,若是創建了多個分區,顯示 /dev/sdb二、/dev/sdb3 等,以此類推,重複輸入這條命令,就能夠進行其它分區的格式化操做了。由於新硬盤加了-c參數,要先檢測磁盤壞道,所以,這個過程全有些長,須要耐心等待……
[root@Linux ~]# fdisk -l //再次查看硬盤信息
[root@Linux ~]# mkdir /dir //新建掛載目錄
[root@Linux ~]# mount /dev/sdb1 /dir //掛載這塊新硬盤
[root@Linux ~]# df -hl //查看分區大小是否和咱們預約的同樣
/dev/sdb1 20G 173M 19G 1% /dir //最後這一行是新硬盤的相關信息
[root@Linux ~]# vi /etc/fstab //編輯 /etc/fstab 文件,設置系統啓動後自動掛載硬盤,最後一行爲添加的相關內容
[root@Linux ~]# df -h //再次查看硬盤信息,最後一行爲新添加的硬盤信息
[root@Linux ~]# reboot //從新啓動系統
[root@Linux ~]# df -h //查看硬盤信息;同時,檢查咱們添加硬盤、掛載硬盤、系統啓動後自動掛載硬盤這一系列的操做是否正確,若是出現了最後一行,則咱們的操做就是正確的
node