Add and expand logical volumes in the LVM of CentOS

Source: Internet
Author: User
Tags hex code

1. View Hard Disk Partitions

# Fdisk-l

Note: assume that the name of the device that adds a hard disk is/dev/sdb.

2. Start partitioning

# Fdisk/dev/sdb

3. View Command help information

Command (m for help): m

4. view existing partition tables

Command (m for help): p

Disk/dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1*1 60800 488375968 7 HPFS/NTFS

Note: we can see that this hard disk already has a partition and all the cylinders have been allocated.

5. Delete the original Partition

Command (m for help): d

6. view the partition table again

Command (m for help): p

Disk/dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

7. Add a partition

Command (m for help): n

Command action
E extended
P primary partition (1-4)

8. Select the partition type (primary partition, extended partition) and partitions

P

1

9. Set the cylindrical range of the partition. the start and end values are default. Press enter.

10. View partition tables

Command (m for help): p

Disk/dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1 1 60800 488375968 + 83 Linux

11. Change the partition type

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L

NOTE: If multiple partitions exist, a prompt is displayed, prompting you to select partitions.

1 0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris 2 1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT- 3 2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT- 4 3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT- 5 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx 6 5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data 7 6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / . 8 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility 9 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt 10 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access 11 a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O 12 b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor 13 c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs 14 e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT 15 f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/ 16 10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b 17 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor 18 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor 19 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary 20 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot fb VMware VMFS 21 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 22 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 23 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 24 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT

12. Set the disk format to linux LVM.

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

13. view the partition table again

Command (m for help): p

Disk/dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1 1 60800 488375968 + 8e Linux LVM

14. Save and exit fdisk

Command (m for help): w
The partition table has been altered!

Calling ioctl () to re-read partition table.
Syncing disks.

If an error occurs, use the partprobe command to reload the partition table.

15. View Hard Disk Partitions

# Fdisk-l

Disk/dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1 1 60800 488375968 + 8e Linux LVM

16. view existing physical volumes in the system

# Pvdisplay

--- Physical volume ---
PV Name/dev/sda2
VG Name VolGroup00
PV Size 297.99 GB/not usable 20.87 MB
Allocatable yes (but full)
PE Size (Kbytes) 32768
Total PE 9535
Free PE 0
Allocated PE 9535.
Pvuuid oa2rNU-Tz2c-N1W0-AKcV-9UnE-ctdp-38dFQd

17. Create a physical volume

# Pvcreate/dev/sdb1

Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created

18. Add a new physical volume to the volume group

# Vgextend VolGroup00/dev/sdb1

Volume group "VolGroup00" successfully extended

19. Add the new space to the original logical volume.

# Lvextend-L + 500G/dev/VolGroup00/LogVol00

20. Activate the resized LVM Partition

# Resize2fs-p/dev/VolGroup00/LogVol00

21. You can add a logical volume if you do not need to resize it.

# Lvcreate-L 200G-n lvol0 VolGroup00

Logical volume "lvol0" created

22. delete a logical volume

# Lvremove/dev/mapper/VolGroup00-lvol0

23. view existing logical volumes

# Lvdisplay
--- Logical volume ---
LV Name/dev/VolGroup00/LogVol00
VG Name VolGroup00
Lvuuid ipf0Gk-3xXU-vN0I-cXbm-ZKLD-XUju-mDe02Z
LV Write Access read/write
LV Status available
# Open 1
LV Size 48.81 GB
Current LE 1562
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 0

--- Logical volume ---
LV Name/dev/VolGroup00/LogVol02
VG Name VolGroup00
Lvuuid RybA0Q-5B8T-bOwA-SsPK-Prai-qsix-kCeWWI
LV Write Access read/write
LV Status available
# Open 1
LV Size 49.91 GB
Current LE 1597
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Blocks device 253: 1

--- Logical volume ---
LV Name/dev/VolGroup00/LogVol03
VG Name VolGroup00
Lvuuid czznK0-VsUK-VAtj-Vbam-PDJS-1yZt-A6BPgK
LV Write Access read/write
LV Status available
# Open 1
LV Size 195.31 GB
Current LE 6250
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 2

--- Logical volume ---
LV Name/dev/VolGroup00/LogVol01
VG Name VolGroup00
Lvuuid zvLpEL-Dj8Y-a0XG-4H7q-ZPaa-XUXY-0ln7qw
LV Write Access read/write
LV Status available
# Open 1
LV Size 3.94 GB
Current LE 126
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 3

24. added the logical volume

# Lvcreate-L 500G-n LogVol04 VolGroup00

25. Format and add a logical volume

# Mkfs. ext3/dev/mapper/VolGroup00-LogVol04

26. mount a logical volume

# Mount/dev/mapper/VolGroup00-LogVol04/data

27. edit/etc/fstab and set the new logical volume to boot and mount. Add the following line.

/Dev/VolGroup00/LogVol04/data ext3 defaults 1 2

28. Test mounting

Mount-

29. View and delete physical volumes

View mounting information

# Df-h
/Dev/mapper/VolGroup00-LogVol04
296G 245 M 281G 1%/backup

Uninstall

# Umount/backup

Delete logical volume

# Lvremove/dev/mapper/VolGroup00-LogVol04

View physical volumes

# Pvdisplay
--- Physical volume ---
PV Name/dev/sda2
VG Name VolGroup00
PV Size 297.99 GB/not usable 20.87 MB
Allocatable yes (but full)
PE Size (Kbytes) 32768
Total PE 9535
Free PE 0
Allocated PE 9535.
Pvuuid oa2rNU-Tz2c-N1W0-AKcV-9UnE-ctdp-38dFQd

--- Physical volume ---
PV Name/dev/sdb1
VG Name VolGroup00
PV Size 465.75 GB/not usable 1.66 MB
Allocatable yes
PE Size (Kbytes) 32768
Total PE 14904
Free PE 5304
Allocated PE 9600.
Pvuuid avEKz2-t5Ko-jsn0-Pvuh-h8DJ-GV0o-ZQfBOL

Remove physical volume from volume group

# Vgreduce VolGroup00/dev/sdb1

Delete physical volume

# Pvremove/dev/sdb1

In this way, you can reformat the disk.


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.