btrfs root and yum update snapshots

ok so now it's Monday and I found a few minutes to continue my weekend project at work :)

Today, I want to take my OL6.1 with UEK setup and convert the root ext4 partition to btrfs. Then use yum update to create a snapshot before rpm installs/updates so that if something goes wrong, one can revert back to the original state.
here's my story :

The default OL6 install uses ext4 for the root fileystem(/). So the first step in my test is to convert the ext4 filesystem into a btrfs filesystem. The cool thing is that btrfs actually lets you do that, there's a tool called btrfs-convert which takes a volume as an argument and then converts ext[2,3,4] to btrfs and leaves the original ext[2,3,4] as a snapshot so you can even go back to it if you want to.

In order to do this I did the following :

- prepared my initrd to have btrfs built in. rebuilt it running mkinitrd using --with-module=btrfs. this way, the kernel module for the btrfs filesystem is included in the initrd.
- find a boot ISO that has btrfs-convert on it (not yet on the OL6 ISOs)
- reboot the machine in rescue mode off of the ISO image
- run btrfs-convert on the root volume in my case it was /dev/mapper/vg_wcoekaersrv3-lv_root
- edit etc/fstab

/dev/mapper/vg_wcoekaersrv3-lv_root /                       ext4    defaults        1 1
to
/dev/mapper/vg_wcoekaersrv3-lv_root /                       btrfs    defaults        1 1
- reboot OL6 again
- at reboot OL presents a message saying that selinux has to re-label the files. This will take a few minutes and a reboot will automatically follow again

From this point on, you have OL6 running with btrfs as root filesystem.

# mount
/dev/mapper/vg_wcoekaersrv3-lv_root on / type btrfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

The original ext snapshot is still available as a subvolume :
# btrfs subvolume list /
ID 256 top level 5 path ext2_saved
I don't need it any more so I am just going to throw it out :
# btrfs subvolume delete /ext2_saved
Delete subvolume '//ext2_saved'

# btrfs subvolume list /
Just to run optimally, it's a good idea to de-fragment the volume as we inherit the old ext4 layout.
# btrfs filesystem defragment /
There. done.
Next up - make sure the yum-plugin-fs-snapshot is installed
# rpm -qa|grep yum-plugin
yum-plugin-fs-snapshot-1.1.30-6.el6.noarch
If not, then just run yum install yum-plugin-fs-snapshot it's on the OL6 media/ULN

