Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2722452
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: LINUX

2006-12-22 21:41:49

解决方法:

建议在对包含重要数据的分区作操作之前先在不包含重要数据的文件系统中进行调整大小的测试。强烈建议在调整前文件系统之前创建和校对数据备份。文章接下来部 分描述了一个未分区空间测试逻辑卷和ext3文 件系统调整的方案。

在这个测试过程中,首 先在一个未分区的磁盘空间创建一个分区(假 设为/dev/hda2)。 然后在该分区上创建物理卷,卷组(TestVG)和 逻辑卷(TestLV)。 最后在逻辑卷上创建ext3文 件系统, 检查之后,挂载使 用。用未分区磁盘空间创建新的物理卷(/dev/hda3), 并添加卷组和逻辑卷。最后,调整现有逻辑卷中的文件系统的大小, 并 且检查整个文件系统的数据一致性。

在测试过程中, 用 到parted ,lvm,mount,mkfs.ext3,de,e2fsck和ext2online程 序。读者被鼓励通过阅读命令手册来熟悉程序。例如:

 # man parted 
 PARTED(8) GNU Parted Manual PARTED(8) 
 NAME 
 GNU Parted - a partition manipulation program 
 SYNOPSIS 
 parted [options] [device [command [options...]...]] 
 ...

parted和lvm程 序可以在交互和非交互模式下运行。这篇文章的所有样例都使用非交互模式。可在线查阅parted和lvm程序的内置可用命令, 来理解命令语法。

为新的物理卷创建一个分区。

执行parted命令,并用print显示可用的未分区磁盘空间:

 # parted /dev/hda print 
 Disk geometry for /dev/hda: 0.000-76318.054 megabytes 
 Disk label type: msdos 
 Minor Start End Type Filesystem Flags 
 1 0.031 101.975 primary ext3 boot 
 4 31118.093 76316.594 extended 
 5 31220.099 76316.594 logical ext3 lvm 
 Information: Don't forget to update /etc/fstab, if necessary. 

这种情况下,parted print命令显示设备/dev/hda从101.975(分 区1的 末端)到31118.093(分 区4的 开始)间 仍有未分配空间。

用parted mkpart命令在可用磁盘空间中创建分区,然后用parted print命令验证:

 # parted /dev/hda "mkpart primary 101.976 2500" 
 Information: Don't forget to update /etc/fstab, if necessary. 
 # parted /dev/hda print 
 Disk geometry for /dev/hda: 0.000-76318.054 megabytes 
 Disk label type: msdos 
 Minor Start End Type Filesystem Flags 
 1 0.031 101.975 primary ext3 boot 
 2 101.975 2502.312 primary ext3 
 4 31118.093 76316.594 extended 
 5 31220.099 76316.594 logical ext3 lvm 
 Information: Don't forget to update /etc/fstab, if necessary. 

在新分区上创建逻辑卷

lvm可用于操作LVM2卷 组、逻辑卷和物理卷。首先,用lvm pvs列出已存在的物理卷。然后用pvcreate在 新分区上创建物理卷,然后再次执行lvm pvs验 证物理卷:

 # lvm pvs 
 PV VG Fmt Attr PSize PFree 
 /dev/hda5 VolGroup00 lvm2 a- 44.03G 0 
 # lvm pvcreate /dev/hda2 
 Physical volume "/dev/hda2" successfully created 
 # lvm pvs 
 PV VG Fmt Attr PSize PFree 
 /dev/hda2 lvm2 -- 2.34G 2.34G 
 /dev/hda5 VolGroup00 lvm2 a- 44.03G 0 

为一个新的逻辑卷创建卷组

创建一个新的卷组前,至少要有一个物理卷是可用的。物理卷用于创建卷组.注意本例中'VolGroup00'卷 组已存在:

 # lvm vgs 
 VG #PV #LV #SN Attr VSize VFree 
 VolGroup00 1 2 0 wz--n 44.03G 0 
 # lvm vgcreate TestVG /dev/hda2 
 Volume group "TestVG" successfully created 
 # lvm vgs 
 VG #PV #LV #SN Attr VSize VFree 
 TestVG 1 0 0 wz--n 2.34G 2.34G 
 VolGroup00 1 2 0 wz--n 44.03G 0 

注 意卷组需要用lvm vgchange -a y激活:

 # lvm vgchange -a y TestVG 
 0 logical volume(s) in volume group "TestVG" now active 
 Now there is a new directory in /dev for the volume group: 
 # ls -ld /dev/TestVG 
 drwx------ 2 root root 60 Jan 17 17:48 /dev/TestVG 

在 新卷组中创建一个测试逻辑卷

