1、创建一个10G分区,并格式为ext4文件系统;

   (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;

   (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;

#fdisk:分区管理
[root@localhost shell]# fdisk /dev/sda
Command (m for help): m
#下面是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)
#p:显示分区列表
#可以看出sd 1-3是主分区,sd4是扩展分区,sd5是建立在扩展分区上的逻辑分区
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x000ba764
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2358    18631680   83  Linux
/dev/sda3            2358        2611     2031616   82  Linux swap / Solaris
/dev/sda4            2611        6527    31456607+   5  Extended
/dev/sda5            2611        5222    20974163+  83  Linux
#n:创建新分区
#由于我的主分区已全部使用,所以我直接建逻辑分区
Command (m for help): n
#起始柱面,可以数字指定,我这里直接回车默认起始柱面,不浪费空间
First cylinder (5223-6527, default 5223): 
Using default value 5223
#结束柱面,+10G,指定为起始柱面后10G
Last cylinder, +cylinders or +size{K,M,G} (5223-6527, default 6527): +10G
#好尴尬哦,超出范围了。别慌,此刻关机,然后硬盘->扩展,增大磁盘空间
Value out of range.
#我就是这么懒。。大小改为2G,哈哈
Last cylinder, +cylinders or +size{K,M,G} (5223-6527, default 6527): +2G
#查看是否添加成功,p显示,可以看到sd6已创建好
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x000ba764
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2358    18631680   83  Linux
/dev/sda3            2358        2611     2031616   82  Linux swap / Solaris
/dev/sda4            2611        6527    31456607+   5  Extended
/dev/sda5            2611        5222    20974163+  83  Linux
/dev/sda6            5223        5484     2104483+  83  Linux
#w:记得保存哦
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: Device or resource busy.
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 shell]# cat /proc/partitions 
major minor  #blocks  name
   8        0   52428800 sda
   8        1     307200 sda1
   8        2   18631680 sda2
   8        3    2031616 sda3
   8        4          1 sda4
   8        5   20974163 sda5
#partx:通知内核重新读取硬盘分区表
[root@localhost shell]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@localhost shell]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
[root@localhost shell]# cat /proc/partitions 
major minor  #blocks  name
   8        0   52428800 sda
   8        1     307200 sda1
   8        2   18631680 sda2
   8        3    2031616 sda3
   8        4          1 sda4
   8        5   20974163 sda5
   8        6    2104483 sda6
