1、创建一个10G分区,并格式为ext4文件系统;
第一步:创建磁盘空间
[root@localhost ~]# fdisk /dev/sdb
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-62914559,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-62914559,默认为 62914559):+10G
分区 1 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.4
正在同步磁盘。
第二步:更新磁盘到内核
[root@localhost ~]# partx -a /dev/sdb
(1) 要求其block大小为2048,预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@localhost ~]# mkfs.ext4 -L MYDATA -m 2 -b 2048 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=MYDATA
OS type: Linux
块大小=2048 (log=1)
分块大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
104857 blocks (2.00%) reserved for the super user
第一个数据块=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: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@localhost ~]# mount /dev/sdb1 /data/mydata -o noatime,noauto
[root@localhost ~]# df /dev/sdb1
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sdb1 10254840 12308 10024626 1% /data/mydata
验证:[root@localhost 桌面]# dumpe2fs -h /dev/sdb1
-------------------------------------------------------------------------------------
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
第一步:划分磁盘
[root@localhost 桌面]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (20973568-62914559,默认为 20973568):
将使用默认值 20973568
Last 扇区, +扇区 or +size{K,M,G} (20973568-62914559,默认为 62914559):+1G
分区 2 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):t
分区号 (1,2,默认 2):
Hex 代码(输入 L 列出所有代码):82 //类型为82
已将分区“Linux”的类型更改为“Linux swap / Solaris”
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
第二步:同步到内核正在同步磁盘。
[root@localhost 桌面]# partx -a /dev/sdb
第三步:创建文件系统partx: /dev/sdb: error adding partitions 1-2
[root@localhost 桌面]# mkswap -L swap /dev/sdb2
mkswap: /dev/sdb2: warning: wiping old swap signature.
正在设置交换空间版本 1,大小 = 1048572 KiB
查看:LABEL=swap, UUID=3ef13691-b278-4903-80ce-f2933eebfefb
[root@localhost 桌面]# fdisk -l /dev/sdb
磁盘 /dev/sdb:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x811e2d7f
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
第四步:激活交换分区/dev/sdb2 20973568 23070719 1048576 82 Linux swap / Solaris
swapon /dev/sdb2
查看
swapon -s
------------------------------------------------------------------------------------------
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin.bash
#
for fname in `fdisk -l | grep "^/dev/sd[a-z]" | cut -d" " -f 1`;do
echo -n "the fdisk name is $fname"
df $fname | awk '{if(NR == 2){printf"\t usespace is %d\t use-percent is %d\n",$4,$5}}'
done
------------------------------------------------------------------------------------------
4、总结RAID的各个级别及其组合方式和性能的不同;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
RAID类型 + 磁盘利用率 + 需要的磁盘数量 + 读写性能 + 是否有容错 + 描述(以需要的磁盘最少为例)
--------------------------------------------------------------------------------------------------------------------------
RADI0 + N*min(s1,s2) + 2 , 2+ + 读写性能提升 + 没有 + 数据均匀放在两个磁盘上,可以同时读写
--------------------------------------------------------------------------------------------------------------------------
RADI1 + 1*min(s1,s2) + 2 , 2+ + 读提升,写下降 + 有 ,1块盘 + 一个使用一个备份,浪费空间最大
--------------------------------------------------------------------------------------------------------------------------
RADI4 +(N-1)*min(s1,s2) + 3 , 3+ + 读写性能提升 + 有 ,1块盘 +二块放数据一块专用方校验,校验容易称为瓶颈,不常用
--------------------------------------------------------------------------------------------------------------------------
RADI5 +(N-1)*min(s1,s2 + 3 , 3+ + 读写性能提升 + 有 ,1块盘 +同RADI4,但校验和数据轮流放在不同磁盘上,
------------------------------------------------------------------------------------------------------------------------
RADI6 +(N-2)*min(s1,s2) + 4 , 4+ + 读写性能提升 + 有 ,2块盘 +同RADI5,2校验和2数据轮流放在不同磁盘上,
--------------------------------------------------------------------------------------------------------------------------
RADI10 + N*min(s1,s2)/2 + 4 , 4+ + 读写性能提升 + 有 + 两两做成RIAD1,组成一起RAID0
每组镜像最多只能坏一块
--------------------------------------------------------------------------------------------------------------------------
RAID01 + 1*min(s1,s2)/2 + 4 , 4+ + 读提升,写下降 + 有 + 分成两组做成RADI0, 然后组做成RAID1
最多只能坏一组
--------------------------------------------------------------------------------------------------------------------------
RAID50 +(n-1)*min(s1,s2)/2+ 6 , 6+ + 读写性能提升 + 有 + 每3块做先成RADI5, 然后组做成RAID0
每组镜像最多只能坏一块
--------------------------------------------------------------------------------------------------------------------------
JBOD + sum(s1,s2)/2 + 2 , 2+ +保持,当跨盘时提升+ 没有 + 将多块磁盘的空间合并一个大的连续空间使用;
(第一个用完用第二个依次使用) 磁盘利用率最大
--------------------------------------------------------------------------------------------------------------------------
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
第一步:创建磁盘
RAID1 的前提最低要求为 2块相同容量的磁盘分区。
第二步:利用软件创建RAID本例子中大小为10G时,使用RAID1 需要的每个磁盘容量个为10G,因为,RAID1的可用容量为总容量的一半,所以创建10G的容量空间需要2块20G的磁盘,加上一块冗余的共需要3块30G的磁盘。并把磁盘分区为FD类型即RAID专用的。
[root@localhost 桌面]# mdadm -C /dev/md1 -l 1 -x 1 -n 2 -c 128 /dev/sdb{1,2,3}
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=10485760K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sdb1 appears to be part of a raid array:
level=raid1 devices=2 ctime=Tue Sep 13 22:32:53 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
mdadm: /dev/sdb2 appears to contain an ext2fs file system
size=10485760K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sdb2 appears to be part of a raid array:
level=raid1 devices=2 ctime=Tue Sep 13 22:32:53 2016
mdadm: /dev/sdb3 appears to contain an ext2fs file system
size=10484736K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sdb3 appears to be part of a raid array:
level=raid1 devices=2 ctime=Tue Sep 13 22:32:53 2016
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
查看:mdadm: array /dev/md1 started.
[root@localhost 桌面]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Tue Sep 13 22:59:54 2016
Raid Level : raid1
Array Size : 10476544 (9.99 GiB 10.73 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Tue Sep 13 23:00:46 2016
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 29dec89e:6a240747:8676eb84:28e5c8bc
Events : 17
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
2 8 19 - spare /dev/sdb3
---------------------------------------------------------------------------------------------------------
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
第一步:划分磁盘
RAID5 最少的磁盘数量为3,或者为3的倍数。 根据本例子的要求组一个大小为4G的RADI5, RADI5的容量为磁盘容量的三分子二,所以需要3块2G的RAID专用磁盘即磁盘类别为FD
第二步:创建软RAID
[root@localhost 桌面]# mdadm -C /dev/md2 -l 5 -n 3 -c 256 /dev/sdb{1,2,3}
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=10485760K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sdb1 appears to be part of a raid array:
level=raid5 devices=3 ctime=Tue Sep 13 23:37:59 2016
mdadm: /dev/sdb2 appears to be part of a raid array:
level=raid5 devices=4 ctime=Tue Sep 13 23:28:06 2016
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
查看RAIDmdadm: array /dev/md2 started.
[root@localhost 桌面]# mdadm -D /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Tue Sep 13 23:46:02 2016
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Tue Sep 13 23:46:11 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 : 79% complete
Name : localhost.localdomain:2 (local to host localhost.localdomain)
UUID : dcb582b6:c2195680:a57f9131:364d527d
Events : 13
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
3 8 19 2 spare rebuilding /dev/sdb3
第三步:创建文件系统
[root@localhost 桌面]# mkfs.ext4 -L MYRADI5 /dev/md2
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=MYRADI5
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
262144 inodes, 1047552 blocks
52377 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1073741824
32 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: 完成
正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
第四步:挂载文件系统
[root@localhost 桌面]# mount /dev/md2 /backup -o auto,noatime,acl
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash
#
declare -i row=0
declare -i row_count=0
if [ $# -le 1 ];then
echo "the parmenter is must more than 1"
else
for i in $@;do
if [ -e $i ];then
row=$( awk 'END{ print NR }' $i )
let row_count+=row
echo "the file $i has $row row"
let ecount++
else
echo "the file $i is not exist"
fi
done
fi
echo "the enter file is $#, efficent file is $ecount,the altogether row is $row_count"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash
#
declare -i xx=0
if [ $# -le 2 ];then
echo "the patamter is must more than 2. Try againg"
else
for i in $@;do
if id $i &> /dev/null;then
echo "the user $i is exist"
else
useradd $i
echo "$i" | passwd --stdin $i &> /dev/null
let xx++
echo "the user $i is add , the password as same as the $i"
fi
done
fi
echo "Altogether user add is $xx"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash
#
declare -i user_num=1
declare -i sum=0
for user_num in $( seq 1 20);do
if id visitor$user_num &> /dev/null; then
echo “The visitor$user_num is exist”
else
useradd visitor$user_num
echo "the user visitor$user_num add "
fi
let sum+=$(id visitor$user_num -u)
done
echo "the add user id sum is $sum"
-------------------------------------------------------------------------------------------
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash
#
space_row=$(awk '/^$/{sum += 1}END{print sum}' /etc/fstab /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions)
jin_row=$(awk '/^#/{sum += 1}END{print sum}' /etc/fstab /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions)
echo "three files as the # begin has $jin_row row "
echo "three files as the space begin has $space_row row "
-----------------------------------------------------------------------------------------------------
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash
#
declare -i sum=0
while read line;do
shell="$(echo $line|cut -d: -f7 )"
if [ "$shell" == "/bin/bash" ];then
echo $line | awk -F: '{sum += $3;printf"The user name is : %s\t and the UID is : %d\n",$1,$3}'
fi
done < /etc/passwd
echo -n "the UID sum is : "
awk -F: '{sum += $3}END{print sum }' /etc/passwd
echo ""
---------------------------------------------------------------------------------------------
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash
#
declare -i i=0
while read line;do
user=$(echo $line |cut -d: -f1 )
fu_group=$(id $user -G | wc -w )
if [ $fu_group -gt 1 ];then
echo "the $user has a supplementary group"
let i++
fi
done < /etc/passwd
echo " "
echo "the user who has supplementay group sum up is $i "
------------------------------------------------------------------------------------
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
第一步:划分磁盘,
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 8e Linux LVM
/dev/sdb2 20973568 41945087 10485760 8e Linux LVM
第二步:创建物理卷
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
[root@localhost ~]# pvdisplay
"/dev/sdb2" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID CcrNV4-PFFQ-CdDm-X8x8-eoGs-RSqP-9hljBM
"/dev/sdb1" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID chKwxe-x135-9qhe-hCcL-xGMp-863A-R2aSVx
第四步创建VG
[root@localhost ~]# vgcreate -s 8M myvg /dev/sdb{1,2}
Volume group "myvg" successfully created
[root@localhost ~]# vgdisplay
--- 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 19.98 GiB
PE Size 8.00 MiB
Total PE 2558
Alloc PE / Size 0 / 0
Free PE / Size 2558 / 19.98 GiB
VG UUID jeV2ch-CePk-Izht-yY01-nvOr-T04l-RcRdJQ
第五步 创建LV
[root@localhost ~]# lvcreate -L 5G -n mylv myvg
WARNING: ext4 signature detected on /dev/myvg/mylv at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/myvg/mylv.
Logical volume "mylv" created.
[root@localhost ~]# lvdisplay /dev/myvg/mylv
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID unEIp2-AV4s-YqEI-RF2t-kPfS-tgN2-Bd1OhU
LV Write Access read/write
LV Creation host, time localhost, 2016-09-14 13:03:22 +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 8192
Block device 253:1
第六步创建文件系统
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=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: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
第七步挂载文件
mkdir /users
[root@localhost ~]# mount /dev/myvg/mylv /users -o auto,acl
--------------------------------------------------------------------------
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
useradd -d /users/magedu magedu
echo "magedu" | passwd --stdin magedu
mkdir /users/magedu -p
cp /etc/* /tmp -r
su - magedu
cp -r /tmp/* ./
---------------------------------------------------------------------------------
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
支持在线扩展所以不需要卸载umount已经加载的磁盘
第一步:检查
检查VG的容量是否可够扩展(如果VG不够只能依据建立的时候将新盘创建为PV,VG
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.98 GiB
PE Size 8.00 MiB
Total PE 2558
Alloc PE / Size 640 / 5.00 GiB
Free PE / Size 1918 / 14.98 GiB 该处表明还有剩余用于扩展
VG UUID jeV2ch-CePk-Izht-yY01-nvOr-T04l-RcRdJQ
第二步扩展LV
[root@localhost ~]# lvresize -L +4G /dev/myvg/mylv
Size of logical volume myvg/mylv changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents).
Logical volume mylv successfully resized.
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID unEIp2-AV4s-YqEI-RF2t-kPfS-tgN2-Bd1OhU
LV Write Access read/write
LV Creation host, time localhost, 2016-09-14 13:03:22 +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 8192
Block device 253:1
第三步扩展文件系统的大小
[root@localhost ~]# df (查看容量没有增加,但LV容量已经增加了)
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/myvg-mylv 5029504 20476 4730500 1% /users
将增加的容量应用到文件系统中
[root@localhost ~]# resize2fs /dev/myvg/mylv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /users; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/myvg/mylv is now 2359296 blocks long.
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/myvg-mylv 8.8G 23M 8.3G 1% /users
-----------------------------------------------------------------------------
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
不支持在线缩减,需要卸载umount
第一步检查
当前使用的容量应该小于缩减后的容量,否则不能缩减;由于不支持在线缩减,所以在用户使用时不能缩减
[root@localhost ~]# df -h /dev/myvg/mylv
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/myvg-mylv 8.8G 23M 8.3G 1% /users
第二步:卸载挂载和检查磁盘(如果不检查会提示)
[root@localhost ~]# umount /dev/myvg/mylv
想跳过检查的提示
[root@localhost ~]# resize2fs /dev/myvg/mylv 7G
resize2fs 1.42.9 (28-Dec-2013)
请先运行 'e2fsck -f /dev/myvg/mylv'.
[root@localhost ~]# e2fsck -f /dev/myvg/mylv
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/myvg/mylv: 12/589824 files (0.0% non-contiguous), 75552/2359296 blocks
第三步:缩减文件系统
[root@localhost ~]# resize2fs /dev/myvg/mylv 7G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/myvg/mylv to 1835008 (4k) blocks.
The filesystem on /dev/myvg/mylv is now 1835008 blocks long.
第五步:缩减VG
[root@localhost ~]# lvreduce -L 7G /dev/myvg/mylv
WARNING: Reducing active logical volume to 7.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
Size of logical volume myvg/mylv changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents).
Logical volume mylv successfully resized.
检查[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID unEIp2-AV4s-YqEI-RF2t-kPfS-tgN2-Bd1OhU
LV Write Access read/write
LV Creation host, time localhost, 2016-09-14 13:03:22 +0800
LV Status available
# open 0
LV Size 7.00 GiB 容量变为7G
Current LE 896
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
第六步:重新挂载
[root@localhost ~]# mount /dev/myvg/mylv /users
[root@localhost ~]# df -lh
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/myvg-mylv 6.8G 23M 6.5G 1% /users
-------------------------------------------------------------------------------------
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
快照尺寸的大小要根据需要保护的文件的大小确定,当小于原来文件系统的容量时,会不到保护的作用。具体可依据读写的频率和原来系统的大小,较小的容量可以分配与原有一样的大小,较大的就依据磁盘改变的频率文件的大小确定,保证一定的冗余。
第一步:创建快照
[root@localhost ~]# lvcreate -L 5G -p r -s -n myvl-snap /dev/myvg/mylv
Logical volume "myvl-snap" created.
第二步:挂载快照
[root@localhost ~]# mount /dev/myvg/myvl-snap /mnt
mount: /dev/mapper/myvg-myvl--snap 写保护,将以只读方式挂载
第三步:验证
拷贝一个文件到系统路径下
[root@localhost ~]# cat /users/
fstab lost+found/
[root@localhost ~]# cp /etc/issue /users/
查看快照的挂载
[root@localhost ~]# ll /mnt
总用量 20
-rw-r--r--. 1 root root 577 9月 14 13:11 fstab
drwx------. 2 root root 16384 9月 14 13:04 lost+found
lvm挂载下有
[root@localhost ~]# ll /users/
总用量 24
-rw-r--r--. 1 root root 577 9月 14 13:11 fstab
-rw-r--r--. 1 root root 23 9月 14 13:58 issue ---新文件
drwx------. 2 root root 16384 9月 14 13:04 lost+found