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
=== modified file 'check.d/no_btrfs_boot'
--- check.d/no_btrfs_boot 2010-01-27 20:14:29 +0000
+++ check.d/no_btrfs_boot 2011-01-28 14:23:38 +0000
@@ -2,6 +2,14 @@
2# grub and other bootloaders that read the filesystem do not support /boot2# grub and other bootloaders that read the filesystem do not support /boot
3# on btrfs. (lilo should work). Detect and warn.3# on btrfs. (lilo should work). Detect and warn.
44
5# grub2 works now.
6ARCH="$(archdetect)"
7case $ARCH in
8 amd64/*|*-amd64/*|i386/*|*-i386/*)
9 exit 0
10 ;;
11esac
12
5. /lib/partman/lib/base.sh13. /lib/partman/lib/base.sh
614
7get_btrfs_root_boot () {15get_btrfs_root_boot () {
816
=== modified file 'debian/changelog'
--- debian/changelog 2010-12-24 22:24:24 +0000
+++ debian/changelog 2011-01-28 14:23:38 +0000
@@ -1,3 +1,16 @@
1partman-btrfs (5ubuntu2) maverick; urgency=low
2
3 * Adding support for creating and respectively mounting btrfs subvolumes
4 corresponding to / and /home, in case of a btrfs rootfs.
5
6 -- Surbhi Palande <surbhi.palande@canonical.com> Fri, 28 Jan 2011 15:35:18 +0200
7
8partman-btrfs (5ubuntu1) natty; urgency=low
9
10 * Allow btrfs /boot on amd64/i386, now that grub2 supports it.
11
12 -- Colin Watson <cjwatson@ubuntu.com> Fri, 07 Jan 2011 15:55:57 +0000
13
1partman-btrfs (5) unstable; urgency=low14partman-btrfs (5) unstable; urgency=low
215
3 [ Updated translations ]16 [ Updated translations ]
417
=== modified file 'debian/control'
--- debian/control 2011-01-17 21:24:40 +0000
+++ debian/control 2011-01-28 14:23:38 +0000
@@ -1,11 +1,17 @@
1Source: partman-btrfs1Source: partman-btrfs
2Section: debian-installer2Section: debian-installer
3Priority: standard3Priority: standard
4Maintainer: Debian Install System Team <debian-boot@lists.debian.org>4Maintainer: Ubuntu Installer Team <ubuntu-installer@lists.ubuntu.com>
5XSBC-Original-Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
5Uploaders: Anton Zinoviev <zinoviev@debian.org>, Joey Hess <joeyh@debian.org>6Uploaders: Anton Zinoviev <zinoviev@debian.org>, Joey Hess <joeyh@debian.org>
6Build-Depends: debhelper (>= 7.0.8), dh-di, po-debconf (>= 0.5.0)7Build-Depends: debhelper (>= 7.0.8), dh-di, po-debconf (>= 0.5.0)
8<<<<<<< TREE
7Vcs-Browser: http://git.debian.org/?p=d-i/partman-btrfs.git9Vcs-Browser: http://git.debian.org/?p=d-i/partman-btrfs.git
8Vcs-Git: git://git.debian.org/d-i/partman-btrfs.git10Vcs-Git: git://git.debian.org/d-i/partman-btrfs.git
11=======
12XS-Debian-Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-btrfs
13Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-core-dev/partman-btrfs/ubuntu
14>>>>>>> MERGE-SOURCE
915
10Package: partman-btrfs16Package: partman-btrfs
11XC-Package-Type: udeb17XC-Package-Type: udeb
1218
=== modified file 'fstab.d/btrfs'
--- fstab.d/btrfs 2010-06-18 10:21:24 +0000
+++ fstab.d/btrfs 2011-01-28 14:23:38 +0000
@@ -2,6 +2,8 @@
22
3. /lib/partman/lib/base.sh3. /lib/partman/lib/base.sh
44
5home_found=unknown
6
5for dev in $DEVICES/*; do7for dev in $DEVICES/*; do
6 [ -d $dev ] || continue8 [ -d $dev ] || continue
7 cd $dev9 cd $dev
@@ -12,23 +14,45 @@
12 [ -f "$id/acting_filesystem" ] || continue14 [ -f "$id/acting_filesystem" ] || continue
13 method=$(cat $id/method)15 method=$(cat $id/method)
14 filesystem=$(cat $id/acting_filesystem)16 filesystem=$(cat $id/acting_filesystem)
17 [ -f "$id/mountpoint" ] || continue
18 mountpoint=$(cat $id/mountpoint)
15 case "$filesystem" in19 case "$filesystem" in
16 btrfs)20 btrfs)
17 [ -f "$id/mountpoint" ] || continue
18 mountpoint=$(cat $id/mountpoint)
19 # due to #249322, #255135, #258117:21 # due to #249322, #255135, #258117:
20 if [ "$mountpoint" = /tmp ]; then22 if [ "$mountpoint" = /tmp ]; then
21 rm -f $id/options/noexec23 rm -f $id/options/noexec
22 fi24 fi
23 options=$(get_mountoptions $dev $id)25 options=$(get_mountoptions $dev $id)
24 if [ "$mountpoint" = / ]; then26 if [ "$mountpoint" = / ]; then
27 if [ $home_found = unknown ]; then
28 home_found=false
29 fi
25 pass=130 pass=1
31 options="${options:+$options,subvol=@}"
32 home_path=$path
33 home_mp="$mountpoint"home
34 home_options=${options%,subvol=*}
35 home_options="${home_options:+$home_options,subvol=@home}"
36 elif [ "$mountpoint" = /home ]; then
37 pass=2
38 options="${options:+$options,subvol=@home}"
39 home_found=true
26 else40 else
27 pass=241 pass=2
28 fi42 fi
29 echo "$path" "$mountpoint" btrfs $options 0 $pass43 echo "$path" "$mountpoint" btrfs $options 0 $pass
30 ;;44 ;;
45 *)
46 if [ "$mountpoint" = /home ]; then
47 home_found=true
48 fi
49 ;;
31 esac50 esac
32 done51 done
33 close_dialog52 close_dialog
34done53done
54
55if [ $home_found = "false" ]; then
56 echo "$home_path" "$home_mp" btrfs "$home_options" 0 2
57 home_found=true
58fi
3559
=== modified file 'mount.d/btrfs'
--- mount.d/btrfs 2010-01-27 20:14:29 +0000
+++ mount.d/btrfs 2011-01-28 14:23:38 +0000
@@ -11,7 +11,26 @@
1111
12case $type in12case $type in
13 btrfs)13 btrfs)
14 mount -t btrfs ${options:+-o "$options"} $fs /target$mp || exit 114 options=${options%,subvol=*}
15 options=${options:+"-o $options"}
16 mkdir -p /target$mp
17 mount -t btrfs $options $fs /target$mp || exit 1
18 case $mp in
19 /)
20 btrfs subvolume create /target$mp/@
21 umount /target$mp
22 options=${options:+"$options,subvol=@"}
23 options=${options:="-o subvol=@"}
24 mount -t btrfs $options $fs /target$mp
25 ;;
26 /home)
27 btrfs subvolume create /target$mp/@home
28 umount /target$mp
29 options=${options:+"$options,subvol=@home"}
30 options=${options:="-o subvol=@home"}
31 mount -t btrfs $options $fs /target$mp
32 ;;
33 esac
15 echo "umount /target$mp"34 echo "umount /target$mp"
16 exit 035 exit 0
17 ;;36 ;;

Subscribers

People subscribed via source and target branches