Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Disks and Volumes, Featured, Filesystems

Linux LVM: Reduce Filesystem and Logical Volume

Submitted by on March 14, 2012 – 5:07 pm 7 Comments

The following example shows how to reduce the size of a filesystem mounted on an LVM logical volume. The instructions below are only for non-root filesystems. No reboot is required, but the filesystem will need to be unmounted. So, if there are any user applications using this filesystem, they will need to be stopped and the users will need to log out.

Example:

Mountpoint: /data
Disk device: /dev/VolGroup01/LogVol00
Filesystem type: ext3

Important: Prior to proceeding with the steps below, create a backup of /data (or whatever is the name of the filesystem you are resizing) using “tar” or “rsync”. Make sure the destination filesystem has sufficient space.

Example:

Using “tar”:

cd / ; tar cvf data.tar /data

Using “rsync”:

cd / ; mkdir /data_backup ; rsync -avu /data/ /data_backup/
  1. Unmount filesystem:a. Check for any processes using the filesystem:
    lsof | grep /data

    b. Terminate these processes (if any):

    Using “while” loop and “kill”:

    lsof | grep /data | awk '{print $2}' | sort | uniq | while read line
    do
    	kill -9 ${line}
    done

    Or using “fuser”:

    fuser -k /data

    Unmount the filesystem:

    umount -f /data

    If that fails with a “busy” error, then try:

    umount -l /data
  2. Scan the logical disk device and fix any inconsistencies:
    e2fsck -f /dev/VolGroup01/LogVol00

    Sample output:

    e2fsck 1.39 (29-May-2006)
    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/VolGroup01/LogVol00: 3880/9830400 files (1.0% non-contiguous), 380181/19658752 blocks
  3. Resize the logical disk device (this example shows resizing down to 19GB):
    resize2fs /dev/VolGroup01/LogVol00 19456M

    Sample output:

    resize2fs 1.39 (29-May-2006)
    Resizing the filesystem on /dev/VolGroup01/LogVol00 to 4980736 (4k) blocks.
    The filesystem on /dev/VolGroup01/LogVol00 is now 4980736 blocks long.
  4. Resize the logical volume to something slightly bigger than the new filesystem size:
    lvresize -L 20G /dev/VolGroup01/LogVol00

    Sample output:

    WARNING: Reducing active logical volume to 20.00 GB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce LogVol00? [y/n]: y
    Reducing logical volume LogVol00 to 20.00 GB
    Logical volume LogVol00 successfully resized
  5. Verify the new size of the logical volume:
    lvdisplay /dev/VolGroup01/LogVol00

    Sample output:

    --- Logical volume ---
    LV Name                /dev/VolGroup01/LogVol00
    VG Name                VolGroup01
    LV UUID                GT3KXD-UUa3-CTJo-cMDo-BKIc-Lrux-t5nVwG
    LV Write Access        read/write
    LV Status              available
    # open                 0
    LV Size                20.00 GB
    Current LE             5120
    Segments               2
    Allocation             inherit
    Read ahead sectors     auto
    - currently set to     256
    Block device           253:2
  6. Remount the filesystem and verify new size:
    mount /dev/VolGroup01/LogVol00
    
    df -h /data
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/VolGroup01-LogVol00
    19G  273M   18G   2% /data
Print Friendly, PDF & Email

