1. 程式人生 > >fdisk分區的過程

fdisk分區的過程

fdisk 分區

1.1 分區

1.1.1 準備環境 添加兩塊100MG(0.1G)的硬盤

reboot 重啟服務器

查看硬盤是否添加成功

fdisk -l 命令

[[email protected] ~]# fdisk -l|grep "/dev/sd[abc]:"

Disk /dev/sda: 10.7 GB, 10737418240 bytes

Disk /dev/sdb: 106 MB, 106954752 bytes

Disk /dev/sdc: 106 MB, 106954752 bytes

1.1.2 創建分區的過程

fdisk給小於2TB磁盤進行分區(MBR

parted 給大於

2TB磁盤進行分區(GPT 小於2TB也可以用)

1.1.3 fdisk進行分區小於2TB的磁盤

【第一步】 fdisk -cu /dev/sdb

創建一個50M的主分區

[[email protected] ~]# fdisk -cu /dev/sdb -c 關掉DOS-compatible模式 -u在列出分區表時,在扇區中給出大小,而不是柱面

Device contains neither a valid DOS partitiontable, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier0xb58dc072.

Changes will remain in memory only, until youdecide to write them.

After that, of course, the previous content won‘tbe recoverable.

Warning: invalid flag 0x0000 of partition table 4will be corrected by w(rite)

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

m print this menu ##顯示幫助

n add a new partition ##新建一個分區

o create a new empty DOS partition table

p print the partition table ##顯示當前的分區信息(顯示分區表的信息)

q quitwithout 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):

Command (m for help): n

Command action

e extended ## 擴展分區

p primary partition (1-4) ## 主分區

p

Partition number (1-4): 1

First sector (2048-208895, default 2048): ##直接按回車

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-208895,default 208895): +50M ###分多大的空間(分50M)

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb58dc072

DeviceBoot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

Command (m for help):

【第二步】 先創建擴展在創建邏輯分區

Command (m for help): n

Command action

e extended

p primary partition (1-4)

e ##擴展分區

Partition number (1-4): 2

First sector (104448-208895, default 104448):

Using default value 104448

Last sector, +sectors or +size{K,M,G}(104448-208895, default 208895): ##剩多少給多少 按回車

Using default value 208895

Command (m for help): n ##新建分區

Command action

l logical (5 or over) ##邏輯分區

p primary partition (1-4)

l

First sector (106496-208895, default 106496): ##按回車

Using default value 106496

Last sector, +sectors or +size{K,M,G}(106496-208895, default 208895): +20 ##分20M的空間

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb58dc072

DeviceBoot Start End Blocks Id System

/dev/sdb1 2048 104447 51200 83 Linux

/dev/sdb2 104448 208895 52224 5 Extended

/dev/sdb5 106496 147455 20480 83 Linux

Command (m for help):

實例1-1刪除分區

Command (m for help): d

Partition number (1-5): 1

實例1-2把磁盤sdb的容量用了創建一個分區 /dev/sdb1 ,把這個分區掛載到/mnt
第一個裏程碑-創建分區

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0c7ada8f

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-208895, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):
Using default value 208895

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0c7ada8f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 208895 103424 83 Linux
Command (m for help): w ##保存退出
The partition table has been altered!

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

第二個裏程碑-通知系統 /dev/sdb磁盤的分區表修改了 變化了

partprobe/dev/sdb ##執行命令即可

第三個裏程碑-格式化創建文件系統

[[email protected] ~]# mkfs.ext4 /dev/sdb1 ##格式化

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

25896 inodes, 103424 blocks

5171 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67371008

13 block groups

8192 blocks per group, 8192 fragments per group

1992 inodes per group

Superblock backups stored on blocks:

8193,24577, 40961, 57345, 73729

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accountinginformation: done

This filesystem will be automatically checked every27 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

第四個裏程碑-讓系統不對我們新創建的分區 進行磁盤檢查

[[email protected] ~]# tune2fs -c 0 -i 0 /dev/sdb1 ##-c掛載次數 -i 每個多少天

tune2fs 1.41.12 (17-May-2010)

Setting maximal mount count to -1

Setting interval between checks to 0 seconds

第五個裏程碑-掛載與檢查

[[email protected] ~]# mount /dev/sdb1 /mnt/ ##掛載

[[email protected] ~]# df -h ##檢查

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 8.8G 1.5G 6.9G 18% /

tmpfs 491M 0 491M 0% /dev/shm

/dev/sda1 190M 35M 146M 19% /boot

/dev/sdb1 94M 1.6M 88M 2% /mnt

第六個歷程碑-需要永久掛載

  1. 掛載命令放入到 /etc/rc.local 文件中

  2. /etc/fstab


本文出自 “13112195” 博客,請務必保留此出處http://13122195.blog.51cto.com/13112195/1956841

fdisk分區的過程