How can I use LVM snapshots in Ubuntu?

Aleksandr Gornostal

I've installed Ubuntu using these options:

  • Erase the disk and install Ubuntu
  • Encrypt the new Ubuntu installation
  • Use LVM

How can I create LVM snapshots, so that I'm able to revert system changes when it's necessary?

Aleksandr Gornostal

Note: all commands should be done from sudo

First, reduce size of your root volume to make some room for a snapshot volume

  • Boot from Live CD
  • fdisk -l to see name of your device.
    Device       Start       End   Sectors   Size Type
    /dev/sda1     2048   1050623   1048576   512M EFI System
    /dev/sda2  1050624   2050047    999424   488M Linux filesystem
    /dev/sda3  2050048 500117503 498067456 237.5G Linux filesystem
    
    /dev/sda3 in my case
  • cryptsetup luksOpen /dev/sda3 crypt1 to decrypt your volume
  • vgscan --mknodes to find all volume groups
    Reading all physical volumes. This may take a while...
    Found volume group "ubuntu-vg" using metadata type lvm2
    
  • vgchange -ay to activate all your volume groups
    2 logical volume(s) in volume group "ubuntu-vg" now active
    
  • lvreduce -r -L -20G /dev/ubuntu-vg/root to reduce size of your root volume by 20 Gb. This may take a while (it took ~4 min for me).
    That space will later be used to create LVM snapshots.
  • vgs to see that you actually got 20G of free space
    VG           #PV   #LV   #SN   Attr     VSize     VFree
    ubuntu-vg     1      2     0   wz--n-   230.44g   20.01g
    
  • reboot and remove Live CD

Create a snapshot (i.e., activate "experimentation" mode)

Now whenever you want to do something risky with your system, run the following command

  • lvcreate -s -n snap -L 20G /dev/ubuntu-vg/root
    Note: /dev/ubuntu-vg/root is a logical volume that you want to have a snapshot of
  • lvs to see that the volume has been created
    LV     VG            Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
    root   ubuntu-vg     owi-aos--- 201.59g                                                    
    snap   ubuntu-vg     swi-a-s---  20.00g      root   0.00                                   
    swap_1 ubuntu-vg     -wi-ao----  15.90g
    
    The snapshot is active from the moment you run lvcreate. You can now start experimenting with new things.

Scenario #1: You want to revert changes

  • lvconvert --merge /dev/mapper/ubuntu--vg-snap
    Logical volume ubuntu-vg/root contains a filesystem in use.
    Can't merge over open origin volume.
    Merging of snapshot ubuntu-vg/snap will occur on next activation of ubuntu-vg/root.
    
  • reboot

Scenario #2: You want to persist changes

  • lvremove /dev/mapper/ubuntu--vg-snap

In Conclusion

You basically have to run lvcreate to start the process and then either run lvconvert --merge or lvremove to end it.

Keep in mind that when the snapshot is active, due to Copy-On-Write strategy all the changes are saved to those 20Gb of space (or whatever value you set). One way of checking the remaining capacity is to look at Data% column of lvs command.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I put back an accidentally disconnected PV into an LVM VG?

분류에서Dev

Can I use GRUB only when I want to use ubuntu

분류에서Dev

Backup LVM snapshots and Grub2 problem

분류에서Dev

How can I find a Ubuntu package to use with Amazon EC2?

분류에서Dev

How many times can I use a bootable usb flash drive to install Ubuntu

분류에서Dev

How i can use a criteria in cicle for i

분류에서Dev

How do I use the latest GCC on Ubuntu?

분류에서Dev

How can I install GTK themes on Ubuntu?

분류에서Dev

How can I install protoc on Ubuntu 16.04?

분류에서Dev

How can I access the Ubuntu filesystem in Windows?

분류에서Dev

How can I flush the DNS on Ubuntu 17.04?

분류에서Dev

Can I use my USB keyboard and mouse on the Ubuntu flagship tablet

분류에서Dev

How can I use the selected category in a databaseQueryProcessor?

분류에서Dev

How can I use onItemSelected in Android?

분류에서Dev

How can I use relative path in CodeIgniter?

분류에서Dev

How can I use CUDA without the monitor?

분류에서Dev

How can I use sharedPreferences in baseAdapter?

분류에서Dev

How can I use typescript in Aptana Studio?

분류에서Dev

How can I use progressbar in Android

분류에서Dev

How long can i use WSAPI 1.42

분류에서Dev

How can i use data in an array in a query

분류에서Dev

How can i use $_POST if the name is a variable?

분류에서Dev

How can I use another drive with Owncloud?

분류에서Dev

How can I use my backup of Thunderbird

분류에서Dev

How can I use vector for entering numbers?

분류에서Dev

How do I check whether I am using LVM?

분류에서Dev

Can I use Ubuntu installers partition tool (Win 8.1 and Ubuntu 13.04)

분류에서Dev

Can someone help me understand what I'm looking at and how and what I should use to expand my storage for my Ubuntu OS on my dual boot laptop

분류에서Dev

How do I decide which manpage to use on the Ubuntu Manuals site?

Related 관련 기사

  1. 1

    How can I put back an accidentally disconnected PV into an LVM VG?

  2. 2

    Can I use GRUB only when I want to use ubuntu

  3. 3

    Backup LVM snapshots and Grub2 problem

  4. 4

    How can I find a Ubuntu package to use with Amazon EC2?

  5. 5

    How many times can I use a bootable usb flash drive to install Ubuntu

  6. 6

    How i can use a criteria in cicle for i

  7. 7

    How do I use the latest GCC on Ubuntu?

  8. 8

    How can I install GTK themes on Ubuntu?

  9. 9

    How can I install protoc on Ubuntu 16.04?

  10. 10

    How can I access the Ubuntu filesystem in Windows?

  11. 11

    How can I flush the DNS on Ubuntu 17.04?

  12. 12

    Can I use my USB keyboard and mouse on the Ubuntu flagship tablet

  13. 13

    How can I use the selected category in a databaseQueryProcessor?

  14. 14

    How can I use onItemSelected in Android?

  15. 15

    How can I use relative path in CodeIgniter?

  16. 16

    How can I use CUDA without the monitor?

  17. 17

    How can I use sharedPreferences in baseAdapter?

  18. 18

    How can I use typescript in Aptana Studio?

  19. 19

    How can I use progressbar in Android

  20. 20

    How long can i use WSAPI 1.42

  21. 21

    How can i use data in an array in a query

  22. 22

    How can i use $_POST if the name is a variable?

  23. 23

    How can I use another drive with Owncloud?

  24. 24

    How can I use my backup of Thunderbird

  25. 25

    How can I use vector for entering numbers?

  26. 26

    How do I check whether I am using LVM?

  27. 27

    Can I use Ubuntu installers partition tool (Win 8.1 and Ubuntu 13.04)

  28. 28

    Can someone help me understand what I'm looking at and how and what I should use to expand my storage for my Ubuntu OS on my dual boot laptop

  29. 29

    How do I decide which manpage to use on the Ubuntu Manuals site?

뜨겁다태그

보관