磁盤及文件系統管理應用實例
1.創建一個10G的分區,并格式化為ext4文件系統
要求其block大小為2048,預留空間百分比為2,卷標為MYDATA,默認掛載屬性包含acl
掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳
- [root@master ~]# fdisk /dev/sdb
- Command (m for help): n
- Partition type:
- p primary (0 primary, 0 extended, 4 free)
- e extended
- Select (default p): p
- Partition number (1-4, default 1): 1
- First sector (2048-41943039, default 2048):
- Using default value 2048
- Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
- Partition 1 of type Linux and of size 10 GiB is set
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1
- [root@master ~]# tune2fs -o acl /dev/sdb1
- [root@master ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata
2.創建一個大小為1G的swap分區,并創建好文件系統,并啟用之,寫一個腳本
獲取并列出當前系統上的所有磁盤設備
顯示每個磁盤設備上每個分區的相關的空間使用信息
- Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G
- Partition 2 of type Linux and of size 1 GiB is set
- Command (m for help): t
- Partition number (1,2, default 2): 2
- Hex code (type L to list all codes): L
- Hex code (type L to list all codes): 82
- Changed type of partition 'Linux' to 'Linux swap / Solaris'
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mkswap -L SWAP /dev/sdb2
- [root@master ~]# swapon /dev/sdb2
- #!/bin/bash
- #
- disks=`fdisk -l|grep -o '^Disk /dev/[sh]d[a-z]'|cut -d' ' -f2`
- echo $disks
- for i in $disks;do
- fdisk -l $i
- done
3.總結RAID的各個級別及其組合方式和性能的不同
RAID(冗余磁盤陣列)是將多塊磁盤當做一塊物理磁盤來使用,以達到容錯或者提高讀寫性能的優勢。按照 組織起來的工作方式的不同,我們可以將RAID分為不同的級別,其中常見的有RAID0、RAID1、RAID5、RAID10
RAID0
俗稱條帶卷,實現將文件分成多個chunk后同時并行存儲到多個盤中。
特性
讀寫性能得到提升
無冗余能力
最少磁盤數為2
可用空間為容量最小的磁盤*磁盤數
RAID1
俗稱鏡像卷,在存儲數據的同時需要再復制一份存入另一個磁盤中。
特性
讀性能提升,寫性能下降
有冗余能力
最少磁盤數為2,偶數
可用空間小于1/2
RAID5
將文件分成多個chunk,兩兩chunk之間作異或運算,各盤輪流存儲校驗碼
特點
讀寫性能提升
有冗余能力
最少磁盤數為3
可用空間為容量最小的磁盤*(磁盤數-1)
RAID10
先兩兩做raid1,后將多組raid1組織成raid0
特點
讀寫性能提升
有冗余能力
最小磁盤數4
可用空間為容量最小的磁盤*磁盤數/2
4.創建一個大小為10G的RAID1,要求有一個空閑盤,而且chunk大小為128k
- [root@master ~]# fdisk /dev/sdb
- Command (m for help): n
- Partition type:
- p primary (1 primary, 0 extended, 3 free)
- e extended
- Select (default p): p
- Partition number (2-4, default 2): 2
- First sector (20973568-41943039, default 20973568):
- Using default value 20973568
- [root@master ~]# fdisk /dev/sdb
- Command (m for help): n
- Partition type:
- p primary (0 primary, 0 extended, 4 free)
- e extended
- Select (default p): p
- Partition number (1-4, default 1): 1
- First sector (2048-104857599, default 2048):
- Using default value 2048
- Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +10G
- Partition 1 of type Linux and of size 10 GiB is set
- Command (m for help): n
- Partition type:
- p primary (1 primary, 0 extended, 3 free)
- e extended
- Select (default p): p
- Partition number (2-4, default 2): 2
- First sector (20973568-104857599, default 20973568): +10G
- Value out of range.
- First sector (20973568-104857599, default 20973568):
- Using default value 20973568
- Last sector, +sectors or +size{K,M,G} (20973568-104857599, default 104857599): +10G
- Partition 2 of type Linux and of size 10 GiB is set
- Command (m for help): n
- Partition type:
- p primary (2 primary, 0 extended, 2 free)
- e extended
- Select (default p): p
- Partition number (3,4, default 3): 3
- First sector (41945088-104857599, default 41945088):
- Using default value 41945088
- Last sector, +sectors or +size{K,M,G} (41945088-104857599, default 104857599): +10G
- Partition 3 of type Linux and of size 10 GiB is set
- Command (m for help): t
- Partition number (1-3, default 3): 1
- Hex code (type L to list all codes): fd
- Changed type of partition 'Linux' to 'Linux raid autodetect'
- Command (m for help): t
- Partition number (1-3, default 3): 2
- Hex code (type L to list all codes): fd
- Changed type of partition 'Linux' to 'Linux raid autodetect'
- Command (m for help): t
- Partition number (1-3, default 3): 3
- Hex code (type L to list all codes): fd
- Changed type of partition 'Linux' to 'Linux raid autodetect'
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mdadm -C /dev/md0 -n 2 -c 128 -x 1 -l 1 -a yes /dev/sdb{1,2,3}
- mdadm: Defaulting to version 1.2 metadata
- mdadm: array /dev/md0 started.
5.創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,且不更新訪問時間戳,且支持acl功
- “`
- [root@master ~]# fdisk /dev/sdb
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 5
- First sector (62918656-104857599, default 62918656):
- Using default value 62918656
- Last sector, +sectors or +size{K,M,G} (62918656-104857599, default 104857599): +2G
- Partition 5 of type Linux and of size 2 GiB is set
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 6
- First sector (67115008-104857599, default 67115008):
- Using default value 67115008
- Last sector, +sectors or +size{K,M,G} (67115008-104857599, default 104857599): +2G
- Partition 6 of type Linux and of size 2 GiB is set
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 7
- First sector (71311360-104857599, default 71311360):
- Using default value 71311360
- Last sector, +sectors or +size{K,M,G} (71311360-104857599, default 104857599): +2G
- Partition 7 of type Linux and of size 2 GiB is set
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mdadm -C /dev/md1 -n 3 -c 256 -l 5 -a yes /dev/sdb{5,6,7}
- mdadm: Defaulting to version 1.2 metadata
- mdadm: array /dev/md1 started.
- [root@master ~]# mke2fs -t ext4 /dev/md1
- [root@master ~]# mkdir /backup
- [root@master ~]# mount -o auto /dev/md1 /backup