Bug 753366

Summary: systemd: btrfs.service is a prerequisite for multi-device btrfs partitions
Product: [openSUSE] openSUSE 12.2 Reporter: Jan Engelhardt <jengelh>
Component: BasesystemAssignee: David Sterba <dsterba>
Status: RESOLVED WONTFIX QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: dsterba, forgotten_HNi0XMrMzY, mirtone_1
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: Linux   
See Also: https://bugzilla.novell.com/show_bug.cgi?id=727383
Whiteboard:
Found By: Beta-Customer Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Jan Engelhardt 2012-03-21 16:10:27 UTC
A btrfs filesystem generated with

# mkfs.btrfs /dev/sd[cdef]

Cannot be mounted before `btrfs device scan` is run.
Since systemd never executes this, it fails to load fstab entries for such device-spanning FSes.

(The fstab entry is just like any other, i.e.
/dev/sdc   /srv   btrfs  nofail   0 0
)
Comment 1 Frederic Crozat 2012-03-21 16:50:46 UTC
I guess btrfsprogs package should ship a .service doing this and this service should be enabled in local-fs-pre.target.

But all of this is the responsability of btrfsprogs maintainer.
Comment 2 Dirk Mueller 2012-03-29 08:24:44 UTC
Reassigning to btrfsprogs maintainer.
Comment 3 DaQ QaD 2012-08-22 01:11:55 UTC
I tried adding /sbin/btrfs device scan to boot.localfs right before fstab is mounted, but it didn't work. Did you even figure out a correct place to add the device scan so that boot is not interrupted?
Comment 4 Jan Engelhardt 2012-08-25 14:39:00 UTC
/etc/init.d/boot.local served my case. But ideally, device scan should be executed whenever a disk is hotplugged.
Someone please Cc the udev maintainer.
Comment 5 Forgotten User S7BaJJXAH- 2012-08-25 14:51:59 UTC
I am not the udev maintainer...
Comment 6 DaQ QaD 2012-08-30 19:23:35 UTC
This is the correct solution to this issue:
http://forums.opensuse.org/english/get-technical-help-here/install-boot-login/477122-boot-halted-btrfs-issue.html#post2481274

To summarize:
btrfs boot script runs before mount script so module cannot be loaded from the file system. As long as your / is not btrfs, not a problem since you will get dropped into super user mode where you can load the module by hand.

The correct solution:
Add btrfs module to initrd so that it is loaded into initial ramdisk.

Details are on that forum entry.
Comment 7 DaQ QaD 2012-08-30 19:36:11 UTC
BTW, this seems like a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=727383
Comment 8 Jan Engelhardt 2012-08-30 19:39:30 UTC
The problem here is not module loading, it's that btrfs mount will fail if the btrfs core does not know all devices.
Comment 9 DaQ QaD 2012-08-30 21:51:36 UTC
I don't think that's correct. Loading module should scan the devices. At the same time, scanning devices will load the module, but only if the file system containing the module is already mounted (and is not btrfs.)

I think the big problem is that module is not loaded when it is supposed to. You can test it by removing your boot.local modification and adding btrfs to initrd as recommended in the forum entry linked above.

I didn't need to modify any scrips or force any device scans after I added btrfs module to ramdisk.
Comment 10 Jan Engelhardt 2012-08-30 23:14:26 UTC
Because "btrfs" is listed in fstab as type for the fs, it will already be autoloaded by the kernel when attempting to mount /dev/sdf.


>Loading module should scan the devices.

Have you actually tested your theories? I doubt it. As a result of `btrfs dev scan`, dmesg will show "device label ... devid ... transid ... /dev/sdX`. No such messages are emitted when loading btrfs.ko.
Comment 11 DaQ QaD 2012-08-30 23:34:53 UTC
(In reply to comment #10)
> Because "btrfs" is listed in fstab as type for the fs, it will already be
> autoloaded by the kernel when attempting to mount /dev/sdf.

That wasn't true in my case. I had btrfs in fstab, yet module wasn't loading.

> >Loading module should scan the devices.
> 
> Have you actually tested your theories? I doubt it. As a result of `btrfs dev
> scan`, dmesg will show "device label ... devid ... transid ... /dev/sdX`. No
> such messages are emitted when loading btrfs.ko.

My logic was that loading the module fixed it for me without having to run 'btrfs dev scan' I also mount FS with multiple devices. I did not actually read the code for btrfs module to confirm this.

Do you have any evidence that shows my test is invalid? Just try it before getting angry.
Comment 12 Jan Engelhardt 2012-08-30 23:51:46 UTC
Daniel Sterba, there should be a udev rule calling `btrfs dev scan $blkdev` (ignore return code) whenever there is a ADD BLOCK event.
Josef Bacik says this is what should be done - and which is what Fedora does.
Comment 13 David Sterba 2012-09-03 15:54:56 UTC
(In reply to comment #6)
> This is the correct solution to this issue:
> http://forums.opensuse.org/english/get-technical-help-here/install-boot-login/477122-boot-halted-btrfs-issue.html#post2481274
> 
> To summarize:
> btrfs boot script runs before mount script so module cannot be loaded from the
> file system. As long as your / is not btrfs, not a problem since you will get
> dropped into super user mode where you can load the module by hand.
> 
> The correct solution:
> Add btrfs module to initrd so that it is loaded into initial ramdisk.
> 
> Details are on that forum entry.

I've read through the forum post, it mentions several problems with multi-device btrfs and boot. Summary:

* missing module in initrd despite btrfs feature is detected
=> really a bug (missing directive in mkinitrd script), already fixed, I'll check if it's actually released via maintenance update

* devices not detected during boot, ie. the missing 'btrfs device scan'
=> unless the module is not loaded, the scan does not happen; formerly the scan step was not done at all, should be ok now

there's a difference when scanning root device and non-root devices:

* root: all steps need to be done from within the initrd environment (like setting up MD/DM/crypto, then scan and mount)

* non-root filesystems may depend on post-initrd setup of MD/DM/crypto devices and this cannot be resolved from initrd at all
=> needs udev rules to detect any new blockdevice (as suggested in comment 12)

I'll push out updated progs (udev rules and other progs fixes) soon.
Comment 14 Forgotten User HNi0XMrMzY 2012-10-13 01:02:15 UTC
Same bug exists on openSUSE 12.2
Comment 15 Jan Engelhardt 2012-10-13 01:48:45 UTC
It certainly is.
Comment 16 Jeff Mahoney 2014-08-07 19:31:27 UTC
This report is against openSUSE 12.2 which is no longer under maintenance. If you are able to reproduce it with openSUSE 13.1 or openSUSE Factory, please re-open and reset the the "Product" field to the appropriate release.

[Note: This should be fixed via the udev rules that call btrfs device ready when a partition is probed.]