Reese Knowledgebase

Create a Logical Volume using Linux LVM

View Kristian Reese's profile on LinkedIn


If you like this article, please +1 or Recommend via FB with the provided buttons above:

Article ID: 137
by: Reese K.
Posted: 16 Oct, 2013
Last updated: 21 Oct, 2013
Views: 1296

Create a Logical Volume using Linux LVM

This example uses a local hard disk to create a logical volume.

1. partition the disk as normal using fdisk.  I new the fdisk options ahead of time from having done this before.

EDS etldev1 ~ # FDISK_CMDLIST="n\np\n1\n\nt\n8e\nw\n"
EDS etldev1 ~ # echo -e -n "${FDISK_CMDLIST}" | ( fdisk /dev/sdc )

This is the same thing as doing it from the fdisk menu as follows:

EDS etldev1 ~ # fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         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-17769, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-17769, default 17769):
Using default value 17769

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

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

2. Initialize the partition for use by LVM using pvcreate.

3. Create a volume group using the block device specified in pvcreate

4. Create a logical volume in the volume group from step 3

Steps 2, 3, 4 are illustrated below

EDS etldev1 ~ # pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

EDS etldev1 ~ # vgcreate vg_dwstore /dev/sdc1
  Volume group "vg_dwstore" successfully created

EDS etldev1 ~ # vgs
  VG              #PV #LV #SN Attr   VSize   VFree  
  vg_dwstore        1   0   0 wz--n- 136.11g 136.11g
  vg_etldev1        1   8   0 wz--n- 135.62g 124.00m
  vg_etldev1_data   1   1   0 wz--n- 136.12g      0

EDS etldev1 ~ # lvcreate -L 136.11g -n lv_dwstore vg_dwstore
  Rounding up size to full physical extent 136.11 GiB
  Logical volume "lv_dwstore" created

EDS etldev1 ~ # mkfs.ext4 /dev/vg_dwstore/lv_dwstore
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
8921088 inodes, 35681280 blocks
1784064 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1089 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
EDS etldev1 ~ #
EDS etldev1 ~ # mkdir /dwstore
EDS etldev1 ~ # mount /dev/vg_dwstore/lv_dwstore /dwstore
EDS etldev1 ~ # df -Ph /dwstore
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dwstore-lv_dwstore  134G  188M  127G   1% /dwstore
EDS etldev1 ~ #

This article was:   Helpful | Not Helpful
Also listed in
folder UNIX -> Linux

Prev   Next
Linux     Couldn't find device with uuid

RSS