N21_第7周_磁盘及文件系统管理

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

1474697680181017.jpg

4、总结RAID的各个级别及其组合方式和性能的不同;

RAID:磁盘阵列(Redundant Arrays of Inexpensive Disks,RAID),独立冗余磁盘阵列。

1474697895692982.jpg1474697910986195.jpg

1474697959737276.jpg1474698084978756.jpg

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

(0)
上一篇 2016-09-26 07:43
下一篇 2016-09-26 07:43

相关推荐

  • 系统排错——如何修复和保护你的系统

    作业 1、破解root口令,并为grub设置保护功能 开机启动时按e进入grub菜单,然后按a 编辑当前菜单的kernel选项,在后面追加1,s,S,single中的任意一个,然后回车,输入b键启动 进入了单用户模式,可以直接修改root密码 如何为grub设置保护功能: (1)、首先生成grub的md5密码 (2)、修改grub.conf文件 (3)、重启…

    Linux干货 2016-09-12
  • 系统基础之压缩归档工具详解

    压缩和解压缩工具 概论  在使用操作系统时,我们常会遇到大文件,会使我们很头疼.在面对时间和空间上的选择,只能选择空间,这就要用到压缩工具和归档工具,下面为大家一一介绍.  压缩文件只压缩文本格式的文件,通常不压缩已经是压缩的文件.  压缩文件就会涉及到压缩比:    原理:通过了解文本文件的数据形式,运用压…

    Linux干货 2016-08-18
  • Linux进程管理和性能监控

    概述     监控系统的各方面的性能,保障各类服务的有序运行,是运维工作的重要组成部分,本篇就介绍一些常用的系统监控命令和相关参数的说明     具体包含以下几个部分:         1、进程管理基…

    Linux干货 2016-09-07
  • Linux文件压缩、解压、归档总结

    一、简介   压缩对我们来说通常意味着减小文件体积,节省硬盘空间。在Windows平台上处理大文件或目录中的文件很多时我们都需要对这些文件进行压缩处理,压缩格式多种多样,如:zip、rar、7z等格式,压缩方式也比较多样话,支持按最大压缩比例或者最快时间进行压缩等多种方式,而生成的压缩包就可以让我们更方便的进行拷贝及归档整理。解压缩顾名思义就是回归…

    Linux干货 2015-09-26
  • linux的基础小命令

    1、ifconfig,显示主机的IP地址 2、echo 用法echo [short-option]… [string]…     -n:不进行换行     string可以使用单引号或双引号引用变量,单引号变量内容不会替换,双引号会替换  &nb…

    Linux干货 2016-10-30
  • Homework Week-7 RAID及bash编程

    1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;    (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; fdisk /dev/sda n …

    Linux干货 2016-09-26

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-27 09:36

    写的很好,如果图是自己画的话,就完美了