Linux如何進行分區和目錄管理

第七周作業

 

1、創建一個10G分區,并格式為ext4文件系統:

1、要求其block大小為2048,預留空間百分比為2,卷標為MYDATA,默認掛載屬性包括acl;

~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1

2、掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,縣不更新文件的訪問時間戳;

~]# mkdir /data/mydata

~]# mount -o noexec,noatime,acl /dev/sdb1 /data/mydata

2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;

[root@yangjifeng ~]# fdisk /dev/sda

 

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to

switch off the mode (command ‘c’) and change display units to

sectors (command ‘u’).

 

Command (m for help): p

 

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000658d7

 

Device Boot????? Start???????? End????? Blocks?? Id? System

/dev/sda1?? *?????????? 1????????? 64????? 512000?? 83? Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2???????????? 64??????? 1370??? 10485760?? 83? Linux

/dev/sda3?????????? 1370??????? 1892???? 4194304?? 82? Linux swap / Solaris

/dev/sda4?????????? 1892??????? 6527??? 37235039+?? 5? Extended

/dev/sda5?????????? 1892 ???????3197??? 10486783?? 83? Linux

 

Command (m for help): n

First cylinder (3198-6527, default 3198):

Using default value 3198

Last cylinder, +cylinders or +size{K,M,G} (3198-6527, default 6527): +1G

 

Command (m for help): p

 

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000658d7

 

Device Boot ???Start???????? End????? Blocks?? Id? System

/dev/sda1?? *?????????? 1????????? 64????? 512000?? 83? Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2???????????? 64??????? 1370??? 10485760?? 83? Linux

/dev/sda3?????????? 1370??????? 1892 ????4194304?? 82? Linux swap / Solaris

/dev/sda4?????????? 1892??????? 6527??? 37235039+?? 5? Extended

/dev/sda5?????????? 1892??????? 3197??? 10486783?? 83? Linux

/dev/sda6?????????? 3198??????? 3329???? 1060258+? 83? Linux

 

Command (m for help): t

Partition number (1-6): 6

Hex code (type L to list codes): 82

Changed system type of partition 6 to 82 (Linux swap / Solaris)

 

Command (m for help): p

 

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000658d7

 

Device Boot????? Start???????? End????? Blocks?? Id? System

/dev/sda1?? *?????????? 1?? ?????64????? 512000?? 83? Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2???????????? 64??????? 1370??? 10485760?? 83? Linux

/dev/sda3?????????? 1370??????? 1892???? 4194304?? 82? Linux swap / Solaris

/dev/sda4?????????? 1892??????? 6527??? 37235039+?? 5? Extended

/dev/sda5?????????? 1892??????? 3197??? 10486783?? 83? Linux

/dev/sda6?????????? 3198??????? 3329???? 1060258+? 82? Linux swap / Solaris

 

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: 設備或資源忙.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

~]# partx -a /dev/sda

3、寫一個腳本:

1、獲取并列出妝前系統上的所有磁盤設備;

2、顯示每個磁盤設備上的分區相關的空間使用信息;

[root@yangjifeng scripts]# vim aboutdisk.sh

 

#!/bin/bash

#

FILESYSTEM=`fdisk -l|grep -o ‘/dev/s[hd][a-z]\>’`

 

for i in $FILESYSTEM;do

 

echo -e? “\033[31m disk : $i \033[0m”

 

echo

 

df -h|egrep “文件系統|Filesystem|$i”

 

echo “——————————————”

 

 

done

[root@yangjifeng scripts]# chmod +x aboutdisk.sh

[root@yangjifeng scripts]# ./aboutdisk.sh

4、總結RAID的各個級別及其組合方式和性能的不同;

??? RAID:Redundant Arrays of Inexpensive Disks

RAID級別:RAID0,RAID1,RAID5,RAID10,RAID01,RAID6,RAID50,RAID60

RAID-0

  • 條帶卷
  • 至少需要兩塊磁盤并行處理,將數據分兩部分讀寫
  • 讀寫性能提高,raid中性能最高
  • 無容錯性
  • 可用空間:N*min(s1,s2,…)

RAID-1

  • 鏡像卷
  • 至少需要兩塊磁盤,兩塊磁盤存儲相同數據,用于備份
  • 讀寫性能相當于一塊獨立磁盤,無提升
  • 容錯性高,raid中容錯性最高
  • 可用空間1*min(s1,s2,…)

RAID-4

  • 至少三塊磁盤
  • 兩塊磁盤做數據存儲,第三塊用作獨立存儲數據校驗碼
  • 讀寫性能提高
  • 有容錯性為一塊磁盤

RAID-5

  • 至少三塊磁盤
  • 三塊磁盤存儲數據及校驗碼,校驗碼分別存儲在三個磁盤上
  • 讀寫性能提高
  • 有容錯性為一塊磁盤
  • 可用空間:(N-1)*min(s1,s2,…)

RAID-6

  • 至少四塊磁盤
  • 增加第二個獨立的奇偶校驗信息塊,分別以不同算法計算
  • 有容錯性為兩塊磁盤
  • 可用空間:(N-2)*min(s1,s2,…)

RAID-10

  • 至少四塊磁盤
  • 兩兩磁盤分別做raid1,再將兩raid1陣列做raid0
  • 讀寫性能提高
  • 有容錯性為兩塊,不同raid1中最多損失一塊
  • 可用空間:N*min(s1,s2,…)/2

RAID-50

  • 至少六塊磁盤
  • 三三磁盤分別做raid5,再將兩raid5陣列做raid0
  • 讀寫能力提高
  • 有容錯性為兩塊磁盤,不同raid5中做多損失一塊磁盤

RAID-60

  • 至少八塊磁盤
  • 四四磁盤分別做raid6,再將兩raid6陣列做raid0
  • 讀寫能力提高
  • 有容錯性為四塊磁盤,不同raid6中最多損壞兩塊磁盤

 

5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128K;

~]# mdadm -C /dev/md1 -n 2 -x 1 -c 128 -l 1 /dev/sdb2 /dev/sdb3 /dev/sdb4

? ? ?~]# mdadm -D /dev/md1

 

