Linux系统中对逻辑卷(LVM)的实现
1.分区并转换lvm格式
[root@localhost ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd8e8fb90.
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 sector (2048-4485119, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4485119, default 4485119): +200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (411648-4485119, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-4485119, default 4485119): +200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (821248-4485119, default 821248):
Using default value 821248
Last sector, +sectors or +size{K,M,G} (821248-4485119, default 4485119): +200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First sector (1230848-4485119, default 1230848):
Using default value 1230848
Last sector, +sectors or +size{K,M,G} (1230848-4485119, default 4485119): +200M
Command (m for help): p
Disk /dev/sdb: 2296 MB, 2296381440 bytes
255 heads, 63 sectors/track, 279 cylinders, total 4485120 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
Disk identifier: 0xd8e8fb90
Device Boot Start End Blocks Id System
/dev/sdb1 2048 411647 204800 83 Linux
/dev/sdb2 411648 821247 204800 83 Linux
/dev/sdb3 821248 1230847 204800 83 Linux
/dev/sdb4 1230848 1640447 204800 83 Linux
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 2296 MB, 2296381440 bytes
255 heads, 63 sectors/track, 279 cylinders, total 4485120 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
Disk identifier: 0xd8e8fb90
Device Boot Start End Blocks Id System
/dev/sdb1 2048 411647 204800 8e Linux LVM
/dev/sdb2 411648 821247 204800 8e Linux LVM
/dev/sdb3 821248 1230847 204800 8e Linux LVM
/dev/sdb4 1230848 1640447 204800 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
2.将分区转换为pv物理卷,将pv加入到一个vg组中,从vg划出lv逻辑卷
[root@localhost ~]# pvcreate /dev/sdb{1,2,3,4} --将分区转换为物理卷
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
Physical volume "/dev/sdb4" successfully created
[root@localhost ~]# pvscan --查看物理卷
PV /dev/sda2 VG VolGroup lvm2 [7.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [200.00 MiB]
PV /dev/sdb2 lvm2 [200.00 MiB]
PV /dev/sdb3 lvm2 [200.00 MiB]
PV /dev/sdb4 lvm2 [200.00 MiB]
Total: 5 [8.29 GiB] / in use: 1 [7.51 GiB] / in no VG: 4 [800.00 MiB]
[root@localhost ~]# vgcreate vg0 /dev/sdb{1,2,3} --将物理卷1,2,3加入到卷组
Volume group "vg0" successfully created
[root@localhost ~]# vgscan --查看卷组
Reading all physical volumes. This may take a while...
Found volume group "vg0" using metadata type lvm2
Found volume group "VolGroup" using metadata type lvm2
[root@localhost ~]# lvcreate -n test -L 150M vg0 --从卷组中分出pv逻辑卷
Rounding up size to full physical extent 152.00 MiB
Logical volume "test" created
[root@localhost ~]# lvcreate -n test1 -L 150M vg0
Rounding up size to full physical extent 152.00 MiB
Logical volume "test1" created
[root@localhost ~]# lvscan
ACTIVE '/dev/vg0/test' [152.00 MiB] inherit
ACTIVE '/dev/vg0/test1' [152.00 MiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [6.51 GiB] inherit
ACTIVE '/dev/VolGroup/lv_swap' [1.00 GiB] inherit
[root@localhost ~]# mkfs.ext4 /dev/vg0/test --格式化物理卷
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
38912 inodes, 155648 blocks
7782 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
19 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/vg0/test /mnt/sdb --挂载
[root@localhost ~]# mkdir /mnt/sdb/12 --可以使用了
[root@localhost ~]# ll /mnt/sdb/
total 14
drwxr-xr-x. 2 root root 1024 Jan 9 15:24 12
drwx------. 2 root root 12288 Jan 9 15:23 lost+found
[root@localhost ~]#