Linux LVM Create, delete, Extend __linux

Source: Internet
Author: User
Tags extend
redhat6.2 on the LVM.
1
First, add a hard drive to RH on the virtual machine.
2
Start RH
3
Enter on the terminal
[beigang@localhost~] $fdisk-L
disk/dev/sdc:1073 MB, 1073741824 bytes
......
DISK/DEV/SDC doesn ' t contain a valid partition table
4
Partition 1
[beigang@localhost~] $fdisk/DEV/SDC
Command (M for help): N
Command Action
E Extended
P primary partition (1-4)
P
Partition number (1-4): 1
The cylinder (1-130, default 1):
Using Default value 1
Last cylinder, +cylinders or +size{k,m,g} (1-130, default 130): +100m

Command (M for help): W
The partition table has been altered!

Calling IOCTL () to re-read partition table.
Syncing disks.
[beigang@localhost~]$

5
View
[beigang@localhost~] $fdisk-L
Device Boot Start End Blocks Id System
/DEV/SDC1 1 112423+ Linux

6
Partition 2
[beigang@localhost~] $fdisk/DEV/SDC
N
P
2
15
+100m
W

7
View
[beigang@localhost~] $fdisk-L
Device Boot Start End Blocks Id System
/DEV/SDC1 1 112423+ Linux
/DEV/SDC2 112455 MB Linux

8
Add Physical volume
[beigang@localhost~] $pvcreate/DEV/SDC1
Writing physical volume data to disk "/DEV/SDC1"
Physical volume "/DEV/SDC1" successfully created
[beigang@localhost~] $pvcreate/DEV/SDC2
Writing physical volume data to disk "/DEV/SDC2"
Physical volume "/DEV/SDC2" successfully created
[beigang@localhost~]$

9
View PV
[beigang@localhost~] $pvs
PV VG Fmt Attr psize pfree
/DEV/SDC1 lvm2 a--109.79m 109.79m
/DEV/SDC2 lvm2 a--109.82m 109.82m
[beigang@localhost~]$

10
Create a volume group
[beigang@localhost~] $vgcreate VG1/DEV/SDC1/DEV/SDC2
Volume Group "VG1" successfully created
[beigang@localhost~]$

11
View Volume Group
[beigang@localhost~] $vgs
VG #PV #LV #SN Attr vsize vfree
VG1 2 0 0 wz--n-216.00m 216.00m
[beigang@localhost~]$

12
Create Logical Volume 1
[beigang@localhost~] $lvcreate-n lv1-l +50m VG1
Rounding up size to full physical extent 52.00 MiB
Logical volume "Lv1" created
[beigang@localhost~]$

13
Create Logical Volume 2 because it is an integer multiple of PE (4M), so there is no increase
[beigang@localhost~] $lvcreate-n lv2-l +60m VG1
Logical volume "Lv2" created
[beigang@localhost~]$

14
viewing logical volumes
[beigang@localhost~] $lvs
LV VG Attr lsize Origin snap% move Log copy% Convert
LV1 vg1-wi-a-52.00m
Lv2 vg1-wi-a-60.00m
[beigang@localhost~]$

15
Format Lv1 The Times could not find the file,
[beigang@localhost~] $mkfs. ext3/dev/vg1/lv1

16
Mount Lv1
[beigang@localhost~] $mount/dev/vg1/lv1/seconddisk/

17
To generate a file on a folder Seconddisk
[beigang@localhost~] $touch/seconddisk/{1..9}.txt
[beigang@localhost~] $ll/seconddisk/
Total 23
-rw-r--r--. 1 Root 0 Nov 8 14:06 1.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 2.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 3.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 4.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 5.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 6.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 7.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 8.txt
-rw-r--r--. 1 Root 0 Nov 8 14:06 9.txt
DRWX------. 2 root 12288 Nov 8 13:51 Lost+found
[beigang@localhost~]$

