Linux lvm extension tutorial and linuxlvm tutorial

Source: Internet
Author: User

Linux lvm extension tutorial and linuxlvm tutorial

Create a logical volume or expand the logical volume for the new hard disk in linux. The experimental environment is the new two 30 GB hard disks, and these two hard disks are made into logical volumes.

1. view the hard disk ID (sdb and sdc)

Ls/dev/| grep ^ sd

2. partitioning a hard disk

// Partition the hard drive sdb

[Root @ rooo ~] # Fdisk/dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x32b0c715.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)

WARNING: DOS-compatible mode is deprecated. It's stronugly recommended

Switch off the mode (command 'C') and change display units

Sectors (command 'U ').

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 1

First cylinder (1-3916, default 1 ):

Using default value 1

Last cylinder, + cylinders or + size {K, M, G} (1-3916, default 3916 ):

Using default value 3916

Command (m for help): w

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

// Partition the hard disk sdc

[Root @ rooo ~] # Fdisk/dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x32b0c715.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)

WARNING: DOS-compatible mode is deprecated. It's stronugly recommended

Switch off the mode (command 'C') and change display units

Sectors (command 'U ').

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 1

First cylinder (1-3916, default 1 ):

Using default value 1

Last cylinder, + cylinders or + size {K, M, G} (1-3916, default 3916 ):

Using default value 3916

Command (m for help): w

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks. · 1

3. Create a pv physical volume

[Root @ rooo ~] # Pvcreate/dev/sdb1/dev/sdc1

Physical volume "/dev/sdb1" successfully created

Physical volume "/dev/sdc1" successfully create

4. Create a vg volume group

[Root @ rooo ~] # Vgcreate testvg/dev/sdb1/dev/sdc1 // testvg is the name of the volume group. The total size is 60 GB.

Volume group "testvg" successfully created

// View the capacity of testvg:

[Root @ rooo ~] # Vgscan

VG # PV # LV # SN Attr VSize VFree

Testvg 3 1 0 wz-n-59.98g 0

Vg_rooo 1 3 0 wz -- n-79.51g 0

5. Create a logical volume

[Root @ rooo ~] # Lvcreate-L 59G-n testlv testvg

Logical volume "testlv" created

// Testlv indicates the logical volume name,-L indicates the logical volume size (the logical volume size cannot be greater than the volume group), and-n defines the logical volume name.

# View the lv capacity

[Root @ rooo ~] # Lvs

Lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert

Testlv testvg-wi-ao ---- 59.00g

Lv_home vg_rooo-wi-ao ---- 27.57g

Lv_root vg_rooo-wi-ao ---- 50.00g

Lv_swap vg_rooo-wi-ao ---- 1.94g

6. format the logical volume

[Root @ rooo ~] # Mkfs. ext4/dev/testvg/testlv

Mke2fs 1.41.12 (17-May-2010)

Filesystem label =

OS type: Linux

Block size = 4096 (log = 2)

Fragment size = 4096 (log = 2)

Stride = 0 blocks, Stripe width = 0 blocks

3866624 inodes, 15466496 blocks

773324 blocks (5.00%) reserved for the super user

First data block = 0

Maximum filesystem blocks = 4294967296

472 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632, 2654208,

4096000,796 11239424

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or

180 days, whichever comes first. Use tune2fs-c or-I to override.

7. Mount logical volumes

Mkdir/data

Mount/dev/testvg/testlv

8. Set automatic mounting upon startup

Vi/etc/fstab

/Dev/testvg/testlv/data ext4 defaults 0 0 // Add at the end of the file

[Root @ rooo ~] # Df-hT

Filesystem Type Size Used Avail Use % Mounted on

/Dev/mapper/vg_rooo-lv_root ext4 50G 7.4G 40G 16%/

Tmpfs 491 M 76 K 491 M 1%/dev/shm

/Dev/sda1 ext4 485 M 35 M 426 M 8%/boot

/Dev/mapper/vg_rooo-lv_home ext4 28G 172 M 26G 1%/home

/Dev/sr0 iso9660 4.2G 4.2G 0 100%/media/cdrom

/Dev/mapper/testvg-testlv ext4 59G 180 M 55G 1%/data

9. Extend the logical volume

(1) first, check whether there is any available space in testvg. If there is still space in the volume group, run the following command to expand it. If there is no space, add a new hard disk, execute the command by (2 ).

View the capacity of testvg: [root @ rooo ~] # Vgscan

VG # PV # LV # SN Attr VSize VFree

Testvg 3 1 0 wz -- n-79.98g 0 (no available space)

Vg_rooo 1 3 0 wz -- n-79.51g 0

[Root @ rooo ~] # Lvextend-L 20G/dev/testvg/testlv

(2) Add new hard disks for expansion

# New disk partition:

[Root @ rooo ~] # Fdisk/dev/sdd

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x5672831a.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)

WARNING: DOS-compatible mode is deprecated. It's stronugly recommended

Switch off the mode (command 'C') and change display units

Sectors (command 'U ').

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 1

First cylinder (1-2610, default 1 ):

Using default value 1

Last cylinder, + cylinders or + size {K, M, G} (1-2610, default 2610 ):

Using default value 2610

Command (m for help): w

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

# Create a physical volume for the Newly Added Disk

[Root @ rooo ~] # Pvcreate/dev/sdd1

Physical volume "/dev/sdd1" successfully created

# Extend the newly created physical volume to the volume group

[Root @ rooo ~] # Vgextend testvg/dev/sdd1

Volume group "testvg" successfully extended

# View the usage of testvg

[Root @ rooo ~] # Vgscan

VG # PV # LV # SN Attr VSize VFree

Testvg 3 1 0 wz-n-79.98g 20.98g

Vg_rooo 1 3 0 wz -- n-79.51g 0

# Add 10 Gb to the testlv logical volume

[Root @ rooo ~] # Lvextend-L + 10G/dev/testvg/testlv

Extending logical volume testlv to 69.00 GiB

Logical volume testlv successfully resized

# View the lv capacity

[Root @ rooo ~] # Lvs

Lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert

Testlv testvg-wi-ao ---- 69.00g

Lv_home vg_rooo-wi-ao ---- 27.57g

Lv_root vg_rooo-wi-ao ---- 50.00g

Lv_swap vg_rooo-wi-ao ---- 1.94g

# View the remaining capacity of the volume group again:

[Root @ rooo ~] # Vgsan

VG # PV # LV # SN Attr VSize VFree

Testvg 3 1 0 wz -- n-79.98g 10.98g (the remaining 10.98G can be extended to testlv or another lv if necessary)

Vg_rooo 1 3 0 wz -- n-79.51g 0

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.