回忆之城
生命在于折腾
posts - 510,comments - 9,trackbacks - 0
(From http://kbase.redhat.com/faq/FAQ_96_4842.shtm)

It is recommended that a resizing procedure be tested before performing it on a filesystem that contains critical data. It is also strongly recommended that data backups are created and verified before resizing filesystems. To assist the reader in becoming familiar with the resizing procedure, the rest of this article describes a scenario in which un-partitioned disk space is used to test logical volume and ext3 filesystem resizing.

In this test procedure, first we create a new partition (/dev/hda2) using un-partitioned disk space. A new volume group (TestVG) and logical volume (TestLV) are then created using a physical volume created on the partition. An ext3 filesystem is then created on the logical volume, it is checked, and then mounted. A new physical volume (/dev/hda3) using the rest of the un-partioned disk space is then created and added to the volume group and logical volume. Finally, the filesystem on the logical volume is resized, and the integrity of the filesystem is checked.

In this test procedure, the parted, lvm, mount, mkfs.ext3, df, e2fsck and ext2online programs are used. The reader is encouraged to become familiar with these programs by consulting the manual pages. For example:

# man parted

PARTED(8) GNU Parted Manual PARTED(8)

NAME
GNU Parted - a partition manipulation program

SYNOPSIS
parted [options] [device [command [options...]...]]
...

The parted and lvm programs can be run in either interactive or non-interactive mode. This article restricts all the examples to non-interactive modes. The reader is also encouraged to consult theparted and lvm online help available for all their built in commands to understand the command syntax for these programs.

Creating a new partition for the new physical volume

The parted program can be used to verify that un-partitioned disk space is available using the print command:

# 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.

In this case the output of the parted print command shows that there is unallocated space between 101.975 (At the end of partition 1) to 31118.093 (The beginning of partition 4) on the /dev/hdadevice.

A new partition is created using only some of the available disk space, using the parted mkpart command, then the print command is used to verify:

# 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.

Create the new physical volume on the new partition

The lvm program is used to manipulate LVM2 volume groups, logical volumes and physical volumes. First use the lvm pvs command to list the physical volumes already present. Then the pvcreate command is used to create the new physical volume using the new partition, and the pvs again to verify the new physical volume:

# 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

Create a new volume group for a new logical volume

When creating a new volume group, at least one physical volume must be available. That physical volume must be used to create the new volume group. Notice that a volume group called 'VolGrouop00' already exists:

# 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

Note that new volume groups must be activated using the lvm vgchange -a y command:

# 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

Create a test logical volume in the new volume group

In this case I wish to allocate all of the volume group's physical extent (available disk space) to a new logical volume. First I use the lvm vgdisplay command to show details of the TestVG volume group:

# 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

The total free physical extent of the volume group is "Free PE / Size 598 / 2.34 GB", so I will use the value 598 in the lvm lvcreate command to create the new logical volume:

# 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

Now a new device has been added to the /dev/TestVG directory:

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

The new device is in fact a symbolic link to /dev/mapper/TestVG-TestLV which is the device node created by the device mapper.

Create a file system on the new logical volume

The new file system on the logical volume is created by using the mkfs.ext3 program:

# 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.

Then check the file system using e2fsck program:

#  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

Mount the new file system

Before mounting the new file system , I create a new mount point, then mount the new logical volume's file system on that mount point. After mounting the file system, I ran the df program to verify the disk space available:

# 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

The resize test procedure

This is the general procedure to resize a filesystem. Begin by adding a new physical volume.

Create a new partition that will contain a new physical volume

Using parted as before, I run the print command to view the partitions, and then mkpart to create a new partition:

# 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.

There is un-partitioned disk space available between 2502.312 (The end of partition 2) and 31118.093 (The beginning of partition 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.

Create the physical volume

The new physical volume is created as before, by running the lvm pvcreate command. The new physical volume will be on /dev/hda3:

# 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

Add the physical volume to the volume group

The physical volume is added to the TestVG volume group using the lvm vgextend command:

# 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

Extend the logical volume in the volume group

As before, first look at the physical extent of the volume group using the lvm vgdisplay command. It shows that TestVG has 7153 free extents in "Free PE / Size 7153 / 27.94 GB":

# 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

I wish to use all the free physical extents on the volume group. I do this using the lvm lvextend command with the option -l+7153 . This adds the 7153 free extents to the logical volume:

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

The file system now has space on the logical volume in which to grow.

Resize the file system

After extending the volume group and the logical volume, it is now possible to resize the file system. This is done using ext2online. First I verify the file system size, perform the resize, and then verify the size again:

# 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

Check the file system integrity after the resize

The file system should be un-mounted before doing a file system check:

#  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

Conclusion

The procedure to test online resizing of filesystems is quite complex. So it is important to practice the procedure and become familiar with the programs and commands. Once this is done, and reasonable precautions such as backing up important data are taken, it should be safe to resize your filesystems.

The information provided in this document is for your information only. The origin of this information may be internal or external to Red Hat. While Red Hat attempts to verify the validity of this information before it is posted, Red Hat makes no express or implied claims to its validity.

© 2003-2006 Red Hat, Inc. All rights reserved. This article is made available for copying and use under the Open Publication License, v1.0 which may be found athttp://www.opencontent.org/openpub/.


posted on 2013-12-02 18:45 回忆之城 阅读(77) 评论(0)  编辑 收藏 引用 所属分类: unix/linux
只有注册用户登录后才能发表评论。