So, now the big experiment. I want to do a yum update. Thanks to the installed plugin, yum will detect that the filesystem is btrfs and it will automatically, prior to installing new rpms, create a snapshot, then install.
In this case a long list, I just added bold fonts to the interesting tidbits...
# yum update
Loaded plugins: fs-snapshot
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package binutils.x86_64 0:2.20.51.0.2-5.20.el6 will be updated
---> Package binutils.x86_64 0:2.20.51.0.2-5.20.el6_1.1 will be an update
---> Package ca-certificates.noarch 0:2010.63-3.el6 will be updated
---> Package ca-certificates.noarch 0:2010.63-3.el6_1.5 will be an update
---> Package certmonger.x86_64 0:0.42-1.el6 will be updated
---> Package certmonger.x86_64 0:0.42-1.el6_1.2 will be an update
---> Package cifs-utils.x86_64 0:4.8.1-2.el6 will be updated
---> Package cifs-utils.x86_64 0:4.8.1-2.el6_1.2 will be an update
---> Package cups.x86_64 1:1.4.2-39.el6 will be updated
---> Package cups.x86_64 1:1.4.2-39.el6_1.1 will be an update
---> Package cups-libs.x86_64 1:1.4.2-39.el6 will be updated
---> Package cups-libs.x86_64 1:1.4.2-39.el6_1.1 will be an update
---> Package ipa-client.x86_64 0:2.0.0-23.el6_1.1 will be updated
---> Package ipa-client.x86_64 0:2.0.0-23.el6_1.2 will be an update
---> Package ipa-python.x86_64 0:2.0.0-23.el6_1.1 will be updated
---> Package ipa-python.x86_64 0:2.0.0-23.el6_1.2 will be an update
---> Package kernel-uek-devel.x86_64 0:2.6.39-100.0.5.el6uek will be installed
---> Package kernel-uek-headers.x86_64 0:2.6.32-100.34.1.el6uek will be updated
---> Package kernel-uek-headers.x86_64 0:2.6.32-200.16.1.el6uek will be updated
---> Package kernel-uek-headers.x86_64 0:2.6.39-100.0.5.el6uek will be an update
---> Package kpartx.x86_64 0:0.4.9-41.0.1.el6 will be updated
---> Package kpartx.x86_64 0:0.4.9-41.0.1.el6_1.1 will be an update
---> Package nss.x86_64 0:3.12.9-9.0.1.el6 will be updated
---> Package nss.x86_64 0:3.12.9-12.0.1.el6_1 will be an update
---> Package nss-sysinit.x86_64 0:3.12.9-9.0.1.el6 will be updated
---> Package nss-sysinit.x86_64 0:3.12.9-12.0.1.el6_1 will be an update
---> Package nss-tools.x86_64 0:3.12.9-9.0.1.el6 will be updated
---> Package nss-tools.x86_64 0:3.12.9-12.0.1.el6_1 will be an update
---> Package perf.x86_64 0:2.6.32-131.6.1.el6 will be updated
---> Package perf.x86_64 0:2.6.32-131.12.1.el6 will be an update
---> Package phonon-backend-gstreamer.x86_64 1:4.6.2-17.el6 will be updated
---> Package phonon-backend-gstreamer.x86_64 1:4.6.2-17.el6_1.1 will be an update
---> Package portreserve.x86_64 0:0.0.4-4.el6 will be updated
---> Package portreserve.x86_64 0:0.0.4-4.el6_1.1 will be an update
---> Package qt.x86_64 1:4.6.2-17.el6 will be updated
---> Package qt.x86_64 1:4.6.2-17.el6_1.1 will be an update
---> Package qt-sqlite.x86_64 1:4.6.2-17.el6 will be updated
---> Package qt-sqlite.x86_64 1:4.6.2-17.el6_1.1 will be an update
---> Package qt-x11.x86_64 1:4.6.2-17.el6 will be updated
---> Package qt-x11.x86_64 1:4.6.2-17.el6_1.1 will be an update
---> Package rsyslog.x86_64 0:4.6.2-3.el6_1.1 will be updated
---> Package rsyslog.x86_64 0:4.6.2-3.el6_1.2 will be an update
---> Package samba-client.x86_64 0:3.5.6-86.el6 will be updated
---> Package samba-client.x86_64 0:3.5.6-86.el6_1.4 will be an update
---> Package samba-common.x86_64 0:3.5.6-86.el6 will be updated
---> Package samba-common.x86_64 0:3.5.6-86.el6_1.4 will be an update
---> Package samba-winbind-clients.x86_64 0:3.5.6-86.el6 will be updated
---> Package samba-winbind-clients.x86_64 0:3.5.6-86.el6_1.4 will be an update
---> Package selinux-policy.noarch 0:3.7.19-93.0.1.el6_1.2 will be updated
---> Package selinux-policy.noarch 0:3.7.19-93.0.1.el6_1.7 will be an update
---> Package selinux-policy-targeted.noarch 0:3.7.19-93.0.1.el6_1.2 will be updated
---> Package selinux-policy-targeted.noarch 0:3.7.19-93.0.1.el6_1.7 will be an update
---> Package tzdata.noarch 0:2011h-2.el6 will be updated
---> Package tzdata.noarch 0:2011h-3.el6 will be an update
---> Package tzdata-java.noarch 0:2011h-2.el6 will be updated
---> Package tzdata-java.noarch 0:2011h-3.el6 will be an update
---> Package xmlrpc-c.x86_64 0:1.16.24-1200.1840.el6 will be updated
---> Package xmlrpc-c.x86_64 0:1.16.24-1200.1840.el6_1.4 will be an update
---> Package xmlrpc-c-client.x86_64 0:1.16.24-1200.1840.el6 will be updated
---> Package xmlrpc-c-client.x86_64 0:1.16.24-1200.1840.el6_1.4 will be an update
--> Finished Dependency Resolution
--> Running transaction check
---> Package kernel-uek-devel.x86_64 0:2.6.32-100.28.9.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
 Package                  Arch   Version                   Repository                       Size
=================================================================================================
Installing:
 kernel-uek-devel         x86_64 2.6.39-100.0.5.el6uek     kernel-uek-2.6.39-100.0.5-alpha 7.3 M
