分类: LINUX
2007-08-01 00:31:19
试验目的:将新加的第二块磁盘sdb全部加到/var(/dev/sda7)分区中。
试验之前分区情况
[root@rac2 ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 3020140 253060 2613664 9% /
/dev/sda1 101086 11395 84472 12% /boot
none 127384 0 127384 0% /dev/shm
/dev/sda2 8064304 63500 7591148 1% /home
/dev/sda3 4032124 2593408 1233888 68% /usr
/dev/sda7 2846172 123852 2577740 5% /var
一)察看分区并将新磁盘分区。
[root@rac2 ~]# fdisk -l
Disk /dev/sda: 19.3 GB, 19327352832 bytes
255 heads, 63 sectors/track, 2349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1033 8193150 83 Linux
/dev/sda3 1034 1543 4096575 83 Linux
/dev/sda4 1544 2349 6474195 5 Extended
/dev/sda5 1544 1925 3068383+ 83 Linux
/dev/sda6 1926 1989 514048+ 82 Linux swap
/dev/sda7 1990 2349 2891668+ 83 Linux
Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
[root@rac2 ~]# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-783, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-783, default 783):
Using default value 783
Command (m for help): p
Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 783 6289416 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1-783, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-783, default 783):
Using default value 783
Command (m for help): p
Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 783 6289416 5 Extended
/dev/sdb5 1 783 6289384+ 83 Linux
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): l
0 Empty 1e Hidden W95 FAT1 75 PC/IX be Solaris boot
1 FAT12 24 NEC DOS 80 Old Minix bf Solaris
2 XENIX root 39 Plan 9 81 Minix / old Lin c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 82 Linux swap c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 83 Linux c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 84 OS/2 hidden C: c7 Syrinx
6 FAT16 42 SFS 85 Linux extended da Non-FS data
7 HPFS/NTFS 4d QNX4.x 86 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 87 NTFS volume set de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 783 6289416 5 Extended
/dev/sdb5 1 783 6289384+ 8e Linux LVM
注意红色的变化。
Command (m for help): w (保存)
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
2)在新分区上创建物理卷
[root@rac2 ~]# pvcreate /dev/sdb5
Physical volume "/dev/sdb5" successfully created
察看
[root@rac2 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb5
VG Name varvg
PV Size 6.00 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 1535
Free PE 1535
Allocated PE 0
PV UUID Hv6qCR-00eO-3GYE-0PkM-jXNV-aHQZ-Xg3Y05
3)创建卷组:
[root@rac2 ~]# vgcreate varvg /dev/sdb5
Volume group "vardg" successfully created
察看
[root@rac2 ~]# vgdisplay
--- Volume group ---
VG Name varvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
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 6.00 GB
PE Size 4.00 MB
Total PE 1535
Alloc PE / Size 0 / 0
Free PE / Size 1535 / 6.00 GB
VG UUID UXfXeP-rC0n-NvPt-ayfh-EUOu-Yut9-Vgvh0j
4、在卷组上创建逻辑卷(LVM):
[root@rac2 ~]# lvcreate -L 3G -n var01 varvg
Logical volume "var01" created
[root@rac2 ~]# ls -rlt /dev/varvg
total 0
lrwxrwxrwx 1 root root 23 Jul 26 23:48 var01 -> /dev/mapper/varvg-var01
5、创建文件系统:
[root@rac2 ~]# mkfs.ext3 /dev/varvg/var01
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
393216 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
6、挂载:
[root@rac2 ~]# mkdir /mnt/lvm
[root@rac2 ~]# mount /dev/varvg/var01 /mnt/lvm
[root@rac2 ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 3020140 253184 2613540 9% /
/dev/sda1 101086 11395 84472 12% /boot
none 127384 0 127384 0% /dev/shm
/dev/sda2 8064304 63500 7591148 1% /home
/dev/sda3 4032124 2593864 1233432 68% /usr
/dev/sda7 2846172 125592 2576000 5% /var
/dev/mapper/varvg-var01
3096336 37416 2901636 2% /mnt/lvm
7)复制数据
考虑到在复制过程中不能产生新数据,进入单用户模式。
#init 1
#cd /
#cp -r /var/* /mnt/lvm
# mv var var.old
如果报var is busy,可先#umount /var 再执行刚才的重命名。
# mkdir var
# umount /mnt/lvm
# mount /dev/varvg/var01 /var
然后,应该设置服务器以使我的新 /home 分区可以在每次启动机器时使用。首先修改 /etc/fstab 以使它包括新的 /var 项:#
# vi /etc/fstab
#
# fs mountpoint type opts dump/pass
/dev/hda3 / reiserfs defaults 1 1
/dev/main/lv_home /home reiserfs defaults 2 2
/dev/hda2 none swap sw 0 0
/dev/hda1 /boot reiserfs noauto 0 0
/dev/cdrom /mnt/cdrom iso9660 noauto,ro 0 0
proc /proc proc defaults 0 0
none /dev/pts devpts mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
8)将之前的分区也加入LVM的管理中,并并入/var分区中。
[root@rac2 ~]#pvcreate /dev/sda7
Physical volume “/dev/sda7” successfully created
[root@rac2 ~]#vgextend –v varvg /dev/sda7
Checking for volume group varvg
Archiving volume group “varvg” metadata (seqno 3)
Adding physical voume ‘/dev/sda7’ to volume group ‘varvg’
Wiping cache of LVM-capable devices
Volume group “varvg” will be extended by 1 new physical volumes
Creating volume group backup “/etc/lvm/backup/varvg”(seqno 4).
Volume group “varvg” successfully extended
[root@rac2 ~]#df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 3020140 253124 2613600 9% /
/dev/sda1 101086 11395 84472 12% /boot
none 127384 0 127384 0% /dev/shm
/dev/sda2 8064304 63500 7591148 1% /home
/dev/sda3 4032124 2593864 1233432 68% /usr
/dev/mapper/varvg-var01
4128448 125740 3793008 4% /var
可用空间增大了,试验是做成功了,但奇怪的是做成功后每次系统启动变慢了很多,主要慢在启动syslogd
(系统提示starting system logger: )
通过察看/var/log/下的日志信息,发现一个很奇怪的问题,LVM配置好后,messages日志就
不纪录系统日志了,时间戳也一直未改变。
感觉LVM更适合存放数据,不适合用来存放系统分区。
哪位大牛能帮助分析一下吗?
[root@rac2 log]#
----------------------------------------------------------------------------
-rw-r--r-- 1 root root 59091 Jul 27 00:03 Xorg.0.log.old
-rw-r--r-- 1 root root 285 Jul 27 00:03 snmpd.log
-rw------- 1 root root 30708 Jul 27 00:03 secure
-rw------- 1 root root 1635273 Jul 27 00:03 messages
-rw------- 1 root root 241864 Jul 27 00:03 boot.log
-rw-r--r-- 1 root root 81 Jul 27 00:23 vmware-tools-guestd
-rw-r--r-- 1 root root 59014 Jul 27 00:44 Xorg.0.log
-rw-r--r-- 1 root root 13511 Jul 31 23:11 dmesg
-rw-rw-r-- 1 root utmp 859776 Jul 31 23:19 wtmp
-r-------- 1 root root 146876 Jul 31 23:19 lastlog
检查syslog未启动,尝试单独启动syslog不成功
[root@rac2 rc3.d]# /etc/init.d/syslog start
Starting system logger:
[failed]
starting kernel logger
个人总结:
1)vgscan 第一次啟用LVM機制一定得執行 vgscan(来源Alex Lin)
2)证明:VG里创建了LV,就不能直接删除,必须先删除LV才能再删vg.
[root@rac2 ~]# vgremove main
Volume group "main" still contains 1 logical volume(s)
[root@rac2 ~]# /usr/sbin/lvdisplay
--- Logical volume ---
VG Name main
LV UUID hCewEx-KykP-W59Q-dO3Y-Ohy1-aC51-2MN8BK
LV Write Access read/write
-------------------------------
[root@rac2 ~]# /usr/sbin/lvremove /dev/main/lv_home
Do you really want to remove active logical volume "lv_home"? [y/n]: y
Logical volume "lv_home" successfully removed
[root@rac2 ~]# vgremove main
Volume group "main" successfully removed
[root@rac2 ~]# vgdisplay
[root@rac2 ~]# pvdisplay
--- NEW Physical volume ---
PV Name /dev/sdb5
VG Name
-------------------------------------
[root@rac2 ~]# pvremove /dev/sdb5
Labels on physical volume "/dev/sdb5" successfully wiped
3) 扩充LV大小用e2fsadm,扩充VG大小用通过将新的PV加到vg里来实现.
参考文档:
1)IBM 林彥明(Alex Lin)的Logical Volume Manager (一)(二).pdf
2) LVM的创建