1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@localhost ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xa0b19c72. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-10443, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +10G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 [root@localhost ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 512000 sda1 8 2 2048000 sda2 8 3 123268096 sda3 8 16 83886080 sdb 8 17 10490413 sdb1 [root@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 -L 'MYDATA' /dev/sdb1 mke2fs 1.41.12 (17-May-2010) 文件系統標簽=MYDATA 操作系統:Linux 塊大小=2048 (log=1) 分塊大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 657408 inodes, 5245206 blocks 104904 blocks (2.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=543162368 321 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 29 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# mkdir -p /data/mydata [root@localhost ~]# echo 'LABEL=MYDATA /data/mydata ext4 defaults,acl 0 0' >> /etc/fstab [root@localhost ~]# mount -a
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
[root@localhost ~]# fdisk /dev/sdb 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (6529-10443, default 6529): Using default value 6529 Last cylinder, +cylinders or +size{K,M,G} (6529-10443, default 10443): +1G Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 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. [root@localhost ~]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 [root@localhost ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1060284 KiB no label, UUID=54ef09ac-5e9e-4453-9269-84936c6c1c19 [root@localhost ~]# swapon /dev/sdb2
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
[root@localhost tmp]# cat t3.sh #!/bin/bash # i=1 fdisk -l /dev/[s,h]d[a-z] | grep "Disk /" for DevName in $(ls /dev/[s,h]d[a-z][1-9]);do if [ $i -eq 1 ] ;then df -h $DevName | awk -v OFS=" " '{print $1,$2,$3,$4,$5,$6}' let i++ else df -h $DevName | grep -v "File" | awk -v OFS=" " -v name=$DevName '{print name,$2,$3,$4,$5,$6}' fi done
4、總結RAID的各個級別及其組合方式和性能的不同;
RAID級別 | RAID0 | RAID1 | RAID5 | RAID6 | RAID10 | RAID01 |
容錯 | 無 | 有 | 有 | 有 | 有 | 有 |
冗余 | 無 | 鏡像 | 奇偶校驗 | 奇偶校驗 | 鏡像 | 鏡像 |
讀性能 | 有所提高 | 有所提高 | 有所提高 | 有所提高 | 有所提高 | 有所提高 |
寫性能 | 有所提高 | 略有下降 | 有所提高 | 有所提高 | 有所提高 | 有所提高 |
最少磁盤數 | 2,2+ | 2,2+ | 3,3+ | 4,4+ | 4,4+ | 4,4+ |
允許磁盤最多損壞數 | 0 | 1 | 1 | 2 | 每組1個 | 每組1個 |
可用容量 | N*min(s1,s2,…) | N*min(s1,s2,…)/2 | (N-1)*min(s1,s2,…) | (N-2)*min(s1,s2,…) | N*min(s1,s2,…)/2 | N*min(s1,s2,…)/2 |
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
[root@localhost ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x75d40809. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-10443, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-10443, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-10443, default 10443): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (2613-10443, default 2613): Using default value 2613 Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +10G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 [root@localhost ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 512000 sda1 8 2 2048000 sda2 8 3 123268096 sda3 8 16 83886080 sdb 8 17 10490413 sdb1 8 18 10490445 sdb2 8 19 10490445 sdb3 [root@localhost ~]# mdadm -C /dev/md0 -n 2 -l 1 -c 128 -x 1 /dev/sdb{1,2,3} mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@localhost ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Aug 1 20:19:54 2016 Raid Level : raid1 Array Size : 10482176 (10.00 GiB 10.73 GB) Used Dev Size : 10482176 (10.00 GiB 10.73 GB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 1 20:20:40 2016 State : clean, resyncing Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Resync Status : 87% complete Name : localhost.localdomain:0 (local to host localhost.localdomain) UUID : 2277076e:bc9b6d70:eabfb522:cee50958 Events : 14 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 18 1 active sync /dev/sdb2 2 8 19 - spare /dev/sdb3
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
[root@localhost ~]# fdisk /dev/sdb 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-10443, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (524-10443, default 524): Using default value 524 Last cylinder, +cylinders or +size{K,M,G} (524-10443, default 10443): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1047-10443, default 1047): Using default value 1047 Last cylinder, +cylinders or +size{K,M,G} (1047-10443, default 10443): +10G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# mdadm -C /dev/md5 -n 3 -l 5 -c 256 /dev/sdb{1,2,3} mdadm: /dev/sdb1 appears to be part of a raid array: level=raid1 devices=2 ctime=Mon Aug 1 20:19:54 2016 mdadm: largest drive (/dev/sdb3) exceeds size (4196864K) by more than 1% Continue creating array? Continue creating array? (y/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md5 started. [root@localhost ~]# mdadm -D /dev/md5 /dev/md5: Version : 1.2 Creation Time : Mon Aug 1 20:35:52 2016 Raid Level : raid5 Array Size : 8393728 (8.00 GiB 8.60 GB) Used Dev Size : 4196864 (4.00 GiB 4.30 GB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 1 20:36:12 2016 State : clean, degraded, recovering Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 256K Rebuild Status : 8% complete Name : localhost.localdomain:5 (local to host localhost.localdomain) UUID : 8d09334e:eb6c0810:f773a7f9:2030c941 Events : 2 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 18 1 active sync /dev/sdb2 3 8 19 2 spare rebuilding /dev/sdb3 [root@localhost ~]# mkfs.ext4 /dev/md5 [root@localhost ~]# mkdir /backup [root@localhost ~]# echo "/dev/md5 /backup ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
7、寫一個腳本
(1) 接受一個以上文件路徑作為參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共為幾個文件統計了其行數;
[root@localhost tmp]# cat test7.sh #!/bin/bash if [ $# -eq 0 ];then echo "Please give a file name !" exit 1 fi for i in $* do echo "$i have $(wc -l $i | cut -d' ' -f1) lines" done echo "本次共為$#個文件統計了其行數!"
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
#!/bin/bash if [ $# -lt 2 ];then echo "At least give two username !" exit 1 fi for i in $* do useradd $i echo "$i:$i" | chpasswd done echo "Total Add $# users !"
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
[root@localhost tmp]# cat test9.sh #!/bin/bash declare -i tid for i in {1..20} do useradd visitor$i let tid+=$(id -u visitor$i) done echo "Total id is $tid !"
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
[root@localhost tmp]# cat test10.sh #!/bin/bash declare -i l1 declare -i space for i in /etc/{rc.d/{rc.sysinit,init.d/functions},fstab} do let l1+=$(grep '^#' $i | wc -l | cut -d' ' -f1) let space+=$(grep '^[[:space:]]*$' $i | wc -l | cut -d' ' -f1) done echo "Comment lines beginning with a '#' total $l1 lines !" echo "Blank lines total $space lines !"
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
[root@localhost tmp]# cat test11.sh #!/bin/bash declare -i uid for i in $(grep bash$ /etc/passwd | cut -d: -f1) do echo "$i, `id -u $i`" let uid+=`id -u $i` done echo "Total uid is $uid !"
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
#!/bin/bash awk '{FS=":"} $3 != $4 {print $1;n++}END{ print n}' /etc/passwd
13、創建一個由至少兩個物理卷組成的大小為20G的卷組;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xdb484fda.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xcbb0c025.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# pvcreate /dev/sd{b,c}1
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
[root@localhost ~]# vgcreate -s 8m myvg /dev/sd{b,c}1
Volume group "myvg" successfully created
[root@localhost ~]# lvcreate -L 5g -n mlv1 myvg
Logical volume "mlv1" created
[root@localhost ~]# mkfs.ext4 /dev/myvg/mlv1
[root@localhost ~]# echo "/dev/myvg/mlv1 /users ext4 defaults,acl 0 0" >> /etc/fstab
[root@localhost ~]# vgdisplay
— Volume group —
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.98 GiB
PE Size 8.00 MiB
Total PE 2558
Alloc PE / Size 640 / 5.00 GiB
Free PE / Size 1918 / 14.98 GiB
VG UUID Yrb5ku-mOoE-cdk3-E0QW-QmyY-hM39-BRGBjk
[root@localhost ~]# lvdisplay
— Logical volume —
LV Path /dev/myvg/mlv1
LV Name mlv1
VG Name myvg
LV UUID oqYvWw-FpYI-Ccd4-KWRG-V2Dq-pcNS-apoGJ6
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-08-02 22:23:21 +0800
LV Status available
# open 1
LV Size 5.00 GiB
Current LE 640
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0
14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;
[root@localhost ~]# useradd -d /users/magedu magedu [root@localhost ~]# echo magedu:123456 | chpasswd [root@localhost ~]# su - magedu [magedu@localhost ~]$ pwd /users/magedu [magedu@localhost ~]$ cp /etc/{passwd,group} . [magedu@localhost ~]$ ls group passwd
15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;
[root@localhost ~]# lvextend -L 9G /dev/myvg/mlv1 Size of logical volume myvg/mlv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mlv1 successfully resized [root@localhost ~]# resize2fs /dev/myvg/mlv1 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/mlv1 is mounted on /users; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/myvg/mlv1 to 2359296 (4k) blocks. The filesystem on /dev/myvg/mlv1 is now 2359296 blocks long. [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/myvg/mlv1 LV Name mlv1 VG Name myvg LV UUID oqYvWw-FpYI-Ccd4-KWRG-V2Dq-pcNS-apoGJ6 LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-08-02 22:23:21 +0800 LV Status available # open 1 LV Size 9.00 GiB Current LE 1152 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@localhost ~]# ls /users/magedu/ group passwd
16、縮減mylv1至7G,確保縮減完成后原有數據完全可用;
[root@localhost ~]# lvreduce -L 7G /dev/myvg/mlv1 WARNING: Reducing active and open logical volume to 7.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mlv1? [y/n]: y Size of logical volume myvg/mlv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mlv1 successfully resized [root@localhost ~]# resize2fs /dev/myvg/mlv1 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/mlv1 is mounted on /users; on-line resizing required On-line shrinking from 2359296 to 1835008 not supported. [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/myvg/mlv1 LV Name mlv1 VG Name myvg LV UUID oqYvWw-FpYI-Ccd4-KWRG-V2Dq-pcNS-apoGJ6 LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-08-02 22:23:21 +0800 LV Status available # open 1 LV Size 7.00 GiB Current LE 896 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@localhost ~]# ls /users/magedu/ group passwd
17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;
[root@localhost ~]# lvcreate -L 5G -p r -s -n mylv1_snapshot /dev/myvg/mlv1 Logical volume "mylv1_snapshot" created
原創文章,作者:N21-天天,如若轉載,請注明出處:http://www.www58058.com/33353
寫的很好,但是為什么排版不一樣那?