linux lv 去除镜像,Linux LVM系列(二)lv缩容

声明:xfs文件系统不支持lv缩容,这里是ext4文件系统

首先看下现在的文件系统挂载和使用情况

[root@aiker01 ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/cl-root xfs 8.6G 5.3G 3.4G 62% /

devtmpfs devtmpfs 2.4G 0 2.4G 0% /dev

tmpfs tmpfs 2.4G 0 2.4G 0% /dev/shm

tmpfs tmpfs 2.4G 8.7M 2.4G 1% /run

tmpfs tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup

/dev/mapper/cl-home xfs 4.0G 33M 4.0G 1% /home

/dev/mapper/cl-var xfs 3.0G 159M 2.8G 6% /var

/dev/sda2 xfs 497M 132M 366M 27% /boot

/dev/mapper/vg1-lv1 ext4 5.9G 16M 5.6G 1% /mnt

tmpfs tmpfs 479M 0 479M 0% /run/user/0

/dev/mapper/vg2-lv2 ext4 3.9G 16M 3.7G 1% /data

[root@aiker01 ~]# ll /mnt/

total 36

-rw-r--r-- 1 root root 9 Dec 7 02:26 1.txt

-rw-r--r-- 1 root root 9 Dec 7 02:26 2.txt

drwxr-xr-x 2 root root 4096 Dec 7 02:34 6

drwxr-xr-x 2 root root 4096 Dec 7 02:34 7

drwxr-xr-x 2 root root 4096 Dec 7 02:34 8

drwx------ 2 root root 16384 Dec 6 03:02 lost+found

[root@aiker01 ~]# cat /mnt/1.txt

12345678

卸载掉lv1卷

[root@aiker01 ~]# umount /mnt/

设置lv卷大小

下面的做法经过试验是会报错的:

[root@aiker01 ~]# lvresize -L 2G /dev/vg1/lv1

WARNING: Reducing active logical volume to 2.00 GiB.

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce vg1/lv1? [y/n]:

WARNING: Invalid input ''.

Do you really want to reduce vg1/lv1? [y/n]: y

Size of logical volume vg1/lv1 changed from <5.99 GiB (1533 extents) to 2.00 GiB (512 extents).

Logical volume vg1/lv1 successfully resized.

[root@aiker01 ~]# e2fsck -f !$

e2fsck -f /dev/vg1/lv1

e2fsck 1.42.9 (28-Dec-2013)

The filesystem size (according to the superblock) is 1569792 blocks

The physical size of the device is 524288 blocks

Either the superblock or the partition table is likely to be corrupt!

Abort? y

[root@aiker01 ~]# e2fsck -f /dev/vg1/lv1

e2fsck 1.42.9 (28-Dec-2013)

The filesystem size (according to the superblock) is 1569792 blocks

The physical size of the device is 524288 blocks

Either the superblock or the partition table is likely to be corrupt!

Abort? yes

正确的做法

刚才的错误可以修正回之前的大小:

[root@aiker01 ~]# lvresize -l 1533 /dev/vg1/lv1

Size of logical volume vg1/lv1 changed from <2.00 GiB (511 extents) to <5.99 GiB (1533 extents).

Logical volume vg1/lv1 successfully resized.

[root@aiker01 ~]# resize2fs /dev/vg1/lv1 5.99G

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Invalid new size: 5.99G

[root@aiker01 ~]# e2fsck -f /dev/vg1/lv1

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/vg1/lv1: 16/392448 files (0.0% non-contiguous), 45115/1569792 blocks

[root@aiker01 ~]# resize2fs /dev/vg1/lv1 4G

resize2fs 1.42.9 (28-Dec-2013)

Resizing the filesystem on /dev/vg1/lv1 to 1048576 (4k) blocks.

The filesystem on /dev/vg1/lv1 is now 1048576 blocks long.

[root@aiker01 ~]# lvresize -L 4G /dev/vg1/lv1 #设置lv大小为4G

WARNING: Reducing active logical volume to 4.00 GiB.

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 <5.99 GiB (1533 extents) to 4.00 GiB (1024 extents).

Logical volume vg1/lv1 successfully resized.

[root@aiker01 ~]# !e2 #检查是lv有错误

e2fsck -f /dev/vg1/lv1

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/vg1/lv1: 16/261632 files (0.0% non-contiguous), 36907/1048576 blocks

[root@aiker01 ~]# lvdisplay /dev/vg1/lv1

--- Logical volume ---

LV Path /dev/vg1/lv1

LV Name lv1

VG Name vg1

LV UUID q6dAzJ-1dbC-2EoY-Fzcp-QqEE-enuU-FS5BLT

LV Write Access read/write

LV Creation host, time aiker01, 2017-12-06 03:02:40 +0800

LV Status available

# open 0

LV Size 4.00 GiB

Current LE 1024

Segments 3

Allocation inherit

Read ahead sectors auto

- currently set to 8192

Block device 253:4

[root@aiker01 ~]# vgdisplay /dev/vg1

--- Volume group ---

VG Name vg1

System ID

Format lvm2

Metadata Areas 3

Metadata Sequence No 23

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 1

Open LV 0

Max PV 0

Cur PV 3

Act PV 3

VG Size <5.99 GiB

PE Size 4.00 MiB

Total PE 1533

Alloc PE / Size 1024 / 4.00 GiB

Free PE / Size 509 / <1.99 GiB

VG UUID dx3XD9-rQBV-QtBu-EebN-wgjI-CQcn-36iIbm

[root@aiker01 ~]# mount /dev/vg1/lv1 /mnt/

[root@aiker01 ~]# ll /mnt/

total 36

-rw-r--r-- 1 root root 9 Dec 7 02:26 1.txt

-rw-r--r-- 1 root root 9 Dec 7 02:26 2.txt

drwxr-xr-x 2 root root 4096 Dec 7 02:34 6

drwxr-xr-x 2 root root 4096 Dec 7 02:34 7

drwxr-xr-x 2 root root 4096 Dec 7 02:34 8

drwx------ 2 root root 16384 Dec 6 03:02 lost+found

[root@aiker01 ~]# cat /mnt/1.txt

12345678

[root@aiker01 ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/cl-root xfs 8.6G 5.3G 3.4G 62% /

devtmpfs devtmpfs 2.4G 0 2.4G 0% /dev

tmpfs tmpfs 2.4G 0 2.4G 0% /dev/shm

tmpfs tmpfs 2.4G 8.7M 2.4G 1% /run

tmpfs tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup

/dev/mapper/cl-home xfs 4.0G 33M 4.0G 1% /home

/dev/mapper/cl-var xfs 3.0G 159M 2.8G 6% /var

/dev/sda2 xfs 497M 132M 366M 27% /boot

tmpfs tmpfs 479M 0 479M 0% /run/user/0

/dev/mapper/vg2-lv2 ext4 3.9G 16M 3.7G 1% /data

/dev/mapper/vg1-lv1 ext4 3.9G 16M 3.7G 1% /mnt

可以清楚的查看后lv1缩容后的大小,里面的文件并没有损坏。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值