• Li Zhijian's avatar
    initramfs: clean old path before creating a hardlink · 2a5d5f5f
    Li Zhijian authored
    [ Upstream commit 7c0950d4 ]
    
    sys_link() can fail due to the new path already existing.  This case
    ofen occurs when we use a concated initrd, for example:
    
    1) prepare a basic rootfs, it contains a regular files rc.local
    lizhijian@:~/yocto-tiny-i386-2016-04-22$ cat etc/rc.local
     #!/bin/sh
     echo "Running /etc/rc.local..."
    yocto-tiny-i386-2016-04-22$ find . | sed 's,^\./,,' | cpio -o -H newc | gzip -n -9 >../rootfs.cgz
    
    2) create a extra initrd which also includes a etc/rc.local
    lizhijian@:~/lkp-x86_64/etc$ echo "append initrd" >rc.local
    lizhijian@:~/lkp/lkp-x86_64/etc$ cat rc.local
    append initrd
    lizhijian@:~/lkp/lkp-x86_64/etc$ ln rc.local rc.local.hardlink
    append initrd
    lizhijian@:~/lkp/lkp-x86_64/etc$ stat rc.local rc.local.hardlink
      File: 'rc.local'
      Size: 14        	Blocks: 8          IO Block: 4096   regular file
    Device: 801h/2049d	Inode: 11296086    Links: 2
    Access: (0664/-rw-rw-r--)  Uid: ( 1002/lizhijian)   Gid: (...
    2a5d5f5f
initramfs.c 13.8 KB