Bug 12644

Summary: Can't format block devices related to systemd-udevd.service and udev-extraconf
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Hongzhi <hongzhi.song>
Component: coreAssignee: Hongzhi <hongzhi.song>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: Medium+ CC: meta.mr.watcher, meta.watcher, randy.macleod, ross.burton, stephano
Version: 2.4   
Target Milestone: 2.6 M4   
Hardware: x86   
OS: x86   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Attachments:
Description Flags
systemd maintainer's advice none

Description Hongzhi 2018-04-03 00:13:30 UTC
Created attachment 4254 [details]
systemd maintainer's advice

1)Overview:
    Block device media can't be format by command:mkfs.ext4, with systemd as init manager and udev-extraconf installed.

2)Bitbake information:
    Build Configuration:
    BB_VERSION           = "1.37.0"
    BUILD_SYS            = "x86_64-linux"
    NATIVELSBSTRING      = "universal-4.8"
    TARGET_SYS           = "i586-poky-linux"
    MACHINE              = "qemux86"
    DISTRO               = "poky"
    DISTRO_VERSION       = "2.4+snapshot-20180403"
    TUNE_FEATURES        = "m32 i586"
    TARGET_FPU           = ""
    meta                 
    meta-poky            
    meta-yocto-bsp       = "master:4574ad343888fd57eabadbcbae5f8123709a6461"

3)Steps to Reproduce:
    1. git clone git://git.yoctoproject.org/poky
    2. branch is master
    3. add follow statements to conf/local.conf
        IMAGE_FSTYPES += "tar.bz2 ext4"
        VIRTUAL-RUNTIME_init_manager = "systemd"
        DISTRO_FEATURES_append = " systemd"
        DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
        KERNEL_FEATURES_append = " cfg/systemd.scc"
        IMAGE_INSTALL_append = " e2fsprogs-mke2fs"
        IMAGE_INSTALL_append = " udev-extraconf"
    4. bitbake core-image-minimal 
    5. dd if=/dev/zero of=b.img bs=100m count=1
       mkfs.ext3 b.img
    6. Boot system with qemu
        runqemu qemux86 slirp nographic qemuparams="-hda b.img"
    7. root@qemux86:~# fdisk /dev/hda -l
       Disk /dev/hda: 100 MB, 104857600 bytes, 204800 sectors
       12 cylinders, 255 heads, 63 sectors/track
       Units: cylinders of 16065 * 512 = 8225280 bytes
    8. root@qemux86:~# mount | grep hda
       root@qemux86:~# umount /dev/hda
       umount: can't unmount /dev/hda: Invalid argument
    9. root@qemux86:~# cat /etc/udev/mount.blacklist
       /dev/loop
       /dev/ram
       /dev/mtdblock
       /dev/md
       /dev/dm-*
   
    10. format /dev/hda using command:mkfs.ext4
root@qemux86:~# mkfs.ext4 /dev/hda 
mke2fs 1.43.8 (1-Jan-2018)
/dev/hda contains a ext4 file system
	last mounted on Tue Apr  3 06:22:41 2018
Proceed anyway? (y,N) y
/dev/hda is apparently in use by the system; will not make a filesystem here!

4)Actual Results: 
    All block media processed by systemd-udevd.service can't be formated, if they dosen't exist in /etc/udev/mount.blacklist.

5) Attachments are my local.conf and email discussion with systemd maintainer.
Comment 1 Randy MacLeod 2018-04-05 07:55:38 UTC
Isn't this a limitation of qemu perhaps? Can you reproduce the problem on hardware?
Comment 2 Hongzhi 2018-04-07 18:40:29 UTC
(In reply to comment #1)
> Isn't this a limitation of qemu perhaps? Can you reproduce the problem on
> hardware?

No, it isn't limited to qemu. I tried several x86-cpus which can reproduce the problem. In fact, it has nothing to do with hardware but with how systemd-udevd works.
Comment 3 Randy MacLeod 2018-04-08 18:17:39 UTC
I don't understand why you think this is a problem.

The upstream maintainer has given you a method whereby you *could* have a single partition and yet still format it after boot time. Am I missing something about how many partitions you have since the root partition can't usually be umounted or formatted when it is in use.
Comment 4 Hongzhi 2018-04-08 19:08:43 UTC
(In reply to comment #3)
> I don't understand why you think this is a problem.
> 
> The upstream maintainer has given you a method whereby you *could* have a
> single partition and yet still format it after boot time. Am I missing
> something about how many partitions you have since the root partition can't
> usually be umounted or formatted when it is in use.

Sorry, I didn't accurate enough to describe it. The root of problem comes from systemd-udevd.service and udev-extraconf recipe. Systemd-udevd.service has a variable, MountFlag that is set 'slave', this means udev will mount all block devices within itself namespace and devices can't be formatted by host space.
Comment 6 Ross Burton 2018-09-26 10:51:37 UTC
Merged in oe-core 4af22800a7af4fcb80cafe08d982a4850d9dd2ad.