10.15 Linux fdisk創(chuàng)建分區(qū)(主分區(qū)、擴展分區(qū)和邏輯分區(qū))過程詳解
本節(jié)我們實際建立一個主分區(qū),看看過程是什么樣子的。命令如下:
[root@localhost ~]# fdisk /dev/sdb …省略部分輸出… Command (m for help): p \#顯示當前硬盤的分區(qū)列表 Disk /dev/sdb: 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: 0xb4b0720c Device Boot Start End Blocks id System \#目前一個分區(qū)都沒有 Command (m for help): n \#那么我們新建一個分區(qū) Command action \#指定分區(qū)類型 e extended \#擴展分區(qū) p primary partition (1-4) \#主分區(qū) p \#這里選擇p,建立一個主分區(qū) Partition number (1-4): 1 \#選擇分區(qū)號,范圍為1~4,這里選擇1 First cylinder (1 -2610, default 1): \#分區(qū)的起始柱面,默認從1開始。因為要從硬盤頭開始分區(qū),所以直接回車 Using default value 1 \#提示使用的是默認值1 Last cylinder, +cylinders or +size{K, M, G}(1-2610, default 2610): +5G \#指定硬盤大小。可以按照柱面指定(1-2610)。我們對柱面不熟悉,那么可以使用size{K, M, G}的方式指定硬盤大小。這里指定+5G,建立一個5GB大小的分區(qū) Command (m for help): \#主分區(qū)就建立了,又回到了fdisk交互界面的提示符 Command (m for help): p \#查詢一下新建立的分區(qū) Disk /dev/sdb: 21.5GB, 21474836480 bytes 255 heads,63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes 1512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xb4b0720c Device Boot Start End Blocks id System /dev/sdb1 1 654 5253223+ 83 [linux](http://www.beylze.cn/linux/) \#dev/sdb1已經建立了吧
總結,建立主分區(qū)的過程就是這樣的:“fdisk 硬盤名 -> n(新建)->p(建立主分區(qū)) -> 1(指定分區(qū)號) -> 回車(默認從 1 柱面開始建立分區(qū))-> +5G(指定分區(qū)大小)”。當然,我們的分區(qū)還沒有格式化和掛載,所以還不能使用。
本節(jié)給大家展示如何建立一個擴展分區(qū)。還記得嗎?主分區(qū)和擴展分區(qū)加起來最多只能建立 4 個,而擴展分區(qū)最多只能建立 1 個。
擴展分區(qū)的建立命令如下:
[root@localhost ~]# fdisk /dev/sdb …省略部分輸出… Command (m for help): n \#新建立分區(qū) Command action e extended p primary partition (1-4) e \#這次建立擴展分區(qū) Partition number (1-4): 2 \#給擴展分區(qū)指定分區(qū)號2 First cylinder (655-2610, default 655): \#擴展分區(qū)的起始柱面。上節(jié)建立的主分區(qū)1已經占用了1~654個柱面,所以我們從655開始建立,注意:如果沒有特殊要求,則不要跳開柱面建立分區(qū),應該緊挨著建立分區(qū) Using default value 655 提示使用的是默認值655 Last cylinder, +cylinders or +size{K, M, G} (655-2610, default 2610): \#這里把整塊硬盤的剩余空間都建立為擴展分區(qū) Using default value 2610 \#提示使用的是默認值2610
這里把 /dev/sdb 硬盤的所有剩余空間都建立為擴展分區(qū),也就是建立一個主分區(qū),剩余空間都建立成擴展分區(qū),再由擴展分區(qū)中建立邏輯分區(qū)(邏輯分區(qū)在后續(xù)章節(jié)中介紹)。
擴展分區(qū)是不能被格式化和直接使用的,所以還要在擴展分區(qū)內部再建立邏輯分區(qū)。
我們來看看邏輯分區(qū)的建立過程,命令如下:
[root@localhost ~]# fdisk /dev/sdb …省略部分輸出… Command (m for help): n \#建立新分區(qū) Command action l logical (5 or over) \#由于在前面章節(jié)中,擴展分區(qū)已經建立,所以這里變成了l(logic) p primary partition (1-4) l \#建立邏輯分區(qū) First cylinder (655-2610, default 655): \#不用指定分區(qū)號,默認會從5開始分配,所以直接選擇起始柱面 \#注意:邏輯分區(qū)是在擴展分區(qū)內部再劃分的,所以柱面是和擴展分區(qū)重疊的 Using default value 655 Last cylinder, +cylinders or +size{K, M, G} (655-2610, default 2610):+2G \#分配2GB大小 Command (m for help): n \#再建立一個邏輯分區(qū) Command action l logical (5 or over) p primary partition (1-4) l First cylinder (917-2610, default 917): Using default value 917 Last cylinder, +cylinders or +size{K, M, G} (917-2610, default 2610):+2G Command (m for help): p \#查看一下已經建立的分區(qū) Disk /dev/sdb: 21.5GB, 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: 0xb4b0720c Device Boot Start End Blocks id System /dev/sdb1 1 654 5253223+ 83 Linux \#主分區(qū) /dev/sdb2 655 2610 15711570 5 Extended \#擴展分區(qū) /dev/sdb5 655 916 2104483+ 83 Linux \#邏輯分區(qū) 1 /dev/sdb6 917 1178 2104483+ 83 Linux \#邏輯分區(qū)2 Command (m for help): w \#保存并退出 The partition table has been altered! Calling ioctl。to re-read partition table. Syncing disks. [root@localhost -]# \#退回到提示符界面
所有的分區(qū)立過程中如果不保存并退出是不會生效的,所以建立錯了也沒有關系,使用 q 命令不保存退出即可。如果使用了 w 命令,就會保存退出。有時因為系統(tǒng)的分區(qū)表正忙,所以需要重新啟動系統(tǒng)才能使新的分區(qū)表生效。命令如下:
Command (m for help): w \#保存并退出 The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. \#要求重新啟動,才能格式化 Syncing disks.
看到了嗎?必須重新啟動!可是重新啟動很浪費時間。如果不想重新啟動,則可以使用 partprobe 命令。這個命令的作用是讓系統(tǒng)內核重新讀取分區(qū)表信息,這樣就可以不用重新啟動了。命令如下:
[root@localhost ~]# partprobe
如果這個命令不存在,則請安裝 parted-2.1-18.el6.i686 這個軟件包。partprobe 命令不是必需的,如果沒有提示重啟系統(tǒng),則直接格式化即可。
Linux
版權聲明:本文內容由網(wǎng)絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內刪除侵權內容。
版權聲明:本文內容由網(wǎng)絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內刪除侵權內容。