Hello, I hope this is the right mailing list for beginners'' questions. If not, please direct me to the right place. I am looking at btrfs to understand some of its features. One of them is the snapshot feature. Please tell me if my following understanding about snapshots in btrfs is correct or not. Btrfs supports both readonly and writeable snapshots. Writeable snapshots are like clone volumes (or subvolumes as in btrfs). We get a point in time copy of the subvolume in both case. I looked through the kernel code and it seems that creating a subvolume and taking a snapshot (readonly and writeable) all have a common ioctl interface. What I am not completely clear about is whether snapshots get same fsid as the source subvolume fsid or different. Also, I do not understand what does it mean to be able to take snapshot of a snapshot. What are benefits compared to say, being able to take snapshots only of the active subvolume and not of the snapshots? Probably before that, I need to get some clarity on why does a subvolume always belong in the directory of some parent subvolume. Is it possible to have more than one root subvolumes or more than one subvolumes in the same parent subvolume directory? Thanks, Aastha Mehta. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, Dec 02, 2012 at 11:17:26PM +0100, Aastha Mehta wrote:> I am looking at btrfs to understand some of its features. One of them > is the snapshot feature. Please tell me if my following understanding > about snapshots in btrfs is correct or not. > > Btrfs supports both readonly and writeable snapshots. Writeable > snapshots are like clone volumes (or subvolumes as in btrfs). We get a > point in time copy of the subvolume in both case. > > I looked through the kernel code and it seems that creating a > subvolume and taking a snapshot (readonly and writeable) all have a > common ioctl interface. > > What I am not completely clear about is whether snapshots get same > fsid as the source subvolume fsid or different.Yes, it''s the same UUID, because they''re all part of the same filesystem.> Also, I do not understand what does it mean to be able to take > snapshot of a snapshot.Snapshots are completely equal partners with their original subvolumes. This is not the case in, say, LVM.> What are benefits compared to say, being able to take snapshots only > of the active subvolume and not of the snapshots?Let''s say you take a snapshot (B) of your root filesystem (A). Then you decide to "roll back" to using the old version, so you mount B as root instead of A. Later that night, your backup process starts up and tries to take a temporary read-only snapshot (C) of your root filesystem (which is now B) so that it can make a stable backup. That''s a snapshot of a snapshot.> Probably before that, I need to get some clarity on why does a > subvolume always belong in the directory of some parent subvolume. Is > it possible to have more than one root subvolumes or more than one > subvolumes in the same parent subvolume directory?No, there''s precisely one top-level subvolume (subvolid=5). Everything else in the filesystem lives within that. However, you can have as many subvolumes as you like below that, and in whatever directories or subvolumes you want. Hugo. -- === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk == PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk --- Quidquid latine dictum sit, altum videtur. ---
On Dec 2, 2012, at 3:46 PM, Hugo Mills <hugo@carfax.org.uk> wrote:> No, there''s precisely one top-level subvolume (subvolid=5).What is subvolid=0? I recently got myself into a subvolume maze and ended up mounting subvolid=0 to get back to the top level and that seemed to work at the time. Chris Murphy -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Subvolid 0 is always the root. On Sun, Dec 2, 2012 at 7:59 PM, Michael <mike@draftx.net> wrote:> > Subvolid=0 is always the root subvolume. > > On Sun, Dec 2, 2012 at 6:32 PM, Chris Murphy <lists@colorremedies.com> wrote: >> >> >> On Dec 2, 2012, at 3:46 PM, Hugo Mills <hugo@carfax.org.uk> wrote: >> >> > No, there''s precisely one top-level subvolume (subvolid=5). >> >> What is subvolid=0? I recently got myself into a subvolume maze and ended up mounting subvolid=0 to get back to the top level and that seemed to work at the time. >> >> Chris Murphy >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Dec 2, 2012, at 6:59 PM, Michael <mike@draftx.net> wrote:> Subvolid=0 is always the root subvolume.OK so then what is subvolid=5? Chris Murphy -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, Dec 02, 2012 at 07:49:17PM -0700, Chris Murphy wrote:> > On Dec 2, 2012, at 6:59 PM, Michael <mike@draftx.net> wrote: > > > Subvolid=0 is always the root subvolume. > > OK so then what is subvolid=5?We''ve parsed subvolid=5 and subvolid=0 to the same results, FS_TREE. FYI, the code is case Opt_subvolid: intarg = 0; error = match_int(&args[0], &intarg); if (!error) { /* we want the original fs_tree */ if (!intarg) *subvol_objectid BTRFS_FS_TREE_OBJECTID; else *subvol_objectid = intarg; } break; thanks, liubo -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, Dec 02, 2012 at 07:49:17PM -0700, Chris Murphy wrote:> > On Dec 2, 2012, at 6:59 PM, Michael <mike@draftx.net> wrote: > > > Subvolid=0 is always the root subvolume. > > OK so then what is subvolid=5?subvolid=5 is the actual ID used internally for the top-level subvolume. subvolid=0 won''t ever turn up as a "real" subvolume ID internally, and is mapped to the same subvolume as subvolid=5 with a piece of special-case code that liubo showed. Hugo. -- === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk == PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk --- I''m on a 30-day diet. So far I''ve lost 18 days. ---
Hello, Thank you so much for your prompt response. Few more questions inline. On 2 December 2012 23:46, Hugo Mills <hugo@carfax.org.uk> wrote:> On Sun, Dec 02, 2012 at 11:17:26PM +0100, Aastha Mehta wrote: >> I am looking at btrfs to understand some of its features. One of them >> is the snapshot feature. Please tell me if my following understanding >> about snapshots in btrfs is correct or not. >> >> Btrfs supports both readonly and writeable snapshots. Writeable >> snapshots are like clone volumes (or subvolumes as in btrfs). We get a >> point in time copy of the subvolume in both case. >> >> I looked through the kernel code and it seems that creating a >> subvolume and taking a snapshot (readonly and writeable) all have a >> common ioctl interface. >> >> What I am not completely clear about is whether snapshots get same >> fsid as the source subvolume fsid or different. > > Yes, it''s the same UUID, because they''re all part of the same > filesystem. >Just to clarify, apart from UUID, is the FSID in the fs_info of the root also same for all snapshots of a subvolume?>> Also, I do not understand what does it mean to be able to take >> snapshot of a snapshot. > > Snapshots are completely equal partners with their original > subvolumes. This is not the case in, say, LVM. > >> What are benefits compared to say, being able to take snapshots only >> of the active subvolume and not of the snapshots? > > Let''s say you take a snapshot (B) of your root filesystem (A). Then > you decide to "roll back" to using the old version, so you mount B as > root instead of A. Later that night, your backup process starts up and > tries to take a temporary read-only snapshot (C) of your root > filesystem (which is now B) so that it can make a stable backup. > That''s a snapshot of a snapshot. >Okay, but still the snapshot can be taken only for a subvolume in use. Is that correct? In your example, C is taken on B after file system was rolled back to version B. What happens when the file system version mounted is A (which contains snapshot B) and we take another snapshot D on this mounted version. Does the snapshot D contain B or only the active contents of A?>> Probably before that, I need to get some clarity on why does a >> subvolume always belong in the directory of some parent subvolume. Is >> it possible to have more than one root subvolumes or more than one >> subvolumes in the same parent subvolume directory? > > No, there''s precisely one top-level subvolume (subvolid=5). > Everything else in the filesystem lives within that. However, you can > have as many subvolumes as you like below that, and in whatever > directories or subvolumes you want. > > Hugo. > > -- > === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ==> PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk > --- Quidquid latine dictum sit, altum videtur. ---Thanks again, Aastha. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Dec 03, 2012 at 10:52:41AM +0100, Aastha Mehta wrote:> On 2 December 2012 23:46, Hugo Mills <hugo@carfax.org.uk> wrote: > > On Sun, Dec 02, 2012 at 11:17:26PM +0100, Aastha Mehta wrote: > >> I am looking at btrfs to understand some of its features. One of them > >> is the snapshot feature. Please tell me if my following understanding > >> about snapshots in btrfs is correct or not. > >> > >> Btrfs supports both readonly and writeable snapshots. Writeable > >> snapshots are like clone volumes (or subvolumes as in btrfs). We get a > >> point in time copy of the subvolume in both case. > >> > >> I looked through the kernel code and it seems that creating a > >> subvolume and taking a snapshot (readonly and writeable) all have a > >> common ioctl interface. > >> > >> What I am not completely clear about is whether snapshots get same > >> fsid as the source subvolume fsid or different. > > > > Yes, it''s the same UUID, because they''re all part of the same > > filesystem. > > > Just to clarify, apart from UUID, is the FSID in the fs_info of the > root also same for all snapshots of a subvolume? > > >> Also, I do not understand what does it mean to be able to take > >> snapshot of a snapshot. > > > > Snapshots are completely equal partners with their original > > subvolumes. This is not the case in, say, LVM. > > > >> What are benefits compared to say, being able to take snapshots only > >> of the active subvolume and not of the snapshots? > > > > Let''s say you take a snapshot (B) of your root filesystem (A). Then > > you decide to "roll back" to using the old version, so you mount B as > > root instead of A. Later that night, your backup process starts up and > > tries to take a temporary read-only snapshot (C) of your root > > filesystem (which is now B) so that it can make a stable backup. > > That''s a snapshot of a snapshot. > > > Okay, but still the snapshot can be taken only for a subvolume in use. > Is that correct?Well, it depends on what you mean by "in use". You can''t snapshot something which doesn''t appear somewhere in your directory hierarchy.> In your example, C is taken on B after file system > was rolled back to version B. What happens when the file system > version mounted is A (which contains snapshot B) and we take another > snapshot D on this mounted version. Does the snapshot D contain B or > only the active contents of A?Snapshots are not recursive. If you have a subvolume inside another: subv1/subv2 and then snapshot that # btrfs sub snap subv1 subv1-A you will end up with a subvolume subv1-A, containing an empty directory called subv2. Note that you don''t have to have subvolumes inside subvolumes at all, if you don''t use the top level of your filesystem as anything other than a place to store and manage subvolumes. Consider this btrfs filesystem layout: / subvolid=5 (=0) root subvolid=256 (default subvol) home subvolid=257 snapshots directory With this in fstab: /dev/sda / btrfs subvolid=256 /dev/sda /home btrfs subvolid=257 /dev/sda /media/btrfs btrfs subvolid=5,noauto We get this filesystem hierarchy: / subvolid=256 home subvolid=257 media directory btrfs subvolid=5 Note that the mount of the full filesystem on /media/btrfs isn''t done automatically -- it only needs to be done when you''re managing subvolumes. So, we can take a snapshot of /, for example: # mount /media/btrfs # btrfs sub snap /media/btrfs/root /media/btrfs/snapshots/root.2012-12-03 # umount /media/btrfs The FS (from its top level) now looks like this: / subvolid=5 (=0) root subvolid=256 (default subvol) home subvolid=257 snapshots directory root.2012-12-03 subvolid=258 To "roll back" root temporarily to the earlier version, you can edit your boot manager''s config to supply "subvolid=258" as a mount parameter. To do so permanently, you can set the default subvolume to 258, and optionally move the snapshot to /root within the btrfs filesystem: # mount /media/btrfs # mv /media/btrfs/root /media/btrfs/root.old # mv /media/btrfs/snapshots/root.2012-12-03 /media/btrfs/root # umount /media/btrfs Hugo. -- === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk == PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk --- I''m on a 30-day diet. So far I''ve lost 18 days. ---
Thanks a lot for the explanation. Regards, Aastha. On 3 December 2012 13:02, Hugo Mills <hugo@carfax.org.uk> wrote:> On Mon, Dec 03, 2012 at 10:52:41AM +0100, Aastha Mehta wrote: >> On 2 December 2012 23:46, Hugo Mills <hugo@carfax.org.uk> wrote: >> > On Sun, Dec 02, 2012 at 11:17:26PM +0100, Aastha Mehta wrote: >> >> I am looking at btrfs to understand some of its features. One of them >> >> is the snapshot feature. Please tell me if my following understanding >> >> about snapshots in btrfs is correct or not. >> >> >> >> Btrfs supports both readonly and writeable snapshots. Writeable >> >> snapshots are like clone volumes (or subvolumes as in btrfs). We get a >> >> point in time copy of the subvolume in both case. >> >> >> >> I looked through the kernel code and it seems that creating a >> >> subvolume and taking a snapshot (readonly and writeable) all have a >> >> common ioctl interface. >> >> >> >> What I am not completely clear about is whether snapshots get same >> >> fsid as the source subvolume fsid or different. >> > >> > Yes, it''s the same UUID, because they''re all part of the same >> > filesystem. >> > >> Just to clarify, apart from UUID, is the FSID in the fs_info of the >> root also same for all snapshots of a subvolume? >> >> >> Also, I do not understand what does it mean to be able to take >> >> snapshot of a snapshot. >> > >> > Snapshots are completely equal partners with their original >> > subvolumes. This is not the case in, say, LVM. >> > >> >> What are benefits compared to say, being able to take snapshots only >> >> of the active subvolume and not of the snapshots? >> > >> > Let''s say you take a snapshot (B) of your root filesystem (A). Then >> > you decide to "roll back" to using the old version, so you mount B as >> > root instead of A. Later that night, your backup process starts up and >> > tries to take a temporary read-only snapshot (C) of your root >> > filesystem (which is now B) so that it can make a stable backup. >> > That''s a snapshot of a snapshot. >> > >> Okay, but still the snapshot can be taken only for a subvolume in use. >> Is that correct? > > Well, it depends on what you mean by "in use". You can''t snapshot > something which doesn''t appear somewhere in your directory hierarchy. > >> In your example, C is taken on B after file system >> was rolled back to version B. What happens when the file system >> version mounted is A (which contains snapshot B) and we take another >> snapshot D on this mounted version. Does the snapshot D contain B or >> only the active contents of A? > > Snapshots are not recursive. If you have a subvolume inside another: > > subv1/subv2 > > and then snapshot that > > # btrfs sub snap subv1 subv1-A > > you will end up with a subvolume subv1-A, containing an empty > directory called subv2. > > Note that you don''t have to have subvolumes inside subvolumes at > all, if you don''t use the top level of your filesystem as anything > other than a place to store and manage subvolumes. > > Consider this btrfs filesystem layout: > > / subvolid=5 (=0) > root subvolid=256 (default subvol) > home subvolid=257 > snapshots directory > > With this in fstab: > > /dev/sda / btrfs subvolid=256 > /dev/sda /home btrfs subvolid=257 > /dev/sda /media/btrfs btrfs subvolid=5,noauto > > We get this filesystem hierarchy: > > / subvolid=256 > home subvolid=257 > media directory > btrfs subvolid=5 > > Note that the mount of the full filesystem on /media/btrfs isn''t > done automatically -- it only needs to be done when you''re managing > subvolumes. > > So, we can take a snapshot of /, for example: > > # mount /media/btrfs > # btrfs sub snap /media/btrfs/root /media/btrfs/snapshots/root.2012-12-03 > # umount /media/btrfs > > The FS (from its top level) now looks like this: > > / subvolid=5 (=0) > root subvolid=256 (default subvol) > home subvolid=257 > snapshots directory > root.2012-12-03 subvolid=258 > > To "roll back" root temporarily to the earlier version, you can edit > your boot manager''s config to supply "subvolid=258" as a mount > parameter. To do so permanently, you can set the default subvolume to > 258, and optionally move the snapshot to /root within the btrfs > filesystem: > > # mount /media/btrfs > # mv /media/btrfs/root /media/btrfs/root.old > # mv /media/btrfs/snapshots/root.2012-12-03 /media/btrfs/root > # umount /media/btrfs > > Hugo. > > -- > === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ==> PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk > --- I''m on a 30-day diet. So far I''ve lost 18 days. ----- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html