Quantcast
Channel: Evaggelos Balaskas - System Engineer
Viewing all articles
Browse latest Browse all 333

The investigation of LVM2

$
0
0

This is a rather large post, so you need to have some time to read through it.

I was interested into learning/identifying how data are written on a hard disk using LVM2.
All that begun when i was trying to extract partitions from a corrupted disk with no partition table!

Steps:

  • Create a disk image
  • Create Physical Volume
  • Create Volume Group
  • Create Logical Volume
  • Format Filesystem

using only basic cmds [ du, fdisk, file, hexdump, losetup, strings, truncate ] and LVM2 basic cmds.

to reduce the size of this post, the latest couple hexdumps are located in separate files (12K and 172K) provide them with links.
Plz click on them just to see the output. They are very interesting.

So lets start

A. Create disk image file


# truncate -s 5G file.img

# du file.img 
0	file.img

# du --apparent-size file.img 
5242880	file.img

# qemu-img info file.img
image: file.img
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 0

# losetup /dev/loop1 file.img

# fdisk -l /dev/loop1

Disk /dev/loop1: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

B. Create Physical Volume


# pvcreate /dev/loop1

# pvck -v /dev/loop1
    Scanning /dev/loop1
  Found label on /dev/loop1, sector 1, type=LVM2 001
  Found text metadata area: offset=4096, size=1044480

# pvdisplay
  "/dev/loop1" is a new physical volume of "5,00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/loop1
  VG Name               
  PV Size               5,00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr

# file file.img 
file.img: LVM2 PV (Linux Logical Volume Manager), UUID: Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr, size: 5368709120

# qemu-img info file.img 
image: file.img
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 8.0K

# du -k file.img 
8	file.img

# du --apparent-size file.img 
5242880	file.img

