四周第一次课(1月2日) 4.10/lvm讲解 4.11/lvm讲解 4.12/lvm讲解 4.13 磁盘故障小案例

Posted 两颗白菜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四周第一次课(1月2日) 4.10/lvm讲解 4.11/lvm讲解 4.12/lvm讲解 4.13 磁盘故障小案例相关的知识,希望对你有一定的参考价值。

四周第一次课(1月2日)
4.10/lvm讲解
4.11/lvm讲解
4.12/lvm讲解
4.13 磁盘故障小案例


onnecting to 192.168.183.128:22...
Connection established.
To escape to local shell, press ‘Ctrl+Alt+]‘.

Last login: Tue Jan 2 19:34:17 2018
[[email protected] ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:f6:5a:ef brd ff:ff:ff:ff:ff:ff
inet 192.168.160.128/24 brd 192.168.160.255 scope global dynamic ens33
valid_lft 1746sec preferred_lft 1746sec
inet6 fe80::9d1c:ba9a:850d:5e30/64 scope link
valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:f6:5a:f9 brd ff:ff:ff:ff:ff:ff
inet 192.168.183.128/24 brd 192.168.183.255 scope global dynamic ens37
valid_lft 1746sec preferred_lft 1746sec
inet6 fe80::aea3:cf3e:1eb8:ac2f/64 scope link
valid_lft forever preferred_lft forever
[[email protected] ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xf357db60 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf357db60

设备 Boot Start End Blocks Id System

命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf357db60

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf357db60

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM

命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (2099200-41943039,默认为 2099200):
将使用默认值 2099200
Last 扇区, +扇区 or +size{K,M,G} (2099200-41943039,默认为 41943039):+1G
分区 2 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助):t
分区号 (1,2,默认 2):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (4196352-41943039,默认为 4196352):
将使用默认值 4196352
Last 扇区, +扇区 or +size{K,M,G} (4196352-41943039,默认为 41943039):+1G
分区 3 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf357db60

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
/dev/sdb3 4196352 6293503 1048576 83 Linux

命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf357db60

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
/dev/sdb3 4196352 6293503 1048576 8e Linux LVM

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。

[[email protected] ~]# fdisk -l

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf357db60

设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
/dev/sdb3 4196352 6293503 1048576 8e Linux LVM

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00098ef8设备 Boot Start End Blocks Id System

/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 5220351 2097152 82 Linux swap / Solaris
/dev/sda3 5220352 83886079 39332864 83 Linux

[[email protected] ~]# yum install -y lvm2
已加载插件:fastestmirror
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 lvm2.x86_64.7.2.02.171-8.el7 将被 安装
--> 正在处理依赖关系 lvm2-libs = 7:2.02.171-8.el7,它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在处理依赖关系 device-mapper-persistent-data >= 0.7.0-0.1.rc6,它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在处理依赖关系 liblvm2app.so.2.2(Base)(64bit),它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在处理依赖关系 libdevmapper.so.1.02(DM_1_02_138)(64bit),它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在处理依赖关系 libdevmapper-event.so.1.02(Base)(64bit),它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在处理依赖关系 liblvm2app.so.2.2()(64bit),它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在处理依赖关系 libdevmapper-event.so.1.02()(64bit),它被软件包 7:lvm2-2.02.171-8.el7.x86_64 需要
--> 正在检查事务
---> 软件包 device-mapper-event-libs.x86_64.7.1.02.140-8.el7 将被 安装
---> 软件包 device-mapper-libs.x86_64.7.1.02.135-1.el7 将被 升级
--> 正在处理依赖关系 device-mapper-libs = 7:1.02.135-1.el7,它被软件包 7:device-mapper-1.02.135-1.el7.x86_64 需要
---> 软件包 device-mapper-libs.x86_64.7.1.02.140-8.el7 将被 更新
---> 软件包 device-mapper-persistent-data.x86_64.0.0.7.0-0.1.rc6.el7 将被 安装
--> 正在处理依赖关系 libaio.so.1(LIBAIO_0.4)(64bit),它被软件包 device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64 需要
--> 正在处理依赖关系 libaio.so.1(LIBAIO_0.1)(64bit),它被软件包 device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64 需要
--> 正在处理依赖关系 libaio.so.1()(64bit),它被软件包 device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64 需要
---> 软件包 lvm2-libs.x86_64.7.2.02.171-8.el7 将被 安装
--> 正在处理依赖关系 device-mapper-event = 7:1.02.140-8.el7,它被软件包 7:lvm2-libs-2.02.171-8.el7.x86_64 需要
--> 正在检查事务
---> 软件包 device-mapper.x86_64.7.1.02.135-1.el7 将被 升级
---> 软件包 device-mapper.x86_64.7.1.02.140-8.el7 将被 更新
---> 软件包 device-mapper-event.x86_64.7.1.02.140-8.el7 将被 安装
---> 软件包 libaio.x86_64.0.0.3.109-13.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

========================================================================
Package 架构 版本 源 大小
========================================================================
正在安装:
lvm2 x86_64 7:2.02.171-8.el7 base 1.3 M
为依赖而安装:
device-mapper-event x86_64 7:1.02.140-8.el7 base 180 k
device-mapper-event-libs x86_64 7:1.02.140-8.el7 base 179 k
device-mapper-persistent-data x86_64 0.7.0-0.1.rc6.el7 base 400 k
libaio x86_64 0.3.109-13.el7 base 24 k
lvm2-libs x86_64 7:2.02.171-8.el7 base 1.0 M
为依赖而更新:
device-mapper x86_64 7:1.02.140-8.el7 base 280 k
device-mapper-libs x86_64 7:1.02.140-8.el7 base 312 k

事务概要
========================================================================
安装 1 软件包 (+5 依赖软件包)
升级 ( 2 依赖软件包)

总下载量:3.6 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/8): device-mapper-event-1.02.140-8.el7.x86_64.r | 180 kB 00:00
(2/8): device-mapper-1.02.140-8.el7.x86_64.rpm | 280 kB 00:00
(3/8): device-mapper-event-libs-1.02.140-8.el7.x86 | 179 kB 00:00
(4/8): device-mapper-libs-1.02.140-8.el7.x86_64.rp | 312 kB 00:00
(5/8): device-mapper-persistent-data-0.7.0-0.1.rc6 | 400 kB 00:00
(6/8): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00
(7/8): lvm2-2.02.171-8.el7.x86_64.rpm | 1.3 MB 00:00
(8/8): lvm2-libs-2.02.171-8.el7.x86_64.rpm | 1.0 MB 00:00
------------------------------------------------------------------------
总计 3.1 MB/s | 3.6 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : 7:device-mapper-libs-1.02.140-8.el7.x86_64 1/10
正在更新 : 7:device-mapper-1.02.140-8.el7.x86_64 2/10
正在安装 : 7:device-mapper-event-libs-1.02.140-8.el7.x86_6 3/10
正在安装 : 7:device-mapper-event-1.02.140-8.el7.x86_64 4/10
正在安装 : 7:lvm2-libs-2.02.171-8.el7.x86_64 5/10
正在安装 : libaio-0.3.109-13.el7.x86_64 6/10
正在安装 : device-mapper-persistent-data-0.7.0-0.1.rc6.el7 7/10
正在安装 : 7:lvm2-2.02.171-8.el7.x86_64 8/10
Created symlink from /etc/systemd/system/sysinit.target.wants/lvm2-lvmpolld.socket to /usr/lib/systemd/system/lvm2-lvmpolld.socket.
清理 : 7:device-mapper-libs-1.02.135-1.el7.x86_64 9/10
清理 : 7:device-mapper-1.02.135-1.el7.x86_64 10/10
验证中 : 7:device-mapper-event-libs-1.02.140-8.el7.x86_6 1/10
验证中 : 7:device-mapper-event-1.02.140-8.el7.x86_64 2/10
验证中 : 7:lvm2-libs-2.02.171-8.el7.x86_64 3/10
验证中 : 7:device-mapper-1.02.140-8.el7.x86_64 4/10
验证中 : 7:device-mapper-libs-1.02.140-8.el7.x86_64 5/10
验证中 : 7:lvm2-2.02.171-8.el7.x86_64 6/10
验证中 : device-mapper-persistent-data-0.7.0-0.1.rc6.el7 7/10
验证中 : libaio-0.3.109-13.el7.x86_64 8/10
验证中 : 7:device-mapper-1.02.135-1.el7.x86_64 9/10
验证中 : 7:device-mapper-libs-1.02.135-1.el7.x86_64 10/10

