谢nntp提供的那篇关于lvm的文档,我根据这份文档在自己本本上做了一个lvm分区,把两个离得很远的分区并成一个分区,用来放基于xen的虚拟机。
环境:rhel5 client
fdisk -l 命令的输出:
Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2330 18715693+ 7 HPFS/NTFS
/dev/sda2 3826 14593 86493960 f W95 Ext'd (LBA)
/dev/sda3 2331 3825 12008587+ 83 Linux
/dev/sda5 3826 9179 43005973+ 7 HPFS/NTFS
/dev/sda6 9180 9192 104391 83 Linux
/dev/sda7 9193 10497 10482381 83 Linux
/dev/sda8 10498 10752 2048256 82 Linux swap / Solaris
/dev/sda9 10753 10765 104391 83 Linux
/dev/sda10 10766 11982 9775521 83 Linux
/dev/sda11 11983 14593 20972826 83 Linux
Partition table entries are not in disk order
其中/dev/sda3是用分区魔术师从/dev/sda1(windows xp的c盘,当初把这个盘分得太大)分出来的。
现在要把/dev/sda3和/dev/sda11做成一个logic volume。
1. 在这两个分区上分别建立physical volume:
# pvcreate /dev/sda3 /dev/sda11
Physical volume "/dev/sda3" successfully created
Physical volume "/dev/sda11" successfully created[/code]
pvscan命令输出:
PV /dev/sda3 lvm2 [11.45 GB]
PV /dev/sda11 lvm2 [20.00 GB]
Total: 2 [31.45 GB] / in use: 0 [0 ] / in no VG: 2 [31.45 GB]
2. 使用vgcreate命令建立volume group,这个volume group就是把两个physical volume合并起来:
[code]# vgcreate xen-volume /dev/sda3 /dev/sda11
Volume group "xen-volume" successfully created[/code]
再看pvscan命令的输出,和前一次不一样了:
[code] PV /dev/sda3 VG xen-volume lvm2 [11.45 GB / 11.45 GB free]
PV /dev/sda11 VG xen-volume lvm2 [20.00 GB / 20.00 GB free]
Total: 2 [31.45 GB] / in use: 2 [31.45 GB] / in no VG: 0 [0 ]
再看看vgdisplay命令的输出:
# vgdisplay -v xen-volume
Using volume group(s) on command line
Finding volume group "xen-volume"
--- Volume group ---
VG Name xen-volume
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 31.45 GB
PE Size 4.00 MB
Total PE 8051
(注:PE的默认尺寸为4M,这个VG一共有8051个PE,总容量就是VG Size的值31.45GB)
Alloc PE / Size 0 / 0
Free PE / Size 8051 / 31.45 GB
VG UUID DTRys2-7H4v-0cej-CSai-08PK-munx-fCNp7N
--- Physical volumes ---
PV Name /dev/sda3
PV UUID 0y5F7N-Nk3b-ert3-pKtr-ErQp-52Uq-npF5ns
PV Status allocatable
Total PE / Free PE 2931 / 2931
PV Name /dev/sda11
PV UUID 0khn2p-QALW-N7c3-Xb60-uEXg-0QZ5-iyfHdu
PV Status allocatable
Total PE / Free PE 5120 / 5120
3. 在上面建立的名为“xen-volume”的volume group上创建一个容量为31G的,名称为“xen-lv”的logic volume:
# lvcreate -L 31G -n xen-lv xen-volume
Logical volume "xen-lv" created
查看Logic volume的device node,这个device node的命名规则是volume group + logic volume:
# ls -al /dev/mapper/
总计 0
drwxr-xr-x 2 root root 80 10-05 14:14 .
drwxr-xr-x 14 root root 3940 10-05 14:14 ..
crw------- 1 root root 10, 62 10-05 09:07 control
brw-rw---- 1 root disk 253, 0 10-05 14:14 xen--volume-xen--lv[/code]
另外,在/dev目录下有一个以volume group为名字的目录,这个目录下有一个以logic volume为名字的软链接文件,这个文件指向/dev/mapper下的device node。
# ls -al /dev/xen-volume/
总计 0
drwx------ 2 root root 60 10-05 14:14 .
drwxr-xr-x 14 root root 3940 10-05 14:14 ..
lrwxrwxrwx 1 root root 31 10-05 14:14 xen-lv -> /dev/mapper/xen--volume-xen--lv
查看Logic volume的属性:
# lvdisplay /dev/xen-volume/xen-lv
--- Logical volume ---
LV Name /dev/xen-volume/xen-lv
VG Name xen-volume
LV UUID mzd2qO-53e6-WHw2-B37n-hqjK-zYha-O3rViE
LV Write Access read/write
LV Status available
# open 0
LV Size 31.00 GB
Current LE 7936
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
4. 在logic volume上建立系统:
[code]# mkfs.ext3 /dev/xen-volume/xen-lv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
4063232 inodes, 8126464 blocks
406323 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
248 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5. 加载logic volume到目录:
# mount /dev/xen-volume/xen-lv /xen/
查看结果:
# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda7 10153988 8359088 1270784 87% /
/dev/sda6 101086 15521 80346 17% /boot
tmpfs 466256 0 466256 0% /dev/shm
/dev/sda1 18715692 14723668 3992024 79% /windows/c
/dev/sda5 43005972 42618084 387888 100% /windows/d
/dev/mapper/xen--volume-xen--lv
31995824 180288 30190244 1% /xen
6. 在/etc/fstab文件里加一行,让logic volume能够自动加载:
/dev/xen-volume/xen-lv /xen ext3 defaults 0 0
附图是lvm分区做完以后system-config-lvm命令的载图。
如果想了解更多英国留学的申请 签证 学校排名 留学论坛 等相关信息以及详细资讯,欢迎点击中英网http://www.uker.net/
网友评论