1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
(1) ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x618744c6. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ~]# kpartx -af /dev/sdb ~]# fdisk -l |grep sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors /dev/sdb120482097356710485760 83 Linux Disk /dev/mapper/sdb1: 10.7 GB, 10737418240 bytes, 20971520 sectors [root@node1 ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) /dev/sdb1 is apparently in use by the system; will not make a filesystem here! 报正在使用哦,解决方法 ~]# dmsetup status sdb1: 0 20971520 linear centos-home: 0 141443072 linear centos-swap: 0 4194304 linear centos-root: 0 104857600 linear ~]# dmsetup remove_all ~]# dmsetup status centos-home: 0 141443072 linear centos-swap: 0 4194304 linear centos-root: 0 104857600 linear ~]# fdisk -l | grep sdb1 /dev/sdb120482097356710485760 83 Linux ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user First data block=0 Maximum filesystem blocks=273678336 320 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ~]# tune2fs -o acl /dev/sdb1 tune2fs 1.42.9 (28-Dec-2013) (2) ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata ~]# cat /etc/mtab | grep 'sdb1' /dev/sdb1 /data/mydata ext4 rw,noexec,noatime,data=ordered 0 0 ~]# df -h | grep sdb1 /dev/sdb19.8G 13M 9.6G 1% /data/mydata
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G Partition 2 of type Linux and of size 1 GiB is set 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. ~]# kpartx /dev/sdb sdb1 : 0 20971520 /dev/sdb 2048 sdb2 : 0 2097152 /dev/sdb 20973568 ~]# partprobe /dev/sdb ~]# cat /proc/diskstats 8 16 sdb 1848 0 35766 5604 555 16633 463296 24749 0 8733 29069 8 17 sdb1 692 0 12206 1987 550 16633 463256 24647 0 5235 25351 8 18 sdb2 98 0 1664 34 0 0 0 0 0 27 33 ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=41508164-eaa0-46e2-b3a0-f2f69197359f ~]# swapon /dev/sdb2 ~]# cat /proc/swaps FilenameTypeSizeUsedPriority /dev/dm-1 partition20971480-1 /dev/sdb2 partition10485720-2
3、写一个脚本 (1)、获取并列出当前系统上的所有磁盘设备; (2)、显示每个磁盘设备上每个分区相关的空间使用信息;
1 #!/bin/bash 2 # 3 echo "show the disk " 4 fdisk -l | grep "^Disk /dev/s" | cut -d ' ' -f2 5 sleep 2 6 echo "show the usage" 7 df -h ~ ~]# bash show.sh show the disk /dev/sdb: /dev/sdc: /dev/sda: /dev/sdd: show the usage Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 14G 37G 27% / devtmpfs 898M 0 898M 0% /dev tmpfs913M 84K 913M 1% /dev/shm tmpfs913M 9.0M 904M 1% /run tmpfs913M 0 913M 0% /sys/fs/cgroup /dev/sda1497M 158M 340M 32% /boot /dev/mapper/centos-home 68G 37M 68G 1% /home tmpfs183M 16K 183M 1% /run/user/42 tmpfs183M 0 183M 0% /run/user/0 /dev/sdb19.8G 13M 9.6G 1% /data/mydata
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID-0: 读、写性能提升; 可用空间:N*min(S1,S2,...) 无容错能力 最少磁盘数:2, 2+ RAID-1: 读性能提升、写性能略有下降; 可用空间:1*min(S1,S2,...) 有冗余能力 最少磁盘数:2, 2+ RAID-4: 1101, 0110, 1011 RAID-5: 读、写性能提升 可用空间:(N-1)*min(S1,S2,...) 有容错能力:1块磁盘 最少磁盘数:3, 3+ RAID-6: 读、写性能提升 可用空间:(N-2)*min(S1,S2,...) 有容错能力:2块磁盘 最少磁盘数:4, 4+ 混合类型 RAID-10: 读、写性能提升 可用空间:N*min(S1,S2,...)/2 有容错能力:每组镜像最多只能坏一块; 最少磁盘数:4, 4+ RAID-01: RAID-50、RAID7 JBOD:Just a Bunch Of Disks 功能:将多块磁盘的空间合并一个大的连续空间使用; 可用空间:sum(S1,S2,...) 常用级别:RAID-0, RAID-1, RAID-5, RAID-10, RAID-50, JBOD
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
~]# fdisk -l | grep sd Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors /dev/sda1 *2048 1026047 512000 83 Linux /dev/sda2 1026048 251658239 125316096 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors [root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/Ma0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS55 EZ-Drivea7 NeXTSTEPf0 Linux/PA-RISC b 11 Hidden FAT1256 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT1663 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris bootff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ...... ~]# mdadm -C /dev/md0 -l 1 -c 128 -n 2 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 mdadm: /dev/sdb1 appears to contain an ext2fs file system size=10485760K mtime=Mon Nov 7 20:49:14 2016 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/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Nov 7 22:11:43 2016 Raid Level : raid1 Array Size : 10477568 (9.99 GiB 10.73 GB) Used Dev Size : 10477568 (9.99 GiB 10.73 GB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Nov 7 22:12:01 2016 State : clean, resyncing Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Resync Status : 11% complete Name : localhost.localdomain:0 (local to host localhost.localdomain) UUID : 051e87e0:f3e7d2bf:0aa4509f:d692dde2 Events : 1 Number Major Minor RaidDevice State 0 8 170 active sync /dev/sdb1 1 8 331 active sync /dev/sdc1 2 8 49- spare /dev/sdd1
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): t Partition number (1,2, default 2): Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ...... ~]# mdadm -C /dev/md1 -l 5 -c 256 -n 3 /dev/sdb2 /dev/sdc2 /dev/sdd2 mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started. ~]# mdadm -D /dev/md1 /dev/md1: Version : 1.2 Creation Time : Mon Nov 7 22:18:45 2016 Raid Level : raid5 Array Size : 8380416 (7.99 GiB 8.58 GB) Used Dev Size : 4190208 (4.00 GiB 4.29 GB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Nov 7 22:19:08 2016 State : clean, degraded, recovering Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 256K Rebuild Status : 19% complete Name : localhost.localdomain:1 (local to host localhost.localdomain) UUID : cc64aeea:4d683284:8d775b59:224e7f55 Events : 4 Number Major Minor RaidDevice State 0 8 180 active sync /dev/sdb2 1 8 341 active sync /dev/sdc2 3 8 502 spare rebuilding /dev/sdd2 ~]# mke2fs -t ext4 /dev/md1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 524288 inodes, 2095104 blocks 104755 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2145386496 64 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, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ~]# echo "/dev/md1 /backup ext4 defaults,noatime,acl 0 0">>/etc/fstab ~]# mount -a ~]# df -h Filesystem Size Used Avail Use% Mounted on ...... /dev/md1 7.8G 36M 7.3G 1% /backup
7、写一个脚本 (1) 接受一个以上文件路径作为参数; (2) 显示每个文件拥有的行数; (3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # declare -i i=0 if [ $# -lt 1 ];then echo "please input file path" exit 1 fi for file in $*;do if [ -f $file ] ;then echo "$file:$(wc -l $file | cut -d' ' -f1)" let i++ else echo "please input file path" fi done echo "file counts:$i" 执行结果 ~]# bash line.sh please input file path ~]# bash line.sh /etc/passwd /etc/fstab /etc/passwd:71 /etc/fstab:13 file counts:2
8、写一个脚本 (1) 传递两个以上字符串当作用户名; (2) 创建这些用户;且密码同用户名; (3) 总结说明共创建了几个用户;
#!/bin/bash # declare -i i=0 if [ $# -lt 2 ];then echo "at lease two!!!!!" exit 2 fi for x in $*;do if id $x &>/dev/null;then备注:if判断后加执行命令时无需加[] useradd $x;echo "$x" | passwd --stdin $x &>/dev/null else useradd $x -p $x &>/dev/null echo "user $x add ok" let i++ fi done echo "totle add user:$i" 执行结果: ~]# bash adduser.sh test1 at lease two!!!!! ~]# bash adduser.sh test1 test2 user test1 add ok user test2 exist totle add user:1 ~]# bash adduser.sh test1 test2 test3 user test1 exist user test2 exist user test3 add ok totle add user:1
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # declare -i number declare -i sum=0 for i in {1..10};do useradd visitor$i echo "useradd visitor$i scuess!" done number=$(id -u visitor$i) sum+=$number echo "sum:$sum" 执行结果: ~]# bash useradd20.sh useradd visitor1 scuess! useradd visitor2 scuess! useradd visitor3 scuess! useradd visitor4 scuess! useradd visitor5 scuess! useradd visitor6 scuess! useradd visitor7 scuess! useradd visitor8 scuess! useradd visitor9 scuess! useradd visitor10 scuess! sum:4031
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # declare -i num1 declare -i num2 declare -i totle declare -i sum for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do num1=$(grep "^#" $i | wc -l) num2=$(grep "^[[:space:]]*$" $i | wc -l) totle+=$num1 sum+=$num2 done echo "totle # line:$totle;totle space line:$sum" 运行结果: ~]# bash sumconf.sh totle # line:91;totle space line:175
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
这里bash的用户只有一个,所以脚本写为/sbin/nologin的用户 #!/bin/bash # declare -i sum=0; declare -i i=0; USER=$(grep "/sbin/nologin" /etc/passwd | awk -F ":" '{print $1}') USERUID=$(grep "/sbin/nologin" /etc/passwd | awk -F ":" '{print $3}') USERUID2=$(grep "/sbin/nologin" /etc/passwd | awk -F ":" '{printf"%n,",$3}') USERUID2=${USERUID2//,/ } 将结果中的USERUID2的逗号全部转换为空格 for i in $USERUID2;do let sum+=$i done echo "user id sum=$sum" echo -e "users is:\n$USER"echo -e /n 换行 echo -e "userid is:\n$USERUID" 运行结果: ~]# bash show.sh user id sum=1057 users is: bin daemon adm lp ... userid is: 1 2 3 ......
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash # declare -i i=0; user=$(awk -F ':' '{printf"%s,", $1}' /etc/passwd) user2=${user//,/ } for username in $user2;do group=$(id $username | cut -d' ' -f3) if [ -n $group ];then echo $username let i++ fi done echo "user number: $i" 运行结果: ~]# bash group2.sh root bin ...... user number: 25
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@localhost ~]# fdisk /dev/sdd Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xcd6e54be. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): +^H Unsupported suffix: '. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G Partition 1 of type Linux and of size 5 GiB is set Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (10487808-41943039, default 10487808): Using default value 10487808 Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G Partition 2 of type Linux and of size 5 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ~]# pvcreate /dev/sdd1 Physical volume "/dev/sdd1" successfully created ~]# pvcreate /dev/sdd2 Physical volume "/dev/sdd2" successfully created ~]# vgcreate myvg -s 8M /dev/sdd1 /dev/sdd2 Volume group "myvg" successfully created ~]# lvcreate -L 5G -n mylv1 myvg Logical volume "mylv1" created. ~]# mkfs.ext4 /dev/myvg/mylv1 mke2fs 1.42.9 (28-Dec-2013) 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ~]# mkdir -p /users ~]# echo "/dev/myvg/mylv1 /users ext4 defaults,acl 0 0">>/etc/fstab ~]# mount -a ~]# df -h |grep users /dev/mapper/myvg-mylv1 4.8G 20M 4.6G 1% /users
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
~]# useradd magedu -d /usersmagedu ~]# su - magedu welcome Tue Nov 8 15:30:58 CST 2016 ~]$ pwd /usersmagedu [magedu@localhost ~]$ cp /etc/fstab . [magedu@localhost ~]$ ls fstab
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created ~]# vgextend myvg /dev/sdc1 Volume group "myvg" successfully extended ~]# lvs LVVG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- 67.45g root centos -wi-ao---- 50.00g swap centos -wi-ao---- 2.00g mylv1 myvg -wi-ao---- 5.00g ~]# lvextend -L 9G /dev/myvg/mylv1 Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. ~]# resize2fs /dev/myvg/mylv1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/myvg/mylv1 is mounted on /users; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long. ~]# df -h | grep users /dev/mapper/myvg-mylv1 8.8G 23M 8.3G 1% /users
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
~]# umount /dev/mapper/myvg-mylv1 ~]# e2fsck -f /dev/mapper/myvg-mylv1 e2fsck 1.42.9 (28-Dec-2013) 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/mapper/myvg-mylv1: 11/589824 files (0.0% non-contiguous), 75551/2359296 blocks ~]# resize2fs /dev/myvg/mylv1 7G resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long. ~]# 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. ~]# mount -a ~]# df -h |grep users /dev/mapper/myvg-mylv1 6.8G 23M 6.5G 1% /users
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
~]# lvcreate -L 1G -n mylv1_snapshot -p r -s /dev/myvg/mylv1 Logical volume "mylv1_snapshot" created. ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- 67.45g root centos -wi-ao---- 50.00g swap centos -wi-ao---- 2.00g mylv1 myvg owi-aos--- 7.00g mylv1_snapshot myvg sri-a-s--- 1.00g mylv1 0.00 ~]# mkdir /lvmsnapshot ~]# mount /dev/myvg/mylv1_snapshot /lvmsnapshot/ mount: /dev/mapper/myvg-mylv1_snapshot is write-protected, mounting read-only ~]# ls -l /lvmsnapshot/ total 16 drwx------. 2 root root 16384 Nov 8 15:25 lost+found
原创文章,作者:N23-苏州-void,如若转载,请注明出处:http://www.178linux.com/58575