将 所有卷组的自然限度(可 用磁盘空间)分 配给一个新的逻辑卷。用 lvm vgdisplay 显示TestVG卷 组的详细信息:

 # lvm vgdisplay TestVG 
 --- Volume group --- 
 VG Name TestVG 
 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 2.34 GB 
 PE Size 4.00 MB 
 Total PE 598 
 Alloc PE / Size 0 / 0 
 Free PE / Size 598 / 2.34 GB 
 VG UUID ebStj9-3KYx-asoc-JBt3-N9kU-vONW-4VdpTB 

卷 组的空闲范围是"Free PE / Size 598 / 2.34 GB",可以用value 598在lvm lvcreate中 创建一个逻辑卷:

 # lvm lvs 
 LV VG Attr LSize Origin Snap% Move Copy% 
 LogVol00 VolGroup00 -wi-ao 43.03G 
 LogVol01 VolGroup00 -wi-ao 1.00G 
 # lvm lvcreate -l598 TestVG -nTestLV 
 Logical volume "TestLV" created 
 # lvm lvs 
 LV VG Attr LSize Origin Snap% Move Copy% 
 TestLV TestVG -wi-a- 2.34G 
 LogVol00 VolGroup00 -wi-ao 43.03G 
 LogVol01 VolGroup00 -wi-ao 1.00G 

现 在在目录/dev/TestVG下 创建了一个新设备:

 # ls -l /dev/TestVG 
 total 0 
 lrwxrwxrwx 1 root root 25 Jan 17 17:48 TestLV -> /dev/mapper/TestVG-TestLV

新设备是个符号链接,它链接到/dev/mapper/TestVG-TestLV,其节点由device-mapper创建。

在 新逻辑卷上创建一个文件系统.

逻 辑卷上的新文件系统用程序mkfs.ext3 创建:

 # mkfs.ext3 /dev/TestVG/TestLV 
 mke2fs 1.35 (28-Feb-2004) 
 max_blocks 627048448, rsv_groups = 19136, rsv_gdb = 149 
 Filesystem label= 
 OS type: Linux 
 Block size=4096 (log=2) 
 Fragment size=4096 (log=2) 
 306432 inodes, 612352 blocks 
 30617 blocks (5.00%) reserved for the super user 
 First data block=0 
 Maximum filesystem blocks=629145600 
 19 block groups 
 32768 blocks per group, 32768 fragments per group 
 16128 inodes per group 
 Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912 
 Writing inode tables: done 
 inode.i_blocks = 7160, i_size = 4243456 
 Creating journal (8192 blocks): done 
 Writing superblocks and filesystem accounting information: done  
 This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

用e2fsck检 测文件系统:

 # e2fsck -f /dev/TestVG/TestLV 
 e2fsck 1.35 (28-Feb-2004) 
 Pass 1: Checking inodes, blocks, and sizes 
 Pass 2: Checking directory structure 
 Pass 3: Checking directory connectivity 
 Pass 4: Checking reference counts 
 Pass 5: Checking group summary information 
 /dev/TestVG/TestLV: 11/306432 files (9.1% non-contiguous), 18728/612352 blocks

安 装新文件系统

先 创建一个安装点,在这个安装点上安装新的逻辑卷文件系统。安装后,运 行df来 校验可用磁盘空间:

 # mkdir /mnt/test 
 # mount /dev/TestVG/TestLV /mnt/test 
 # df -h /mnt/test 
 Filesystem Size Used Avail Use% Mounted on 
 /dev/mapper/TestVG-TestLV 
 2.3G 36M 2.2G 2% /mnt/test

LVM大小调整步骤如下。

这 是调整文件系统大小的大体步骤。首先添加一个物理卷。

在 这之前,创建一个分区以供物理卷使用。使用parted,运 行print查 看分区,然 后用mkpart创 建一个分区:

 # parted /dev/hda print 
 Disk geometry for /dev/hda: 0.000-76318.054 megabytes 
 Disk label type: msdos 
 Minor Start End Type Filesystem Flags 
 1 0.031 101.975 primary ext3 boot 
 2 101.975 2502.312 primary ext3 
 4 31118.093 76316.594 extended 
 5 31220.099 76316.594 logical ext3 lvm 
 Information: Don't forget to update /etc/fstab, if necessary.

