标签:第七周作业
第七周作业
1、创建一个10G分区,并格式为ext4文件系统;
[root@STCO6 /]# fdisk /dev/sdb 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 Partition number (1-4): 1 First cylinder (1-2610, default 1): 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 /]# fdisk /dev/sdb 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): p 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: 0x0e54b55e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux Command (m for help): q
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@STCO6 ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sdb1 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 657408 inodes, 5245206 blocks 104904 blocks (2.00%) reserved for the super user First data block=0 Maximum filesystem blocks=543162368 321 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 30 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@STCO6 ~]# mkdir -p /data/mydata [root@STCO6 ~]# mount -t ext4 -o noexec,noatime,acl /dev/sdb1 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@STCO6 ~]# fdisk /dev/sdb 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 Partition number (1-4): 2 First cylinder (1307-2610, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): +1G Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 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@STCO6 ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1060284 KiB no label, UUID=ae1b57f3-472d-4ae4-8620-2fb40c5916be [root@STCO6 ~]# swapon /dev/sdb2 [root@STCO6 ~]# 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: 0x000b04eb Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM 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: 0x0e54b55e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 1438 1060290 82 Linux swap / Solaris Disk /dev/mapper/vg_stco6-lv_root: 18.8 GB, 18798870528 bytes 255 heads, 63 sectors/track, 2285 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: 0x00000000 Disk /dev/mapper/vg_stco6-lv_swap: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0x00000000
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@STCO6 ~]# cat /tmp/disk.sh #!/bin/bash # disk=$(fdisk -l|egrep -o "/dev/sd.?\>") for i in $disk;do echo $i df -h|awk ‘/‘${i//\//\\/}‘/{print $0}‘ done [root@STCO6 ~]# chmod u+x /tmp/disk.sh [root@STCO6 ~]# bash -n /tmp/disk.sh [root@STCO6 ~]# /tmp/disk.sh /dev/sda /dev/sda1 477M 40M 412M 9% /boot /dev/sdb
4、总结RAID的各个级别及其组合方式和性能的不同;
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@STCO6 ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xbb65f33a. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 Partition number (1-4): 1 First cylinder (1-4568, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-4568, default 4568): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-4568, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-4568, default 4568): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (2613-4568, default 2613): Using default value 2613 Last cylinder, +cylinders or +size{K,M,G} (2613-4568, default 4568): +10G Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): fd Changed system type of partition 1 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): fd Changed system type of partition 2 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): fd Changed system type of partition 3 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 ~]# mdadm -C /dev/md0 -a yes -n 2 -x 1 -l 1 -c 128 /dev/sdc{1,2,3} 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@STCO6 ~]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdc3[2](S) sdc2[1] sdc1[0] 10482176 blocks super 1.2 [2/2] [UU] unused devices: <none>
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@STCO6 ~]# fdisk /dev/sdd Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x5466fe3b. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 Partition number (1-4): 1 First cylinder (1-1958, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1958, default 1958): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (524-1958, default 524): Using default value 524 Last cylinder, +cylinders or +size{K,M,G} (524-1958, default 1958): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1047-1958, default 1047): Using default value 1047 Last cylinder, +cylinders or +size{K,M,G} (1047-1958, default 1958): +4G Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): fd Changed system type of partition 1 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): fd Changed system type of partition 2 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): fd Changed system type of partition 3 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 ~]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sda{1,2,3} mdadm: cannot open /dev/sda1: Device or resource busy [root@STCO6 ~]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sdd{1,2,3} mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started. [root@STCO6 ~]# mke2fs -t 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 525200 inodes, 2098432 blocks 104921 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 65 block groups 32768 blocks per group, 32768 fragments per group 8080 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@STCO6 ~]# mkdir /backup [root@STCO6 ~]# echo "/dev/md1 /backup ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
[root@STCO6 tmp]# cat line.sh #!/bin/bash # declare -i sum=0 if [ $# -lt 1 ];then echo “请至少给出一条文件路径” && exit 1 fi for i in $@;do if [ -f $i ];then echo "$i 的文件的行数是: `wc -l $i | cut -d" " -f1` " let sum++ else echo "$i 错误的文件路径" fi done echo "本次统计的文件数为: $sum" [root@STCO6 tmp]# bash -n line.sh [root@STCO6 tmp]# chmod u+x line.sh [root@STCO6 tmp]# ./line.sh testScript1 testScript2 testScript3 testScript4 testScript5 testScript6 testScript7 testScript1 的文件的行数是: 3 testScript2 的文件的行数是: 5 testScript3 的文件的行数是: 3 testScript4 的文件的行数是: 11 testScript5 的文件的行数是: 9 testScript6 的文件的行数是: 9 testScript7 错误的文件路径 本次统计的文件数为: 6
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
[root@STCO6 tmp]# cat adduser.sh #!/bin/bash # declare -i name=0 if [ $# -lt 2 ] ;then echo "请输入至少两个待创建的用户名" && exit 1 fi for i in $@;do id $i &> /dev/null if [ $? -eq 0 ];then echo "用户 $i 已存在" else useradd $i && echo "$i" | passwd --stdin $i let name++ fi done echo "创建的用户数量:$name" [root@STCO6 tmp]# chmod +x adduser.sh [root@STCO6 tmp]# bash -n adduser.sh [root@STCO6 tmp]# ./adduser.sh TU1 TU2 TU3 TU4 TU5 TU6 Changing password for user TU1. passwd: all authentication tokens updated successfully. Changing password for user TU2. passwd: all authentication tokens updated successfully. Changing password for user TU3. passwd: all authentication tokens updated successfully. Changing password for user TU4. passwd: all authentication tokens updated successfully. Changing password for user TU5. passwd: all authentication tokens updated successfully. Changing password for user TU6. passwd: all authentication tokens updated successfully. 创建的用户数量:6
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
[root@STCO6 tmp]# cat Createuser.sh #!/bin/bash # declare -i sum=0 for i in {1..20};do useradd visitor$i && echo "visitor$i UID 是: `id -u visitor$i`" let sum+=$(id -u visitor$i) done echo "用户 UID 之和 : $sum" [root@STCO6 tmp]# chmod u+x Createuser.sh [root@STCO6 tmp]# bash -n Createuser.sh [root@STCO6 tmp]# ./Createuser.sh visitor1 UID 是: 3031 visitor2 UID 是: 3032 visitor3 UID 是: 3033 visitor4 UID 是: 3034 visitor5 UID 是: 3035 visitor6 UID 是: 3036 visitor7 UID 是: 3037 visitor8 UID 是: 3038 visitor9 UID 是: 3039 visitor10 UID 是: 3040 visitor11 UID 是: 3041 visitor12 UID 是: 3042 visitor13 UID 是: 3043 visitor14 UID 是: 3044 visitor15 UID 是: 3045 visitor16 UID 是: 3046 visitor17 UID 是: 3047 visitor18 UID 是: 3048 visitor19 UID 是: 3049 visitor20 UID 是: 3050 用户 UID 之和 : 60810
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
[root@STCO6 tmp]# cat line2.sh #!/bin/bash # sum=0 files=(/etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab) for i in ${files[@]};do echo $i "#开头的行数: $(grep ‘^#‘ $1 | wc -l)" let sum+=`cat $i|grep ‘^$‘|wc -l` done echo "空白的总行数: $sum" [root@STCO6 tmp]# chmod +x line2.sh [root@STCO6 tmp]# bash -n line2.sh [root@STCO6 tmp]# ./line2.sh /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab /etc/rc.d/rc.sysinit #开头的行数: 44 /etc/rc.d/init.d/functions #开头的行数: 44 /etc/fstab #开头的行数: 44 空白的总行数: 206
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
[root@STCO6 tmp]# cat bashuser.sh #!/bin/bash # declare -i sum=0 user=$(grep "/bin/bash$" /etc/passwd) for i in $user;do uid=`echo $i | cut -d: -f3` user=`echo $i | cut -d: -f1` echo "$user UID is $uid" let sum+=$uid done echo "默认shell为bash的用户UID之和为:$sum" [root@STCO6 tmp]# chmod +x line2.sh [root@STCO6 tmp]# chmod +x bashuser.sh [root@STCO6 tmp]# bash -n bashuser.sh [root@STCO6 tmp]# ./bashuser.sh root UID is 0 suyi UID is 500 testuser UID is 501 testuser1 UID is 502 testuser2 UID is 503 testuser3 UID is 504 testuser4 UID is 505 testuser5 UID is 506 mageia UID is 1100 openstack UID is 3003 hadoop UID is 2500 bash UID is 3004 testbash UID is 3005 basher UID is 3006 fedora UID is 3008 user1 UID is 3009 user10 UID is 3010 user11 UID is 3011 user12 UID is 3012 user13 UID is 3013 user14 UID is 3014 user15 UID is 3015 user16 UID is 3016 user17 UID is 3017 user18 UID is 3018 user19 UID is 3019 user20 UID is 3020 user21 UID is 3021 TU1 UID is 3022 TU2 UID is 3023 TU3 UID is 3024 TU4 UID is 3025 TU5 UID is 3026 TU6 UID is 3027 TU7 UID is 3028 5 UID is 3029 TU8 UID is 3030 visitor1 UID is 3031 visitor2 UID is 3032 visitor3 UID is 3033 visitor4 UID is 3034 visitor5 UID is 3035 visitor6 UID is 3036 visitor7 UID is 3037 visitor8 UID is 3038 visitor9 UID is 3039 visitor10 UID is 3040 visitor11 UID is 3041 visitor12 UID is 3042 visitor13 UID is 3043 visitor14 UID is 3044 visitor15 UID is 3045 visitor16 UID is 3046 visitor17 UID is 3047 visitor18 UID is 3048 visitor19 UID is 3049 visitor20 UID is 3050 默认shell为bash的用户UID之和为:149386
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
[root@STCO6 tmp]# cat Groupuser.sh #!/bin/bash # declare -i user=0 name=`cut -d: -f1 /etc/passwd` for i in $name;do group=`id $i|cut -d" " -f3|awk -F"," ‘{print $2}‘` if [ -n "$group" ];then echo "$i 拥有附加组" let user++ fi done echo "拥有附加组的用户总数是: $user" [root@STCO6 tmp]# chmod +x Groupuser.sh [root@STCO6 tmp]# bash -n Groupuser.sh [root@STCO6 tmp]# ./Groupuser.sh bin 拥有附加组 daemon 拥有附加组 adm 拥有附加组 postfix 拥有附加组 slackware 拥有附加组 openstack 拥有附加组 拥有附加组的用户总数是: 6
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@STCO6 ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x5924ad3c. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 Partition number (1-4): 1 First cylinder (1-5221, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-5221, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-5221, default 5221): +10G Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdc: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x5924ad3c Device Boot Start End Blocks Id System /dev/sdc1 1 1306 10490413+ 8e Linux LVM /dev/sdc2 1307 2612 10490445 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 ~]# partx -a /dev/sdc BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 [root@STCO6 ~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created [root@STCO6 ~]# pvcreate /dev/sdc2 Physical volume "/dev/sdc2" successfully created [root@STCO6 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_stco6 lvm2 a--u 19.51g 0 /dev/sdc1 lvm2 ---- 10.00g 10.00g /dev/sdc2 lvm2 ---- 10.00g 10.00g [root@STCO6 ~]# vgcreate -s 8M testvg /dev/sdc{1,2} Volume group "testvg" successfully created [root@STCO6 ~]# vgdisplay --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 20.00 GiB PE Size 8.00 MiB Total PE 2560 Alloc PE / Size 0 / 0 Free PE / Size 2560 / 20.00 GiB VG UUID yW39bc-tG1d-WxfL-i5P9-U1HO-Ilem-xG1YtM --- Volume group --- VG Name vg_stco6 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.51 GiB PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 0 / 0 VG UUID vTi8LR-3pAa-zALe-D2rO-AWdO-fsf4-MVP3O1 [root@STCO6 ~]# lvcreate -L 5G -n mylv1 testvg Logical volume "mylv1" created. [root@STCO6 ~]# mkfs.ext4 /dev/testvg/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 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@STCO6 ~]# echo "/dev/testvg/mylv1 /users ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@STCO6 ~]# useradd -d /users/magedu magedu [root@STCO6 ~]# su - magedu [magedu@STCO6 ~]$ cp /etc/fstab /etc/issue ./
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@STCO6 magedu]# lvextend -L +4G /dev/testvg/mylv1 Size of logical volume testvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. [root@STCO6 magedu]# lvdisplay --- Logical volume --- LV Path /dev/testvg/mylv1 LV Name mylv1 VG Name testvg LV UUID TU9EXH-JTTx-s4Sp-5Z3C-ipCQ-Rsbi-yVBIj3 LV Write Access read/write LV Creation host, time STCO6, 2016-09-17 15:35:26 +0800 LV Status available # open 1 LV Size 9.00 GiB Current LE 1152 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/vg_stco6/lv_root LV Name lv_root VG Name vg_stco6 LV UUID mm31j6-AvWw-agrn-RmkG-TXbb-fAlP-ZcQzDD LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:13 +0800 LV Status available # open 1 LV Size 17.51 GiB Current LE 4482 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_stco6/lv_swap LV Name lv_swap VG Name vg_stco6 LV UUID welimE-WYab-IkFQ-Y43Q-5RBQ-c6Ju-yIeNPE LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:19 +0800 LV Status available # open 1 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@STCO6 ~]# umount /dev/testvg/mylv1 [root@STCO6 ~]# e2fsck -f /dev/testvg/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/testvg/mylv1: 23/327680 files (0.0% non-contiguous), 55914/1310720 blocks [root@STCO6 ~]# resize2fs /dev/testvg/mylv1 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/testvg/mylv1 to 2359296 (4k) blocks. The filesystem on /dev/testvg/mylv1 is now 2359296 blocks long. [root@STCO6 ~]# lvreduce -L 7G /dev/testvg/mylv1 WARNING: Reducing active logical volume to 7.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce testvg/mylv1? [y/n]: y Size of logical volume testvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized. [root@STCO6 ~]# lvdisplay --- Logical volume --- LV Path /dev/testvg/mylv1 LV Name mylv1 VG Name testvg LV UUID TU9EXH-JTTx-s4Sp-5Z3C-ipCQ-Rsbi-yVBIj3 LV Write Access read/write LV Creation host, time STCO6, 2016-09-17 15:35:26 +0800 LV Status available # open 0 LV Size 7.00 GiB Current LE 896 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/vg_stco6/lv_root LV Name lv_root VG Name vg_stco6 LV UUID mm31j6-AvWw-agrn-RmkG-TXbb-fAlP-ZcQzDD LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:13 +0800 LV Status available # open 1 LV Size 17.51 GiB Current LE 4482 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_stco6/lv_swap LV Name lv_swap VG Name vg_stco6 LV UUID welimE-WYab-IkFQ-Y43Q-5RBQ-c6Ju-yIeNPE LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:19 +0800 LV Status available # open 1 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@STCO6 ~]# lvcreate -L 1G -n snapmylv -p r -s /dev/testvg/mylv1 Logical volume "snapmylv" created. [root@STCO6 ~]# cd /dev/testvg [root@STCO6 testvg]# ll total 0 lrwxrwxrwx. 1 root root 7 Sep 17 16:41 mylv1 -> ../dm-2 lrwxrwxrwx. 1 root root 7 Sep 17 16:41 snapmylv -> ../dm-5
标签:第七周作业
原文地址:http://257023.blog.51cto.com/247023/1853389