Merge lp:~csurbhi/partman-btrfs/testing-subvol into lp:partman-btrfs

Proposed by Surbhi Palande
Status: Superseded
Proposed branch: lp:~csurbhi/partman-btrfs/testing-subvol
Merge into: lp:partman-btrfs
Diff against target: 155 lines (+74/-4) (has conflicts)
5 files modified
check.d/no_btrfs_boot (+8/-0)
debian/changelog (+13/-0)
debian/control (+7/-1)
fstab.d/btrfs (+26/-2)
mount.d/btrfs (+20/-1)
Text conflict in debian/control
To merge this branch: bzr merge lp:~csurbhi/partman-btrfs/testing-subvol
Reviewer Review Type Date Requested Status
Ubuntu Installer Team Pending
Review via email: mp+47807@code.launchpad.net

This proposal has been superseded by a proposal from 2011-01-31.

Description of the change

Our aim is to be able to do automatic snapshots of home and / separately. Having a separate subvolume for / and another subvolume for /home allows us to take snapshots of these subvolumes independently.

Note that we have two basic scenarios:
1) /home is a separate partition and is mounted on dir home in /
2) /home is not a separate partition and is simply a dir under /

We need to basically achieve the following through the installer:
1) create the subvolume @ for / and @home for /home (just a naming convention discussed)
2) mount @ on / and mount @home on /home
3) prepare fstab such that every time the subvolumes are mounted.

====

Code:
1) fstab.d/btrfs checks if /home is a separate partition or not. If / is btrfs formatted then it adds an entry to mount the subvol=@home on /home even if /home is not a separate partition.
2) In case /home is a separate btrfs partition then it adds an entry to mount the subvolume=@home on /home.
3) Only when both / and /home are not btrfs formatted, then no entry corresponding to @home is added.

mount.d/btrfs gets the mountpoints by reading the fstab.d/btrfs and so it always gets to mount /home in both the cases discussed above.

======

Testing:
1) have tested the code for the following cases:
a) /home:btrfs /:btrfs
b) no separate /home, /:btrfs
c) /home:ext2 /:btrfs
d) /home:btrfs, /:ext2
e) /home:ext2 /:ext2
f) no separate /home, /:ext2

====

Please do let me know what you think of it! Thanks!

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :
Download full text (4.0 KiB)

Could you propose this for merging into
lp:~ubuntu-core-dev/partman-btrfs/ubuntu instead, rather than the
upstream lp:partman-btrfs? That way I won't see the changes from
5ubuntu1 in the review diff.

On Fri, Jan 28, 2011 at 02:14:14PM -0000, Surbhi Palande wrote:
> Code:
> 1) fstab.d/btrfs checks if /home is a separate partition or not. If / is btrfs formatted then it adds an entry to mount the subvol=@home on /home even if /home is not a separate partition.
> 2) In case /home is a separate btrfs partition then it adds an entry to mount the subvolume=@home on /home.
> 3) Only when both / and /home are not btrfs formatted, then no entry corresponding to @home is added.

Your general approach looks fine to me.

> if [ "$mountpoint" = / ]; then
> + if [ $home_found = unknown ]; then

In shell, a good rule of thumb is to always put "" around any word
containing $ unless there's a specific reason not to. It doesn't matter
in practice here because the value of home_found is always a single
word, but it would be good style to use "$home_found" instead (and
similar for other $-expansions in your branch). I know this guideline
isn't followed universally in the installer, but I'd like to see at
least new code following it.

