1. Create a 20G filesystem with block size 2048, filesystem ext4 and volume label TEST. This partition is required to be automatically mounted to the / tetsing directory on boot, and the default mounting attribute is acl.
2. Create a 5G file system, label HUGE, and require this partition to boot automatically to mount to / mogdata, file system type ext3
3. Write a script to complete the following functions:
Complete with the if statement you learned earlier
(1) List all disk devices identified by the current system
(2) Display disk space information if the number of disks is 1
Otherwise, display the space usage information on the last disk.
3. Write a script to complete the following functions:
Complete with the if statement you learned earlier
(1) Let the user enter a disk
(2) Display its disk space information if it exists
Otherwise, display Fool.
1. Create a 20G filesystem with block size 2048, filesystem ext4 and volume label TEST. This partition is required to be automatically mounted to the / tetsing directory on boot, and the default mounting attribute is acl.
1,Display all disk blocks and partition information [root@localhost scripts]# fdisk -l /dev/[sh]d[a-z] 2,according to 2610 cylinders and End Determine whether partitioning is possible and confirm partitioning 3,Management partition [root@localhost scripts]# fdisk /dev/sdb n,p, , +20G, w 4,Update the Kernel Recognition Partition Table [root@localhost scripts]# partx -a /dev/sdb [root@localhost scripts]# partx -a /dev/sdb 5,format partition [root@localhost scripts]# mke2fs -t ext4 -b 2048 -L 'TEST' /dev/sdb2 6,View default mount properties [root@localhost scripts]# dumpe2fs -h /dev/sdb2 Default mount options: (none) 7,Adjust default mount properties acl [root@localhost scripts]# tune2fs -o acl /dev/sdb2 8,View default mount properties [root@localhost scripts]# dumpe2fs -h /dev/sdb2 Default mount options: acl ##Hey
2. Create a 5G file system, label HUGE, and require this partition to boot automatically to mount to / mogdata, file system type ext3
1,See sdb Zoning table [root@localhost scripts]# kpartx -l /dev/sdb sdb1 : 0 20980827 /dev/sdb 63 sdb2 : 0 224910 /dev/sdb 20980890 2,Destroy partition table [root@localhost scripts]# dd if=/dev/zero of=/dev/sdb bs=512 count=1 1+0 records in 1+0 records out 512 bytes (512 B) copied, 0.00428946 s, 119 kB/s [root@localhost scripts]# kpartx -l /dev/sdb [root@localhost scripts]# 3,Administration sdb [root@localhost scripts]# fdisk /dev/sdb n,p,1, ,+5G,w 4,Let the kernel reread the partition table [root@localhost scripts]# partx -a /dev/sdb 5,Format [root@localhost scripts]# mkfs.ext2 -L 'HUGE' /dev/sdb1 [root@localhost scripts]# tune2fs -O has_journal /dev/sdb1 [root@localhost scripts]# blkid /dev/sdb1 /dev/sdb1: LABEL="HUGE" UUID="1b4a4a93-20a1-439e-b40b-50989cf21fed" SEC_TYPE="ext2" TYPE="ext3" 6,Start up and mount to/mogdata 1)Create directories [root@localhost scripts]# mkdir /mogdata 2)Check whether to create [root@localhost scripts]# ls -ld /mogdata drwxr-xr-x 2 root root 4096 Aug 10 16:29 /mogdata 3)To configure fstab [root@localhost scripts]# vim + /etc/fstab UUID="1b4a4a93-20a1-439e-b40b-50989cf21fed" /mogdata ext4 defaults,sync,noatime,nosuid 2 3 2:Backup every other day 3: Detection order
3. Write a script to complete the following functions:
Complete with the if statement you learned earlier
(1) List all disk devices identified by the current system
(2) Display disk space information if the number of disks is 1
Otherwise, display the space usage information on the last disk.
1,Write scripts [root@localhost scripts]# vim test1.sh #!/bin/bash # Version: 0.0.2 # Author: Lcc.org # Desc: Complete by using the if statement you learned earlier. (1) List all disk devices identified by the current system. (2) If the number of disks is 1, display their disk space information. Otherwise, display the space usage information on the last disk. # bash Weak Type: Direct Assignment without Definition. Default Character Type. Participate in Implicit Conversion of Operations diskfile=`ls /dev/[sh]d[a-z]` COUNT=$(ls /dev/[sh]d[a-z] | wc -l) #Numeric judgment: - eq,-ne,-lt,-le,-gt,-ge if [ $COUNT -eq 1 ] then #Display status information for specified devices fdisk -l $diskfile #Custom state return value: In a bash script, the script is terminated once an exit command is encountered, and the exit status code is the value after exit. exit 0 else #Segmentation with blanks,from-n after#Specified fields as the number of fields per row fdisk -l `echo $diskfile | xargs -n1 | tail -1` exit 0 fi 2,Test grammar(No information is the best information.) [root@localhost scripts]# bash -n test1.sh 3,Give executive authority [root@localhost scripts]# chmod a+x test1.sh 4,Confirmation of implementation results [root@localhost scripts]# ls -ld test1.sh -rwxr-xr-x 1 root root 450 Aug 10 16:44 test1.sh 5,Running scripts(The last one is displayed.) [root@localhost scripts]# ./test1.sh Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0xf6885d69 Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223+ 83 Linux
3. Write a script to complete the following functions:
Complete with the if statement you learned earlier
(1) Let the user enter a disk
(2) Display its disk space information if it exists
Otherwise, display Fool.
1,Write scripts [root@localhost scripts]# cat test2.sh #!/bin/bash # Version: 0.0.3 # Author: Lcc.org # Desc:................. read -t 5 -p 'Enter a special file: ' diskfile [ ! -n "$diskfile" ] && echo "あなたははしごそれをtakeるMethodをknowっていますか?" && exit 1 if fdisk -l | fgrep "Disk $diskfile" &> /dev/null then fdisk -l $diskfile exit 0 else echo "Vitis vinifera L." exit 250 fi 2,Function 1)Give blank space [root@localhost scripts]# bash test2.sh Enter a special file: あなたははしごそれをtakeるMethodをknowっていますか? 2)No blank, no equipment [root@localhost scripts]# bash test2.sh Enter a special file: lala Vitis vinifera L. 3)No blank, equipment [root@localhost scripts]# bash test2.sh Enter a special file: /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0xf6885d69 Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223+ 83 Linux