我的需求是,將新硬盤(pán)只分一個(gè)區來(lái)使用
fdisk -l #查看硬盤(pán)掛在情況
Disk /dev/xvda: 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: 0x00073f45
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 2611 20970496 83 Linux
Disk /dev/xvdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x00000000
從上述返回的信息看到,第二塊硬盤(pán) /dev/xvdb 未掛載,
fdisk /dev/xvdb #對第二塊硬盤(pán)進(jìn)行操作
Command (m for help): n #新增加一個(gè)分區
Command action
e extended
p primary partition (1-4)
p #選擇“增加主分區“
Partition number (1-4):1 #選擇作為1號分區
First cylinder (1-65270, default 1): #直接回車(chē),新的分區從硬盤(pán)的第1扇區開(kāi)始
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-65270, default 65270): #直接回車(chē),新的分區到硬盤(pán)的末尾結束,即整塊硬盤(pán)只分一個(gè)區,也是主分區。
Using default value 65270
Command (m for help): t #選擇分區類(lèi)型
Selected partition 1
Hex code (type L to list codes): 83 #選擇第83號分區類(lèi)型(linux類(lèi)型)
Command (m for help): w #保存到硬盤(pán)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
fdisk -l #再次查看硬盤(pán)掛載情況,可發(fā)現新的硬盤(pán)已經(jīng)ready
Disk /dev/xvda: 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: 0x00073f45
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 2611 20970496 83 Linux
Disk /dev/xvdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x30550159
Device Boot Start End Blocks Id System
/dev/xvdb1 1 65270 524281243+ 83 Linux
mkfs -t ext4 -c /dev/xvdb1 #格式化硬盤(pán)
格式化中。。。
以下內容轉載自:http://lbyzx123.iteye.com/blog/835004
關(guān)于硬盤(pán)分區:主分區(包含擴展分區)、邏輯分區,主分區最多有4個(gè)(包含擴展分區)。
因此我們在對硬盤(pán)分區時(shí)最好劃分主分區連續,比如說(shuō):主分區一、主分區二、擴展分區。
此文章以fdisk工具為例,對一個(gè)硬盤(pán)劃分。
1、fdisk -l 查看系統上的硬盤(pán),找到需要分區的硬盤(pán)后比如說(shuō):/dev/sdb.
然后,fdisk /dev/sdb
進(jìn)入該設備。此時(shí)出現:
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 注:這是刪除一個(gè)分區的動(dòng)作;
l list known partition types 注:l是列出分區類(lèi)型,以供我們設置相應分區的類(lèi)型;
m print this menu 注:m 是列出幫助信息;
n add a new partition 注:添加一個(gè)分區;
o create a new empty DOS partition table
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 改變分區類(lèi)型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分區表寫(xiě)入硬盤(pán)并退出;
x extra functionality (experts only) 注:擴展應用,專(zhuān)家功能;
具體每個(gè)參數的含義,請仔細閱讀。常用的就是:d l m p q t w
2、列出當前操作硬盤(pán)的分區情況,用p
Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux
3、通過(guò)fdisk的d指令來(lái)刪除一個(gè)分區
Command (m for help): p 注:列出分區情況;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux
Command (m for help): d 注:執行刪除分區指定;
Partition number (1-6): 6 注:我想刪除 sda6 ,就在這里輸入 6 ;
Command (m for help): p 注:再查看一下硬盤(pán)分區情況,看是否刪除了?
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
Command (m for help):
警告:刪除分區時(shí)要小心,請看好分區的序號,如果您刪除了擴展分區,擴展分區之下的邏輯分區都會(huì )刪除;所以操作時(shí)一定要小心;如果知道自己操作錯了,請不要驚慌,用q不保存退出;切記切記?。。?!在分區操作錯了之時(shí),千萬(wàn)不要輸入w保存退出?。?!
4、通過(guò)fdisk的n指令增加一個(gè)分區
Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
Command (m for help): n 注:增加一個(gè)分區;
Command action
l logical (5 or over) 注:增加邏輯分區,分區編號要大于5;為什么要大于5,因為已經(jīng)有sda5了;
p primary partition (1-4) 注:增加一個(gè)主分區;編號從 1-4 ;但sda1 和sda2都被占用,所以只能從3開(kāi)始;
p
Partition number (1-4): 3
No free sectors available 注:失敗中,為什么失???
注:我試圖增加一個(gè)主分區,看來(lái)是失敗了,為什么失???因為我們看到主分區+擴展分區把整個(gè)磁盤(pán)都用光了,看擴展分區的End的值,再看一下 p輸出信息中有125 cylinders;最好還是看前面部份;那里有提到; 所以我們只能增加邏輯分區了;
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:在這里輸入l,就進(jìn)入劃分邏輯分區階段了;
First cylinder (51-125, default 51): 注:這個(gè)就是分區的Start 值;這里最好直接按回車(chē),如果您輸入了一個(gè)非默認的數字,會(huì )造成空間浪費;
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:這個(gè)是定義分區大小的,+200M 就是大小為200M ;當然您也可以根據p提示的單位cylinder的大小來(lái)算,然后來(lái)指定 End的數值?;仡^看看是怎么算的;還是用+200M這個(gè)辦法來(lái)添加,這樣能直觀(guān)一點(diǎn)。如果您想添加一個(gè)10G左右大小的分區,請輸入 +10000M ;
Command (m for help):
5、通過(guò)fdisk的t指令指定分區類(lèi)型
Command (m for help): t 注:通過(guò)t來(lái)指定分區類(lèi)型;
Partition number (1-6): 6 注:要改變哪個(gè)分區類(lèi)型呢?我指定了6,其實(shí)也就是sda6
Hex code (type L to list codes):L 注:在這里輸入L,就可以查看分區類(lèi)型的id了;
Hex code (type L to list codes): b 注:如果我想讓這個(gè)分區是 W95 FAT32 類(lèi)型的,通過(guò)L查看得知 b是表示的是,所以輸入了b;
Changed system type of partition 6 to b (W95 FAT32) 注:系統信息,改變成功;是否是改變了,請用p查看;
Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 75 201568+ b W95 FAT32
6、fdisk 的退出,用q或者 w
其中 q是 不保存退出,w是保存退出
7、一個(gè)添加分區的例子
本例中我們會(huì )添加兩個(gè)200M的主分區,其它為擴展分區,在擴展分區中我們添加兩個(gè)200M大小的邏輯分區;
Command (m for help): p 注:列出分區表;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
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 注:添加主分區1;
First cylinder (1-125, default 1): 注:直接回車(chē),主分區1的起始位置;默認為1,默認就好;
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-125, default 125): +200M 注:指定分區大小,用+200M來(lái)指定大小為200M
Command (m for help): n 注:添加新分區;
Command action
e extended
p primary partition (1-4)
p 注:添加主分區
Partition number (1-4): 2 注:添加主分區2;
First cylinder (26-125, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-125, default 125): +200M 注:指定分區大小,用+200M來(lái)指定大小為200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e 注:添加擴展分區;
Partition number (1-4): 3 注:指定為3 ,因為主分區已經(jīng)分了兩個(gè)了,這個(gè)也算主分區,從3開(kāi)始;
First cylinder (51-125, default 51): 注:直接回車(chē);
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): 注:直接回車(chē),把其余的所有空間都給擴展分區;
Using default value 125
Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ 83 Linux
/dev/sda2 26 50 201600 83 Linux
/dev/sda3 51 125 604800 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:添加邏輯分區;
First cylinder (51-125, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:添加一個(gè)大小為200M大小的分區;
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l 注:添加一個(gè)邏輯分區;
First cylinder (76-125, default 76):
Using default value 76
Last cylinder or +size or +sizeM or +sizeK (76-125, default 125): +200M 注:添加一個(gè)大小為200M大小的分區;
Command (m for help): p 列出分區表;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ 83 Linux
/dev/sda2 26 50 201600 83 Linux
/dev/sda3 51 125 604800 5 Extended
/dev/sda5 51 75 201568+ 83 Linux
/dev/sda6 76 100 201568+ 83 Linux
然后我們根據前面所說(shuō)通過(guò)t指令來(lái)改變分區類(lèi)型; 最后不要忘記w保存退出;
五、對分區進(jìn)行格式化,以及加載;
先提示一下;用 mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs 等命令來(lái)格式化分區,比如我想格式化 sda6為ext3文件系統,則輸入;
[root@localhost beinan]# mkfs -t ext3 -c /dev/sda6 具體參數含義,請man mkfs。
如果我想加載 sda6到目前系統來(lái)存取文件,應該有mount 命令,但首先您得建一個(gè)掛載目錄;比如 /mnt/sda6 ;
[root@localhost beinan]# mkdir /mnt/sda6
[root@localhost beinan]# mount /dev/sda6 /mnt/sda6
[root@localhost beinan]# df -lh
Filesystem 容量 已用 可用 已用% 掛載點(diǎn)
/dev/hda8 11G 8.4G 2.0G 81% /
/dev/shm 236M 0 236M 0% /dev/shm
/dev/hda10 16G 6.9G 8.3G 46% /mnt/hda10
/dev/sda6 191M 5.6M 176M 4% /mnt/sda6
聯(lián)系客服