[root@localhost shell]# mke2fs -b 2048 -m 2 -L "MYDATA" -t ext4 /dev/sda6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYDATA
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131560 inodes, 1052240 blocks
21044 blocks (2.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=538968064
65 block groups
16384 blocks per group, 16384 fragments per group
2024 inodes per group
Superblock backups stored on blocks: 
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#创建挂载目录
[root@localhost shell]# mkdir -p /data/mydata
#挂载
[root@localhost shell]# mount -o noexec,noatime,acl -t ext4 /dev/sda6 /data/mydata


2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;

Command (m for help): n
First cylinder (5485-6527, default 5485): 
Using default value 5485
Last cylinder, +cylinders or +size{K,M,G} (5485-6527, default 6527): +1G
#l:显示所有文件类型,可以看到82是linux swap类型
Command (m for help): 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
#t:调整文件系统类型
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 82
Changed system type of partition 7 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: Device or resource busy.
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 /dev/sda
# 1:      2048-   616447 (   614400 sectors,    314 MB)
# 2:    616448- 37879807 ( 37263360 sectors,  19078 MB)
# 3:  37879808- 41943039 (  4063232 sectors,   2080 MB)
# 4:  41943040-104856254 ( 62913215 sectors,  32211 MB)
# 5:  41943103- 83891429 ( 41948327 sectors,  21477 MB)
# 6:  83891493- 88100459 (  4208967 sectors,   2154 MB)
# 7:  88100523- 90221039 (  2120517 sectors,   1085 MB)
[root@localhost ~]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
[root@localhost ~]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
BLKPG: Device or resource busy
error adding partition 7
#mkswap 创建swap文件系统
[root@localhost ~]# mkswap /dev/sda7
Setting up swapspace version 1, size = 1060252 KiB
no label, UUID=e21172dc-387a-418d-beb6-9d0d0c38f179


3、写一个脚本

   (1)、获取并列出当前系统上的所有磁盘设备;

   (2)、显示每个磁盘设备上每个分区相关的空间使用信息;

[root@localhost week7]# cat third.sh
#/bin/bash
for i in $(fdisk -l | grep -o "^Disk /dev/sd[a-z]\>" | cut -d ' ' -f2);do
df -h $i*;
done
[root@localhost week7]# ./third.sh
Filesystem      Size  Used Avail Use% Mounted on
-               485M  256K  484M   1% /dev
/dev/sda1       291M   34M  242M  13% /boot
/dev/sda2        18G  9.2G  7.5G  56% /
-               485M  256K  484M   1% /dev
-               485M  256K  484M   1% /dev
-               485M  256K  484M   1% /dev
/dev/sda6       2.0G   74M  1.9G   4% /data/mydata
-               485M  256K  484M   1% /dev


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

raid 0:将数据平均分配到每个磁盘中。读写性能提升,但没有容错能力。
raid 1:多个备份。数据被拷贝多份写在每个磁盘中。读性能提高,写性能降低。有容错能力,但磁盘空间利用率低。
raid 4:增加了一块校验分区。通过奇偶校验存储校验码,当其中一块存储块坏了,可以算出其中的值。有容错能力,写能力降低。
raid 5:也是奇偶校验,不过不是把校验码存储在单独的一个分区上。而是交换的存储在所有分区上。有容错能力,但只能坏一块磁盘分区,读写性能提升。
raid 6:根据两种不同算法算出两种校验码存储在两块不同的奇偶校验盘上,容错能力提升,但写两次校验码,写能力降低,空间利用率降低。
raid-10:先做raid1,再做raid0.读写性能提升,有容错能力。



5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;

[root@localhost ~]# mdadm -C /dev/md0 -n 2 -x 1 -l 1 -c 256  /dev/sda{8,9,10}
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? n
mdadm: create aborted.
[root@localhost ~]# mdadm -C /dev/md0 -n 2 -x 1 -l 1 -c 256  -a yes /dev/sda{8,9,10}
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 : Sun Sep 25 22:49:32 2016
     Raid Level : raid1
     Array Size : 1059200 (1034.55 MiB 1084.62 MB)
  Used Dev Size : 1059200 (1034.55 MiB 1084.62 MB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent
    Update Time : Sun Sep 25 22:50:29 2016
          State : clean 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1
           Name : localhost.localdomain:0  (local to host localhost.localdomain)
           UUID : bc9655fc:708e6986:1431473a:acb36dd5
         Events : 17
,
    Number   Major   Minor   RaidDevice State
       0       8        8        0      active sync   /dev/sda8
       1       8        9        1      active sync   /dev/sda9
       2       8       10        -      spare   /dev/sda10


6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;

[root@localhost ~]# mdadm -C /dev/md1 -n 3 -l 5 -c 256 /dev/sda{11,12,13}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]# mount -o exec,noatime,acl -t ext4 /dev/md1 /backup
mount: wrong fs type, bad option, bad superblock on /dev/md1,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
#格式化为ext4文件系统
[root@localhost ~]# mkfs.ext4 /dev/md1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
132464 inodes, 529536 blocks
26476 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=545259520
17 block groups
32768 blocks per group, 32768 fragments per group
7792 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#挂载
[root@localhost ~]# mount -o exec,noatime,acl -t ext4 /dev/md1 /backup


7、写一个脚本

   (1) 接受一个以上文件路径作为参数;

   (2) 显示每个文件拥有的行数;

   (3) 总结说明本次共为几个文件统计了其行数;

[root@localhost week7]# ./seven.sh ~/shell/week7/seven.sh ~/shell/week7/third.sh
/root/shell/week7/seven.sh has 16 lines
/root/shell/week7/third.sh has 4 lines
there are 2 files
[root@localhost week7]# cat seven.sh
#/bin/bash
if [ $# -eq 0 ];then
    echo "args must greater than 0"
    exit 2
fi
count=0
for filename in $@;do
    if [ ! -f $filename ];then
echo "$filename is not a file or filepath is not correct"
exit 3
    fi
    lines=$(wc -l $filename | cut -d ' ' -f1)
    echo "$filename has $lines lines"
    let count++
done
echo "there are $count files"
#执行结果
[root@localhost week7]# ./seven.sh ~/shell/week7/seven.sh ~/shell/week7/third.sh
/root/shell/week7/seven.sh has 16 lines
/root/shell/week7/third.sh has 4 lines
there are 2 files


8、写一个脚本

   (1) 传递两个以上字符串当作用户名;

   (2) 创建这些用户;且密码同用户名;

   (3) 总结说明共创建了几个用户;

[root@localhost week7]# cat eight.sh
#!/bin/bash
if [ $# -lt 2 ];then
    echo "参数个数不能少于两个"
    exit 2
fi
count=0
for i in $@;do
    username=$i
    grep "^$username" /etc/passwd &> /dev/null
    if [ $? -ne 0 ];then
        useradd $username
        let count++
    fi
    echo $username | passwd --stdin $username > /dev/null
done
echo "一共创建了$count个用户"
#执行结果,如果用户存在就不创建只修改密码,不存在则创建
[root@localhost week7]# ./eight.sh test1 test2 test3
一共创建了0个用户
[root@localhost week7]# ./eight.sh test4 test5 test6
一共创建了3个用户


9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;

[root@localhost week7]# cat nine.th
#!/bin/bash
idsum=0
for i in $(seq 1 20);do
    username=visitor$i
    
#   判断用户是否存在,不存在则创建用户
    grep "^$username" /etc/passwd &> /dev/null
    if [ $? -ne 0 ];then
        useradd $username
    fi
    
#获取每个用户的id    
    idnum=$(id $username | grep -o "uid=[0-9]\+" | cut -d'=' -f2)
#累计id和
#shell数值运算:1.let sum=num1+num2  2.sum=$[num1+num2] 3.sum=$((num1+num2)) 4.sum=$(expr$num1 + $num2)
    idsum=$[idsum+$idnum]
done
echo "sum of id is $idsum"
    
[root@localhost week7]# ./nine.th
sum of id is 10650


10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;

[root@localhost week7]# cat ten.sh
#!/bin/bash
#定义数组 declare -a
declare -a array
#数组赋值
#1.逐一赋值  array[0]="apple" array[1]="pear" array="banana"
#2.统一赋值  array=("apple" "pear" "banana") 或者 array="apple pear banana"
#3.上面两种混合赋值:array=([0]="apple" [2]="banana")
#4.从标准输入流赋值 read -a array
array[0]="/etc/rc.d/rc.sysinit"
array[1]="/etc/rc.d/init.d/functions"
array[2]="/etc/fstab"
#进入for循坏对数组中每个元素进行处理
#${#array[@]}:数组长度
for ((i=0;i<${#array[@]};i++));do
#${array[i]}:取出数组第i个数据值
    puncnum=$(grep "^#" ${array[i]} | wc -l)
    spacenum=$(grep "^$" ${array[i]} | wc -l)
    echo "${array[i]} has $puncnum lines of # and $spacenum lines of space"
done 
#查看执行结果
[root@localhost week7]# ./ten.sh
/etc/rc.d/rc.sysinit has 44 lines of # and 96 lines of space
/etc/rc.d/init.d/functions has 40 lines of # and 72 lines of space
/etc/fstab has 7 lines of # and 1 lines of space


11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;

#呵呵哒,awk就是强大,没用脚本就完成任务了
[root@localhost week7]# grep "bash$" /etc/passwd | awk -F : 'BEGIN{idsum=0} {print $1","$3;idsum=idsum+$3} END{print "sum of uid is "idsum}'
root,0
nat,500
yannic,501
user1,502
user2,503
test1,504
hadoop,505
bash,508
testbash,509
basher,510
username,512
user10,513
user11,514
user12,515
user13,516
user14,517
user15,518
user16,519
user17,520
user18,521
user19,522
visitor1,523
visitor2,524
visitor3,525
visitor4,526
visitor5,527
visitor6,528
visitor7,529
visitor8,530
visitor9,531
visitor10,532
visitor11,533
visitor12,534
visitor13,535
visitor14,536
visitor15,537
visitor16,538
visitor17,539
visitor18,540
visitor19,541
visitor20,542
sum of uid is 20879


12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;

[root@localhost week7]# cat twelve.sh
#!/bin/bash
count=0
echo -n "these users has supple groups : "
for user in $(cut -d":" -f1 /etc/passwd);do
    id $user | grep "groups=.*," > /dev/null
    if [ $? -eq 0 ];then
echo -n "$user "
let count++
    fi
done
echo 
echo "total amount of users has supple groups is $count"
[root@localhost week7]# ./twelve.sh
these users has supple groups : bin daemon adm postfix nat 
total amount of users has supple groups is 5


13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;

#1.创建分区,并调整文件系统类型为8e(lvm)
#2.创建pv
[root@localhost week7]# pvcreate /dev/sda{6,7}
[root@localhost week7]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sda6       lvm2 a--  2.01g 2.01g
  /dev/sda7       lvm2 a--  1.01g 1.01g
#3.创建卷组
#-s:指明PE大小
[root@localhost week7]# vgcreate -s 8M vg1 /dev/sda{6,7}
  Volume group "vg1" successfully created
#4.创建逻辑卷
#-L:指定逻辑卷大小,我这里大小不够,就指定为1G啦
#-n:逻辑卷的名字
[root@localhost week7]# lvcreate -L 1G -n mylv1 vg1
  Logical volume "mylv1" created
[root@localhost week7]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/mylv1
  LV Name                mylv1
  VG Name                vg1
  LV UUID                YwWy6v-Mhpp-1sd8-emNY-DQ5W-LdWh-CDmx21
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-09-26 08:38:47 -0700
  LV Status              available
  # open                 0
  LV Size                1.00 GiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
#5.挂载
#格式化文件系统
[root@localhost week7]# mkfs.ext4 /dev/vg1/mylv1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#在/etc/fstab 文件中增加一行
/dev/vg1/mylv1          /users                  ext4    defaults,acl    0 0


14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;

[root@localhost week7]# useradd -d /users/magedu magedu
[root@localhost week7]# su - magedu


15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;

#lvextend:扩展逻辑卷
#-L :size大小 3G表示扩展至3G,+3G:表示增加3G大小
[root@localhost ~]# lvextend -L 3G /dev/vg1/mylv1
  Extending logical volume mylv1 to 3.00 GiB
  Logical volume mylv1 successfully resized
#resize2fs:同步文件系统
[root@localhost ~]# resize2fs /dev/vg1/mylv1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg1/mylv1 is mounted on /users; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg1/mylv1 to 786432 (4k) blocks.
The filesystem on /dev/vg1/mylv1 is now 786432 blocks long.


16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;

#1.先卸载
[root@localhost ~]# umount /dev/vg1/mylv1
#2.检测逻辑卷剩余空间
[root@localhost ~]# e2fsck -f /dev/vg1/mylv1
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg1/mylv1: 11/196608 files (0.0% non-contiguous), 20924/786432 blocks
#3.将文件系统减少大小
[root@localhost ~]# resize2fs /dev/vg1/mylv1 2G
#4.逻辑卷减少大小
[root@localhost ~]# lvreduce -L 2G /dev/vg1/mylv1
  WARNING: Reducing active logical volume to 2.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv1? [y/n]: y
  Reducing logical volume mylv1 to 2.00 GiB
  Logical volume mylv1 successfully resized


17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;

[root@localhost ~]# lvcreate -L 1G -s -n lv1snapshot /dev/vg1/mylv1
  Logical volume "lv1snapshot" created


这次作业做得比较潦草,最近比较忙,有些错误还有一些我也知道有问题的地方,后面我再回来改吧。不好意思~