您的位置:首页 > 运维架构 > Linux

16. lvm 磁盘故障小案例

2018-01-03 09:57 162 查看
4.10 lvm

1.准备磁盘分区:

fdisk /dev/sdb

n 创建三个新分区,分别1G

t 改变分区类型为8e

2.准备物理卷

pvcreate /dev/sdb1

pvcreate /dev/sdb2

pvcreate /dev/sdb3

pvdisplay/pvs 列出当前的物理卷

pvremove /dev/sdb3 删除物理卷

yum provides "/*/pvcreate"

yum -y install lvm2

partprobe - inform the OS of partition table changes

partprobe is a program that informs the operating system kernel

of partition table changes, by requesting that

the operating system re-read the partition table.

# partprobe

pvcreate - Initialize physical volume(s) for use by LVM

# pvcreate /dev/sdb1

WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y

Wiping xfs signature on /dev/sdb1.

Physical volume "/dev/sdb1" successfully created.

pvdisplay - Display various attributes of physical volume(s)

# 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 0TaR4c-d2Z7-3Der-Y5aO-w0dd-ndri-NOsc81

pvs - Display information about physical volumes

# 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

vgcreate - Create a volume group

# vgcreate vg1 /dev/sdb1 /dev/sdb2

Volume group "vg1" successfully created

vgdisplay - Display volume group information

# vgdisplay

--- Volume group ---

VG Name vg1

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 1.99 GiB

PE Size 4.00 MiB

Total PE 510

Alloc PE / Size 0 / 0

Free PE / Size 510 / 1.99 GiB

VG UUID AQQcU6-xIfd-jOQZ-cDLK-BQ9E-HIgi-xptazX

vgs - Display information about volume groups

# vgs

VG #PV #LV #SN Attr VSize VFree

vg1 2 0 0 wz--n- 1.99g 1.99g

lvcreate - Create a logical volume

# lvcreate -L 100M -n lv1 vg1

Logical volume "lv1" created.

# mkfs.ext4 /dev/vg1/lv1

# mount /dev/vg1/lv1 /mnt/

# df -h

文件系统 容量 已用 可用 已用% 挂载点

/dev/sda3 18G 1.2G 17G 7% /

devtmpfs 483M 0 483M 0% /dev

tmpfs 493M 0 493M 0% /dev/shm

tmpfs 493M 6.9M 486M 2% /run

tmpfs 493M 0 493M 0% /sys/fs/cgroup

/dev/sda1 197M 97M 100M 50% /boot

tmpfs 99M 0 99M 0% /run/user/0

/dev/mapper/vg1-lv1 93M 1.6M 85M 2% /mnt

# ll /dev/mapper/vg1-lv1

lrwxrwxrwx. 1 root root 7 1月 3 10:02 /dev/mapper/vg1-lv1 -> ../dm-0

# ll /dev/vg1/lv1

lrwxrwxrwx. 1 root root 7 1月 3 10:02 /dev/vg1/lv1 -> ../dm-0

# mkdir /mnt/test

# touch /mnt/test/123.txt

# echo "123" > /mnt/test/123.txt

lvresize - Resize a logical volume

# 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.

e2fsck - check a Linux ext2/ext3/ext4 file system

-f Force checking even if the file system seems clean.

# 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), 8899/102400 blocks

resize2fs - ext2/ext3/ext4 file system resizer

# 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.

# mount /dev/vg1/lv1 /mnt/

# df -h

文件系统 容量 已用 可用 已用% 挂载点

/dev/sda3 18G 1.2G 17G 7% /

devtmpfs 483M 0 483M 0% /dev

tmpfs 493M 0 493M 0% /dev/shm

tmpfs 493M 6.9M 486M 2% /run

tmpfs 493M 0 493M 0% /sys/fs/cgroup

/dev/sda1 197M 97M 100M 50% /boot

tmpfs 99M 0 99M 0% /run/user/0

/dev/mapper/vg1-lv1 190M 1.6M 175M 1% /mnt

# umount /mnt/

# e2fsck -f /dev/vg1/lv1

# 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.

# 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.

# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

lv1 vg1 -wi-a----- 100.00m

# mount /dev/vg1/lv1 /mnt/

xfs扩容

# umount /mnt/

# mkfs.xfs -f /dev/vg1/lv1

# mount /dev/vg1/lv1 /mnt/

# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

lv1 vg1 -wi-ao---- 100.00m

# 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.

# df -h /dev/vg1/lv1

文件系统 容量 已用 可用 已用% 挂载点

/dev/mapper/vg1-lv1 97M 5.2M 92M 6% /mnt

# 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

# df -h /mnt

文件系统 容量 已用 可用 已用% 挂载点

/dev/mapper/vg1-lv1 297M 5.5M 292M 2% /mnt

vgextend - Add physical volumes to a volume group

# vgextend vg1 /dev/sdb3

Volume group "vg1" successfully extended

vgs

VG #PV #LV #SN Attr VSize VFree

vg1 3 1 0 wz--n- <2.99g <2.70g

# lvresize -L 500M /dev/vg1/lv1

Size of logical volume vg1/lv1 changed from 300.00 MiB (75 extents) to 500.00 MiB (125 extents).

Logical volume vg1/lv1 successfully resized.

# xfs_growfs /dev/vg1/lv1

meta-data=/dev/mapper/vg1-lv1 isize=512 agcount=12, agsize=6400 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0 spinodes=0

data = bsize=4096 blocks=76800, 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 76800 to 128000

# df -hT /mnt/

文件系统 类型 容量 已用 可用 已用% 挂载点

/dev/mapper/vg1-lv1 xfs 497M 5.7M 491M 2% /mnt

4.13 磁盘故障小案例

vim /etc/fstab
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux