Hello,

here [*] you can find my script. 
----> Please pay attention to the fact that it is only tested on my *ubuntu* 
box. <----

The program has 4 main commands:

$ ./snapmng.sh
        snapmng.sh [-n] create <snapname> [<comment>]   Create a new snapshot.
        snapmng.sh list                                 List the  snapshots.
        snapmng.sh [-n] delete <snapname>               Delete a snapshot.
        snapmng.sh update-grub                          Update grub menulist.
        snapmng.sh help                                 Show help (this).

        If the switch '-n' is passed, then 'create' and 'delete' commands
        don't update the grub menu.
        If <snapname> is equal to '.' in the 'create' command, the name is
        generated automatically like snap-YYYYMMDD.

** list
This is the simplest; this function lists the snapshot on the basis of the 
content of the file /var/btrfs/snaplist.txt

** update-grub
This is the most triky function. This function update the grub menu on the 
basis of the snapshot contained in the /var/btrfs/snaplist.txt.

The first entry of the grub menu is extracted. Then for every snapshots this 
entry is added to the end of the "/boot/grub/menu.lst", replacing 
"subvol=rootfs" with "subvol=<snapshotname>".
These entries are delimited by the two following rows:

        ### BEGIN BTRFS SNAPSHOT ITEMS
        [...]
        ### END BTRFS SNAPSHOT ITEMS

So it is possible to update the "/boot/grub/menu.lst" file without affecting 
the other entries.

** create
this command creates a new snapshot and update the grub config file. If the 
switch "-n" is passed the menu.lst file will not be updated.

** delete
this command deletes a snapshot  and update the grub config file. If the 
switch "-n" is passed the menu.lst file will not be updated


I repeat the btrfs filesystem layout.

Nomenclature: 
-- root of system -> where there are the typical directories/files like /bin, 
/sbin /usr /etc...
-- root of the (btrfs) file-system -> where there are the snapshots or 
subvolumes

Under root of the filesystem there are the *subvolume* for the root of the 
system. Its name is "rootfs", and contains the standard filesystem  (/bin /usr 
/sbin /etc ... ).
The snapshot of the root of the system is still under /

So the filesystem layout is

/
  \
  +--rootfs     system root (subvolume)
  |    \
  |     +--/bin
  |     +--/sbin
  |     +--/etc
  |     +--/usr
  |         [...]
  +--snap-123      snapshot of the system root #123
  |    \
  |     +--/bin
  |     +--/sbin
  |         [...]
  +--snap-3456     snapshot of the system root #3456
  |    \
  |     +--/bin
  |     +--/sbin
  |         [...]

At the boot time as root is not mounted the root of the filesystem, but the 
subvolume/snapshot "rootfs"

Tipically in my ubuntu the grub entry is

        title           Ubuntu 9.10, kernel 2.6.31-17-generic
        root            (hd0,0)
        kernel          /vmlinuz root=/dev/sdX ro rootflags=subvol=rootfs 
        initrd          /initrd.img-2.6.31-17-generic
        quiet

Note the part "rootflags=subvol=rootfs".
Pay attention that the prefix "rootflags" is debian related (it should works 
for both debian and ubuntu). For examples for Fedora, the prefix would be 
"rootfsflags".

for administration purpose the root of the btrfs filesystem is mounted under 
/var/btrfs. In my /etc/fstab there are the following lines:

  /dev/sdX  /           btrfs  subvol=rootfs,errors=remount-ro,noatime  0 1
  /dev/sdX  /var/btrfs  btrfs  subvol=.,errors=remount-ro,noatime       0 1


[*] http://cassiopea.homelinux.net/git/?p=snapmng/.git;a=summary

BR
Goffredo

On Wednesday 06 January 2010, you (Piavlo) wrote:
>  Hi Goffredo,
> 
> I'm interested in your script.
> 
> BTW great article - seems to be very similar to how opensolaris handles
> boot environments with zfs.
> 
> Also I think it's better to keep the /boot as separate btrfs subvolume -
> in order to have only one
> instance of /boot/grub/menu.lst and kernels independent of all the
> rootfs snapshots - of course this will
> work only of grub2 can be told to look for /boot/grub/menu.lst under the
> btrfs boot subvolume - otherwise
> we need to store the /boot as normal directory under the root subvolume
> of the btrfs filesystem.
> 
> I've implemented your idea , but currently the /boot is stored under
> ext3 with legacy-grub.
> Need to check it will work with boot inside btrfs with grub2.
> 
> Thanks
> Alex
> 
> Goffredo Baroncelli wrote:
> > On Wednesday 06 January 2010, TARUISI Hiroaki wrote:
> >   
> >> Thanks for your greetings.
> >>
> >> I read your article, and could follow your idea, which looks
> >> very practical rule to me.
> >> But we may need some application which support to create or maintain
> >> these rules because the relation mount point and subvolumes and
> >> snapshots gets complicated as number of subvolumes increases.
> >>     
> >
> > I wrote a little script which handle the snapshot 
creation/deleting/listing 
> > and grub config file update.
> >
> > This script supposing the layout which I discussed
> >
> > - under /var/btrfs is mounter the real root btrfs filesystem
> > - under the real root file-system there are the snapshots and the root of 
the 
> > system (rootfs)
> > - in /var/btrfs/snaplist.txt there is the list of snaphsot
> > - in /boot/grub/menu.lst there is the grub configuration
> >
> > In you are interested, I can send you.
> >
> > BR 
> > Goffredo
> >
> >   
> 
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATinwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to