Updating:
 binutils                 x86_64 2.20.51.0.2-5.20.el6_1.1  ol6_latest                      2.8 M
 ca-certificates          noarch 2010.63-3.el6_1.5         ol6_latest                      531 k
 certmonger               x86_64 0.42-1.el6_1.2            ol6_latest                      193 k
 cifs-utils               x86_64 4.8.1-2.el6_1.2           ol6_latest                       41 k
 cups                     x86_64 1:1.4.2-39.el6_1.1        ol6_latest                      2.3 M
 cups-libs                x86_64 1:1.4.2-39.el6_1.1        ol6_latest                      314 k
 ipa-client               x86_64 2.0.0-23.el6_1.2          ol6_latest                       88 k
 ipa-python               x86_64 2.0.0-23.el6_1.2          ol6_latest                      491 k
 kernel-uek-headers       x86_64 2.6.39-100.0.5.el6uek     kernel-uek-2.6.39-100.0.5-alpha 716 k
 kpartx                   x86_64 0.4.9-41.0.1.el6_1.1      ol6_latest                       41 k
 nss                      x86_64 3.12.9-12.0.1.el6_1       ol6_latest                      772 k
 nss-sysinit              x86_64 3.12.9-12.0.1.el6_1       ol6_latest                       28 k
 nss-tools                x86_64 3.12.9-12.0.1.el6_1       ol6_latest                      749 k
 perf                     x86_64 2.6.32-131.12.1.el6       ol6_latest                      998 k
 phonon-backend-gstreamer x86_64 1:4.6.2-17.el6_1.1        ol6_latest                      125 k
 portreserve              x86_64 0.0.4-4.el6_1.1           ol6_latest                       22 k
 qt                       x86_64 1:4.6.2-17.el6_1.1        ol6_latest                      4.0 M
 qt-sqlite                x86_64 1:4.6.2-17.el6_1.1        ol6_latest                       50 k
 qt-x11                   x86_64 1:4.6.2-17.el6_1.1        ol6_latest                       12 M
 rsyslog                  x86_64 4.6.2-3.el6_1.2           ol6_latest                      450 k
 samba-client             x86_64 3.5.6-86.el6_1.4          ol6_latest                       11 M
 samba-common             x86_64 3.5.6-86.el6_1.4          ol6_latest                       13 M
 samba-winbind-clients    x86_64 3.5.6-86.el6_1.4          ol6_latest                      1.1 M
 selinux-policy           noarch 3.7.19-93.0.1.el6_1.7     ol6_latest                      741 k
 selinux-policy-targeted  noarch 3.7.19-93.0.1.el6_1.7     ol6_latest                      2.4 M
 tzdata                   noarch 2011h-3.el6               ol6_latest                      438 k
 tzdata-java              noarch 2011h-3.el6               ol6_latest                      150 k
 xmlrpc-c                 x86_64 1.16.24-1200.1840.el6_1.4 ol6_latest                      103 k
 xmlrpc-c-client          x86_64 1.16.24-1200.1840.el6_1.4 ol6_latest                       25 k
Removing:
 kernel-uek-devel         x86_64 2.6.32-100.28.9.el6       installed                        22 M

Transaction Summary
=================================================================================================
Install       1 Package(s)
Upgrade      29 Package(s)
Remove        1 Package(s)