6、創建一個大小為4G的RAID5設備,CHUNK大小為256k,格式化ext4文件系統,要求可開機自動掛載到/backup目錄,而且不要新訪問時間戳,且支持ACL功能;

?~]# mdadm -C /dev/md5 -n 3 -c 256 -l 5 /dev/sdb1 /dev/sdb2 /dev/sdb3

? ? ?~]# mdadm -D /dev/md5

? ? ?~]# mkfs -t ext4 /dev/md5

? ? ?~]# mount -o auto,acl,noatime /dev/md5 /backup

 

7、寫一個腳本:

1、接受一個以上文件路徑作為參數;

2、顯示每個擁有的行數;

3、總結說明本次共為幾個文件統計了其行數;

scripts]# vim filelines.sh

#!/bin/bash

#

SUM=0

[ $# -lt 1 ] && echo “Son,you must input something” && exit 2

 

for file in $@;do

 

if [ -f $file ];then

 

LINES=`cat $file |wc -l`

 

echo “$file have $LINES lines”

 

let SUM=$SUM+$LINES

else

echo “$file is not exist”

fi

done

echo “$@ have $SUM lines in total.”

scripts]# chmod +x filelines.sh

scripts]# ./filelines.sh /etc/issue /etc/rc.d/init.d/functions

/etc/issue have 3 lines

/etc/rc.d/init.d/functions have 815 lines

/etc/issue /etc/rc.d/init.d/functions have 818 lines in total.

8、寫一個腳本:

1、傳遞兩個以上字符串當作用戶名;

2、創建這些用戶,且密碼同用戶名;

3、總結說明共創建幾個用戶;

#!/bin/bash

#

SUM=0

 

[ $# -lt 1 ] && echo “Son,you are wrong” && exit 2

 

for string in $*;do

 

[ $(echo “$string” |wc -c) -le 3 ] && echo “$string less than 3 letters” && continue

 

if id $string &> /dev/null;then

 

echo “user $string is exist!”

 

else

useradd $string

 

echo “$string” |passwd –stdin $string &> /dev/null

 

echo “add user $string sucess!”

 

let SUM+=1

fi

done

 

echo “add $SUM users in total.”

9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;

scripts]# vim useradd1.sh

#!/bin/bash

#

SUM_UID=0

 

for((i=1;i<=20;i++));do

adduser visitor$i

UID1=`id -u visitor$i`

let SUM_UID+=$UID1

 

done

 

echo “ID intotle $SUM_UID”

[root@yangjifeng scripts]# chmod +x useradd1.sh

[root@yangjifeng scripts]# ./useradd1.sh

ID intotle 10290

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/87345

(0)
N27_yangjifengN27_yangjifeng
上一篇 2017-09-18 11:01
下一篇 2017-09-18 11:52

相關推薦

  • 簡述計算機網絡數據鏈路層

    數據鏈路層    數據鏈路層是什么?      數據鏈路層工作在七層網絡模型的第二層,它定義了在單個鏈路上如何傳輸數據。 數據鏈路層:是為了提供功能上和規程上的方法,以便建立、維護和釋放網絡實體間的數據鏈路 。 物理鏈路(物理線路):是由傳輸介質與設備組成的。原始的物理傳輸線路是指沒有采用高層差錯控…

    Linux干貨 2017-05-15
  • LVM管理

    LVM管理

    2017-12-28
  • CentOS通過bind配置DNS服務器

    一、創建DNS主服務器 1、安裝bind并配置主配置文件     主服務器為CentOS 7,主服務地址為172.16.11.55     安裝bind [root@xinfeng ~]# yum install bind  &n…

    Linux干貨 2016-04-18
  • Linux軟件包安裝

    Linux系統和Windows系統在軟件包安裝上區別很大:     軟件運行環境:         API: Application Programming Interface    POSIX: P…

    Linux干貨 2016-08-21
  • 文件查找find與壓縮

    1.locate:   locate是查詢系統上預建的文件索引數據庫    /var/lib/mlocate/mlocate.db   依賴于事先構建的索引   索引的構建是在系統較為空閑時自動進行(周期性任務),管理 員手動更新數據庫(updatedb)    缺點:索引構建過…

    Linux干貨 2016-08-18
  • RAID概述

    1、引言 RAID全稱Redundant Arrays of Inexpensive Disks / Redundant Arrays of Independent Disks,即獨立冗余磁盤陣列。RAID可以通過相關技術(軟件/硬件),將多個較小的磁盤整合成為一個較大的磁盤整體,而且能從某些方面提高數據的讀寫及數據保護。RAID分為不同…

    Linux干貨 2016-12-24
欧美性久久久久