(Good reason not to put "" around a word containing $ are when you
explicitly want word splitting to be performed, or in the first argument
to 'case' which is never word-split so doesn't require quoting.)

More generally, I think there may be an ordering problem here. You're
iterating in disk/partition order, so this will go wrong if it happens
that the /home partition is on an earlier disk or partition than /.
This probably won't be the common case but we should still deal with it.

I suggest that you should make this file have two loops, both with
roughly the same form (don't worry about optimising away multiple calls
to 'open_dialog PARTITIONS' etc. - this code is run a few times, but it
isn't particularly time-critical). The first should just check whether
there's a partition with mountpoint=/home. The second should be more or
less what was there before your change, but with the extra changes to
options and home_options. That way, it will work whichever way round
the partitions happen to be.

> - mount -t btrfs ${options:+-o "$options"} $fs /target$mp || exit 1
> + options=${options%,subvol=*}
> + options=${options:+"-o $options"}

I'd find it clearer to put the quotes around the whole $-expansion here
(and similarly below), i.e.:

  options="${options:+-o $options}"

This means you don't have to wonder whether it's quoted that way because
the "" are supposed to end up in the value of options.

> + mkdir -p /target$mp

You can skip this - mount.d scripts are called from
partman-target/finish.d/mount_partitions, which always creates the
directory first.

> + mount -t btrfs $options $fs /target$mp || exit 1
> + case $mp in
> + /)
> + btrfs subvolume create /target$mp/@
> + umount /target$mp
> + options=${options:+"$options,subvol=@"}
> + options=${options:="-o subvol=@"}

Using := here is odd. "${options:=-o subvol=@}" assigns to options, and
then you assign the result of that to options again ...

The repe...

Read more...

55. By Surbhi Palande

Adding support for creating and respectively mounting btrfs subvolumes
corresponding to / and /home, in case of a btrfs rootfs.

Unmerged revisions

55. By Surbhi Palande

Adding support for creating and respectively mounting btrfs subvolumes
corresponding to / and /home, in case of a btrfs rootfs.

54. By Colin Watson

releasing version 5ubuntu1

53. By Colin Watson

set Maintainer and Vcs-Bzr for Ubuntu

52. By Colin Watson

Allow btrfs /boot on amd64/i386, now that grub2 supports it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'check.d/no_btrfs_boot'
2--- check.d/no_btrfs_boot 2010-01-27 20:14:29 +0000
3+++ check.d/no_btrfs_boot 2011-01-28 14:23:38 +0000
4@@ -2,6 +2,14 @@
5 # grub and other bootloaders that read the filesystem do not support /boot
6 # on btrfs. (lilo should work). Detect and warn.
7
8+# grub2 works now.
9+ARCH="$(archdetect)"
10+case $ARCH in
11+ amd64/*|*-amd64/*|i386/*|*-i386/*)
12+ exit 0
13+ ;;
14+esac
15+
16 . /lib/partman/lib/base.sh
17
18 get_btrfs_root_boot () {
19
20=== modified file 'debian/changelog'
21--- debian/changelog 2010-12-24 22:24:24 +0000
22+++ debian/changelog 2011-01-28 14:23:38 +0000
23@@ -1,3 +1,16 @@
24+partman-btrfs (5ubuntu2) maverick; urgency=low
25+
26+ * Adding support for creating and respectively mounting btrfs subvolumes
27+ corresponding to / and /home, in case of a btrfs rootfs.
28+
29+ -- Surbhi Palande <surbhi.palande@canonical.com> Fri, 28 Jan 2011 15:35:18 +0200
30+
31+partman-btrfs (5ubuntu1) natty; urgency=low
32+
33+ * Allow btrfs /boot on amd64/i386, now that grub2 supports it.
34+
35+ -- Colin Watson <cjwatson@ubuntu.com> Fri, 07 Jan 2011 15:55:57 +0000
36+
37 partman-btrfs (5) unstable; urgency=low
38
39 [ Updated translations ]
40
41=== modified file 'debian/control'
42--- debian/control 2011-01-17 21:24:40 +0000
43+++ debian/control 2011-01-28 14:23:38 +0000
44@@ -1,11 +1,17 @@
45 Source: partman-btrfs
46 Section: debian-installer
47 Priority: standard
48-Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
49+Maintainer: Ubuntu Installer Team <ubuntu-installer@lists.ubuntu.com>
50+XSBC-Original-Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
51 Uploaders: Anton Zinoviev <zinoviev@debian.org>, Joey Hess <joeyh@debian.org>
52 Build-Depends: debhelper (>= 7.0.8), dh-di, po-debconf (>= 0.5.0)
53+<<<<<<< TREE
54 Vcs-Browser: http://git.debian.org/?p=d-i/partman-btrfs.git
55 Vcs-Git: git://git.debian.org/d-i/partman-btrfs.git
56+=======
57+XS-Debian-Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-btrfs
58+Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-core-dev/partman-btrfs/ubuntu
59+>>>>>>> MERGE-SOURCE
60
61 Package: partman-btrfs
62 XC-Package-Type: udeb
63
64=== modified file 'fstab.d/btrfs'
65--- fstab.d/btrfs 2010-06-18 10:21:24 +0000
66+++ fstab.d/btrfs 2011-01-28 14:23:38 +0000
67@@ -2,6 +2,8 @@
68
69 . /lib/partman/lib/base.sh
70
71+home_found=unknown
72+
73 for dev in $DEVICES/*; do
74 [ -d $dev ] || continue
75 cd $dev
76@@ -12,23 +14,45 @@
77 [ -f "$id/acting_filesystem" ] || continue
78 method=$(cat $id/method)
79 filesystem=$(cat $id/acting_filesystem)
80+ [ -f "$id/mountpoint" ] || continue
81+ mountpoint=$(cat $id/mountpoint)
82 case "$filesystem" in
83 btrfs)
84- [ -f "$id/mountpoint" ] || continue
85- mountpoint=$(cat $id/mountpoint)
86 # due to #249322, #255135, #258117:
87 if [ "$mountpoint" = /tmp ]; then
88 rm -f $id/options/noexec
89 fi
90 options=$(get_mountoptions $dev $id)
91 if [ "$mountpoint" = / ]; then
92+ if [ $home_found = unknown ]; then
93+ home_found=false
94+ fi
95 pass=1
96+ options="${options:+$options,subvol=@}"
97+ home_path=$path
98+ home_mp="$mountpoint"home
99+ home_options=${options%,subvol=*}
100+ home_options="${home_options:+$home_options,subvol=@home}"
101+ elif [ "$mountpoint" = /home ]; then
102+ pass=2
103+ options="${options:+$options,subvol=@home}"
104+ home_found=true
105 else
106 pass=2
107 fi
108 echo "$path" "$mountpoint" btrfs $options 0 $pass
109 ;;
110+ *)
111+ if [ "$mountpoint" = /home ]; then
112+ home_found=true
113+ fi
114+ ;;
115 esac
116 done
117 close_dialog
118 done
119+
120+if [ $home_found = "false" ]; then
121+ echo "$home_path" "$home_mp" btrfs "$home_options" 0 2
122+ home_found=true
123+fi
124
125=== modified file 'mount.d/btrfs'
126--- mount.d/btrfs 2010-01-27 20:14:29 +0000
127+++ mount.d/btrfs 2011-01-28 14:23:38 +0000
128@@ -11,7 +11,26 @@
129
130 case $type in
131 btrfs)
132- mount -t btrfs ${options:+-o "$options"} $fs /target$mp || exit 1
133+ options=${options%,subvol=*}
134+ options=${options:+"-o $options"}
135+ mkdir -p /target$mp
136+ mount -t btrfs $options $fs /target$mp || exit 1
137+ case $mp in
138+ /)
139+ btrfs subvolume create /target$mp/@
140+ umount /target$mp
141+ options=${options:+"$options,subvol=@"}
142+ options=${options:="-o subvol=@"}
143+ mount -t btrfs $options $fs /target$mp
144+ ;;
145+ /home)
146+ btrfs subvolume create /target$mp/@home
147+ umount /target$mp
148+ options=${options:+"$options,subvol=@home"}
149+ options=${options:="-o subvol=@home"}
150+ mount -t btrfs $options $fs /target$mp
151+ ;;
152+ esac
153 echo "umount /target$mp"
154 exit 0
155 ;;

Subscribers

People subscribed via source and target branches