N21_第7周_磁盘及文件系统管理
作业题目:
1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@localhost ~]# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 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: 0x00048a22 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 548 4194304 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 548 2611 16571392 83 Linux Command (m for help): d Partition number (1-4): 3 Command (m for help): p Disk /dev/sda: 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: 0x00048a22 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 548 4194304 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (548-2610, default 548): Using default value 548 Last cylinder, +cylinders or +size{K,M,G} (548-2610, default 2610): +10G Command (m for help): wq [root@localhost ~]# fdisk -l Disk /dev/sda: 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: 0x00048a22 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 548 4194304 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 548 1853 10484094+ 83 Linux
# partx -a /dev/sda # mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sda3 # mkdir -p /data/mydata # mount -t ext4 -o noexec,noatime,acl /dev/sda3 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@localhost data]# 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): n Command action e extended p primary partition (1-4) p Selected partition 4 First cylinder (1854-2610, default 1854): Using default value 1854 Last cylinder, +cylinders or +size{K,M,G} (1854-2610, default 2610): +1000M Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Hex code (type L to list codes): 82 Changed system type of partition 1 to 82 (Linux swap / Solaris) Command (m for help): wq The partition table has been altered! [root@localhost data]# partx -a /dev/sda [root@localhost data]# mkswap /dev/sdb4 [root@localhost data]# swapon /dev/sda5
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@localhost ~]# vi getFdisk.sh #!/bin/bash Disk_name=$(fdisk -l | awk -F'[ :]+' '/^Disk \/dev\/sd?/ {print $2}') for i in ${Disk_name}; do fdisk -l $i done
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID:磁盘阵列(Redundant Arrays of Inexpensive Disks,RAID),独立冗余磁盘阵列。
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 1 -c 128 -n 2 -x 1 /dev/sdb{6,7,8}
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
# mdadm -C /dev/md0 -a yes -n 3 -c 256 -l 5 /dev/sdb{1,2,3} # mke2fs -t ext4 /dev/md0
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash if [[ $# -eq 0 ]]; then echo -e "\nusage: sh $0 <FILE...>\n" exit 1 else for i in "$@"; do wc -l ${i} done echo "Total number of files: $#" fi
[root@localhost ~]# sh getFileMessage.sh /home/test1.txt /home/test2.txt 3 /home/test1.txt 0 /home/test2.txt Total number of files: 2
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash Num_user=0 if [[ $# -le 1 ]]; then echo -e "\nusage: sh $0 <arg1> <arg2>..." echo -e "Pls enter at least two strings.\n" exit 1 else for i in "$@"; do useradd ${i} &>/dev/null if [[ $? -eq 0 ]]; then let Num_user+=1 echo "${i}" | passwd --stdin ${i} &>/dev/null fi done echo "The number of users created: ${Num_user}" echo -e "User lists:" echo "$*" | sed -r 's/[[:space:]]+/\n/g' fi
[root@localhost ~]# sh createUser.sh abc bcd cde The number of users created: 3 User lists: abc bcd cde
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
[root@localhost ~]# vi create20users.sh #!/bin/bash sum=0 for i in visitor{1..20}; do useradd $i let sum+=$(id -u $i) done echo "The sum of UID is: $sum"
[root@localhost ~]# sh create20users.sh The sum of UID is: 10250
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash if [[ $# -ne 1 ]]; then echo 'Pls enter only one argument.' else echo "The number of #: $(grep '^#' $1 | wc -l)" echo "The number of blank lines: $(grep '^$' $1 | wc -l)" fi
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash Sum_uid=0 echo "UserName:UID lists" for i in $(grep '\<bash\>$' /etc/passwd | cut -d : -f1); do echo "${i}:$(id -u ${i})" let Sum_uid+=$(id -u ${i}) done echo "The sum of UID: $Sum_uid"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash Sum_user=0 echo "User list:" while read line; do User_name=$(echo ${line} | cut -d: -f1) Num=$(id -G ${User_name} | wc -w) if [[ ${Num} -eq 2 ]]; then echo "${User_name}" let Sum_user+=1 fi done < /etc/passwd echo "The number of user: ${Sum_user}"
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
# pvcreate /dev/sdb /dev/sdc # vgcreate -s 8M myvg /dev/sd{b,c} # lvcreate -L 5G -n mylv1 /dev/myvg # mkfs.ext4 /dev/myvg/mylv1 # echo "/dev/myvg/mylv1 /users ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
# useradd -d /users/magedu magedu # su - magedu $ pwd /users/magedu $ cp /etc/fstab /etc/issue ./
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
# cp /etc/fstab ./ # lvextend -L +4G -n /dev/myvg/mylv1 # resize2fs /dev/myvg/mylv1
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
# umount /users # e2fsck -f /dev/myvg/mylv1 # resize2fs /dev/myvg/mylv1 7G # lvreduce -L 7G -n /dev/myvg/mylv1
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
# lvcreate -L 3G -p r -s -n mylv1_bak /dev/myvg/mylv1
其它,fdisk分区命令
Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)
原创文章,作者:365,如若转载,请注明出处:http://www.178linux.com/48827
评论列表(1条)
写的很好,如果图是自己画的话,就完美了