Chinaunix首页 | 论坛 | 博客
  • 博客访问: 852212
  • 博文数量: 275
  • 博客积分: 3904
  • 博客等级: 中校
  • 技术积分: 4605
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-17 21:10
文章分类

全部博文(275)

文章存档

2014年(9)

2013年(124)

2012年(142)

分类: 系统运维

2013-04-08 10:40:56

办理 行动 :

提议在对包孕 重要 数据的分区作操纵 之前先在不包孕 重要 数据的文件体系 中举办调度 巨细 的。凶猛提议在调度 前文件体系 之前创建 和校订 数据备份。文章接下来部 分刻画 了一个未分区空间测试逻辑卷和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 

结论

联机调度 文件体系 的测试过程非常繁杂 .所 以在实际 操纵 中,对和下令 的熟识 异常重要 ,诸如备份重要 数据等操纵 时,肯定 要做好防备 法子,这 样手法在调度 文件体系 时十拿九稳 。

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