2502.312(分 区2末)和31118.093(分 区4始)之 间 有可用的未分区磁盘空间:

 # parted /dev/hda "mkpart primary 2502.313 31118.092" 
 Information: Don't forget to update /etc/fstab, if necessary. 
 # parted /dev/hda print 
 Disk geometry for /dev/hda: 0.000-76318.054 megabytes 
 Disk label type: msdos 
 Minor Start End Type Filesystem Flags 
 1 0.031 101.975 primary ext3 boot 
 2 101.975 2502.312 primary ext3 
 3 2502.312 31118.093 primary 
 4 31118.093 76316.594 extended 
 5 31220.099 76316.594 logical ext3 lvm 
 Information: Don't forget to update /etc/fstab, if necessary.
 # ls -l /dev/TestVG 
 total 0 
 lrwxrwxrwx 1 root root 25 Jan 17 17:48 TestLV -> /dev/mapper/TestVG-TestLV

创建物理卷

和之前一样在/dev/hda3上 用lvm pvcreate创建一个物理卷:

 # lvm pvs 
 PV VG Fmt Attr PSize PFree 
 /dev/hda2 TestVG lvm2 a- 2.34G 0 
 /dev/hda5 VolGroup00 lvm2 a- 44.03G 0 
 # lvm pvcreate /dev/hda3 
 Physical volume "/dev/hda3" successfully created 
 # lvm pvs 
 PV VG Fmt Attr PSize PFree 
 /dev/hda2 TestVG lvm2 a- 2.34G 0 
 /dev/hda3 lvm2 -- 27.94G 27.94G  
 /dev/hda5 VolGroup00 lvm2 a- 44.03G 0

在 卷组中添加物理卷

用lvm vgextend命 令将物理卷添加到TestVG卷 组中:

 # lvm vgextend TestVG /dev/hda3 
 Volume group "TestVG" successfully extended 
 # lvm pvs 
 PV VG Fmt Attr PSize PFree  
 /dev/hda2 TestVG lvm2 a- 2.34G 0 
 /dev/hda3 TestVG lvm2 a- 27.94G 27.94G 
 /dev/hda5 VolGroup00 lvm2 a- 44.03G 0

在 卷组中扩展逻辑卷

和 之前一样,首 先用命令lvm vgdisplay查看物理卷的范围。它显示TestVG在"Free PE / Size 7153 / 27.94 GB"中 有7153个 空闲的范围区域:

# lvm vgdisplay TestVG 
--- Volume group --- 
VG Name TestVG 
System ID 
Format lvm2 
Metadata Areas 2 
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 2 
Act PV 2 
VG Size 30.28 GB 
PE Size 4.00 MB 
Total PE 7751 
Alloc PE / Size 598 / 2.34 GB 
Free PE / Size 7153 / 27.94 GB 
VG UUID ebStj9-3KYx-asoc-JBt3-N9kU-vONW-4VdpTB

若想使用卷组上所有的空闲物理卷,使用 lvextend 命令和选项“-l+7153” 来完成操作。将空闲7153M空间添加到逻辑卷:

# lvm lvextend -l+7153 /dev/TestVG/TestLV
Extending logical volume TestLV to 30.28 GB
Logical volume TestLV successfully resized

此时的文件系统拥有足够的空间供逻辑卷扩展调整文件系统。扩展卷组和逻辑卷后,就可以调整文件系统了.用 ext2online来完成。首先校验文件系统大小,执行调整,然后再次确认大小:

# df -h /mnt/test 
Filesystem Size Used Avail Use% Mounted on 
/dev/mapper/TestVG-TestLV 
2.3G 36M 2.2G 2% /mnt/test 
# ext2online /dev/TestVG/TestLV 
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b 
# df -h /mnt/test 
Filesystem Size Used Avail Use% Mounted on 
/dev/mapper/TestVG-TestLV 
30G 39M 29G 1% /mnt/test

调整后检验文件系统的完整性,检验文件系统之前需要把文件系统卸载。否则有如下提示

# e2fsck -f /dev/TestVG/TestLV 
e2fsck 1.35 (28-Feb-2004) 
/dev/TestVG/TestLV is mounted. 
WARNING!!! Running e2fsck on a mounted filesystem may cause 
SEVERE filesystem damage. 
Do you really want to continue (y/n)? no 
check aborted.

卸 载文件系统,检查文件系统。

# umount /mnt/test 
# e2fsck -f /dev/TestVG/TestLV 
e2fsck 1.35 (28-Feb-2004) 
Pass 1: Checking inodes, blocks, and sizes 
Pass 2: Checking directory structure 
Pass 3: Checking directory connectivity 
Pass 4: Checking reference counts 
Pass 5: Checking group summary information 
/dev/TestVG/TestLV: 11/3919104 files (9.1% non-contiguous), 132827/7937024 blocks

结论

联机调整文件系统的测试过程非常复杂.所 以在实际操作中,对程序和命令的熟悉十分重要,诸如备份重要数据等操作时,一定要做好预防措施,这 样才能在调整文件系统时万无一失。

阅读(1680) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~