一、对磁盘分区:
[root@localhost /]# fdisk /dev/sdb //执行fdisk /dev/sdb命令
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): p //显示已有分区
Disk /dev/sdb: 82.0 GB, 81963220480 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xecebeceb
Device Boot Start End Blocks Id System
Command (m for help): n //新建一个分区
Command action
e extended //扩展分区
p primary partition (1-4) //主要分区
p
Partition number (1-4): 1 //输入序号,主要分区只能为4个。
First cylinder (1-9964, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-9964, default 9964): //指定分区大小,可以用“+10G”这种形式来写。
Using default value 9964
Command (m for help): p //再次查看分区是否建立
Disk /dev/sdb: 82.0 GB, 81963220480 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xecebeceb
Device Boot Start End Blocks Id System
/dev/sdb1 1 9964 80035798+ 83 Linux //可以看到分区已成功建立
Command (m for help): t //更改分区类型
Selected partition 1
Hex code (type L to list codes): 8e //指定为lvm类型,也可以用L来查看有哪些类型。
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p //再次查看分区
Disk /dev/sdb: 82.0 GB, 81963220480 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xecebeceb
Device Boot Start End Blocks Id System
/dev/sdb1 1 9964 80035798+ 8e Linux LVM //发现system已变为lvm
Command (m for help): w //将更改写入磁盘,执行W才会生效,Q退出不保存。
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]# partprobe /dev/sdb
我装的64位系统命令是partx�Ca /dev/sda3
#这一步很重要,否则ls /dev/sdb 没有新建立的分区。
[root@localhost /]# fdisk /dev/sdb //再次查看分区
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): p
Disk /dev/sdb: 82.0 GB, 81963220480 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xecebeceb
Device Boot Start End Blocks Id System
/dev/sdb1 1 9964 80035798+ 8e Linux LVM
Command (m for help): q //退出不保存。
[root@localhost /]#
到这里分区已完成。
二、建立PV物理卷
pvcreate /dev/sdb1 //建立物理卷
Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created
[root@localhost /]# pvscan //查看物理卷信息
PV /dev/sdb1 lvm2 [76.33 GiB]
Total: 1 [76.33 GiB] / in use: 0 [0 ] / in no VG: 1 [76.33 GiB]
[root@localhost /]# pvdisplay //查看更详细的物理卷信息
"/dev/sdb1" is a new physical volume of "76.33 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1 //PV名称
VG Name //VG名称,由于没有建立VG,所以这里为空
PV Size 76.33 GiB //PV大小
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ZVd7r6-IUzP-6765-hxJY-cNRt-0uF2-XCeKtN //UUID,每个硬件设备都有一个ID。
[root@localhost /]#
三、建立VG
vgcreate vg1 /dev/sdb1 //建立vg1 后面跟的是PV的名称,注:系统可能会提示运行vgscan来创建文件。
Volume group "vg1" successfully created
[root@localhost /]# vgchange -a y vg1 //激活VG1
0 logical volume(s) in volume group "vg1" now active
[root@localhost /]# vgscan //查看VG1的信息
Reading all physical volumes. This may take a while...
Found volume group "vg1" using metadata type lvm2
[root@localhost /]# vgdisplay //查看VG1的详细信息
--- Volume group ---
VG Name vg1 //VG名称
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 76.32 GiB //VG大小
PE Size 4.00 MiB //VG的每个PE大小
Total PE 19539 //PE的个数。
Alloc PE / Size 0 / 0
Free PE / Size 19539 / 76.32 GiB //空闲大小
VG UUID lXM5BW-PmDX-7kXE-x2O0-mihI-jO4L-jKMAXp
四、建立逻辑卷
lvcreate -L 2G -n lv1-backup vg1 //建立LV -L 指定大小,-n指定名称,最后跟VG名称
Logical volume "lv1-backup" created
[root@localhost /]# mkfs -t ext4 /dev/vg1/lv1-backup //格式化LV,-t指定格式
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost /]# mount /dev/vg1/lv1-backup /backup/ //将LV挂载到目录
[root@localhost /]# df -h //查看目录的大小,
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda2 20G 2.0G 18G 11% /
tmpfs 742M 0 742M 0% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/mapper/vg1-lv1--backup
2.0G 67M 1.9G 4% /backup //LV1已经被挂载进来,这时可以使用它了。
[root@localhost /]# lvscan //查看LV1信息
ACTIVE '/dev/vg1/lv1-backup' [2.00 GiB] inherit
[root@localhost /]# lvdisplay /dev/vg1/lv1-backup //查看LV1更详细信息
--- Logical volume ---
LV Name /dev/vg1/lv1-backup
VG Name vg1
LV UUID YR67fr-n5ze-EfSx-TgKf-2099-UFdi-vHOcZU
LV Write Access read/write
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
更多的说明“百分一”将不断更新,请大家多多指教。
到这里LV的建立已经完成。下结将讨论LV增加空间,减少空间,删除LV。