一、 测试系统环境
系统平台:Red Hat Linux Advanced Server 2.1
内核版本:2.4.18
服务器:DELL 6300
LVM内核支持版本:1.0.1
LVM工具版本:1.0.1
文件系统:reiserfs
二、 安装步骤
a) 内核编译
make mrproper
make menuconfig
内核配置。
[*] Multiple devices driver support (RAID and LVM)
<*> Logical volume manager (LVM) support
由于是全新的内核,同时增加了AIC7XXXX SCSI驱动支持、reiserfs和EXT3文件系统的支持。
SCSI support --->
SCSI low-level drivers --->
<*> Adaptec AIC7xxx support
(253) Maximum number of TCQ commands per device
(15000) Initial bus reset delay in milli-seconds
File systems --->
<*> Reiserfs support
[*] Have reiserfs do extra internal checking
[*] Stats in /proc/fs/reiserfs
<*> Ext3 journalling file system support (EXPERIMENTAL)
b) 安装LVM工具
cd /root
tar zxvf lvm_1.0.1.tar.gz
cd LVM/1.0.1
./configure
make
make install
echo “/sbin/vgscan” >>/etc/rc.d/rc.local
echo “/sbin/vgchange -a y “>>/etc/rc.d/rc.local
三、 测试
a) 创建分区并初始化为物理卷
用fdisk创建分区/dev/sda7、/dev/sda8、/dev/sdb1、/dev/sdb2、/dev/sdb3、/deb/sdc1、/dev/sdc2、/dev/sdc3、/dev/sdc4,分区格式为8E(LVM标准分区)
初始化为物理卷
pvcreate /dev/sda7
pvcreate /dev/sda8
pvcreate /dev/sdb1
pvcreate /dev/sdb2
pvcreate /dev/sdb3
pvcreate /dev/sdc1
pvcreate /dev/sdc2
pvcreate /dev/sdc3
pvcreate /dev/sdc4
b) 在不同的硬盘上同时创建LVM卷组
vgcreate lvmtest /dev/sda7 /dev/sdb1
成功创建lvmtest卷组
c) 删除其中的一个卷组
vgreduce lvmtest /dev/sdb1
成功,/dev/sdb1并没有分配给逻辑卷(LV)使用,可以成功删除。已经配空间给LV后的物理卷不能再删除
d) 增加物理卷
将刚才成功从卷组中删除的物理卷重新加入卷组
vgextend lvmtest /dev/sdb1
成功
e) 创建逻辑
lvcreate –L 3G –n lvm1 lvmtest
成功创建一个名为lvm1、大小为3G的逻辑卷
lvcreate –L 3G –n lvm2lvmtest
成功创建一个名为lvm1、大小为3G的逻辑卷
f) 格式化逻辑卷
mkreiserfs /dev/lvmtest/lvm1
mkreiserfs /dev/lvmtest/lvm2
成功
g) 将逻辑卷mount到测试目录
mkdri /mntvm1
mkdir /mnt/lvm2
mount /dev/lvmtest/lvm1 /mnt/lvm1
mount /dev/lvmtest/lvm2 /mnt/lvm2
成功
h) 数据读写测试
cp –rf /var /mnt/lvm1
cp –rf /usr /mnt/lvm1
cp –rf /var /mnt/lvm2
cp –rf /var /mnt/lvm2
总大小为1.2G,写入正常。
i) 系统引导时自动mount
修改/etc/fstab增加如下两行
/dev/lvmtest/lvm1 /mnt/lvm1 reiserfs defaults 1 2
/dev/lvmtest/lvm2 /mnt/lvm2 reiserfs defaults 1 2
重新启动计算机,/mnt/lvm1和/mnt/lvm2两个目录正常mount上去。
[root@lvm root]# df -ah
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 1.9G 298M 1.5G 16% /
none 0 0 0 - /proc
none 0 0 0 - /dev/pts
/dev/sda5 1.4G 20k 1.3G 1% /home
none 1006M 0 1006M 0% /dev/shm
/dev/sda3 1.4G 1.3G 154M 89% /usr
/dev/sda6 1.4G 27M 1.3G 2% /var
/dev/lvmtest/lvm1 3.0G 1.2G 1.8G 38% /mnt/lvm1
/dev/lvmtest/lvm2 3.0G 1.2G 1.8G 38% /mnt/lvm2
j) 逻辑卷扩容
lvextend –L+2G /dev/lvmtest/lvm2
resize_reiserfs –f /dev/lvmtest/lvm2
用df –ah查看,/mnt/lvm2目录的增长的2G,文件读写正常。
[root@lvm root]# lvextend -L+2G /dev/lvmtest/lvm2
lvextend -- extending logical volume "/dev/lvmtest/lvm2" to 5.00 GB
lvextend -- doing automatic backup of volume group "lvmtest"
lvextend -- logical volume "/dev/lvmtest/lvm2" successfully extended
[root@lvm root]# resize_reiserfs -f /dev/lvmtest/lvm2
<-------------resize_reiserfs, 2001------------->
reiserfsprogs 3.x.0j
[root@lvm root]# df -ah
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 1.9G 298M 1.5G 16% /
none 0 0 0 - /proc
none 0 0 0 - /dev/pts
/dev/sda5 1.4G 20k 1.3G 1% /home
none 1006M 0 1006M 0% /dev/shm
/dev/sda3 1.4G 1.3G 154M 89% /usr
/dev/sda6 1.4G 27M 1.3G 2% /var
/dev/lvmtest/lvm1 3.0G 1.2G 1.8G 38% /mnt/lvm1
/dev/lvmtest/lvm2 5.0G 1.2G 3.8G 23% /mnt/lvm2
k) 逻辑卷减容
lvreduce –L-2G /dev/lvmtest/lvm2
umount /mnt/lvm2
resize_reiserfs –f /dev/lvmtest/lvm2
mount /dev/lvmtest/lvm2 /mnt/lvm2
用df –ah 查看,/mnt/lvm2目录成功减小了2G,读写测试正常。
[root@lvm root]# lvreduce -L-2G /dev/lvmtest/lvm2
lvreduce -- WARNING: reducing active and open logical volume to 3.00 GB
lvreduce -- THIS MAY DESTROY YOUR DATA (filesystem etc.)
lvreduce -- do you really want to reduce "/dev/lvmtest/lvm2"? [y/n]: y
lvreduce -- doing automatic backup of volume group "lvmtest"
lvreduce -- logical volume "/dev/lvmtest/lvm2" successfully reduced
[root@lvm root]# umount /mnt/lvm2
[root@lvm root]# resize_reiserfs /dev/lvmtest/lvm2
<-------------resize_reiserfs, 2001------------->
reiserfsprogs 3.x.0j
reiserfs_open: bread failed reading bitmap #24 (786432)
reiserfs_open: bread failed reading bitmap #25 (819200)
reiserfs_open: bread failed reading bitmap #26 (851968)
reiserfs_open: bread failed reading bitmap #27 (884736)
reiserfs_open: bread failed reading bitmap #28 (917504)
reiserfs_open: bread failed reading bitmap #29 (950272)
reiserfs_open: bread failed reading bitmap #30 (983040)
reiserfs_open: bread failed reading bitmap #31 (1015808)
reiserfs_open: bread failed reading bitmap #32 (1048576)
reiserfs_open: bread failed reading bitmap #33 (1081344)
reiserfs_open: bread failed reading bitmap #34 (1114112)
reiserfs_open: bread failed reading bitmap #35 (1146880)
reiserfs_open: bread failed reading bitmap #36 (1179648)
reiserfs_open: bread failed reading bitmap #37 (1212416)
reiserfs_open: bread failed reading bitmap #38 (1245184)
reiserfs_open: bread failed reading bitmap #39 (1277952)
You are running BETA version of reiserfs shrinker.
This version is only for testing or VERY CAREFUL use.
Backup of you data is recommended.
Do you want to continue? [y/N]:y
Fetching on-disk bitmap..done
Processing the tree: 0%....20%....40%....60%....80%....100% left 0, 5153 /sec
nodes processed (moved):
int 119 (0),
leaves 18732 (0),
unfm 269739 (0),
total 288590 (0).
ReiserFS report:
blocksize 4096
block count 786432 (1310720)
free blocks 489608 (1013880)
bitmap block count 24 (40)
Syncing..done
在对分区减容时,时间相对较长,时间长短与减容分区的容量大小有关。减容不能在线实现,必须要将LV所在的mount点umount下来,并且减容操作有一定的风险。
l) 跨不同物理硬盘创建多VG(卷组)
新建VG。
vgcreate –s 32M lvmtest2 /dev/sda8 /dev/sdb2 /dev/sdc2
[root@lvm log]# vgcreate -s 32M lvmtest2 /dev/sda8 /dev/sdb2 /dev/sdc2
vgcreate -- INFO: maximum logical volume size is 1.00 Terabyte
vgcreate -- doing automatic backup of volume group "lvmtest2"
vgcreate -- volume group "lvmtest2" successfully created and activated
[root@lvm log]# vgdisplay lvmtest2
--- Volume group ---
VG Name lvmtest2
VG Access read/write
VG Status available/resizable
VG # 1
MAX LV 255
Cur LV 0
Open LV 0
MAX LV Size 1.00 TB
Max PV 255
Cur PV 3
Act PV 3
VG Size 13.91 GB
PE Size 32.00 MB
Total PE 445
Alloc PE /