天天看點

磁盤及檔案系統管理應用執行個體

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 

p primary (0 primary, 0 extended, 4 free) 

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 

first sector (20973568-104857599, default 20973568): +10g 

value out of range. 

first sector (20973568-104857599, default 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 

p primary (2 primary, 0 extended, 2 free) 

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 

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' 

partition number (1-3, default 3): 2 

partition number (1-3, default 3): 3 

[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功

“` 

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 

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 

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 

[root@master ~]# mdadm -c /dev/md1 -n 3 -c 256 -l 5 -a yes /dev/sdb{5,6,7} 

mdadm: array /dev/md1 started. 

[root@master ~]# mke2fs -t ext4 /dev/md1 

[root@master ~]# mkdir /backup 

[root@master ~]# mount -o auto /dev/md1 /backup 

作者:佚名

來源:51cto

繼續閱讀