Выбрать главу

Read ahead sectors 0

Block device 253:3

--- Logical volume ---

LV Name /dev/main/multimedia-snap

VG Name main

LV UUID 7U5wVQ-qIWU-7bcz-J4vT-zAPh-xGVN-CDNfjx

LV Write Access read/write

LV snapshot status active destination for /dev/main/multimedia

LV Status available

# open 0

LV Size 512.00 MB

Current LE 128

COW-table size 128.00 MB

COW-table LE 32

Allocated to snapshot 0.02%

Snapshot chunk size 8.00 KB

Segments 1

Allocation inherit

Read ahead sectors 0

Block device 253:6

This display shows the volume group, attributes (again, see man lvm ), and logical volume size. Additional information is shown for snapshot volumes and LVs that are being copied or moved between PVs. The Block device shown in the lvdisplay output is the major and minor device number.

6.1.1.3.3. Growing a logical volume

To increase the size of a logical volume, use the lvextend command:

# lvextend /dev/main/multimedia --size 1G

Extending logical volume multimedia to 1.00 GB

Logical volume multimedia successfully resized

Specify the LV device as the first argument, and use the --size option to specify the new size for the volume. Use a numeric size with one of the size suffixes from Table 6-2 as the value for the --size option.

Table 6-2. Size suffixes used by LVM

Suffix Name Size Approximation
k, K Kibibyte (kilobyte) 210 = 1,024 bytes Thousand bytes
m, M Mebibyte (megabyte) 220 = 1,048,576 bytes Million bytes
g, G Gibibyte (gigabyte) 230 = 1,073,741,824 bytes Billion bytes
t, T Tebibyte (terabyte) 240 = 1,099,511,627,776 bytes Trillion bytes

Once you have resized the LV, resize the filesystem contained inside:

#

resize2fs /dev/main/multimedia

resize2fs 1.39 (29-May-2006)

Resizing the filesystem on /dev/main/multimedia to 1048576 (1k) blocks.

The filesystem on /dev/main/multimedia is now 1048576 blocks long.

Note that you do not need to specify the filesystem size; the entire LV size will be used.

If the resize2fs fails with the message No space left on device, the new size is too large for the existing allocation tables

6.1.1.3.4. Shrinking a logical volume

Before reducing the size of a logical volume, you must first reduce the size of the filesystem inside the LV. This must be done when the filesystem is unmounted:

# umount /dev/main/multimedia

Next, run a filesystem check to verify the integrity of the filesystem. This is required in order to prevent data loss that may occur if there is data near the end of the filesystem (this is the area that will be freed up by shrinking) and that data is not properly accounted for in the filesystem tables:

# fsck -f /dev/main/multimedia

e2fsck 1.38 (30-Jun-2005)

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/main/multimedia: 11/117248 files (9.1% non-contiguous), 8043/262144 blocks

Now use resize2fs to reduce the size of the filesystem:

# resize2fs /dev/main/multimedia 740M

resize2fs 1.38 (30-Jun-2005)

Resizing the filesystem on /dev/main/multimedia to 189440 (4k) blocks.

The filesystem on /dev/main/multimedia is now 189440 blocks long.

Note that resize2fs expects the size to be the second argument (there is no --size option as there is with the LVM commands).

The LVM commands accept sizes containing decimals (such as 1.2G), but resize2fs does not; use the next smaller unit to eliminate the decimal point (1200M). 

Both the filesystem commands and the LVM commands round off sizes to the closest multiple of their internal allocation units. This means that resize2fs and lvreduce may interpret a size such as 750M slightly differently. In order to avoid the potential disaster of resizing the LV to be smaller than the filesystem, always resize the filesystem so that it is slightly smaller than the planned LV size, resize the LV, and then grow the filesystem to exactly fill the LV. In this case, I'm resizing the filesystem to 740 MB and will resize the LV to 750 MB.

Now that the filesystem has been resized, you can shrink the logical volume:

# lvreduce /dev/main/multimedia --size 750M

Rounding up size to full physical extent 752.00 MB

WARNING: Reducing active logical volume to 752.00 MB

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce multimedia? [y/n]: y

Reducing logical volume multimedia to 752.00 MB

Logical volume multimedia successfully resized