自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

磁盤分區(qū)創(chuàng)建及bash 簡單應用

存儲 存儲設(shè)備
以下是磁盤分區(qū)創(chuàng)建及bash 簡單應用,希望對磁盤分區(qū)困惑的小伙伴們得到幫助。

 1、創(chuàng)建一個10G分區(qū),并格式為ext4文件系統(tǒng);

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

(2)掛載至/data/mydata目錄,要求掛載是禁止程序自動運行,并且更新文件的訪問時間戳;

[[203331]]

  1. [root@danry ~]# fdisk /dev/sdb  
  2. Welcome to fdisk (util-linux 2.23.2). 
  3.  
  4. Changes will remain in memory only, until you decide to write them. 
  5. Be careful before using the write command. 
  6.  
  7. Device does not contain a recognized partition table 
  8. Building a new DOS disklabel with disk identifier 0xb74243b2. 
  9.  
  10. Command (m for help): n 
  11. Partition type: 
  12.    p   primary (0 primary, 0 extended, 4 free
  13.    e   extende 
  14. Select (default p): p 
  15. Partition number (1-4, default 1): 1 
  16. First sector (2048-41943039, default 2048):  
  17. Using default value 2048 
  18. Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G 
  19. Partition 1 of type Linux and of size 10 GiB is set 
  20.  
  21. Command (m for help): P 
  22.  
  23. Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors 
  24. Units = sectors of 1 * 512 = 512 bytes 
  25. Sector size (logical/physical): 512 bytes / 512 bytes 
  26. I/O size (minimum/optimal): 512 bytes / 512 bytes 
  27. Disk label type: dos 
  28. Disk identifier: 0xb74243b2 
  29.  
  30.    Device Boot      Start         End      Blocks   Id  System 
  31. /dev/sdb1            2048    20973567    10485760   83  Linux 
  32.  
  33. Command (m for help): W 
  34. The partition table has been altered! 
  35.  
  36. Calling ioctl() to re-read partition table
  37. Syncing disks. 
  38. [root@danry ~]# mke2fs -t ext4 -L MYDATA -m 2 -b 2048 /dev/sdb1 
  39. mke2fs 1.42.9 (28-Dec-2013) 
  40. Filesystem label=MYDATA 
  41. OS type: Linux 
  42. Block size=2048 (log=1) 
  43. Fragment size=2048 (log=1) 
  44. Stride=0 blocks, Stripe width=0 blocks 
  45. 655360 inodes, 5242880 blocks 
  46. 104857 blocks (2.00%) reserved for the super user 
  47. First data block=0 
  48. Maximum filesystem blocks=273678336 
  49. 320 block groups 
  50. 16384 blocks per group, 16384 fragments per group 
  51. 2048 inodes per group 
  52. Superblock backups stored on blocks:  
  53.     16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,  
  54.     2048000, 3981312 
  55.  
  56. Allocating group tables: done                             
  57. Writing inode tables: done                             
  58. Creating journal (32768 blocks): done 
  59. Writing superblocks and filesystem accounting information: done    
  60.  
  61. [root@danry ~]# tune2fs -o acl /dev/sdb1 
  62. tune2fs 1.42.9 (28-Dec-2013) 
  63. [root@danry ~]# blkid /dev/sdb1 
  64. /dev/sdb1: LABEL="MYDATA" UUID="fa82387d-d7ab-41ec-be8b-54b25b4c57ac" TYPE="ext4"  
  65. [root@danry ~]#  
  66.  
  67. [root@danry ~]# mount -o acl,noexec,noatime /dev/sdb1 /data/Mydata 

2、創(chuàng)建一個大小為1G的swap分區(qū),并創(chuàng)建好文件系統(tǒng),并啟用之;

  1. [root@danry ~]# fdisk /dev/sdb  
  2. Welcome to fdisk (util-linux 2.23.2). 
  3.  
  4. Changes will remain in memory only, until you decide to write them. 
  5. Be careful before using the write command. 
  6.  
  7.  
  8. Command (m for help): n 
  9. Partition type: 
  10.    p   primary (1 primary, 0 extended, 3 free
  11.    e   extended 
  12. Select (default p): p 
  13. Partition number (2-4, default 2): 2 
  14. First sector (20973568-41943039, default 20973568):  
  15. Using default value 20973568 
  16. Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G 
  17. Partition 2 of type Linux and of size 1 GiB is set 
  18.  
  19. Command (m for help): P 
  20.  
  21. Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors 
  22. Units = sectors of 1 * 512 = 512 bytes 
  23. Sector size (logical/physical): 512 bytes / 512 bytes 
  24. I/O size (minimum/optimal): 512 bytes / 512 bytes 
  25. Disk label type: dos 
  26. Disk identifier: 0xb74243b2 
  27.  
  28.    Device Boot      Start         End      Blocks   Id  System 
  29. /dev/sdb1            2048    20973567    10485760   83  Linux 
  30. /dev/sdb2        20973568    23070719     1048576   83  Linux 
  31.  
  32. Command (m for help): W 
  33. The partition table has been altered! 
  34.  
  35. Calling ioctl() to re-read partition table
  36.  
  37. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 
  38. The kernel still uses the old table. The new table will be used at 
  39. the next reboot or after you run partprobe(8) or kpartx(8) 
  40. Syncing disks. 
  41.  
  42. [root@danry ~]# partx  -a /dev/sdb 
  43. partx: /dev/sdb: error adding partition 1 
  44. [root@danry ~]# mkswap /dev/sdb2 
  45. Setting up swapspace version 1, size = 1048572 KiB 
  46. no label, UUID=ab39844d-56fd-412e-bdb8-08703c3dbf81 
  47. [root@danry ~]# swapo 
  48. swapoff  swapon    
  49. [root@danry ~]# swapo 
  50. swapoff  swapon    
  51. [root@danry ~]# swapon  /dev/sdb2  
  52.  
  53. [root@danry ~]# free -m 
  54.               total        used        free      shared  buff/cache   available 
  55. Mem:           1823         282        1169           9         371        1344 
  56. Swap:          3071           0        3071 
  57. [root@danry ~]# 

3、寫一個腳本

(1)獲取并列出當前系統(tǒng)上的所有磁盤設(shè)備;

(2)顯示每個磁盤設(shè)備上每個分區(qū)相關(guān)的空間使用信息;

  1. [root@localhost Desktop]# cat lsdisk.sh  
  2. #!/bin/bash 
  3. #Author:Danry 
  4. #Description: Display disk partition information! 
  5. display=`ls /dev/[s,h]d[a-z]` 
  6. fdisk -l $display 
  7. [root@localhost Desktop]# 
  8.  
  9. [root@localhost Desktop]# bash lsdisk.sh  
  10. Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors 
  11. Units = sectors of 1 * 512 = 512 bytes 
  12. Sector size (logical/physical): 512 bytes / 512 bytes 
  13. I/O size (minimum/optimal): 512 bytes / 512 bytes 
  14. Disk label type: dos 
  15. Disk identifier: 0x0008508b 
  16.  
  17.    Device Boot      Start         End      Blocks   Id  System 
  18. /dev/sda1   *        2048     1026047      512000   83  Linux 
  19. /dev/sda2         1026048    41943039    20458496   8e  Linux LVM 
  20.  
  21. Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors 
  22. Units = sectors of 1 * 512 = 512 bytes 
  23. Sector size (logical/physical): 512 bytes / 512 bytes 
  24. I/O size (minimum/optimal): 512 bytes / 512 bytes 
  25.  
  26. [root@localhost Desktop]# 

4、總結(jié)Raid的哥哥級別及其組合方式和性能不同;

Raid2、Raid3、Raid4現(xiàn)在幾乎已經(jīng)很少用到了

Raid0:至少兩塊硬盤,一個數(shù)據(jù)打散后寫入到不同的硬盤當中,其增加讀寫性能,降低了數(shù)據(jù)的安全性,磁盤可用率100%。

Raid1:至少兩塊硬盤,一塊硬盤寫數(shù)據(jù),一塊硬盤做備份,其增加數(shù)據(jù)安全性,降低了數(shù)據(jù)的讀寫性能,磁盤可用率50%。

Raid4:至少三塊硬盤,其中兩塊硬盤存放數(shù)據(jù),一塊硬盤存放校驗值,增加了數(shù)據(jù)的讀寫性,也增加了數(shù)據(jù)的安全性,磁盤可用率(磁盤數(shù)-1)

Raid5:至少三塊硬盤,其中兩塊硬盤存放數(shù)據(jù),一塊硬盤存放校驗值,其每次數(shù)據(jù)校驗盤是輪流交替的,增加了數(shù)據(jù)的讀寫性,也增加了數(shù)據(jù)的安全性,磁盤可用率(磁盤數(shù)-1)

Raid10:至少4塊硬盤,其組合先引用Raid1的安全特性,再引用Raid0的讀寫特,若4快盤則:倆倆為一組,每組最多可壞一塊硬盤,磁盤可用率50%性。

Raid01:至少4塊硬盤,其組合是先引用Raid0的讀寫特性,再引用Raid1安全特性,若4快盤則:倆倆為一組,每組最多可壞一塊硬盤,磁盤可用率50%。

5、創(chuàng)建一個大小為10G的Raid1,要求一個空閑盤,而且CHUN大小為128K;

  1. [root@localhost Desktop]# mdadm -C /dev/md1 -n 2 -x 1 -c 128 -l 1 /dev/sdb1 /dev/sdb2 /dev/sdb3 
  2. mdadm: /dev/sdb1 appears to contain an ext2fs file system 
  3.        size=10485760K  mtime=Sat Mar  4 13:38:10 2017 
  4. mdadm: Note: this array has metadata at the start and 
  5.     may not be suitable as a boot device.  If you plan to 
  6.     store '/boot' on this device please ensure that 
  7.     your boot-loader understands md/v1.x metadata, or use 
  8.     --metadata=0.90 
  9. Continue creating array?  
  10. Continue creating array? (y/n) y 
  11. mdadm: Defaulting to version 1.2 metadata 
  12. mdadm: array /dev/md1 started. 
  13. [root@localhost scripts]# mdadm -D /dev/md1  
  14. /dev/md1: 
  15.         Version : 1.2 
  16.   Creation Time : Sat Mar  4 16:27:42 2017 
  17.      Raid Level : raid1 
  18.      Array Size : 5238784 (5.00 GiB 5.36 GB) 
  19.   Used Dev Size : 5238784 (5.00 GiB 5.36 GB) 
  20.    Raid Devices : 2 
  21.   Total Devices : 3 
  22.     Persistence : Superblock is persistent 
  23.  
  24.     Update Time : Sat Mar  4 16:27:58 2017 
  25.           State : clean, resyncing  
  26.  Active Devices : 2 
  27. Working Devices : 3 
  28.  Failed Devices : 0 
  29.   Spare Devices : 1 
  30.  
  31.   Resync Status : 64% complete 
  32.  
  33.            Name : localhost.localdomain:1  (local to host localhost.localdomain) 
  34.            UUID : 345d614a:1c8921d7:4a62d97c:6d9555cc 
  35.          Events : 10 
  36.  
  37.     Number   Major   Minor   RaidDevice State 
  38.        0       8       17        0      active sync   /dev/sdb1 
  39.        1       8       18        1      active sync   /dev/sdb2 
  40.  
  41.        2       8       19        -      spare   /dev/sdb3 

6、創(chuàng)建一個大小為4G的Raid5設(shè)備,chunk大小為256K,格式化ext4文件系統(tǒng),要求自動掛載至、backup目錄,而且不更新訪問時間戳,切支持acl功能;

  1. [root@localhost Desktop]# mdadm -C /dev/md5 -n 4 -c 256 -l 5 /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 
  2. mdadm: /dev/sdb1 appears to contain an ext2fs file system 
  3.        size=10485760K  mtime=Sat Mar  4 13:38:10 2017 
  4. mdadm: /dev/sdb1 appears to be part of a raid array: 
  5.        level=raid1 devices=2 ctime=Sat Mar  4 16:27:42 2017 
  6. Continue creating array? y 
  7. mdadm: Defaulting to version 1.2 metadata 
  8. mdadm: array /dev/md5 started. 
  9. [root@localhost scripts]# mdadm -D /dev/md5  
  10. /dev/md5: 
  11.         Version : 1.2 
  12.   Creation Time : Sat Mar  4 16:33:41 2017 
  13.      Raid Level : raid5 
  14.      Array Size : 3142656 (3.00 GiB 3.22 GB) 
  15.   Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB) 
  16.    Raid Devices : 4 
  17.   Total Devices : 4 
  18.     Persistence : Superblock is persistent 
  19.  
  20.     Update Time : Sat Mar  4 16:33:47 2017 
  21.           State : clean  
  22.  Active Devices : 4 
  23. Working Devices : 4 
  24.  Failed Devices : 0 
  25.   Spare Devices : 0 
  26.  
  27.          Layout : left-symmetric 
  28.      Chunk Size : 256K 
  29.  
  30.            Name : localhost.localdomain:5  (local to host localhost.localdomain) 
  31.            UUID : afc5cf68:aa1f4f34:f3047c47:d0b6f61c 
  32.          Events : 18 
  33.  
  34.     Number   Major   Minor   RaidDevice State 
  35.        0       8       17        0      active sync   /dev/sdb1 
  36.        1       8       18        1      active sync   /dev/sdb2 
  37.        2       8       19        2      active sync   /dev/sdb3 
  38.        4       8       20        3      active sync   /dev/sdb4 
  39. [root@localhost Desktop]# echo "/dev/md5 /backup ext4 defaults,acl,noatime,nodiratime 0 0" >> /etc/fstab [root@localhost scripts]# mount -a 

7、寫一個腳本

(1)、接受一個以上字符串當做用戶名;

(2)、顯示每個文件擁有的行數(shù);

(3)、總結(jié)說明本次共為幾個文件統(tǒng)計了其行數(shù);

  1. #!/bin/bash 
  2. #Author:Danry 
  3. #Description: 
  4. if [ $# -le 1 ] 
  5.     then 
  6.         echo "please input someting" && exit 2 
  7. fi 
  8.  
  9. for i in $* 
  10.     do  
  11.         echo "$i line:$(cat $i | wc -l)" 
  12.     done  
  13.         echo "there are $# files" 
  14.  
  15. [root@danry Desktop]# bash test.sh abc.txt  
  16. abc.txt line:6 
  17. there are 1 files 
  18.  
  19.  
  20. [root@danry Desktop]# cat abc.txt  
  21. hao  
  22. nihao  
  23. hello  
  24. world 
  25. good 
  26. morning` 
  27. [root@danry Desktop]# 

8、寫一個腳本

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

(2)、創(chuàng)建這些用戶;且密碼通用戶名;

(3)、總結(jié)說明共創(chuàng)建了幾個用戶;

  1. #!/bin/bash 
  2. #Author:Danry 
  3. #Description: 
  4. if [ $# -le 1 ] 
  5.     then  
  6.         echo "Must be more than two characters" && exit 2  
  7. fi 
  8.  
  9. sum=0 
  10. for user in $@ 
  11. do 
  12.     if id $user &> /dev/null 
  13.         then 
  14.             echo "user $user already exists!" 
  15.             continue 
  16.     else 
  17.         useradd $user  
  18.         echo "$user" | passwd --stdin $user  &>/dev/null 
  19.         echo "$user has been created." 
  20.         let sum++ 
  21.     fi 
  22. done 
  23.  
  24. echo "$sum users created." 
  25.  
  26. [root@danry Desktop]# bash test2.sh  nihao nibuhao 
  27. nihao has been created. 
  28. nibuhao has been created. 
  29. 2 users created. 
  30. [root@danry Desktop]# 

9、寫一個腳本,新增20個用戶,vistitor1-visitor20;計算它們的ID之和;

  1. #!/bin/bash 
  2. for n in `seq 20` 
  3.     do 
  4.         username=visitor$n 
  5.         useradd $username 
  6.         uid=`id -u $username` 
  7.         let sumuserid+=$uid 
  8.  
  9.     done 
  10.     echo "The users id SUM:$sumuserid" 
  11.  
  12. [root@localhost Desktop]# bash test.sh  
  13. Creating mailbox file: File exists 
  14. Creating mailbox file: File exists 
  15. Creating mailbox file: File exists 
  16. Creating mailbox file: File exists 
  17. Creating mailbox file: File exists 
  18. Creating mailbox file: File exists 
  19. Creating mailbox file: File exists 
  20. Creating mailbox file: File exists 
  21. Creating mailbox file: File exists 
  22. Creating mailbox file: File exists 
  23. Creating mailbox file: File exists 
  24. Creating mailbox file: File exists 
  25. Creating mailbox file: File exists 
  26. Creating mailbox file: File exists 
  27. Creating mailbox file: File exists 
  28. Creating mailbox file: File exists 
  29. Creating mailbox file: File exists 
  30. Creating mailbox file: File exists 
  31. Creating mailbox file: File exists 
  32. Creating mailbox file: File exists 
  33. The users id SUM:20210 
  34. [root@localhost Desktop]# 
  35.  
  36. [root@localhost Desktop]# tail -20 /etc/passwd 
  37. visitor1:x:1001:1001::/home/visitor1:/bin/bash 
  38. visitor2:x:1002:1002::/home/visitor2:/bin/bash 
  39. visitor3:x:1003:1003::/home/visitor3:/bin/bash 
  40. visitor4:x:1004:1004::/home/visitor4:/bin/bash 
  41. visitor5:x:1005:1005::/home/visitor5:/bin/bash 
  42. visitor6:x:1006:1006::/home/visitor6:/bin/bash 
  43. visitor7:x:1007:1007::/home/visitor7:/bin/bash 
  44. visitor8:x:1008:1008::/home/visitor8:/bin/bash 
  45. visitor9:x:1009:1009::/home/visitor9:/bin/bash 
  46. visitor10:x:1010:1010::/home/visitor10:/bin/bash 
  47. visitor11:x:1011:1011::/home/visitor11:/bin/bash 
  48. visitor12:x:1012:1012::/home/visitor12:/bin/bash 
  49. visitor13:x:1013:1013::/home/visitor13:/bin/bash 
  50. visitor14:x:1014:1014::/home/visitor14:/bin/bash 
  51. visitor15:x:1015:1015::/home/visitor15:/bin/bash 
  52. visitor16:x:1016:1016::/home/visitor16:/bin/bash 
  53. visitor17:x:1017:1017::/home/visitor17:/bin/bash 
  54. visitor18:x:1018:1018::/home/visitor18:/bin/bash 
  55. visitor19:x:1019:1019::/home/visitor19:/bin/bash 
  56. visitor20:x:1020:1020::/home/visitor20:/bin/bash 
  57. [root@localhost Desktop]# 
責任編輯:武曉燕 來源: 運維部落
相關(guān)推薦

2009-10-19 18:01:35

Linux磁盤分區(qū)

2020-01-11 19:00:01

GParted磁盤分區(qū)工具開源

2011-01-18 09:51:59

Linux磁盤分區(qū)

2011-01-18 10:25:19

Linux磁盤分區(qū)

2011-08-10 15:54:12

虛擬磁盤VHD

2011-01-18 10:00:59

Linux磁盤分區(qū)

2017-05-10 07:00:20

磁盤分區(qū)dcfldd工具備份分區(qū)

2014-06-09 10:09:31

Linux磁盤分區(qū)

2009-12-15 08:50:58

Windows 7系統(tǒng)分區(qū)

2013-08-23 14:07:45

磁盤分區(qū)

2017-03-09 14:58:19

GPartedLinux磁盤分區(qū)

2023-01-31 14:00:01

TIAPUUID

2014-06-06 13:51:36

磁盤分區(qū)IO分析

2019-02-11 14:50:21

Linux分區(qū)命令

2014-05-30 09:44:18

磁盤分區(qū)Windows平臺

2021-07-30 23:05:22

Windows 11Windows微軟

2010-03-02 15:09:26

Linux mount

2009-05-18 09:23:00

網(wǎng)管遠程備份

2018-06-25 11:58:23

Linuxparted磁盤分區(qū)

2022-04-12 17:39:14

Linux磁盤分區(qū)
點贊
收藏

51CTO技術(shù)棧公眾號