1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@client ~]# fdisk /dev/xvdc 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): p Partition number (1-4, default 1): 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 Extended 41 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 bootable 4f 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/M a0 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 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 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 FAT16 63 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 boot ff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): 8e Changed type of partition ‘Linux‘ to ‘Linux LVM‘ Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@client ~]# partprobe /dev/xvdc [root@client ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/xvdc1 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 [root@client ~]# tune2fs -o acl /dev/xvdc1 tune2fs 1.42.9 (28-Dec-2013) [root@client ~]# mkdir -p /data/mydata [root@client ~]# mount -o noexec,noatime /dev/xvdc1 /data/mydata/ [root@client ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/xvda1 ext4 79G 1.5G 74G 2% / devtmpfs devtmpfs 487M 0 487M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 26M 471M 6% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/xvdc1 ext4 9.8G 13M 9.6G 1% /data/mydata
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@client ~]# fdisk /dev/xvdc 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): 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): t Partition number (1,2, default 2): 2 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 Extended 41 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 bootable 4f 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/M a0 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 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 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 FAT16 63 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 boot ff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): 82 Changed type of partition ‘Linux‘ to ‘Linux swap / Solaris‘ Command (m for help): p Disk /dev/xvdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xbc3623c2 Device Boot Start End Blocks Id System /dev/xvdc1 2048 20973567 10485760 8e Linux LVM /dev/xvdc2 20973568 23070719 1048576 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@client ~]# partprobe /dev/xvdc [root@client ~]# mkswap /dev/xvdc2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=006e648a-6f1f-4205-9c95-6913e59de4d7 [root@client ~]# swapon /dev/xvdc2 [root@client ~]# free total used free shared buff/cache available Mem: 1015476 73828 145940 25728 795708 760100 Swap: 1048572 0 1048572
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@Client ~]# vim a #!/bin/bash fdisk -l | grep -E "^/dev"| cut -d" " -f1 df -hT [root@Client ~]# chmod 740 a [root@Client ~]# ./a /dev/sda1 #获取并列出磁盘设备 /dev/sda2 Filesystem Type Size Used Avail Use% Mounted on #显示空间使用信息 /dev/mapper/vg_client-lv_root ext4 18G 3.4G 13G 21% / tmpfs tmpfs 491M 72K 491M 1% /dev/shm /dev/sda1 ext4 477M 35M 418M 8% /boot
4、总结RAID的各个级别及其组合方式和性能的不同;
常用的RAID主要分为RAID-0,RAID-1,RAID-5,RAID-10,RAID-50 RAID-0:连续以位或字节为单位分割数据,并行读/写于多个磁盘上,至少需要2块磁盘;具有很高的数据传输率,没有数据冗余,但并没有为数据的可靠性提供保证,一个磁盘失效将影响到所有数据; RAID-1:在成对的独立磁盘上产生互为备份的数据,至少需要2块磁盘;提供了很高的数据安全性和可用性,提高了性能; RAID-5:不单独指定的奇偶盘,而是在所有磁盘上交叉地存取数据及奇偶校验信息,至少需要3块磁盘;适合于小数据块和随机读写的数据,提高了读写性能; RAID-10:先做RAID-1,再做RAID-0,至少需要4块磁盘;是高可靠性与高效磁盘结构; RAID-50:先做RAID-5,再RAID-0,至少需要6块磁盘;有冗余能力,每组镜像最多只能坏一块。
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@client ~]# mdadm -C /dev/md1 -n 2 -x 1 -l 1 -c 128 /dev/xvda1 /dev/xvdb1 /dev/xvdc1 #由于创建一个RAID1需要2个磁盘,另外需要一个空闲盘,所以需要先fdisk命令分3个新区出来,因为磁盘大小不够分3个10GB的了,就直接写命令了
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
#和上一小题一样 直接写命令出来了 分区假设已经创建存在了 mdadm -C /dev/md1 -n 3 -l 5 -c 256 /dev/xvda2 /dev/xvdb2 /dev/xvdc2 mkfs.ext4 /dev/md1 mkdir /backup echo "/dev/md1 /backup ext4 defaults,noatime,acl 0 0" >> /etc/fstab mount -a df -hT
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
[root@Client ~]# vim b #!/bin/bash for i in $@ do echo "$i的行数为:" $(wc -l $i | cut -d" " -f1) done echo "一共读取了$#个文件的行数" [root@Client ~]# chmod 740 b [root@Client ~]# ./b /etc/fstab /etc/passwd /etc/yum.repos.d/filepackages.repo /etc/fstab的行数为: 15 /etc/passwd的行数为: 60 /etc/yum.repos.d/filepackages.repo的行数为: 6 一共读取了3个文件的行数
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
[root@Client ~]# vim c #!/bin/bash for i in $@ do useradd $i echo "$i" | passwd --stdin $i done echo "一共创建了$#个新用户" [root@Client ~]# chmod 740 c [root@Client ~]# ./c us1 us2 us3 Changing password for user us1. passwd: all authentication tokens updated successfully. Changing password for user us2. passwd: all authentication tokens updated successfully. Changing password for user us3. passwd: all authentication tokens updated successfully. 一共创建了3个新用户 [root@Client ~]# tail -n 3 /etc/passwd us1:x:3024:3024::/home/us1:/bin/bash us2:x:3025:3025::/home/us2:/bin/bash us3:x:3026:3026::/home/us3:/bin/bash
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
[root@Client ~]# vim d #!/bin/bash declare -i sum for((i=1;i<=20;i++)) do useradd visitor$i echo "用户visitor$i创建成功" let sum+=$(id -u visitor$i) done echo "ID之和为:" $sum [root@Client ~]# chmod 740 d [root@Client ~]# ./d 用户visitor1创建成功 用户visitor2创建成功 用户visitor3创建成功 用户visitor4创建成功 用户visitor5创建成功 用户visitor6创建成功 用户visitor7创建成功 用户visitor8创建成功 用户visitor9创建成功 用户visitor10创建成功 用户visitor11创建成功 用户visitor12创建成功 用户visitor13创建成功 用户visitor14创建成功 用户visitor15创建成功 用户visitor16创建成功 用户visitor17创建成功 用户visitor18创建成功 用户visitor19创建成功 用户visitor20创建成功 ID之和为: 61450
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
[root@Client ~]# vim e #!/bin/bash declare -i sumshare sumspace for i in $@ do let sumshare+=$(grep -Ec "^#" $i) let sumspace+=$(grep -Ec "^$" $i) done echo "以#号开头行的总数是:$sumshare, 空白行的总数是:$sumspace" [root@Client ~]# chmod 740 e [root@Client ~]# ./e /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab 以#号开头行的总数是:94, 空白行的总数是:206
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
[root@Client ~]# vim f #!/bin/bash awk -F":" ‘/\/bin\/bash$/{printf "%-10s %d\n",$1,$3;sum+=$3}END{print "默认shell为bash的用户UID之和为:"sum}‘ /etc/passwd [root@Client ~]# chmod 740 f [root@Client ~]# ./f root 0 mu 500 user1 501 user2 502 user3 503 dff_grt 504 mageia 1100 mageiaa 1140 openstack 3003 hadoop 505 bash 3005 testbash 3006 basher 3007 fedora 3009 user10 3010 user11 3011 user12 3012 user13 3013 user14 3014 user15 3015 user16 3016 user17 3017 user18 3018 user19 3019 user111 3020 user 3021 222 3022 user333 3023 us1 3024 us2 3025 us3 3026 aaa1 3027 aaa2 3028 aaa3 3029 llus1 3030 llus2 3031 llus3 3032 table1 3033 table2 3034 table3 3035 tle1 3036 tle2 3037 tle3 3038 le1 3039 le2 3040 le3 3041 l1 3042 l2 3043 l3 3044 xl1 3045 xl2 3046 xl3 3047 dxl1 3048 dxl2 3049 dxl3 3050 tll1 3051 tll2 3052 tll3 3053 ql1 3054 ql2 3055 ql3 3056 xql1 3057 xql2 3058 xql3 3059 qxql1 3060 qxql2 3061 qxql3 3062 visitor1 3063 visitor2 3064 visitor3 3065 visitor4 3066 visitor5 3067 visitor6 3068 visitor7 3069 visitor8 3070 visitor9 3071 visitor10 3072 visitor11 3073 visitor12 3074 visitor13 3075 visitor14 3076 visitor15 3077 visitor16 3078 visitor17 3079 visitor18 3080 visitor19 3081 visitor20 3082 默认shell为bash的用户UID之和为:242643
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
[root@Client ~]# vim x #!/bin/bash for i in $(awk -F":" ‘{print $1;}‘ /etc/passwd) do groups $i | cut -d: -f2 | awk ‘{if(NF!=1){print $1}}‘ done [root@Client ~]# chmod 740 x [root@Client ~]# ./x bin daemon adm postfix user1 distro clouds
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@client ~]# fdisk /dev/xvdc 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): 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): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +10G Value out of range. Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +9.9G Unsupported suffix: ‘.9G‘. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): ^[[A Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +9G Partition 2 of type Linux and of size 9 GiB is set Command (m for help): t Partition number (1,2, default 2): 1 Hex code (type L to list all codes): 8e Changed type of partition ‘Linux‘ to ‘Linux LVM‘ Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 8e Changed type of partition ‘Linux‘ to ‘Linux LVM‘ Command (m for help): p Disk /dev/xvdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xbc3623c2 Device Boot Start End Blocks Id System /dev/xvdc1 2048 20973567 10485760 8e Linux LVM /dev/xvdc2 20973568 39847935 9437184 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@client ~]# partprobe /dev/xvdc [root@client ~]# pvcreate /dev/xvdc1 /dev/xvdc2 WARNING: Device for PV 95Xxz4-qU1Y-8CnZ-Vy2Y-brf4-LwNF-0ik9Ra not found or rejected by a filter. WARNING: ext4 signature detected on /dev/xvdc1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/xvdc1. Physical volume "/dev/xvdc1" successfully created WARNING: Device for PV 95Xxz4-qU1Y-8CnZ-Vy2Y-brf4-LwNF-0ik9Ra not found or rejected by a filter. Physical volume "/dev/xvdc2" successfully created [root@client ~]# vgcreate -s 8M myvg1 /dev/xvdc1 /dev/xvdc2 WARNING: Device for PV 95Xxz4-qU1Y-8CnZ-Vy2Y-brf4-LwNF-0ik9Ra not found or rejected by a filter. WARNING: Device for PV 95Xxz4-qU1Y-8CnZ-Vy2Y-brf4-LwNF-0ik9Ra not found or rejected by a filter. Volume group "myvg1" successfully created [root@client ~]# vgdisplay --- Volume group --- VG Name myvg1 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 18.98 GiB PE Size 8.00 MiB Total PE 2430 Alloc PE / Size 0 / 0 Free PE / Size 2430 / 18.98 GiB VG UUID 2P1Nsg-BKXZ-vbNw-NUYq-Axxi-8fmX-H5BBb2 [root@client ~]# lvcreate -L 5G -n mylv1 myvg1 Logical volume "mylv1" created. [root@client ~]# mkfs.ext4 /dev/myvg1/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 [root@client ~]# mkdir -p /users [root@client ~]# echo "/dev/myvg1/mylv1 /users ext4 defaults,acl 0 0" >> /etc/fstab [root@client ~]# mount -a [root@client ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda1 82436784 1656192 76570008 3% / devtmpfs 498576 0 498576 0% /dev tmpfs 507676 0 507676 0% /dev/shm tmpfs 507676 6668 501008 2% /run tmpfs 507676 0 507676 0% /sys/fs/cgroup tmpfs 101536 0 101536 0% /run/user/0 /dev/mapper/myvg1-mylv1 5029504 20472 4730504 1% /users
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@Client ~]# mkdir -p /users/magedu [root@Client ~]# useradd -d /users/magedu/ magedu [root@Client ~]# su - magedu [magedu@Client ~]$ cp /etc/* ~
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@client ~]# lvextend -L +4G -n /dev/myvg1/mylv1 Size of logical volume myvg1/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. [root@client ~]# resize2fs /dev/myvg1/mylv1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/myvg1/mylv1 is mounted on /users; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/myvg1/mylv1 is now 2359296 blocks long. [root@client ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/xvda1 ext4 79G 1.6G 74G 3% / devtmpfs devtmpfs 487M 0 487M 0% /dev tmpfs tmpfs 496M 0 496M 0% /dev/shm tmpfs tmpfs 496M 6.6M 490M 2% /run tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup tmpfs tmpfs 100M 0 100M 0% /run/user/0 /dev/mapper/myvg1-mylv1 ext4 8.8G 23M 8.3G 1% /users
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@client ~]# umount /dev/myvg1/mylv1 [root@client ~]# e2fsck -f /dev/myvg1/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/myvg1/mylv1: 11/589824 files (0.0% non-contiguous), 75551/2359296 blocks [root@client ~]# resize2fs /dev/myvg1/mylv1 7G resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/myvg1/mylv1 to 1835008 (4k) blocks. The filesystem on /dev/myvg1/mylv1 is now 1835008 blocks long. [root@client ~]# lvreduce -L 7G -n /dev/myvg1/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 myvg1/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized. [root@client ~]# mount -a [root@client ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda1 82436784 1656340 76569860 3% / devtmpfs 498576 0 498576 0% /dev tmpfs 507676 0 507676 0% /dev/shm tmpfs 507676 6668 501008 2% /run tmpfs 507676 0 507676 0% /sys/fs/cgroup tmpfs 101536 0 101536 0% /run/user/0 /dev/mapper/myvg1-mylv1 7093752 23028 6711812 1% /users
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@client ~]# lvcreate -L 2G -p r -s -n mylv1_bf /dev/myvg1/mylv1 Logical volume "mylv1_bf" created.
本文出自 “果麦” 博客,转载请与作者联系!
原文地址:http://guomai.blog.51cto.com/8530387/1854758