- 硬盤分區的劃分標準 :主分區、擴展分區和邏輯分區
- 在一塊硬盤上,如果是MBR分區方式,那麼它的主分區最多隻能有4個,或者3個主分區和1個擴展分區;在擴展分區上我們可以創建多個邏輯分區
分區編號:主分區1-4 ,邏輯分區5………
名稱 | 概念 | 最大數量 | 最小數量 |
---|---|---|---|
主分區 | 主要是用來啓動操作系統的,它主要放的是操作系統的啓動或引導程序 MBR分區中,最多有4個主分區 | 4 | 1 |
邏輯分區 | 邏輯分區必須建立在擴展分區之上,而不是建立在主分區上,可建立多個 | n | 0 |
擴展分區 | 不能使用,它只是做爲邏輯分區的容器存在的;我們真正存放數據的是主分區和邏輯分區,大量數據都放在邏輯分區中 | 1 | 0 |
fdisk命令:
增加一個分區
- fdisk -l 查看系統上的分區信息
[root@fei ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes //總計21.5G
255 heads, 63 sectors/track, 2610 cylinders // 255個磁面,63個扇區,2610個磁柱
Units = cylinders of 16065 * 512 = 8225280 bytes //每個磁柱容量
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005936c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1332 10485760 83 Linux
/dev/sda3 1332 1593 2097152 82 Linux swap / Solaris
- fdisk /dev/sda 對/dev/sda/進行分區
磁盤分區表示:
hda1 hda2 hdb1 hdb2……
sda1 sda2 sdb1 sdb2……
hd大多爲IDE硬盤 , sd大多爲SCSI或移動存儲
[root@fei ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help):
註釋 ://Command (m for help):
查看幫助信息:輸入m,看到如下信息
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 注:l是列出分區類型,以供我們設置相應分區的類型;
m print this menu 注: m 是列出幫助信息;
n add a new partition 注:添加一個分區;
o create a new empty DOS partition table 創建一個新的DOS分區表
p print the partition table 注:p列出分區表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition’s system id 注:t 改變分區類型 id;
u change display/entry units 改變現實單位
v verify the partition table
w write table to disk and exit 注:把分區表寫入硬盤並退出;
x extra functionality (experts only) 注:擴展應用,專家功能;
- 選擇n 來添加一個分區
Command (m for help): n
Command action
e extended //e,擴展分區
p primary partition (1-4) //p,主分區1-4
p
Selected partition 4 //因爲sda1-3已分,所有默認sda4
First cylinder (1593-2610, default 1593): //磁柱開始位置,採用默認,直接回車
Using default value 1593 //磁柱開始位置
Last cylinder, +cylinders or +size{K,M,G} (1593-2610, default 2610): +100M //磁柱解釋位置,設置磁盤分區大小
Command (m for help): p //查看一下當前磁盤信息
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005936c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1332 10485760 83 Linux
/dev/sda3 1332 1593 2097152 82 Linux swap / Solaris
/dev/sda4 1593 1606 111459 83 Linux //添加成功,sda4
Command (m for help): wq //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
- partprobe 或者 partx -a /dev/sda 分區之後,讓內核更新分區信息,否則系統需要restart後,內核才能識別新的分區
- mkfs.ext4 /dev/sda4 創建文件系統,格式化
[root@fei ~]# mkfs.ext4 /dev/sda4
mke2fs 1.41.12 (17-May-2010)
文件系統標籤=
操作系統:Linux
塊大小=1024 (log=0)
分塊大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
3776 inodes, 15068 blocks
753 blocks (5.00%) reserved for the super user
第一個數據塊=1
Maximum filesystem blocks=15466496
2 block groups
8192 blocks per group, 8192 fragments per group
1888 inodes per group
Superblock backups stored on blocks:
8193
正在寫入inode表: 完成
Creating journal (1024 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
- 將/dev/sda4 掛載
[root@fei ~]# mount /dev/sda4 /mnt
[root@fei ~]# df-h
-bash: df-h: command not found
[root@fei ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.8G 1.4G 8.0G 15% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 190M 35M 145M 20% /boot
/dev/sr0 3.7G 3.7G 0 100% /media
/dev/sda4 14M 130K 13M 2% /mnt //已將/dev/sda4掛載
刪除一個分區
[root@fei ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): d //刪除一個分區
Partition number (1-4): 4 //選擇刪除一個分區,如果刪除了擴展分區,擴展分區之下的邏輯分區都會刪除
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005936c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1332 10485760 83 Linux
/dev/sda3 1332 1593 2097152 82 Linux swap / Solaris
//sda4已經被刪除
Command (m for help): wq //若之前有錯誤操作,只有不輸入w只輸入q退出即可