第21天筆記 磁盤管理 Fdsik 創(chuàng)建分區(qū)
Raid是廉價(jià)冗余磁盤陣列(Redundant Array of Inexpensive Disk)的簡(jiǎn)稱, 有時(shí)也簡(jiǎn)稱磁盤陣列(Disk Array)惫撰。
RAID分為兩類:
軟RAID,系統(tǒng)層面實(shí)現(xiàn)的歉糜,性能差。
硬RAID咒精,硬件層面實(shí)現(xiàn)的锌钮,性能好陨闹。
主板板載RAID:功能弱,0聘芜,1
獨(dú)立RAID卡:功能強(qiáng)兄渺,0,1,5,10 *****工作選擇。
LVM全稱(Logic Volume Management (Manager))邏輯卷管理,它的最大用途是可以【靈活的管理磁盤的容量】汰现,讓磁盤分區(qū)可以隨意放大或縮小挂谍,便于更好的應(yīng)用磁盤的剩余空間,如果過于強(qiáng)調(diào)性能與備份瞎饲,那么還是應(yīng)該使用RAID功能口叙,而不是LVM。
LVM是軟件層面實(shí)現(xiàn)的企软,性能太低庐扫。性能降低5-10%。
買服務(wù)器插滿磁盤仗哨,分區(qū)規(guī)劃好形庭,永遠(yuǎn)都不需要LVM。
RAID1又稱為Mirror或Mirroring(鏡像)厌漂,
它的宗旨是最大限度的保證用戶數(shù)據(jù)的可用性和可修復(fù)性萨醒。
RAID1的操作方式是把用戶寫入一個(gè)磁盤的數(shù)據(jù)百分之百地自動(dòng)復(fù)制到另外
一個(gè)磁盤上,從而實(shí)現(xiàn)存儲(chǔ)雙份的數(shù)據(jù)苇倡。
RAID5描述 中庸
RAID5是一種存儲(chǔ)性能富纸、數(shù)據(jù)安全和存儲(chǔ)成本兼顧的存儲(chǔ)解決方案。
RAID5需要三塊或以上的物理磁盤旨椒,可以提供熱備盤實(shí)現(xiàn)故障的恢復(fù)晓褪;
采用【奇偶校驗(yàn)】,可靠性強(qiáng)综慎,且只有同時(shí)損壞兩塊硬盤時(shí)數(shù)據(jù)才會(huì)完全損壞涣仿,
只損壞一塊硬盤時(shí),系統(tǒng)會(huì)根據(jù)存儲(chǔ)的奇偶校驗(yàn)位重建數(shù)據(jù),臨時(shí)提供服務(wù)好港;此時(shí)如果有熱備盤愉镰,系統(tǒng)還會(huì)自動(dòng)在熱備盤上重建故障磁盤上的數(shù)據(jù);
分區(qū)知識(shí):
回憶:
(1)什么是分區(qū)钧汹?
磁盤分區(qū)就相當(dāng)于給磁盤打隔斷丈探。
(2)磁盤和分區(qū)在Linux里的命名。
IDE /dev/hda hdb
SCSI sda sdb
分區(qū)數(shù)字表示:sda1 sda2 sda3
(3)磁盤分區(qū)類型和特點(diǎn):
1拔莱、主分區(qū)(primary)P
1)系統(tǒng)中必須要存在的分區(qū)碗降,系統(tǒng)盤選擇主分區(qū)安裝。
2)數(shù)字編號(hào)只能是1-4.sda1辨宠、sda2遗锣、sda3货裹、sda4嗤形。
3)主分區(qū)最多四個(gè),最少一個(gè)弧圆。
2赋兵、擴(kuò)展分區(qū)(extend)E
1)相當(dāng)于一個(gè)獨(dú)立的小磁盤。獨(dú)立的分區(qū)表搔预,不能獨(dú)立存在霹期。
2)有獨(dú)立的分區(qū)表。
3)不能獨(dú)立存在拯田,即不能直接存放數(shù)據(jù)历造。
4)必須在擴(kuò)展分區(qū)上建立邏輯分區(qū)才能存放數(shù)據(jù)。
5)占用主分區(qū)的編號(hào)(主分區(qū)+擴(kuò)展分區(qū))之和最多4個(gè)船庇。
6)擴(kuò)展分區(qū)可以沒有吭产,最多只能有一個(gè)。
3鸭轮、邏輯分區(qū)(logic)L
2)數(shù)字編號(hào)只能是從5開始臣淤。
3)存放于擴(kuò)展分區(qū)之上。
4)存放任意普通數(shù)據(jù)窃爷。
磁盤分區(qū)注意事項(xiàng)要點(diǎn)
一塊硬盤的分區(qū)方式只能為如下組合之一:
(1)任意多個(gè)主分區(qū)邑蒋,但要求1≤主分區(qū)數(shù)量≤4。
例如:一個(gè)硬盤可以分為4個(gè)主分區(qū)3個(gè)主分區(qū)2個(gè)主分區(qū)或1個(gè)主分區(qū)按厘。
(2)擴(kuò)展分區(qū)可以和主分區(qū)組合医吊,但要求2≤(主分區(qū)+擴(kuò)展分區(qū))數(shù)量≤4)。
例如:3個(gè)主分區(qū)+1個(gè)擴(kuò)展分區(qū)或2個(gè)主分區(qū)+1個(gè)擴(kuò)展分區(qū)或1個(gè)主分區(qū)+1個(gè)擴(kuò)展分區(qū)逮京。
當(dāng)總分區(qū)的數(shù)量大于4個(gè)的時(shí)候卿堂,必須提前分一個(gè)擴(kuò)展分區(qū),擴(kuò)展分區(qū)最多只能有一個(gè)造虏。
(3)如果要分成四個(gè)磁盤分區(qū)的話御吞,那么最多就是可以:
P + P + P + P
P + P + P + E
問題:如果給一個(gè)磁盤分6個(gè)分區(qū)有哪些方案麦箍,同時(shí)寫出分區(qū)/dev/sda(數(shù)字)。
3P+1E(3L)? 1 2 3 5 6 7
2P+1E(4L)? 12 5678
1P+1E(5L)? 1 56789
分區(qū)分完了陶珠,空間還有剩余浪費(fèi)掉空間挟裂。
P + P + P + P
(4)磁盤分區(qū)工作原理:
磁盤是按柱面分區(qū)的。
磁盤分區(qū)登記的地點(diǎn)揍诽,磁盤分區(qū)表诀蓉。
磁盤分區(qū)表存放分區(qū)結(jié)果信息的。
磁盤分區(qū)表位置暑脆,0磁道0磁頭1扇區(qū)(512字節(jié))
占用1扇區(qū)的前446字節(jié)(系統(tǒng)引導(dǎo)信息的)后面的64字節(jié)(分區(qū)表)渠啤,
剩下2個(gè)字節(jié)分區(qū)結(jié)束標(biāo)志。
磁盤分區(qū)表的容量是有限的添吗,64字節(jié)沥曹,一個(gè)分區(qū)固定占16字節(jié)。
64/16=4分區(qū)(主分區(qū)+擴(kuò)展分區(qū))
(5)磁盤分區(qū)實(shí)戰(zhàn)
磁盤分區(qū)關(guān)鍵就是修改64字節(jié)的的分區(qū)表而已碟联。
磁盤分區(qū)常用命令fdisk妓美,修改MBR分區(qū)表,MBR格式鲤孵。
缺陷壶栋,被修改的磁盤大小不能大于2T。
磁盤分區(qū)其他命令parted,gpt分區(qū)格式普监,既能修改小于2T也能修改大于2T的磁盤贵试。
小于2T就用fdisk
大于2T就用parted
[root@yurenkang ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x248d9b1d.
Command (m for help): n
Partition type:
p? primary (0 primary, 0 extended, 4 free)
e? extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +150M
Partition 1 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
Command (m for help): n
Partition type:
p? primary (1 primary, 0 extended, 3 free)
e? extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (309248-2097151, default 309248):
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-2097151, default 2097151): +150M
Partition 2 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
/dev/sdb2? ? ? ? ? 309248? ? ? 616447? ? ? 153600? 83? Linux
Command (m for help): n
Partition type:
p? primary (2 primary, 0 extended, 2 free)
e? extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (616448-2097151, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +150M
Partition 3 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
/dev/sdb2? ? ? ? ? 309248? ? ? 616447? ? ? 153600? 83? Linux
/dev/sdb3? ? ? ? ? 616448? ? ? 923647? ? ? 153600? 83? Linux
Command (m for help):
Command (m for help): n
Partition type:
p? primary (3 primary, 0 extended, 1 free)
e? extended
Select (default e):
Using default response e
Selected partition 4
First sector (923648-2097151, default 923648):
Using default value 923648
Last sector, +sectors or +size{K,M,G} (923648-2097151, default 2097151):
Using default value 2097151
Partition 4 of type Extended and of size 573 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
/dev/sdb2? ? ? ? ? 309248? ? ? 616447? ? ? 153600? 83? Linux
/dev/sdb3? ? ? ? ? 616448? ? ? 923647? ? ? 153600? 83? Linux
/dev/sdb4? ? ? ? ? 923648? ? 2097151? ? ? 586752? ? 5? Extended
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (925696-2097151, default 925696):
Using default value 925696
Last sector, +sectors or +size{K,M,G} (925696-2097151, default 2097151): +150M
Partition 5 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
/dev/sdb2? ? ? ? ? 309248? ? ? 616447? ? ? 153600? 83? Linux
/dev/sdb3? ? ? ? ? 616448? ? ? 923647? ? ? 153600? 83? Linux
/dev/sdb4? ? ? ? ? 923648? ? 2097151? ? ? 586752? ? 5? Extended
/dev/sdb5? ? ? ? ? 925696? ? 1232895? ? ? 153600? 83? Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (1234944-2097151, default 1234944):
Using default value 1234944
Last sector, +sectors or +size{K,M,G} (1234944-2097151, default 2097151): +150M
Partition 6 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
/dev/sdb2? ? ? ? ? 309248? ? ? 616447? ? ? 153600? 83? Linux
/dev/sdb3? ? ? ? ? 616448? ? ? 923647? ? ? 153600? 83? Linux
/dev/sdb4? ? ? ? ? 923648? ? 2097151? ? ? 586752? ? 5? Extended
/dev/sdb5? ? ? ? ? 925696? ? 1232895? ? ? 153600? 83? Linux
/dev/sdb6? ? ? ? 1234944? ? 1542143? ? ? 153600? 83? Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 7
First sector (1544192-2097151, default 1544192):
Using default value 1544192
Last sector, +sectors or +size{K,M,G} (1544192-2097151, default 2097151): +150M
Partition 7 of type Linux and of size 150 MiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@yurenkang ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0x248d9b1d
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sdb1? ? ? ? ? ? 2048? ? ? 309247? ? ? 153600? 83? Linux
/dev/sdb2? ? ? ? ? 309248? ? ? 616447? ? ? 153600? 83? Linux
/dev/sdb3? ? ? ? ? 616448? ? ? 923647? ? ? 153600? 83? Linux
/dev/sdb4? ? ? ? ? 923648? ? 2097151? ? ? 586752? ? 5? Extended
/dev/sdb5? ? ? ? ? 925696? ? 1232895? ? ? 153600? 83? Linux
/dev/sdb6? ? ? ? 1234944? ? 1542143? ? ? 153600? 83? Linux
/dev/sdb7? ? ? ? 1544192? ? 1851391? ? ? 153600? 83? Linux