Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to try the snapshot functionality but I don't understand all the picture.
I'm on Ubuntu server 11.10 and I've created two Volume Group and some Logical Volumes inside like this:

root@darwin:~# vgdisplay
      --- Volume group ---
      VG Name               data
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  2
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               272.24 GiB
      PE Size               4.00 MiB
      Total PE              69694
      Alloc PE / Size       69694 / 272.24 GiB
      Free  PE / Size       0 / 0
      VG UUID               YRDCLM-ZfZN-kCoi-PIse-qMdn-2MBm-OmegqH

      --- Volume group ---
      VG Name               os
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  4
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                3
      Open LV               3
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               67.75 GiB
      PE Size               4.00 MiB
      Total PE              17343
      Alloc PE / Size       17343 / 67.75 GiB
      Free  PE / Size       0 / 0
      VG UUID               ZRX1mD-CyhV-7u9f-15bh-2rnT-Nbee-1QD20u
root@darwin:~# lvdisplay
  --- Logical volume ---
  LV Name                /dev/data/var
  VG Name                data
  LV UUID                FuJlvb-NZ3H-YoaO-6Qsn-SYuz-QaHb-Ms2YtX
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                272.24 GiB
  Current LE             69694
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Name                /dev/os/boot
  VG Name                os
  LV UUID                HE0izv-zuXu-0cZT-L3o2-O9Cj-5wEX-R4O6SB
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                188.00 MiB
  Current LE             47
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

  --- Logical volume ---
  LV Name                /dev/os/swap
  VG Name                os
  LV UUID                4hlke0-kl3r-xVbN-Myjz-dH6H-hkRI-Uh7ncl
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                1.86 GiB
  Current LE             476
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2

  --- Logical volume ---
  LV Name                /dev/os/root
  VG Name                os
  LV UUID                7qpM1B-DjHp-v6Ju-Ia4L-TPtP-5sCF-UR6Mr3
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                65.70 GiB
  Current LE             16820
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:3

and this is the df -h:

root@darwin:~# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/os-root    65G  1.1G   61G   2% /
    udev                  2.0G   12K  2.0G   1% /dev
    tmpfs                 792M  244K  792M   1% /run
    none                  5.0M     0  5.0M   0% /run/lock
    none                  2.0G     0  2.0G   0% /run/shm
    /dev/mapper/data-var  268G  528M  254G   1% /var
    /dev/mapper/os-boot   183M   51M  123M  30% /boot

At this point I don't understand if I need to shirink one LV making space for a new partition that will contains the snapshot, 'cause I tried to create a new LV but it says that there isn't enougth space. Am I right? If so, what is the correct way to shrink? For now, I want to create a snapshot of /

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Shrinking filesystems is possible but has its risks and is not recommended. It's going to be doubly difficult because the filesystem you'll likely need to shrink is /var - filesystems must be unmounted to shrink them (unlike growing, which is an online operation), so you'll need to boot from a recovery disc to do so. (It might be possible in single-user mode too.)

Procedure:

# Make sure /var is not mounted
umount /var
# Resize ext3 filesystem
resize2fs /dev/data/var <newsize>
# Resize LV
lvreduce -L <newsize> /dev/data/var

I'd also run an fsck of the volume once it's done to ensure there are no errors in the filesystem.

Make sure that you take into account that the LV size must be greater than the filesystem size - in your case at least 4MB larger as that's the physical extent size.

Have a read of the resize2fs and lvreduce man pages to understand the size specifications - in particular of lvreduce -L.

share|improve this answer
    
Ok I'll try with an ubuntu live cd. It's not a problem losing data, It's a fresh new install so if I lose something I can reformat and reinstall. Another thing that I don't understand, the LV for the snapshot must be the same (or greater) size of the used space in the partition I want to backup? Maybe a "future" dimension...? –  Kreker Feb 21 '12 at 15:30
add comment

Linux Logical Volume Manager (LVM) is based on HP-UX LVM - which is in turn, based on Veritas VxVM.

One important difference between Linux LVM and HP-UX LVM is that a snapshot in Linux requires a preconfigured logical volume to act as the repository for snapshot data.

According to your vgdisplay, you've no space left on either volume:

  Free  PE / Size       0 / 0

You do need to reduce volumes. Most filesystems do not support shrinking - and those that do do not recommend the practice. Apparently, XFS and JFS won't reduce (although XFS filesystems can be made larger). The filesystem ext2fs does support shrinking, but it's not a recommended practice: are you sure you won't lose some data?

Best practice is to do the following:

  1. Backup the volume to shrink - use rsync or a dump variant.
  2. Boot to a rescue disk - one that supports LVM.
  3. Use lvreduce to reduce the size of the logical volume.
  4. Use mkfs to create a fresh filesystem.
  5. Use dump or rsync to recreate the filesystem from backup.
  6. Reboot.

This is an invasive process and requires backup! If you've no backups (check that they are good!) then you will lose data!

share|improve this answer
    
I think I will recreate the VG and reformat all system. Is a good thing to not partition all the space for using it in the future for all the LV? –  Kreker Feb 22 '12 at 7:44
    
The best partitioning scheme is an on-going debate; because of the size of disks today some recommend a single partition for everything. Me, I recommend partitioning: /var /tmp /home and / at least - and perhaps /usr. If you're running a database, putting the database on its own partion is probably good too. With partitions you can use different options for each partition if you like. –  Mei Feb 22 '12 at 15:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.