第七周作业
1、创建一个10G分区,并格式为ext4文件系统;
[root@qq ~]# fdisk /dev/sdb #使用fdisk命令进行分区; Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x61b9ad0b. 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): p #用p命令查看现有分区,由于是新盘什么都没; Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x61b9ad0b Device Boot Start End Blocks Id System Command (m for help): n #新建分区,理论上可以建4个主分区或3个主分区1个扩展分区,建完扩展分区后可建多个逻辑分区; Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-26108, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-26108, default 26108): +10G Command (m for help): p Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x61b9ad0b Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux Command (m for help): w #分完分区后,w保存写入; The partition table has been altered! [root@qq ~]# partx -a -n 1 /dev/sdb #使用partx命令在不关机情况下让内核重读分区表 BLKPG: Device or resource busy error adding partition 1 [root@qq ~]# [root@qq ~]# [root@qq ~]# partx -a -n 1 /dev/sdb BLKPG: Device or resource busy error adding partition 1 [root@qq ~]#
-
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@qq ~]# 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 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. /dev/sdb1: LABEL="MYDATA" UUID="f4c97dcc-3bd4-413c-b56d-a5179398713d" TYPE="ext4" [root@qq ~]# tune2fs -o acl /dev/sdb1 #设置acl功能; tune2fs 1.41.12 (17-May-2010) [root@qq ~]# echo $? 0
-
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@qq ~]# mount -o noexec,noatime,acl /dev/sdb1 /data/mydata/ [root@qq ~]# [root@qq ~]# more /etc/mtab | grep /dev/sdb1 /dev/sdb1 /data/mydata ext4 rw,noexec,noatime,acl 0 0 [root@qq ~]#
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-26108, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-26108, default 26108): +1G Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 #将分区设置为swap格式,可用l(字母)命令查看所有的分区类型; Changed system type of partition 2 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x61b9ad0b Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 1438 1060290 82 Linux swap / Solaris #已经设置swap类型 [root@qq tmp]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 [root@qq tmp]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 [root@qq tmp]# mkswap /dev/sdb2 #用mkswap命令设置为swap格式; Setting up swapspace version 1, size = 1060284 KiB no label, UUID=5c6c92b7-7896-454a-bcd3-ee9120b7fb51 [root@qq tmp]# swapon /dev/sdb2 #启动swap分区; [root@qq tmp]# free -m #原来是4G的swap,现在已经是5G多了; total used free shared buffers cached Mem: 482 175 307 0 20 71 -/+ buffers/cache: 84 398 Swap: 5131 0 5131
3、写一个脚本
-
(1)、获取并列出当前系统上的所有磁盘设备;
-
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@qq tmp]# vim disk.sh #!/bin/bash # fdisk -l | grep -o "^/[^[:space:]]\+" df -lh
4、总结RAID的各个级别及其组合方式和性能的不同;
常见的RAID如下:
-
RADI0(条带卷):
-
由两块或两块以上硬盘组成;
-
IO读写速度是RAID中最快的,但是无容错能力;
-
可用空间:N*min(S1,S2,……)
-
RAID1(镜像卷):
-
由两块或两块以上硬盘相互作镜像组成;
-
读速度由于从多个磁盘读取,所以速度会相应提高;但是写入数据要拷贝副本到另外的磁盘可能会导致写入速度略有下降;有容错能力,由于另外一个磁盘是镜像卷,当主磁盘故障时,由于镜像卷磁盘数据一模一样,所以不会影响到数据的正常性;
-
可用空间:1*min(S1,S2,……)
-
RADI5:
-
最少需要三块硬盘组成;
-
有容错能力,写入数据的同时还要将数据的奇偶校验信息分别存放在各个磁盘,当其中一个磁盘损坏时,可通过其它磁盘的数据和奇偶信息去恢复损坏的数据;RAID5可以理解成是在RAID0的基础上加了奇偶检验功能,所以写入速度比单独写入一块硬盘的速度略慢,但却比RAID1快;要注意的是,数据块(chunks)和校验位必须要按顺序即默认为左对称的方式排放;
-
RAID5理论上只能坏一块磁盘;
-
可用空间:(N-1)*min(S1,S2,……)
-
RIAD6:
-
最少需要四块硬盘组成;
-
有容错能力,可以看作是RAID5的升级版,理论上能坏两块磁盘后,还能保持数据正常;
-
可用空间:(N-2)*min(S1,S1,……)
-
RAID10:
-
最少需要四块硬盘组成;
-
它的基本原理是,先4块硬盘两两先做成2个RAID1,然后这两个RAID1阵列再继续做出RAID0模式;读写性能有提升,有容错能力,前提是不要一组镜像盘同时故障,如果两组镜像盘各坏一个,不会损坏数据;
-
可用空间:N*min(S1,S2,……)/2
-
JBOD:
-
将多块磁盘的空间合并一个大的连续空间使用,无容错能力;
-
可用空间:sum(S1,S2,……)
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
Command (m for help): p Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x61b9ad0b Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 1438 1060290 82 Linux swap / Solaris /dev/sdb3 1439 26108 198161775 5 Extended /dev/sdb5 1439 2744 10490413+ fd Linux raid autodetect RAID分区类型; /dev/sdb6 2745 4050 10490413+ fd Linux raid autodetect /dev/sdb7 4051 4312 2104483+ fd Linux raid autodetect /dev/sdb8 4313 4574 2104483+ fd Linux raid autodetect /dev/sdb9 4575 4836 2104483+ fd Linux raid autodetect /dev/sdb10 4837 6142 10490413+ fd Linux raid autodetect /dev/sdb11 6143 7448 10490413+ fd Linux raid autodetect /dev/sdb12 7449 8754 10490413+ fd Linux raid autodetect /dev/sdb13 8755 10060 10490413+ fd Linux raid autodetect /dev/sdb14 10061 11366 10490413+ 8e Linux LVM LVM文件系统类型; /dev/sdb15 11367 12672 10490413+ 8e Linux LVM /dev/sdb16 12673 13587 7349706 8e Linux LVM [root@qq tmp]# mdadm /dev/md0 -C -n 2 -x 1 -a yes -c 128 -l 5 /dev/sdb{11,12,13} mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@qq tmp]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Aug 1 18:10:12 2016 Raid Level : raid5 Array Size : 10482176 (10.00 GiB 10.73 GB) Used Dev Size : 10482176 (10.00 GiB 10.73 GB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 1 18:10:12 2016 State : clean, degraded, recovering #状态为clean,说明创建完成 Active Devices : 1 Working Devices : 3 Failed Devices : 0 Spare Devices : 2 Layout : left-symmetric Chunk Size : 128K Rebuild Status : 0% complete #进度条 Name : qq.localdomain:0 (local to host qq.localdomain) UUID : cd6c0b6b:89de1553:3be0084c:68c9aa06 Events : 1 Number Major Minor RaidDevice State 0 8 27 0 active sync /dev/sdb11 3 8 28 1 spare rebuilding /dev/sdb12 2 8 29 - spare /dev/sdb13 #热备盘
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@qq tmp]# mdadm /dev/md1 -C -n 3 -a yes -c 256 -l 5 /dev/sdb{7,8,9} mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started. [root@qq tmp]# cat /proc/mdstat Personalities : [raid1] [raid6] [raid5] [raid4] md1 : active raid5 sdb9[3] sdb8[1] sdb7[0] 4204544 blocks super 1.2 level 5, 256k chunk, algorithm 2 [3/2] [UU_] [==>..................] recovery = 13.6% (287944/2102272) finish=1.7min speed=16937K/sec [root@qq tmp]# mke2fs -t ext4 /dev/md1 [root@qq tmp]# vim /etc/fstab /dev/md1 /backup ext4 defaults,acl,noatime 0 0 [root@qq tmp]# mount -a [root@qq tmp]# df -lh | grep /dev/md1 /dev/md1 3.9G 8.1M 3.7G 1% /backup
7、写一个脚本
-
(1) 接受一个以上文件路径作为参数;
-
(2) 显示每个文件拥有的行数;
-
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # declare -i i=0 if [ $# -lt 1 ]; then echo "please input file path,dont input empty" exit 2 fi for file in $*; do if [ -f $file ]; then echo "$file line number:$(wc -l $file | cut -d" " -f1)" let i++ else echo "please input correct file path" fi done echo "statistical file count=$i" 测试: [root@qq shell_scripts]# bash file-line-1.sh please input file path,dont input empty [root@qq shell_scripts]# [root@qq shell_scripts]# [root@qq shell_scripts]# bash file-line-1.sh /etc/issue /etc/grub.conf /etc/issue line number:3 /etc/grub.conf line number:17 statistical file count=2 [root@qq shell_scripts]#
8、写一个脚本
-
(1) 传递两个以上字符串当作用户名;
-
(2) 创建这些用户;且密码同用户名;
-
(3) 总结说明共创建了几个用户;
#!/binbash # declare -i i=0 if [ $# -lt 2 ];then echo "last input two username" exit 2 fi for username in $@; do id $username &> /dev/null if [ $? -eq 0 ]; then echo "$username exist" else useradd $username echo "$username" | passwd --stdin $username &> /dev/null let i++ fi done echo "add user count: $i" 测试: [root@qq shell_scripts]# bash two-user.sh qq last input two username [root@qq shell_scripts]# bash two-user.sh user10 110 user10 exist add user count: 1 [root@qq shell_scripts]# [root@qq shell_scripts]# bash two-user.sh user120 user119 add user count: 2
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # declare -i sum=0; for ((i=1;i<=20;i++)); do useradd visitor$i; echo "useradd visitor$i success!" sum+=$(id -u visitor$i) done echo "All user uid sum: $sum" 测试: [root@qq serven]# bash user1-20.sh useradd visitor1 success! useradd visitor2 success! useradd visitor3 success! useradd visitor4 success! useradd visitor5 success! useradd visitor6 success! useradd visitor7 success! useradd visitor8 success! useradd visitor9 success! useradd visitor10 success! useradd visitor11 success! useradd visitor12 success! useradd visitor13 success! useradd visitor14 success! useradd visitor15 success! useradd visitor16 success! useradd visitor17 success! useradd visitor18 success! useradd visitor19 success! useradd visitor20 success! All user uid sum: 11110
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # declare -i sum1=0; declare -i sum2=0; for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab}; do sum1+=$( grep -c '^#' $i ) sum2+=$( grep -c '^[[:space:]]*$' $i ) done echo "#start line number: $sum1" echo "space line number: $sum2" 测试: [root@qq serven]# bash space-line.sh #start line number: 91 space line number: 179
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash # declare -i sum=0; declare -i i=0; grep "\/bin\/bash$" /etc/passwd | awk -v FS=":" '{print $1,"\t",$3}' for i in $(awk -F: '/bash$/{print $3}' /etc/passwd); do let sum+=$i done echo "user uid sum= $sum" 测试: [root@qq serven]# bash -x shell-bash.sh + declare -i sum=0 + declare -i i=0 + awk -v FS=: '{print $1,"\t",$3}' + grep '\/bin\/bash$' /etc/passwd root 0 docker 523 qq 524 myuser 525 magedu 545 ++ awk -F: '/bash$/{print $3}' /etc/passwd + for i in '$(awk -F: '\''/bash$/{print $3}'\'' /etc/passwd)' + let sum+=0 + for i in '$(awk -F: '\''/bash$/{print $3}'\'' /etc/passwd)' + let sum+=523 + for i in '$(awk -F: '\''/bash$/{print $3}'\'' /etc/passwd)' + let sum+=524 + for i in '$(awk -F: '\''/bash$/{print $3}'\'' /etc/passwd)' + let sum+=525 + for i in '$(awk -F: '\''/bash$/{print $3}'\'' /etc/passwd)' + let sum+=545 + echo 'user uid sum= 2117' user uid sum= 2117
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash # declare -i i=0; for user in `cut -d: -f1 /etc/passwd`; do group=$(id $user | cut -d" " -f3 | awk -F, '{print $2}') if [ -n "$group" ]; then echo $user let i++ fi done echo "user number: $i" 测试: [root@qq serven]# bash sub-group.sh bin daemon adm postfix magedu user number: 5
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
Command (m for help): p Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x61b9ad0b Device Boot Start End Blocks Id System /dev/sdb14 10061 11366 10490413+ 8e Linux LVM /dev/sdb15 11367 12672 10490413+ 8e Linux LVM /dev/sdb16 12673 13587 7349706 8e Linux LVM [root@qq tmp]# pvcreate /dev/sdb14 Physical volume "/dev/sdb14" successfully created [root@qq tmp]# pvcreate /dev/sdb15 Physical volume "/dev/sdb15" successfully created [root@qq tmp]# [root@qq tmp]# pvs #显示pvs信息 PV VG Fmt Attr PSize PFree /dev/sdb14 lvm2 --- 10.00g 10.00g /dev/sdb15 lvm2 --- 10.00g 10.00g [root@qq tmp]# vgcreate myvg -s 8 /dev/sdb{14,15} #创建vg,-s选项设置PM大小; Volume group "myvg" successfully created [root@qq tmp]# [root@qq tmp]# vgs #显示vg信息 VG #PV #LV #SN Attr VSize VFree myvg 2 0 0 wz--n- 20.00g 20.00g [root@qq tmp]# vgdisplay myvg #显示vg详细信息 --- Volume group --- VG Name myvg 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 scLSYH-yaX4-R16R-ZqI2-BrnX-VYnS-4czFEA [root@qq tmp]# lvcreate -L 5G -n mylv1 myvg #创建lv Logical volume "mylv1" created [root@qq tmp]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg -wi-a----- 5.00g [root@qq tmp]# lvdisplay #显示lv详细信息; --- Logical volume --- LV Path /dev/myvg/mylv1 LV Name mylv1 VG Name myvg LV UUID xZqrTJ-SIhP-DKhe-yY1o-aspI-mD1G-EWtQu0 LV Write Access read/write LV Creation host, time qq.localdomain, 2016-08-01 23:10:48 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 640 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@qq tmp]# mke2fs -t ext4 /dev/myvg/mylv1 #格式为ext4格式; 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 [root@qq tmp]# vim /etc/fstab #更新分区表; /dev/md1 /backup ext4 defaults,acl,noatime 0 0 /dev/myvg/mylv1 /users ext4 defaults,acl 0 0 [root@qq tmp]# df -lh #查看磁盘空间使用情况,lv已经挂载上去; Filesystem Size Used Avail Use% Mounted on /dev/md1 3.9G 8.1M 3.7G 1% /backup /dev/mapper/myvg-mylv1 4.8G 10M 4.6G 1% /users
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@qq tmp]# useradd -d /users/magedu magedu [root@qq tmp]# cat /etc/passwd | grep magedu magedu:x:545:545::/users/magedu:/bin/bash [root@qq tmp]# [root@qq tmp]# su - magedu [magedu@qq ~]$ pwd /users/magedu [magedu@qq ~]$ cp /etc/fstab . [magedu@qq ~]$ cp -a /etc/ .
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@qq tmp]# lvextend -L 9G /dev/myvg/mylv1 #lv扩展至9G容量 Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized [root@qq tmp]# lvdisplay /dev/myvg/mylv1 --- Logical volume --- LV Path /dev/myvg/mylv1 LV Name mylv1 VG Name myvg LV UUID xZqrTJ-SIhP-DKhe-yY1o-aspI-mD1G-EWtQu0 LV Write Access read/write LV Creation host, time qq.localdomain, 2016-08-01 23:10:48 +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:0 [root@qq magedu]# resize2fs /dev/myvg/mylv1 #刷新lv resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/mylv1 is mounted on /users; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/myvg/mylv1 to 2359296 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long. [root@qq magedu]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/md1 3.9G 8.1M 3.7G 1% /backup /dev/mapper/myvg-mylv1 8.8G 24M 8.3G 1% /users #df空间使用情况已经更新; [root@qq magedu]# pwd /users/magedu [root@qq magedu]# cat /etc/fstab #可以正常读取文件 # # /etc/fstab # Created by anaconda on Thu Jul 28 00:37:31 2016 ……
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
操作须得按步骤来,有一定风险; 1、首先的取消分区挂载; [root@qq ~]# umount /dev/myvg/mylv1 2、检查分区是否正常; [root@qq ~]# e2fsck -f /dev/myvg/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/myvg/mylv1: 11/589824 files (0.0% non-contiguous), 74975/2359296 blocks 3、刷新lv; [root@qq ~]# resize2fs /dev/myvg/mylv1 resize2fs 1.41.12 (17-May-2010) The filesystem is already 2359296 blocks long. Nothing to do! 4、lv缩减至7G; [root@qq ~]# lvcreate -L 7G /dev/myvg/mylv1 Volume group name expected (no slash) Run `lvcreate --help' for more information. [root@qq ~]# lvreduce -L 7G /dev/myvg/mylv1 WARNING: Reducing active logical volume to 7.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv1? [y/n]: y Size of logical volume myvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized 5、重新挂载分区; [root@qq ~]# mount /dev/myvg/mylv1 /users/ [root@qq ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/md1 3.9G 8.1M 3.7G 1% /backup /dev/mapper/myvg-mylv1 6.8G 16M 6.4G 1% /users 6、验证lv的分区使用情况;正常能否正常读取,写入; [root@qq users]# vim /users/fstab iiiii # # /etc/fstab # Created by anaconda on Thu Jul 28 00:37:31 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' ……
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@qq users]# lvcreate -L 1GB -n mylv1.snapshot.bak -p r -s /dev/myvg/mylv1 #创建镜像 Logical volume "mylv1.snapshot.bak" created [root@qq users]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg owi-aos--- 7.00g mylv1.snapshot.bak myvg sri-a-s--- 1.00g mylv1 0.00 [root@qq /]# mkdir /snapshot [root@qq /]# mount /dev/myvg/mylv1.snapshot.bak /snapshot/ 挂载镜像; mount: block device /dev/mapper/myvg-mylv1.snapshot.bak is write-protected, mounting read-only [root@qq /]# ls /snapshot/ #查看镜像内容 fstab lost+found
原创文章,作者:Net21_仲樂,如若转载,请注明出处:http://www.178linux.com/31609
评论列表(2条)
写的很好,排版也很棒,加油
@马哥教育:3Q