Total size: 63 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
fs-snapshot: snapshotting /: /yum_20110926132957
  Updating   : nss-sysinit-3.12.9-12.0.1.el6_1.x86_64                                       1/61 
  Updating   : nss-3.12.9-12.0.1.el6_1.x86_64                                               2/61 
  Updating   : xmlrpc-c-1.16.24-1200.1840.el6_1.4.x86_64                                    3/61 
  Updating   : xmlrpc-c-client-1.16.24-1200.1840.el6_1.4.x86_64                             4/61 
  Updating   : samba-winbind-clients-3.5.6-86.el6_1.4.x86_64                                5/61 
  Updating   : samba-common-3.5.6-86.el6_1.4.x86_64                                         6/61 
  Updating   : certmonger-0.42-1.el6_1.2.x86_64                                             7/61 
  Updating   : nss-tools-3.12.9-12.0.1.el6_1.x86_64                                         8/61 
  Updating   : ca-certificates-2010.63-3.el6_1.5.noarch                                     9/61 
  Updating   : 1:qt-4.6.2-17.el6_1.1.x86_64                                                10/61 
  Updating   : 1:qt-sqlite-4.6.2-17.el6_1.1.x86_64                                         11/61 
  Updating   : 1:qt-x11-4.6.2-17.el6_1.1.x86_64                                            12/61 
  Updating   : 1:phonon-backend-gstreamer-4.6.2-17.el6_1.1.x86_64                          13/61 
  Updating   : portreserve-0.0.4-4.el6_1.1.x86_64                                          14/61 
  Updating   : ipa-python-2.0.0-23.el6_1.2.x86_64                                          15/61 
  Updating   : 1:cups-libs-1.4.2-39.el6_1.1.x86_64                                         16/61 
  Updating   : selinux-policy-3.7.19-93.0.1.el6_1.7.noarch                                 17/61 
  Updating   : selinux-policy-targeted-3.7.19-93.0.1.el6_1.7.noarch                        18/61 
  Updating   : 1:cups-1.4.2-39.el6_1.1.x86_64                                              19/61 
  Updating   : ipa-client-2.0.0-23.el6_1.2.x86_64                                          20/61 
  Updating   : samba-client-3.5.6-86.el6_1.4.x86_64                                        21/61 
  Updating   : tzdata-2011h-3.el6.noarch                                                   22/61 
  Updating   : cifs-utils-4.8.1-2.el6_1.2.x86_64                                           23/61 
  Updating   : rsyslog-4.6.2-3.el6_1.2.x86_64                                              24/61 
  Installing : kernel-uek-devel-2.6.39-100.0.5.el6uek.x86_64                               25/61 
  Updating   : kernel-uek-headers-2.6.39-100.0.5.el6uek.x86_64                             26/61 
  Updating   : binutils-2.20.51.0.2-5.20.el6_1.1.x86_64                                    27/61 
  Updating   : tzdata-java-2011h-3.el6.noarch                                              28/61 
  Updating   : perf-2.6.32-131.12.1.el6.x86_64                                             29/61 
  Updating   : kpartx-0.4.9-41.0.1.el6_1.1.x86_64                                          30/61 
  Cleanup    : selinux-policy-targeted-3.7.19-93.0.1.el6_1.2.noarch                        31/61 
  Cleanup    : selinux-policy-3.7.19-93.0.1.el6_1.2.noarch                                 32/61 
  Cleanup    : tzdata-2011h-2.el6.noarch                                                   33/61 
  Cleanup    : kernel-uek-headers.x86_64                                                   34/61 
  Cleanup    : kernel-uek-headers.x86_64                                                   35/61 
  Cleanup    : tzdata-java-2011h-2.el6.noarch                                              36/61 
  Cleanup    : perf-2.6.32-131.6.1.el6.x86_64                                              37/61 
  Cleanup    : kernel-uek-devel-2.6.32-100.28.9.el6.x86_64                                 38/61 
  Cleanup    : ipa-client-2.0.0-23.el6_1.1.x86_64                                          39/61 
  Cleanup    : certmonger-0.42-1.el6.x86_64                                                40/61 
  Cleanup    : 1:qt-x11-4.6.2-17.el6.x86_64                                                41/61 
  Cleanup    : 1:phonon-backend-gstreamer-4.6.2-17.el6.x86_64                              42/61 
  Cleanup    : samba-client-3.5.6-86.el6.x86_64                                            43/61 
  Cleanup    : 1:cups-1.4.2-39.el6.x86_64                                                  44/61 
  Cleanup    : samba-common-3.5.6-86.el6.x86_64                                            45/61 
  Cleanup    : 1:qt-sqlite-4.6.2-17.el6.x86_64                                             46/61 
  Cleanup    : 1:qt-4.6.2-17.el6.x86_64                                                    47/61 
  Cleanup    : xmlrpc-c-client-1.16.24-1200.1840.el6.x86_64                                48/61 
  Cleanup    : nss-tools-3.12.9-9.0.1.el6.x86_64                                           49/61 
  Cleanup    : ca-certificates-2010.63-3.el6.noarch                                        50/61 
  Cleanup    : nss-sysinit-3.12.9-9.0.1.el6.x86_64                                         51/61 
  Cleanup    : nss-3.12.9-9.0.1.el6.x86_64                                                 52/61 
  Cleanup    : xmlrpc-c-1.16.24-1200.1840.el6.x86_64                                       53/61 
  Cleanup    : samba-winbind-clients-3.5.6-86.el6.x86_64                                   54/61 
  Cleanup    : 1:cups-libs-1.4.2-39.el6.x86_64                                             55/61 
  Cleanup    : portreserve-0.0.4-4.el6.x86_64                                              56/61 
  Cleanup    : ipa-python-2.0.0-23.el6_1.1.x86_64                                          57/61 
  Cleanup    : cifs-utils-4.8.1-2.el6.x86_64                                               58/61 
  Cleanup    : rsyslog-4.6.2-3.el6_1.1.x86_64                                              59/61 
  Cleanup    : binutils-2.20.51.0.2-5.20.el6.x86_64                                        60/61 
  Cleanup    : kpartx-0.4.9-41.0.1.el6.x86_64                                              61/61 