# hexdump -C file.img 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  4c 41 42 45 4c 4f 4e 45  01 00 00 00 00 00 00 00  |LABELONE........|
00000210  58 36 35 f2 20 00 00 00  4c 56 4d 32 20 30 30 31  |X65. ...LVM2 001|
00000220  5a 68 36 37 61 6a 78 41  56 36 77 42 6f 77 71 66  |Zh67ajxAV6wBowqf|
00000230  57 39 32 47 55 35 78 57  45 65 65 48 44 6d 72 72  |W92GU5xWEeeHDmrr|
00000240  00 00 00 40 01 00 00 00  00 00 10 00 00 00 00 00  |...@............|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  00 00 00 00 00 00 00 00  00 10 00 00 00 00 00 00  |................|
00000270  00 f0 0f 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000280  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001000  16 d6 8e db 20 4c 56 4d  32 20 78 5b 35 41 25 72  |.... LVM2 x[5A%r|
00001010  30 4e 2a 3e 01 00 00 00  00 10 00 00 00 00 00 00  |0N*>............|
00001020  00 f0 0f 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00001030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*

# strings -t d file.img 
    512 LABELONE
    536 LVM2 001Zh67ajxAV6wBowqfW92GU5xWEeeHDmrr
   4100  LVM2 x[5A%r0N*>

C. Create Volume Group


# vgcreate volgr01 /dev/loop1
  Volume group "volgr01" successfully created

# vgdisplay
  --- Volume group ---
  VG Name               volgr01
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               5,00 GiB
  PE Size               4,00 MiB
  Total PE              1279
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1279 / 5,00 GiB
  VG UUID               Ub2ISW-x7wd-R8iy-GexG-JGUG-ECI1-kdpBrK

# file file.img
file.img: LVM2 PV (Linux Logical Volume Manager), UUID: Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr, size: 5368709120

# qemu-img info file.img 
image: file.img
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 8.0K

# du -k file.img 
8	file.img

# du --apparent-size file.img 
5242880	file.img

# hexdump -C file.img 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  4c 41 42 45 4c 4f 4e 45  01 00 00 00 00 00 00 00  |LABELONE........|
00000210  58 36 35 f2 20 00 00 00  4c 56 4d 32 20 30 30 31  |X65. ...LVM2 001|
00000220  5a 68 36 37 61 6a 78 41  56 36 77 42 6f 77 71 66  |Zh67ajxAV6wBowqf|
00000230  57 39 32 47 55 35 78 57  45 65 65 48 44 6d 72 72  |W92GU5xWEeeHDmrr|
00000240  00 00 00 40 01 00 00 00  00 00 10 00 00 00 00 00  |...@............|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000260  00 00 00 00 00 00 00 00  00 10 00 00 00 00 00 00  |................|
00000270  00 f0 0f 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000280  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001000  93 f4 58 bc 20 4c 56 4d  32 20 78 5b 35 41 25 72  |..X. LVM2 x[5A%r|
00001010  30 4e 2a 3e 01 00 00 00  00 10 00 00 00 00 00 00  |0N*>............|
00001020  00 f0 0f 00 00 00 00 00  00 02 00 00 00 00 00 00  |................|
00001030  c5 02 00 00 00 00 00 00  97 b4 9e 26 00 00 00 00  |...........&....|
00001040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001200  76 6f 6c 67 72 30 31 20  7b 0a 69 64 20 3d 20 22  |volgr01 {.id = "|
00001210  55 62 32 49 53 57 2d 78  37 77 64 2d 52 38 69 79  |Ub2ISW-x7wd-R8iy|
00001220  2d 47 65 78 47 2d 4a 47  55 47 2d 45 43 49 31 2d  |-GexG-JGUG-ECI1-|
00001230  6b 64 70 42 72 4b 22 0a  73 65 71 6e 6f 20 3d 20  |kdpBrK".seqno = |
00001240  31 0a 66 6f 72 6d 61 74  20 3d 20 22 6c 76 6d 32  |1.format = "lvm2|
00001250  22 20 23 20 69 6e 66 6f  72 6d 61 74 69 6f 6e 61  |" # informationa|
00001260  6c 0a 73 74 61 74 75 73  20 3d 20 5b 22 52 45 53  |l.status = ["RES|
00001270  49 5a 45 41 42 4c 45 22  2c 20 22 52 45 41 44 22  |IZEABLE", "READ"|
00001280  2c 20 22 57 52 49 54 45  22 5d 0a 66 6c 61 67 73  |, "WRITE"].flags|
00001290  20 3d 20 5b 5d 0a 65 78  74 65 6e 74 5f 73 69 7a  | = [].extent_siz|
000012a0  65 20 3d 20 38 31 39 32  0a 6d 61 78 5f 6c 76 20  |e = 8192.max_lv |
000012b0  3d 20 30 0a 6d 61 78 5f  70 76 20 3d 20 30 0a 6d  |= 0.max_pv = 0.m|
000012c0  65 74 61 64 61 74 61 5f  63 6f 70 69 65 73 20 3d  |etadata_copies =|
000012d0  20 30 0a 0a 70 68 79 73  69 63 61 6c 5f 76 6f 6c  | 0..physical_vol|
000012e0  75 6d 65 73 20 7b 0a 0a  70 76 30 20 7b 0a 69 64  |umes {..pv0 {.id|
000012f0  20 3d 20 22 5a 68 36 37  61 6a 2d 78 41 56 36 2d  | = "Zh67aj-xAV6-|
00001300  77 42 6f 77 2d 71 66 57  39 2d 32 47 55 35 2d 78  |wBow-qfW9-2GU5-x|
00001310  57 45 65 2d 65 48 44 6d  72 72 22 0a 64 65 76 69  |WEe-eHDmrr".devi|
00001320  63 65 20 3d 20 22 2f 64  65 76 2f 6c 6f 6f 70 31  |ce = "/dev/loop1|
00001330  22 0a 0a 73 74 61 74 75  73 20 3d 20 5b 22 41 4c  |"..status = ["AL|
00001340  4c 4f 43 41 54 41 42 4c  45 22 5d 0a 66 6c 61 67  |LOCATABLE"].flag|
00001350  73 20 3d 20 5b 5d 0a 64  65 76 5f 73 69 7a 65 20  |s = [].dev_size |
00001360  3d 20 31 30 34 38 35 37  36 30 0a 70 65 5f 73 74  |= 10485760.pe_st|
00001370  61 72 74 20 3d 20 32 30  34 38 0a 70 65 5f 63 6f  |art = 2048.pe_co|
00001380  75 6e 74 20 3d 20 31 32  37 39 0a 7d 0a 7d 0a 0a  |unt = 1279.}.}..|
00001390  7d 0a 23 20 47 65 6e 65  72 61 74 65 64 20 62 79  |}.# Generated by|
000013a0  20 4c 56 4d 32 20 76 65  72 73 69 6f 6e 20 32 2e  | LVM2 version 2.|
000013b0  30 32 2e 39 38 28 32 29  20 28 32 30 31 32 2d 31  |02.98(2) (2012-1|
000013c0  30 2d 31 35 29 3a 20 54  68 75 20 4e 6f 76 20 20  |0-15): Thu Nov  |
000013d0  38 20 31 31 3a 33 31 3a  35 34 20 32 30 31 32 0a  |8 11:31:54 2012.|
000013e0  0a 63 6f 6e 74 65 6e 74  73 20 3d 20 22 54 65 78  |.contents = "Tex|
000013f0  74 20 46 6f 72 6d 61 74  20 56 6f 6c 75 6d 65 20  |t Format Volume |
00001400  47 72 6f 75 70 22 0a 76  65 72 73 69 6f 6e 20 3d  |Group".version =|
00001410  20 31 0a 0a 64 65 73 63  72 69 70 74 69 6f 6e 20  | 1..description |
00001420  3d 20 22 22 0a 0a 63 72  65 61 74 69 6f 6e 5f 68  |= ""..creation_h|
00001430  6f 73 74 20 3d 20 22 6d  79 77 6f 72 6b 22 09 23  |ost = "mywork".#|
00001440  20 4c 69 6e 75 78 20 6d  79 77 6f 72 6b 20 33 2e  | Linux mywork 3.|
00001450  36 2e 36 2d 31 2d 41 52  43 48 20 23 31 20 53 4d  |6.6-1-ARCH #1 SM|
00001460  50 20 50 52 45 45 4d 50  54 20 4d 6f 6e 20 4e 6f  |P PREEMPT Mon No|
00001470  76 20 35 20 31 31 3a 35  37 3a 32 32 20 43 45 54  |v 5 11:57:22 CET|
00001480  20 32 30 31 32 20 78 38  36 5f 36 34 0a 63 72 65  | 2012 x86_64.cre|
00001490  61 74 69 6f 6e 5f 74 69  6d 65 20 3d 20 31 33 35  |ation_time = 135|
000014a0  32 33 36 37 31 31 34 09  23 20 54 68 75 20 4e 6f  |2367114.# Thu No|
000014b0  76 20 20 38 20 31 31 3a  33 31 3a 35 34 20 32 30  |v  8 11:31:54 20|
000014c0  31 32 0a 0a 00 00 00 00  00 00 00 00 00 00 00 00  |12..............|
000014d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*

# strings -t d file.img 
    512 LABELONE
    536 LVM2 001Zh67ajxAV6wBowqfW92GU5xWEeeHDmrr
   4100  LVM2 x[5A%r0N*>
   4608 volgr01 {
   4618 id = "Ub2ISW-x7wd-R8iy-GexG-JGUG-ECI1-kdpBrK"
   4664 seqno = 1
   4674 format = "lvm2" # informational
   4706 status = ["RESIZEABLE", "READ", "WRITE"]
   4747 flags = []
   4758 extent_size = 8192
   4777 max_lv = 0
   4788 max_pv = 0
   4799 metadata_copies = 0
   4820 physical_volumes {
   4840 pv0 {
   4846 id = "Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr"
   4892 device = "/dev/loop1"
   4915 status = ["ALLOCATABLE"]
   4940 flags = []
   4951 dev_size = 10485760
   4971 pe_start = 2048
   4987 pe_count = 1279
   5010 # Generated by LVM2 version 2.02.98(2) (2012-10-15): Thu Nov  8 11:31:54 2012
   5089 contents = "Text Format Volume Group"
   5127 version = 1
   5140 description = ""
   5158 creation_host = "mywork"	# Linux mywork 3.6.6-1-ARCH #1 SMP PREEMPT Mon Nov 5 11:57:22 CET 2012 x86_64
   5261 creation_time = 1352367114	# Thu Nov  8 11:31:54 2012

From this point hexdump will be out of this post, so i you want (it would be useful) click on the relative links.

D. Create Logical Volume


# lvcreate -l +100%FREE -n /dev/volgr01/lv_volume
  Logical volume "lv_volume" created

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/volgr01/lv_volume
  LV Name                lv_volume
  VG Name                volgr01
  LV UUID                OpoaHx-kD4m-9mSO-Nj7W-i7LN-2Sxg-KFhkXw
  LV Write Access        read/write
  LV Creation host, time mywork, 2012-11-08 11:41:51 +0200
  LV Status              available
  # open                 0
  LV Size                5,00 GiB
  Current LE             1279
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:22

# file file.img 
file.img: LVM2 PV (Linux Logical Volume Manager), UUID: Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr, size: 5368709120

# qemu-img info file.img 
image: file.img
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 12K

# du -k file.img
12	file.img

# du --apparent-size file.img 
5242880	file.img

# hexdump -C file.img 

Click here to see the hexdump (12K)


# strings -t d file.img
    512 LABELONE
    536 LVM2 001Zh67ajxAV6wBowqfW92GU5xWEeeHDmrr
   4100  LVM2 x[5A%r0N*>
   4608 volgr01 {
   4618 id = "Ub2ISW-x7wd-R8iy-GexG-JGUG-ECI1-kdpBrK"
   4664 seqno = 1
   4674 format = "lvm2" # informational
   4706 status = ["RESIZEABLE", "READ", "WRITE"]
   4747 flags = []
   4758 extent_size = 8192
   4777 max_lv = 0
   4788 max_pv = 0
   4799 metadata_copies = 0
   4820 physical_volumes {
   4840 pv0 {
   4846 id = "Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr"
   4892 device = "/dev/loop1"
   4915 status = ["ALLOCATABLE"]
   4940 flags = []
   4951 dev_size = 10485760
   4971 pe_start = 2048
   4987 pe_count = 1279
   5010 # Generated by LVM2 version 2.02.98(2) (2012-10-15): Thu Nov  8 11:31:54 2012
   5089 contents = "Text Format Volume Group"
   5127 version = 1
   5140 description = ""
   5158 creation_host = "mywork"	# Linux mywork 3.6.6-1-ARCH #1 SMP PREEMPT Mon Nov 5 11:57:22 CET 2012 x86_64
   5261 creation_time = 1352367114	# Thu Nov  8 11:31:54 2012
   5632 volgr01 {
   5642 id = "Ub2ISW-x7wd-R8iy-GexG-JGUG-ECI1-kdpBrK"
   5688 seqno = 2
   5698 format = "lvm2" # informational
   5730 status = ["RESIZEABLE", "READ", "WRITE"]
   5771 flags = []
   5782 extent_size = 8192
   5801 max_lv = 0
   5812 max_pv = 0
   5823 metadata_copies = 0
   5844 physical_volumes {
   5864 pv0 {
   5870 id = "Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr"
   5916 device = "/dev/loop1"
   5939 status = ["ALLOCATABLE"]
   5964 flags = []
   5975 dev_size = 10485760
   5995 pe_start = 2048
   6011 pe_count = 1279
   6032 logical_volumes {
   6051 lv_volume {
   6063 id = "OpoaHx-kD4m-9mSO-Nj7W-i7LN-2Sxg-KFhkXw"
   6109 status = ["READ", "WRITE", "VISIBLE"]
   6147 flags = []
   6158 creation_host = "mywork"
   6183 creation_time = 1352367711
   6210 segment_count = 1
   6229 segment1 {
   6240 start_extent = 0
   6257 extent_count = 1279
   6278 type = "striped"
   6295 stripe_count = 1	# linear
   6322 stripes = [
   6334 "pv0", 0
   6353 # Generated by LVM2 version 2.02.98(2) (2012-10-15): Thu Nov  8 11:41:51 2012
   6432 contents = "Text Format Volume Group"
   6470 version = 1
   6483 description = ""
   6501 creation_host = "mywork"	# Linux mywork 3.6.6-1-ARCH #1 SMP PREEMPT Mon Nov 5 11:57:22 CET 2012 x86_64
   6604 creation_time = 1352367711	# Thu Nov  8 11:41:51 2012

E. Format FileSystem


# mkfs.ext2 /dev/volgr01/lv_volume 

mke2fs 1.42.6 (21-Sep-2012)
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1309696 blocks
65484 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

# mount /dev/volgr01/lv_volume /mnt/

# df -h /mnt/
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/volgr01-lv_volume  5,0G   10M  4,7G   1% /mnt

# file file.img 
file.img: LVM2 PV (Linux Logical Volume Manager), UUID: Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr, size: 5368709120

# qemu-img info file.img 
image: file.img
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 82M

# du -k file.img
83680	file.img

# du --apparent-size file.img 
5242880	file.img
# hexdump -C file.img 

Click here to see the hexdump (172K)


# strings -t d file.img
    512 LABELONE
    536 LVM2 001Zh67ajxAV6wBowqfW92GU5xWEeeHDmrr
   4100  LVM2 x[5A%r0N*>
   4608 volgr01 {
   4618 id = "Ub2ISW-x7wd-R8iy-GexG-JGUG-ECI1-kdpBrK"
   4664 seqno = 1
   4674 format = "lvm2" # informational
   4706 status = ["RESIZEABLE", "READ", "WRITE"]
   4747 flags = []
   4758 extent_size = 8192
   4777 max_lv = 0
   4788 max_pv = 0
   4799 metadata_copies = 0
   4820 physical_volumes {
   4840 pv0 {
   4846 id = "Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr"
   4892 device = "/dev/loop1"
   4915 status = ["ALLOCATABLE"]
   4940 flags = []
   4951 dev_size = 10485760
   4971 pe_start = 2048
   4987 pe_count = 1279
   5010 # Generated by LVM2 version 2.02.98(2) (2012-10-15): Thu Nov  8 11:31:54 2012
   5089 contents = "Text Format Volume Group"
   5127 version = 1
   5140 description = ""
   5158 creation_host = "mywork"	# Linux mywork 3.6.6-1-ARCH #1 SMP PREEMPT Mon Nov 5 11:57:22 CET 2012 x86_64
   5261 creation_time = 1352367114	# Thu Nov  8 11:31:54 2012
   5632 volgr01 {
   5642 id = "Ub2ISW-x7wd-R8iy-GexG-JGUG-ECI1-kdpBrK"
   5688 seqno = 2
   5698 format = "lvm2" # informational
   5730 status = ["RESIZEABLE", "READ", "WRITE"]
   5771 flags = []
   5782 extent_size = 8192
   5801 max_lv = 0
   5812 max_pv = 0
   5823 metadata_copies = 0
   5844 physical_volumes {
   5864 pv0 {
   5870 id = "Zh67aj-xAV6-wBow-qfW9-2GU5-xWEe-eHDmrr"
   5916 device = "/dev/loop1"
   5939 status = ["ALLOCATABLE"]
   5964 flags = []
   5975 dev_size = 10485760
   5995 pe_start = 2048
   6011 pe_count = 1279
   6032 logical_volumes {
   6051 lv_volume {
   6063 id = "OpoaHx-kD4m-9mSO-Nj7W-i7LN-2Sxg-KFhkXw"
   6109 status = ["READ", "WRITE", "VISIBLE"]
   6147 flags = []
   6158 creation_host = "mywork"
   6183 creation_time = 1352367711
   6210 segment_count = 1
   6229 segment1 {
   6240 start_extent = 0
   6257 extent_count = 1279
   6278 type = "striped"
   6295 stripe_count = 1	# linear
   6322 stripes = [
   6334 "pv0", 0
   6353 # Generated by LVM2 version 2.02.98(2) (2012-10-15): Thu Nov  8 11:41:51 2012
   6432 contents = "Text Format Volume Group"
   6470 version = 1
   6483 description = ""
   6501 creation_host = "mywork"	# Linux mywork 3.6.6-1-ARCH #1 SMP PREEMPT Mon Nov 5 11:57:22 CET 2012 x86_64
   6604 creation_time = 1352367711	# Thu Nov  8 11:41:51 2012
4468768 lost+found
Tag(s): lvm, hexdump

Viewing all articles
Browse latest Browse all 333

Trending Articles