Red Hat Bugzilla – Bug 1489882
dracut --include <src> <tgt> doesn't work
Last modified: 2018-04-10 14:11:42 EDT
Description of problem: When trying to include a directory in the initramfs using "--include <src> <tgt>", the initramfs gets created without including the files in the <src> top directory and following errors are printed for each file in <src> directory: cp: failed to access '/var/tmp/initramfs.91CQHL///myfile': No such file or directory Version-Release number of selected component (if applicable): dracut-033-502.el7.x86_64 but also before, at least since dracut-033-240.el7.x86_64 (RHEL7.1) How reproducible: Always Steps to Reproduce: 1. Create some source to include mkdir mydir touch mydir/myfile mkdir mydir/mysubdir touch mydir/mysubdir/myfile 2. Run dracut to include "mydir" and check content dracut --include mydir / /tmp/myinitramfs -f Actual results: cp: failed to access '/var/tmp/initramfs.CRA4FA///myfile': No such file or directory lsinitrd content: drwxr-xr-x 2 root root 0 Sep 8 16:39 mysubdir -rw-r--r-- 1 root root 0 Sep 8 16:39 mysubdir/myfile Expected results: no cp error + lsinitrd content: -rw-r--r-- 1 root root 0 Sep 8 16:39 myfile drwxr-xr-x 2 root root 0 Sep 8 16:39 mysubdir -rw-r--r-- 1 root root 0 Sep 8 16:39 mysubdir/myfile Suggested fix (/usr/sbin/dracut): [...] 1442 chmod --reference="$i" "$s" 1443 fi 1444 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/* 1445 else => replace line 1446 1446 cp --reflink=auto --sparse=auto -fa -t "$s" "$i" => by 1446 cp --reflink=auto --sparse=auto -fa -t "${initdir}/${tgt}" "$i" 1447 fi 1448 done [...]
If I am not mistaken --include does not work recursively. It can only copy one level of files. It is written in the man page, but the formulation is kinda clumsy. But this is still a valid RFE.
Here the issue is that the files in top dir "mydir/*" are not copied (in the above case mydir/myfile). And btw subdirs are copied as someone would expect.
I have the same issue. Having looked into /usr/bin/dracut it appears that the line: cp --reflink=auto --sparse=auto -fa -t "$s" "$i" in the else clause is the culprit. It is using $s where this is the destination file not the destination directory. As a test I used 'dirname $s' instead and this worked. So I suspect the value of $s needs to checked after being initialised to see if it is a file or a directory.
It looks like we need to backport https://github.com/dracutdevs/dracut/commit/c9364f6ea296a03073bc4096756e3a61ca095c0e
And the backport https://github.com/lnykryn/dracut/tree/bz1489882
Verified with dracut-033-535.el7: [root@localhost ~]# rpm -q dracut dracut-033-535.el7.x86_64 [root@localhost ~]# mkdir mydir [root@localhost ~]# touch mydir/myfile [root@localhost ~]# mkdir mydir/mysubdir [root@localhost ~]# touch mydir/mysubdir/myfile [root@localhost ~]# dracut --include mydir / /tmp/myinitramfs -f [root@localhost ~]# lsinitrd /tmp/myinitramfs | grep 'myfile\|mysubdir' -rw-r--r-- 1 root root 0 Feb 23 10:46 myfile drwxr-xr-x 2 root root 0 Feb 23 10:46 mysubdir -rw-r--r-- 1 root root 0 Feb 23 10:46 mysubdir/myfile [root@localhost ~]# Moving to VERIFIED.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2018:0964