Removed:
  kernel-uek-devel.x86_64 0:2.6.32-100.28.9.el6                                                  

Installed:
  kernel-uek-devel.x86_64 0:2.6.39-100.0.5.el6uek                                                

Updated:
  binutils.x86_64 0:2.20.51.0.2-5.20.el6_1.1                                                     
  ca-certificates.noarch 0:2010.63-3.el6_1.5                                                     
  certmonger.x86_64 0:0.42-1.el6_1.2                                                             
  cifs-utils.x86_64 0:4.8.1-2.el6_1.2                                                            
  cups.x86_64 1:1.4.2-39.el6_1.1                                                                 
  cups-libs.x86_64 1:1.4.2-39.el6_1.1                                                            
  ipa-client.x86_64 0:2.0.0-23.el6_1.2                                                           
  ipa-python.x86_64 0:2.0.0-23.el6_1.2                                                           
  kernel-uek-headers.x86_64 0:2.6.39-100.0.5.el6uek                                              
  kpartx.x86_64 0:0.4.9-41.0.1.el6_1.1                                                           
  nss.x86_64 0:3.12.9-12.0.1.el6_1                                                               
  nss-sysinit.x86_64 0:3.12.9-12.0.1.el6_1                                                       
  nss-tools.x86_64 0:3.12.9-12.0.1.el6_1                                                         
  perf.x86_64 0:2.6.32-131.12.1.el6                                                              
  phonon-backend-gstreamer.x86_64 1:4.6.2-17.el6_1.1                                             
  portreserve.x86_64 0:0.0.4-4.el6_1.1                                                           
  qt.x86_64 1:4.6.2-17.el6_1.1                                                                   
  qt-sqlite.x86_64 1:4.6.2-17.el6_1.1                                                            
  qt-x11.x86_64 1:4.6.2-17.el6_1.1                                                               
  rsyslog.x86_64 0:4.6.2-3.el6_1.2                                                               
  samba-client.x86_64 0:3.5.6-86.el6_1.4                                                         
  samba-common.x86_64 0:3.5.6-86.el6_1.4                                                         
  samba-winbind-clients.x86_64 0:3.5.6-86.el6_1.4                                                
  selinux-policy.noarch 0:3.7.19-93.0.1.el6_1.7                                                  
  selinux-policy-targeted.noarch 0:3.7.19-93.0.1.el6_1.7                                         
  tzdata.noarch 0:2011h-3.el6                                                                    
  tzdata-java.noarch 0:2011h-3.el6                                                               
  xmlrpc-c.x86_64 0:1.16.24-1200.1840.el6_1.4                                                    
  xmlrpc-c-client.x86_64 0:1.16.24-1200.1840.el6_1.4                                             

Complete!

Well, wasn't that easy! You can see the snapshot here :

# btrfs subvolume list /
ID 256 top level 5 path yum_20110926132957
So if something went wrong in the rpm update or you want to revert to the prior copy of the OS/filesystem, you can boot back into the snapshot, using subvolid=256 as filesystem mount options for / in fstab.

If you want to just default to the snapshot then you can run btrfs subvol set-default 256 and you are just running from the old snapshot state going forward.
Comments:

Which ISO did you use that had btrfs-convert? FC15?

Posted by Peter on September 26, 2011 at 11:40 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Wim Coekaerts is the Senior Vice President of Linux and Virtualization Engineering for Oracle. He is responsible for Oracle's complete desktop to data center virtualization product line and the Oracle Linux support program.

You can follow him on Twitter at @wimcoekaerts

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today