[Linux] basic lvm operations

Source: Internet
Author: User

[Linux] basic lvm operations

Two new hard disks are added for the experiment:

[Root @ jp ~] # Fdisk-l

Disk/dev/sda: 107.3 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sda1*1 255 2048256 83 Linux

/Dev/sda2 256 777 4192965 82 Linux swap/Solaris

/Dev/sda3 778 13054 98615002 + 83 Linux

Disk/dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Disk/dev/sdb doesn' t contain a valid partition table

Disk/dev/sdc: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Disk/dev/sdc doesn' t contain a valid partition table

Divide/dev/sdb into three zones.

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

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

Building a new DOS disklabel. 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)

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 1

First cylinder (1-652, default 1): 1

Last cylinder or + size or + sizeM or + sizeK (1-652, default 652): + 1000 M

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 2

First cylinder (124-652, default 124 ):

Using default value 124

Last cylinder or + size or + sizeM or + sizeK (124-652, default 652): + 2000 M

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 3

First cylinder (368-652, default 368 ):

Using default value 368

Last cylinder or + size or + sizeM or + sizeK (368-652, default 652 ):

Using default value 652

Command (m for help): p

Disk/dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sdb1 1 123 987966 83 Linux

/Dev/sdb2 124 367 1959930 83 Linux

/Dev/sdb3 368 652 2289262 + 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl () to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

/Dev/sdc can be divided into two zones:

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

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

Building a new DOS disklabel. 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)

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 1

First cylinder (1-652, default 1 ):

Using default value 1

Last cylinder or + size or + sizeM or + sizeK (1-652, default 652): + 2000 M

Command (m for help): n

Command action

E extended

P primary partition (1-4)

P

Partition number (1-4): 2

First cylinder (245-652, default 245 ):

Using default value 245

Last cylinder or + size or + sizeM or + sizeK (245-652, default 652 ):

Using default value 652

Command (m for help): p

Disk/dev/sdc: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sdc1 1 244 1959898 + 83 Linux

/Dev/sdc2 245 652 3277260 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

Create PV for all partitions

[Root @ jp ~] # Pvcreate/dev/sdb1

Physical volume "/dev/sdb1" successfully created

[Root @ jp ~] # Pvcreate/dev/sdb2

Physical volume "/dev/sdb2" successfully created

[Root @ jp ~] # Pvcreate/dev/sdb3

Physical volume "/dev/sdb3" successfully created

[Root @ jp ~] # Pvcreate/dev/sdc1

Physical volume "/dev/sdc1" successfully created

[Root @ jp ~] # Pvcreate/dev/sdc2

Physical volume "/dev/sdc2" successfully created

Create a VG and put/dev/sdb1 and/dev/sdc1 In the VG.

[Root @ jp ~] # Vgcreate test1/dev/sdb1/dev/sdc1

/Dev/cdrom: open failed: No medium found

Volume group "test1" successfully created

Add a disk to VG:

[Root @ jp ~] # Vgextend test1/dev/sdb2

Volume group "test1" successfully extended

View VG information:

[Root @ jp ~] # Vgdisplay

--- Volume group ---

VG Name test1

System ID

Format lvm2

Metadata Areas 3

Metadata Sequence No 4

VG Access read/write

VG Status resizable

Max lv 0

Cur LV 1

Open LV 1

Max PV 0

Cur PV 3

Act PV 3

VG Size 4.68 GB

PE Size 4.00 MB

Total PE 1197

Alloc PE/Size 300/1 .17 GB

Free PE/Size 897/3 .50 GB

Vg uuid 0ux9KE-yHJP-07Y0-9yCd-ppG2-wWe0-78nLbh

Create an LV and extract m from VG: test1 to the LV: lv_test1.

[Root @ jp ~] # Lvcreate-L 1000 M-n lv_test1 test1

Logical volume "lv_test1" created

Format the LV. The LV can only store data after formatting.

[Root @ jp ~] # Mke2fs-j/dev/test1/lv_test1

Mke2fs 1.39 (29-may-2006)

Filesystem label =

OS type: Linux

Block size = 4096 (log = 2)

Fragment size = 4096 (log = 2)

128000 inodes, 256000 blocks

12800 blocks (5.00%) reserved for the super user

First data block = 0

Maximum filesystem blocks = 264241152

8 block groups

32768 blocks per group, 32768 fragments per group

16000 inodes per group

Superblock backups stored on blocks:

32768,983 04, 163840,229 376

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or

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

Mount LV:

[Root @ jp ~] # Mkdir/test

[Root @ jp ~] # Mount/dev/test1/lv_test1/test

[Root @ jp ~] # Df-h

Filesystem Size Used Avail Use % Mounted on

/Dev/sda3 92G 20 GB 67G 23%/

/Dev/sda1 1.9G 42 M 1.8G 3%/boot

Tmpfs 1014 M 0 1014 M 0%/dev/shm

/Dev/mapper/test1-lv_test1

985 MB 18 M 918 M 2%/test

After mounting, the LV capacity can be reached.

If you want to start LV at system startup, it is best to write LV01 into the fstable file.

Adjust the LV size

[Root @ jp ~] # Lvresize-L + 200 M/dev/test1/lv_test1

Extending logical volume lv_test1 to 1.17 GB

Logical volume lv_test1 successfully resized

[Root @ jp ~] # Resize2fs/dev/test1/lv_test1

Resize2fs 1.39 (29-May-2006)

Filesystem at/dev/test1/lv_test1 is mounted on/test; on-line resizing required

Ming an on-line resize of/dev/test1/lv_test1 to 307200 (4 k) blocks.

The filesystem on/dev/test1/lv_test1 is now 307200 blocks long.

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.