已安装:
lvm2.x86_64 7:2.02.171-8.el7

作为依赖被安装:
device-mapper-event.x86_64 7:1.02.140-8.el7
device-mapper-event-libs.x86_64 7:1.02.140-8.el7
device-mapper-persistent-data.x86_64 0:0.7.0-0.1.rc6.el7
libaio.x86_64 0:0.3.109-13.el7
lvm2-libs.x86_64 7:2.02.171-8.el7

作为依赖被升级:
device-mapper.x86_64 7:1.02.140-8.el7
device-mapper-libs.x86_64 7:1.02.140-8.el7

完毕!
[[email protected] ~]# yum provides"/*/pvcreate"
已加载插件:fastestmirror
没有该命令:provides/*/pvcreate。请使用 /usr/bin/yum --help
[[email protected] ~]# pvcreate /dev/sdb1
Device /dev/sdb1 not found (or ignored by filtering).
[[email protected] ~]# partprobe
[[email protected] ~]# ls /dev/sdb1
/dev/sdb1
[[email protected] ~]# pvcreate /dev/sdb1
Can‘t open /dev/sdb1 exclusively. Mounted filesystem?
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sdb 20G 33M 20G 1% /mnt
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
[[email protected] ~]# umount /mnt
[[email protected] ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
[[email protected] ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[[email protected] ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.

[[email protected] ~]# pvdisplay
"/dev/sdb1" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID sw1OV6-5gko-ZDeT-AOK4-HAVf-2lpI-1dsfVe

"/dev/sdb3" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID QLjTPP-MfK8-qbQG-M8i3-zioD-UJ8q-QQGB4Z

"/dev/sdb2" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID pjxkTY-jhl4-comB-kxLx-L2RG-9yu9-8sWdyn

[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 1.00g 1.00g
/dev/sdb2 lvm2 --- 1.00g 1.00g
/dev/sdb3 lvm2 --- 1.00g 1.00g
[[email protected] ~]#
[[email protected] ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
Volume group "vg1" successfully created
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 1.99g 1.99g

[[email protected] ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mount /dev/vg1/lv1 /mnt/\
>
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.6M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
/dev/mapper/vg1-lv1 93M 1.6M 85M 2% /mnt
[[email protected] ~]# ls -l /dev/vg1/lv1
lrwxrwxrwx 1 root root 7 1月 2 21:09 /dev/vg1/lv1 -> ../dm-0
[[email protected] ~]# ls -l /dev/mapper//vg1-lv1
lrwxrwxrwx 1 root root 7 1月 2 21:09 /dev/mapper//vg1-lv1 -> ../dm-0
[[email protected] ~]# mkdir /mnt/1212

[[email protected] ~]# echo

[[email protected] ~]# echo "1111111111111111111"> /mnt/23.txt
[[email protected] ~]#
[[email protected] ~]# lvresize -L 200M /dev/vg
vg1/ vga_arbiter
[[email protected] ~]# lvresize -L 200M /dev/vg
vg1/ vga_arbiter
[[email protected] ~]# lvresize -L 200M /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
Logical volume vg1/lv1 successfully resized.
[[email protected] ~]# umount /mnt/
[[email protected] ~]# lvresize -L 200M /dev/vg1/lv1
New size (50 extents) matches existing size (50 extents).
[[email protected] ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8898/102400 blocks
[[email protected] ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.

[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.6M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
/dev/mapper/vg1-lv1 190M 1.6M 175M 1% /mnt
[[email protected] ~]# ls /mnt
1212 23.txt lost+found
[[email protected] ~]# cat /mnt/23.txt
1111111111111111111
[[email protected] ~]# umount /mnt/
[[email protected] ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11886/204800 blocks
[[email protected] ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 204800 blocks long. Nothing to do!

[[email protected] ~]# lvresize -L 100M /dev/vg1/lv1
WARNING: Reducing active logical volume to 100.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y
Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
Logical volume vg1/lv1 successfully resized.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 100.00m
[[email protected] ~]# lvresize -L 100M /dev/vg1/lv1
New size (25 extents) matches existing size (25 extents).
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 100.00m
[[email protected] ~]# !mount
mount /dev/vg1/lv1
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 1.99g 1.89g
[[email protected] ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mount /dev/vg1/lv1

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.6M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 100.00m
[[email protected] ~]# mount /mnt/
mount: /dev/sdb 已经挂载或 /mnt 忙
[[email protected] ~]# mount /dev/vg1/lv1
mount: 在 /etc/fstab 中找不到 /dev/vg1/lv1
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg1 lvm2 a-- 1020.00m 920.00m
/dev/sdb2 vg1 lvm2 a-- 1020.00m 1020.00m
/dev/sdb3 lvm2 --- 1.00g 1.00g
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 1.99g 1.89g

[[email protected] ~]# mkdir /mnt/1212
[[email protected] ~]# ls /mnt/
1212
[[email protected] ~]# lvresize -L 200M /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
Logical volume vg1/lv1 successfully resized.
[[email protected] ~]# !e2fsck
e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 11/25688 files (9.1% non-contiguous), 8896/102400 blocks
[[email protected] ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.

[[email protected] ~]# mount /dev/vg1/lv1
mount: 在 /etc/fstab 中找不到 /dev/vg1/lv1
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.6M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
[[email protected] ~]# ls /mnt/
1212
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg1 lvm2 a-- 1020.00m 820.00m
/dev/sdb2 vg1 lvm2 a-- 1020.00m 1020.00m
/dev/sdb3 lvm2 --- 1.00g 1.00g
[[email protected] ~]# !e2fsck
e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 11/49400 files (9.1% non-contiguous), 11884/204800 blocks
[[email protected] ~]# lvresize -L 112M /dev/vg1/lv1
WARNING: Reducing active logical volume to 112.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 112.00 MiB (28 extents).
Logical volume vg1/lv1 successfully resized.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 112.00m
[[email protected] ~]#
[[email protected] ~]# mount /dev/vg1/lv1
[[email protected] ~]# mkfs.xfs -f /dev/vg1/lv1
meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=7168 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=28672, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# mount /dev/vg1/lv1
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 

Connecting to 192.168.183.128:22...
Connection established.
To escape to local shell, press ‘Ctrl+Alt+]‘.

Last login: Tue Jan 2 19:34:49 2018 from 192.168.183.1
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg1 lvm2 a-- 1020.00m 908.00m
/dev/sdb2 vg1 lvm2 a-- 1020.00m 1020.00m
/dev/sdb3 lvm2 --- 1.00g 1.00g
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 1.99g 1.88g
[[email protected] ~]# vgremove
234/ .bash_logout .ssh/
2.txt .bash_profile .tcshrc
anaconda-ks.cfg.1 .bashrc 新建文本文档_(2).txt
.bash_history .cshrc
[[email protected] ~]# vgremove /dev/
Display all 163 possibilities? (y or n)
[[email protected] ~]# lvcreate -L 150M -n lv2 vg1
Rounding up size to full physical extent 152.00 MiB
Logical volume "lv2" created.
[[email protected] ~]# lvcreate -L 150M -n lv1 vg1
Rounding up size to full physical extent 152.00 MiB
Logical Volume "lv1" already exists in volume group "vg1"
[[email protected] ~]# mkfs.ext4 /dev/cg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
无法对 /dev/cg1/lv1 进行 stat 调用 --- 没有那个文件或目录

The device apparently does not exist; did you specify it correctly?
[[email protected] ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
28672 inodes, 114688 blocks
5734 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
14 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mount /dev/vg1/lv1
mount: 在 /etc/fstab 中找不到 /dev/vg1/lv1
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# mount /dev/vg1/lv1 /mnt/
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
/dev/mapper/vg1-lv1 105M 1.6M 96M 2% /mnt
[[email protected] ~]# ls -l /dev/vg1/lv1
lrwxrwxrwx 1 root root 7 1月 2 22:20 /dev/vg1/lv1 -> ../dm-0
[[email protected] ~]# ls -l /dev/mapper//vg1-lv1
lrwxrwxrwx 1 root root 7 1月 2 22:20 /dev/mapper//vg1-lv1 -> ../dm-0
[[email protected] ~]# mkdir /mnt/1212
[[email protected] ~]# touch /mnt/23.txt
[[email protected] ~]# echo "1111111111111" > /mnt/23.txt
[[email protected] ~]# lvcreate -L 150M -n lv1 vg1
Rounding up size to full physical extent 152.00 MiB
Logical Volume "lv1" already exists in volume group "vg1"
[[email protected] ~]# umount /mnt/
[[email protected] ~]# lvcreate -L 300M -n lv1 vg1
Logical Volume "lv1" already exists in volume group "vg1"
[[email protected] ~]# lvcreate -L 300M /dev/vg1/lv1
Volume group name expected (no slash)
Run `lvcreate --help‘ for more information.
[[email protected] ~]# lvresize -L 300M /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 112.00 MiB (28 extents) to 300.00 MiB (75 extents).
Logical volume vg1/lv1 successfully resized.
[[email protected] ~]# !e2fsck
-bash: !e2fsck: event not found
[[email protected] ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/28672 files (7.7% non-contiguous), 9273/114688 blocks
[[email protected] ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 307200 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 307200 blocks long.

[[email protected] ~]# !mount
mount /dev/vg1/lv1 /mnt/

[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
/dev/mapper/vg1-lv1 287M 2.0M 266M 1% /mnt

[[email protected] ~]# umount /mnt/
[[email protected] ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/77824 files (7.7% non-contiguous), 15981/307200 blocks
[[email protected] ~]# resize2fs /dev/vg1/lv1 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 102400 blocks long.

[[email protected] ~]# lvresize -L 100M /dev/vg1/lv1
WARNING: Reducing active logical volume to 100.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: Y
Size of logical volume vg1/lv1 changed from 300.00 MiB (75 extents) to 100.00 MiB (25 extents).
Logical volume vg1/lv1 successfully resized.

[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 100.00m
[[email protected] ~]# ls -l /dev/vg1/lv1
lrwxrwxrwx 1 root root 7 1月 2 22:33 /dev/vg1/lv1 -> ../dm-0
[[email protected] ~]# ls /dev/vg1/lv1
/dev/vg1/lv1
[[email protected] ~]# ls /mnt/
1212
[[email protected] ~]# umount /mnt/
umount: /mnt/:未挂载
[[email protected] ~]# mkfs.xfs -f /dev/vg1/lv1
meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# !mount
mount /dev/vg1/lv1 /mnt/
[[email protected] ~]# ls /mnt/
[[email protected] ~]# touch /mnt/233.txt
[[email protected] ~]# echo "12121212121" > !$
echo "12121212121" > /mnt/233.txt
[[email protected] ~]# cat !$
cat /mnt/233.txt
12121212121
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 100.00m

[[email protected] ~]# lvresize -L 300M /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).
Logical volume vg1/lv1 successfully resized.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 300.00m

[[email protected] ~]# xfs_growfs -L 300M /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
xfs_growfs: XFS_IOC_FSGROWFSLOG xfsctl failed: 无效的参数
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
/dev/mapper/vg1-lv1 97M 5.2M 92M 6% /mnt
[[email protected] ~]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 76800
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.1G 37G 3% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
/dev/mapper/vg1-lv1 297M 5.5M 292M 2% /mnt
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 2 0 wz--n- 1.99g 1.55g
[[email protected] ~]# fdisk -l /dev/sdb

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 2 0 wz--n- 1.99g 1.55g
[[email protected] ~]# vgextend vg1 /dev/sdb3
Volume group "vg1" successfully extended
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 3 2 0 wz--n- <2.99g <2.55g

 

 

 

硬盘配置故障

[[email protected] ~]# /etc/fstab

以上是关于四周第一次课(1月2日) 4.10/lvm讲解 4.11/lvm讲解 4.12/lvm讲解 4.13 磁盘故障小案例的主要内容,如果未能解决你的问题,请参考以下文章

四周第1次课(2月26日)

四周第一次课(1月2日)

Linux学习笔记第四周第一次课(2月26日)

Linux学习笔记第四周第一次课(2月26日)

Linux20180416四周第一次课(4月11日)

Linux20180416四周第一次课(4月11日)