18
Delete/dev/vg1/lv1,/dev/vg1/lv2
[beigang@localhost~] $lvremove/DEV/VG1/LV1
Can ' t remove open Logical Volume "LV1"
[beigang@localhost~] $umount/seconddisk/
[beigang@localhost~] $lvremove/DEV/VG1/LV1
Do your really want to remove active logical volume LV1? [y/n]: Y
Logical volume "LV1" successfully removed
[beigang@localhost~]$
[beigang@localhost~] $lvremove/dev/vg1/lv2
Do your really want to remove active logical volume LV2? [y/n]: Y
Logical volume "Lv2" successfully removed

19
Delete/DEV/VG1
[beigang@localhost~] $vgremove/DEV/VG1
Volume Group "VG1" successfully removed
[beigang@localhost~]$

20
Delete Physical Volume
[beigang@localhost~] $pvremove/DEV/SDC3
Labels on physical volume "/DEV/SDC3" successfully wiped
[beigang@localhost~] $pvremove/DEV/SDC2
Labels on physical volume "/DEV/SDC2" successfully wiped
[beigang@localhost~] $pvremove/DEV/SDC1
Labels on physical volume "/DEV/SDC1" successfully wiped
[beigang@localhost~]$


It is worth saying that in the LVM, the file type does not have to be 8e,83, see the following ID.
[beigang@localhost~] $fdisk-L
Device Boot Start End Blocks Id System
/DEV/SDC1 1 112423+ Linux
/DEV/SDC2 112455 MB Linux


===================
===================
===================
The following is done on the basis of the completion of the 17th step above to Lv2 to do an extension.
1
First, Fdisk, get a/dev/sdc3.
View:
[Beigang@localhost~]$ fdisk-l | Grep/sdb
/DEV/SDC1 1 112423+ Linux
/DEV/SDC2 112455 MB Linux
/DEV/SDC3 112455 Linux

2
Increase PV Failure
[Beigang@localhost~]$ PVCREATE/DEV/SDC3
DEVICE/DEV/SDC3 not found (or ignored by filtering).

3
Load Disc partation:
[beigang@localhost~]$ partx-a/DEV/SDC
Blkpg:device or resource busy
Error adding partition 1
Blkpg:device or resource busy
Error adding partition 2
[beigang@localhost~]$ partx-a/DEV/SDC
Blkpg:device or resource busy
Error adding partition 1
Blkpg:device or resource busy
Error adding partition 2
Blkpg:device or resource busy
Error adding partition 3

4
Add PV:
[Beigang@localhost~]$ PVCREATE/DEV/SDC3
Writing physical volume data to disk "/DEV/SDC3"
Physical volume "/DEV/SDC3" successfully created

5
Extended SDB3 to VG:
[Beigang@localhost~]$ VGEXTEND/DEV/VG1/DEV/SDC3
Volume Group "VG1" successfully extended
[beigang@localhost~]$

6
View VG:
[Beigang@localhost~]$ VGs
VG #PV #LV #SN Attr vsize vfree
VG1 3 1 0 wz--n-324.00m 272.00m
Volgroup 1 2 0 wz--n-19.51g 0

View LV:
[Beigang@localhost~]$ LVs
LV VG Attr lsize Origin snap% move Log copy% Convert
Lv2 vg1-wi-a-52.00m

7
Extended LV
[beigang@localhost~]$ lvextend-l +50m/dev/vg1/lv2
Rounding up size to full physical extent 52.00 MiB
Extending logical Volume Lv2 to 104.00 MiB
Logical Volume Lv2 successfully resized
[beigang@localhost~]$

8
View:
[Beigang@localhost~]$ LVs
LV VG Attr lsize Origin snap% move Log copy% Convert
Lv2 vg1-wi-a-104.00m

9
Mount again to view, Lv2 only 51M, just extended has not really added
[Beigang@localhost~]$ mount/dev/vg1/lv2/mnt
[Beigang@localhost~]$ df-h
FileSystem Size Used Avail use% mounted on
/dev/mapper/vg1-lv2
51M 4.9M 43M 11%/mnt
[beigang@localhost~]$

10
Resize again:
[Beigang@localhost~]$ Resize2fs/dev/vg1/lv2

11
Again DF View:
[Beigang@localhost~]$ df-h
FileSystem Size Used Avail use% mounted on
/dev/mapper/vg2-lv2 101M 5.3M 91M 6%/mnt
[beigang@localhost~]$


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.