7 Comments »

  • ericmreitz says:

    3. The temperature of evaporation is much higher for water than alcohol. Without knowing more about the chemistry of alcohol, which of the follwing is the most logical chemical explanation for this phenomenon?

    a. Ionic bonds form between alcohol molecules. These are the weakest type of bond and are easier to break than the hydrogen bonds between water molecules.
    b. fewer hydrogen bonds form between alcohol molecules. As a result, less heat is needed for alcohol molecules to break away from solution and enter the air.
    c. Alcohol has a higher surface tension than water. this means that alcohol molecules can easily break away from other alcohol molecules and evaporate at a lower temp.
    d. Alcohol molecules are more cohesive than water molecules. this means that as alcohol molecules evaporate, they pull other alcohol molecules into the air along with them.

    4. Photosynthesis requires many steps to make glucose. As a result of the synthesis process,

    a. all carbons from the six carbon dioxide atoms are found in glucose
    b. water is synthesized by plant from H2 and O2.
    c. More atoms are present at the beginning than at the end.

    5. Which of the following will contain more heat but has a lower temp?
    a. an olymic-sized heated indoor swimming pool
    b. the water used in a dishwasher
    c. the boiling water in a pot for noodles
    d. a gas-powered lawnmower engine after it has been used for an hour.

  • HASTHEANSWERS says:

    Please show as much science as you can. I’m interested.
    I always thought it was because of the magnetic poles being on 2 opposite sides of the earth, creating a circle of matter around it. Is this true?
    Please don’t act like I’m retarded. Any answers making fun of me will be reported and thumbed down.

  • Krazy Bob says:

    i convert my basic volume to dynamic and i don’t know how i can ? and i click one of my volume (mark as active) so i can run only one OS.i follow the instruction given by disk management help but it does’t work.

  • Mike says:

    We are building a new house and it will be “roughed-in” for CV.

    My question is this: When they rough it in, where is the best place to have the unit mounted? Naturally, the utility room in the unfinished part of the basement is a logical place but I’d heard that having it in the garage would cut down on the minute dust particles that don’t get filtered. As well, having it in the garage would make it quieter. Then, when I mentioned this to my agent, he said that having that volume of air being sucked out of the house while vacuuming (in the winter, when the windows would always be closed) would cause air to try to re-enter the house wherever it can, be it through window or door frames, therefore causing an obvious problem.

  • Arminator says:

    I have a IBM server with a 3 drive raid 5 array (Serveraid 7k) that has one logical drive and two partitions (boot and data). I added an additional physical drive in the array, how to I expand my data partition live without losing data? Will running LDM to expand the logical drive repartition/format it?

  • Denali says:

    Hello, i brought a new laptop re loaded with windows vista. so when i looked at the partitions i saw a logical drive and i deleted it because i don’t use it, now the partition is a “d: 108GB RAW” and its us-less…

    so how do i remake a logical drive and don’t have a reinstall windows vista and i don’t want any boot loader to come when i make my d drive a logical drive.

    HELP?

  • ouch says:

    According to Archimedes’s Principle, the buoyant force exerts on the submerged object equals to the weight of the displaced liquid. However, it doesn’t make logical sense to me.
    Let’s I replaced a 10 kg block into the fresh water and it’s completely submerged in the water.Then weight of the displaced water is roughly 100 N according to Archimedes’ Principle.
    Now, if I replaced another identical iron block into the oil, then I’m pretty sure it will displaced the same amount of force, which is also 100 N.
    However, since the density of water and oil are not the same, by holding the weight in constant means the volume of both fluids being displaced is different. In the other words, the iron cube displaced a larger volume of oil than the water [since oil’s density is smaller, which makes the volume to be bigger].
    It just doesn’t make sense to me. I thought the volume of displacement will be the same regardless of the fluid’s density.
    Let’s say my cube is 0.1 m^3 and I replaced it into a beaker with full of water, my instinct tells me that there has to be 0.1 m^3 of volume being replaced. Therefore, it will displace 0.1 m^3 of water if it’s in the water solution and 0.1 m^3 of oil if it’s in the oil solution.
    But, according to Archimedes, he said that only the weight of the displaced fluid will be same.
    I know I have some misconception [otherwise Archimedes is wrong, which seems to be impossible], but I don’t know where I went wrong.
    If the volume of displaced water is less than that of oil, how so?
    I learn it in the math class; if you take out some volume, then you just subtract off the number [regardless of its shape. In science, regardless of its density].

Leave a Reply to HASTHEANSWERS Cancel reply

%d bloggers like this: