Linux LVM Safely remove hard drive or partition tutorial

Source: Internet
Author: User
Tags uuid

LVM logical volumes, which may consist of one or more hard disks or partitions, can safely delete hard drives or partitions in logical volumes. Applicable to the scene, I have two small hard drives, I would like to change one of the small hard drive to large. First of all, the logical volume of small hard disk, safely removed. The following is a detailed procedure for the operation.

1, view the partition situation

[Root@iz94zz3wqciz data]# Df-h
FileSystem Size Used Avail use% mounted on
/DEV/XVDA1 20G 15G 4.6G 76%/
Tmpfs 498M 0 498M 0%/dev/shm
/dev/mapper/myfiles-fastdfs
27G 9.9G 16G 39%/mnt/fastdfs
The 27G here is made up of a 22G hard drive and a 5G hard drive.

2, cancel the mount, the hard drive detection

[Root@iz94zz3wqciz ~]# umount/mnt/fastdfs///Cancel Hang

[Root@iz94zz3wqciz ~]# e2fsck-f/DEV/MAPPER/MYFILES-FASTDFS//disk detection
E2fsck 1.41.12 (17-may-2010)
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/mapper/myfiles-fastdfs:103722/1769472 files (0.1% non-contiguous), 2686136/7072768 blocks

3, to redefine the size of the logical volume

[Root@iz94zz3wqciz ~]# resize2fs-p/dev/mapper/myfiles-fastdfs 21G//Redefine size
RESIZE2FS 1.41.12 (17-may-2010)
Resizing the filesystem On/dev/mapper/myfiles-fastdfs to 5505024 (4k) blocks.
Begin Pass 2 (max = 529848)
Relocating blocks Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin Pass 3 (max = 216)
Scanning Inode Table Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Begin Pass 4 (max = 66693)
Updating inode references Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The filesystem On/dev/mapper/myfiles-fastdfs is now 5505024 blocks long.

[Root@iz94zz3wqciz ~]# lvreduce-l 21g/dev/mapper/myfiles-fastdfs//Redefine size
Warning:reducing active Logical Volume to 21.00 GiB
This May DESTROY YOUR DATA (filesystem etc.)
Do your really want to reduce fastdfs? [y/n]: Y
The Size of logical volume MYFILES/FASTDFS changed from 26.98 GiB (6907 extents) to 21.00 GiB (5376 extents).
Logical Volume Fastdfs successfully resized
From 27G to 21G, greater than the 5G disk to be deleted, even if the 5G plate data is full, you can remove all


4, view the physical volume situation

[Root@iz94zz3wqciz ~]# Pvdisplay-m
---physical volume---
PV NAME/DEV/XVDB1
VG Name Myfiles
PV Size 21.99 gib/not usable 4.78 MiB
Allocatable Yes
PE Size 4.00 MiB
Total PE 5629
Free PE 253
Allocated PE 5376
PV UUID N2kxpi-fjet-rq8p-madf-z3th-fk3l-ow1stl

---physical segments---
Physical extent 0 to 5375:
Logical Volume/dev/myfiles/fastdfs
Logical extents 0 to 5375
Physical extent 5376 to 5628:
Free

---physical volume---
PV NAME/DEV/XVDC1
VG Name Myfiles
PV Size 4.99 gib/not usable 2.41 MiB
allocatable Yes//activation state, writable
PE Size 4.00 MiB
Total PE 1278//All 1278PE
Free PE 1278//idle 1278PE, which means this hard drive is empty
Allocated PE 0
PV UUID 4snw6e-xtha-7lyy-l2k8-uvwv-xxan-wqxf0i

---physical segments---
Physical extent 0 to 1277:
Free

5, log off the hard drive you want to delete XVDC1

 
[Root@iz94zz3wqciz ~]# PVCHANGE-XN/DEV/XVDC1//Logoff XVDC1
Physical volume "/DEV/XVDC1" changed
1 Physical volume changed/0 physical volumes not changed

[Root@iz94zz3wqciz ~]# Pvdisplay-m
---physical volume---
PV NAME/DEV/XVDB1
VG Name Myfiles
PV Size 21.99 gib/not usable 4.78 MiB
Allocatable Yes
PE Size 4.00 MiB
Total PE 5629
Free PE 253
Allocated PE 5376
PV UUID N2kxpi-fjet-rq8p-madf-z3th-fk3l-ow1stl

---physical segments---
Physical extent 0 to 5375:
Logical Volume/dev/myfiles/fastdfs
Logical extents 0 to 5375
Physical extent 5376 to 5628:
Free

---physical volume---
PV NAME/DEV/XVDC1
VG Name Myfiles
PV Size 4.99 gib/not usable 2.41 MiB
Allocatable no//No activation status
PE Size 4.00 MiB
Total PE 1278
Free PE 1278
Allocated PE 0
PV UUID 4snw6e-xtha-7lyy-l2k8-uvwv-xxan-wqxf0i

---physical segments---
Physical extent 0 to 1277:
Free

6, move the data, move the data of the disk you want to delete to another disk

[Root@iz94zz3wqciz ~]# pvmove-i 1/DEV/XVDC1
No data to move for Myfiles
This step, very important, if the plate has data, do not do this step, will cause data loss


7, remove the hard disk or partition from the logical volume group and delete the physical volume

[Root@iz94zz3wqciz ~]# vgreduce MYFILES/DEV/XVDC1//Removed from logical volume group
Removed "/DEV/XVDC1" from volume Group "myfiles"

[Root@iz94zz3wqciz ~]# PVREMOVE/DEV/XVDC1
Labels on physical volume "/DEV/XVDC1" successfully//delete physical volumes


8, Mount and view the results

[Root@iz94zz3wqciz ~]# mount-a 
 
[Root@iz94zz3wqciz ~]# df-h 
FILESYSTEM  &N bsp;         size  Used Avail use% mounted on 
/dev/xvda1              20g   15g  4.6g  76%/ 
tmpfs                 498M      0  498m   0%/dev/shm 
/dev/mapper/myfiles-fastdfs 
                         21g  9.9g  9.8g  51%/mnt/fastdfs 
Here, it's safe to delete a hard drive or partition.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.