一个新的磁盘,如何去做LVM?
一、格式化磁盘
[root@localhost ~]# fdisk -l #查看当前的设备有哪些
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
……此处省略部分输出内容……
/dev/sda3 153 2610 19743885 83 Linux
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
……此处省略部分输出内容……
Disk /dev/sdb doesn't contain a valid partition table
……此处省略部分输出内容……
Disk /dev/sdc doesn't contain a valid partition table
从格式化磁盘开始
[root@localhost ~]# fdisk /dev/sdb ##对第二块磁盘进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
此处省………………略若干字
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n ##n表示new,建立新的分区
p primary partition (1-4)
p ###代表主分区
Partition number (1-4): 1 ##主分区号
First cylinder (1-5221, default 1): 1##磁盘分区起始点
Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221): +10000M ##指定第一个分区大小为10G
Command (m for help): n #继续新建分区
Command action
e extended
p primary partition (1-4)
p ##依旧是主分区
Partition number (1-4): 2 ##编号为2
First cylinder (1218-5221, default 1218):
Using default value 1218 ##起始点直接回车表示默认
Last cylinder or +size or +sizeM or +sizeK (1218-5221, default 5221): +20000M ###指定大小为20G
Command (m for help): n ##新建分区
Command action
e extended
p primary partition (1-4)
p ##选择主分区
Partition number (1-4): 3 ##主分区编号为3
First cylinder (3651-5221, default 3651):
Using default value 3651 ###直接回车默认
Last cylinder or +size or +sizeM or +sizeK (3651-5221, default 5221):
Using default value 5221 ####回车默认
Command (m for help): t ###使用t表示转换分区类型
Partition number (1-4): 1 ###输入分区号
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): p ###列出所有分区
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
……
Device Boot Start End Blocks Id System
/dev/sdb1 1 1217 9775521 8e Linux LVM
/dev/sdb2 1218 2434 9775552+ 8e Linux LVM
/dev/sdb3 2435 5221 22386577+ 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 ~]# partprobe /dev/sdb /dev/sdc
二、建立PV(物理卷)
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
/dev/cdrom: open failed: Read-only file system
Physical volume "/dev/sdb1" successfully created
Attempt to close device '/dev/cdrom' which is not open.
Physical volume "/dev/sdb3" successfully created
[root@localhost ~]# pvdisplay ###展示物理卷
"/dev/sdb1" is a new physical volume of "9.32 GB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 9.32 GB
……此处省略……部分显示结果
PV Size 21.35 GB
Allocatable NO
…………
PV UUID rdfuEk-FUli-Iyks-sGrO-1bco-G7ND-NYyrjM
三、建立VG卷组
[root@localhost ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3 ####建立名称为vg1的卷组
Volume group "vg1" successfully created
[root@localhost ~]# vgdisplay ###列出卷组
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
………………………………
Free PE / Size 10237 / 39.99 GB
VG UUID sgtFaV-Hd31-dCag-jPbq-50Ia-WOQa-Ccwo3x
四、建立LV逻辑卷
[root@localhost ~]# lvcreate -L 15000M -n lv1 vg1 ###创建名为lv1,大小为15G的逻辑卷
/dev/cdrom: open failed: Read-only file system
Logical volume "lv1" created
[root@localhost ~]# lvdisplay ###展示逻辑卷
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID fPAVct-8lZ2-Nvs6-KK2n-IMqo-1enG-hHt2tN
LV Write Access read/write
LV Status available
# open 0
LV Size 14.65 GB
Current LE 3750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
格式化LV1并挂载
[root@localhost ~]# mkfs.ext3 /dev/vg1/lv1 ###将lv1格式化成ext3格式
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1921984 inodes, 3840000 blocks
192000 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3934257152
118 block groups
32768 blocks per group, 32768 fragments per group
16288 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/vg1/lv1 /mnt/ ####将逻辑卷挂载到/mnt
[root@localhost ~]# mount ###查看当前的挂在情况
/dev/sda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/mapper/vg1-lv1 on /mnt type ext3 (rw)
扩大LV
[root@localhost ~]# df -Th ####查看当前的分区挂载
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 19G 4.1G 14G 24% /
/dev/sda1 ext3 190M 12M 169M 7% /boot
tmpfs tmpfs 125M 0 125M 0% /dev/shm
/dev/mapper/vg1-lv1
ext3 15G 165M 14G 2% /mnt
Disk /dev/sdc: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 366 2939863+ 8e Linux LVM
[root@localhost ~]# vgdisplay #####查看卷组的状态
--- Volume group ---
VG Name vg1
System ID
……
Alloc PE / Size 3750 / 14.65 GB
Free PE / Size 6487 / 25.34 GB
VG UUID sgtFaV-Hd31-dCag-jPbq-50Ia-WOQa-Ccwo3x
[root@localhost ~]# vgextend vg1 /dev/sdc1 #####将/dev/sdc1扩到卷组vg1中
/dev/cdrom: open failed: Read-only file system
No physical volume label read from /dev/sdc1
Physical volume "/dev/sdc1" successfully created
Volume group "vg1" successfully extended
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size 42.79 GB
PE Size 4.00 MB
Total PE 10954
Alloc PE / Size 3750 / 14.65 GB
Free PE / Size 7204 / 28.14 GB
VG UUID sgtFaV-Hd31-dCag-jPbq-50Ia-WOQa-Ccwo3x
[root@localhost ~]# lvextend -L +2000M /dev/vg1/lv1 ####对lv进行扩容
/dev/cdrom: open failed: Read-only file system
Extending logical volume lv1 to 16.60 GB
Logical volume lv1 successfully resized