1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
fdisk /dev/sdb歡迎使用 fdisk (util-linux 2.23.2)。更改將停留在內存中,直到您決定將更改寫入磁盤。使用寫入命令前請三思。命令(輸入 m 獲取幫助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分區號 (2-4,默認 2):起始 扇區 (20973568-41943039,默認為 20973568):將使用默認值 20973568Last 扇區, +扇區 or +size{K,M,G} (20973568-41943039,默認為 41943039):+10G分區 2 已設置為 Linux 類型,大小設為 10 GiB命令(輸入 m 獲取幫助):wThe partition table has been altered!# mke2fs -t ext4 -b 2048 -L MYDATA -m 2 /dev/sdb2# mkdir -pv /data/mydata# mount -t ext4 -o defaults,noexec,nodiratime,acl /dev/sdb2 /data/mydata/
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
# fdisk /dev/sdb命令(輸入 m 獲取幫助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分區號 (2-4,默認 2):起始 扇區 (20973568-41943039,默認為 20973568):將使用默認值 20973568Last 扇區, +扇區 or +size{K,M,G} (20973568-41943039,默認為 41943039):+1G分區 2 已設置為 Linux 類型,大小設為 1 GiB命令(輸入 m 獲取幫助):t分區號 (1,2,默認 2):Hex 代碼(輸入 L 列出所有代碼):82已將分區“Linux”的類型更改為“Linux swap / Solaris”命令(輸入 m 獲取幫助):wThe partition table has been altered!# partx -a /dev/sdb# cat /proc/partitions major minor #blocks name 8 0 41943040 sda 8 1 2048 sda1 8 2 1048576 sda2 8 3 31461376 sda3 8 16 20971520 sdb 8 17 10485760 sdb1 8 18 1048576 sdb2 11 0 1048575 sr0 253 0 10485760 dm-0 253 1 1048576 dm-1 253 2 5242880 dm-2# mkswap /dev/sdb2正在設置交換空間版本 1,大小 = 1048572 KiB無標簽,UUID=13400b7b-46b9-4acf-8314-b52055a3a71f[root@localhost ~]# swapon -a /deb/sdb2# swapon -s文件名 類型 大小 已用 權限/dev/dm-1 partition 1048572 0 -1/dev/sdb2 partition 1048572 0 -2
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
#!/bin/bashecho -e "All of disk:\n `fdisk -l | grep '磁盤' | awk -F , '{print $1}'`"echo -e "The Disk partation information:\n `df -h`"
4、總結RAID的各個級別及其組合方式和性能的不同;
RAID-0: 讀、寫性能最好; 可用空間:N*min(S1,S2,...) 無容錯能力 最少磁盤數:2, 2+RAID-1: 讀性能提升、寫性能略有下降; 可用空間:1*min(S1,S2,...) 有冗余能力 最少磁盤數:2, 2+,必須為偶數塊磁盤RAID-5: 讀性能一樣,寫懲罰為4 可用空間:(N-1)*min(S1,S2,...) 有容錯能力:1塊磁盤 最少磁盤數:3, 3+,奇數塊磁盤RAID-10: 讀性能一樣,寫懲罰為2 可用空間:N*min(S1,S2,...)/2 有容錯能力:每組鏡像最多只能壞一塊; 最少磁盤數:4, 4+,必須為偶數塊磁盤
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
# fdisk /dev/sdaWARNING: 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): nFirst cylinder (4307-15665, default 4307): Using default value 4307Last cylinder, +cylinders or +size{K,M,G} (4307-15665, default 15665): +10GCommand (m for help): nFirst cylinder (5613-15665, default 5613): Using default value 5613Last cylinder, +cylinders or +size{K,M,G} (5613-15665, default 15665): +10GCommand (m for help): nFirst cylinder (6919-15665, default 6919): Using default value 6919Last cylinder, +cylinders or +size{K,M,G} (6919-15665, default 15665): +10GCommand (m for help): tPartition number (1-8): 7Hex code (type L to list codes): fdChanged system type of partition 7 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-8): 8Hex code (type L to list codes): fdChanged system type of partition 8 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-9): 9Hex code (type L to list codes): fdChanged system type of partition 9 to fd (Linux raid autodetect)Command (m for help): wThe partition table has been altered!]# partx -a /dev/sda]# mdadm -C /dev/md0 -a yes -n 2 -l 1 -x 1 -c 128 /dev/sda{7,8,9}
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
]# fdisk /dev/sdaWARNING: 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): nFirst cylinder (8225-15665, default 8225): Using default value 8225Last cylinder, +cylinders or +size{K,M,G} (8225-15665, default 15665): +2GCommand (m for help): nFirst cylinder (8487-15665, default 8487): Using default value 8487Last cylinder, +cylinders or +size{K,M,G} (8487-15665, default 15665): +2GCommand (m for help): nFirst cylinder (8749-15665, default 8749): Using default value 8749Last cylinder, +cylinders or +size{K,M,G} (8749-15665, default 15665): +2GCommand (m for help): tPartition number (1-12): 10Hex code (type L to list codes): fd Changed system type of partition 10 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-12): 11Hex code (type L to list codes): fdChanged system type of partition 11 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-12): 12Hex code (type L to list codes): fdChanged system type of partition 12 to fd (Linux raid autodetect)Command (m for help): wThe partition table has been altered!]# partx -a /dev/sda]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sda{10,11,12}]# mkfs.ext4 /dev/md1
7、寫一個腳本
(1) 接受一個以上文件路徑作為參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共為幾個文件統計了其行數;
#!/bin/bashif [ $# -le 1 ];then echo "more than 2 arg!" exitelse for i in $*;do echo "$i total lines: `wc -l $i | cut -d" " -f1`" donefiecho "Total args: $#"
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
#!/bin/bashif [ $# -le 2 ];then echo "more than 3 arg!" exitelse for i in $*;do id $i &> /dev/null if [ $? -eq 0 ];then echo "$i exists" else useradd $i && echo "$i" | passwd --stdin $i let x++ fi donefiecho "Total create users: $x"
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
#!/bin/bashfor i in {1..20};do useradd visitor$i let x+= `id -u visitor$i`doneecho "sum of visitor user id: $x"
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
#!/bin/bashfor i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do let sum1+= $(`grep "^#" $i | wc -l`) let sum1+= $(`grep "^$" $i | wc -l`)doneecho "total #begin lines:$sum1"echo "total spacelines:$sum2"
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
#!/bin/bashfor i in `grep "/bin/bash$" /etc/passwd | cut -d: -f1`;do echo "user:$i,uid:`id -u $i`" let x+=`id -u $i`doneecho "sum of UID:$x`"
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
#!/bin/bashfor i in `cut -d: -f1 /etc/passwd`;do id $i | grep "," &> /dev/null if [ $? -eq 0 ];then echo "user: $i" && let x++ fidoneecho "sum: $x"
13、創建一個由至少兩個物理卷組成的大小為20G的卷組;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;
[root@localhost ~]# pvcreate /dev/sda{3,5}[root@localhost ~]# vgcreate -s 8M myvg /dev/sda{3,5}[root@localhost ~]# lvcreate -L 5G -n mylv1 myvg[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv1[root@localhost ~]# mkdir /users[root@localhost ~]# echo "/dev/myvg/mylv1 /users ext4 defaults,acl 0 0" >> /etc/fstab
14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;
[root@localhost ~]# useradd -d /users/magedu magedu[root@localhost ~]# su - magedu[magedu@localhost ~]$ cp /etc/rc.sysinit .[magedu@localhost ~]$ cp /tmp/* .
15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;
[root@localhost ~]# lvresize +9G /dev/myvg/mylv1[root@localhost ~]# resize2fs /dev/myvg/mylv1
16、縮減mylv1至7G,確??s減完成后原有數據完全可用;
[root@localhost ~]# umount /dev/myvg/mylv1[root@localhost ~]# e2fsck -f /dev/myvg/mylv1[root@localhost ~]# resize2fs /dev/myvg/mylv1 7G[root@localhost ~]# lvreduce -L 7G /dev/myvg/mylv1[root@localhost ~]# mount -a
17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;
[root@localhost ~]# lvcreate -L 2G -s -p r -n mysnap1 /dev/myvg/mylv1
原創文章,作者:N21_smile,如若轉載,請注明出處:http://www.www58058.com/47087
條理清晰一些,