zoukankan      html  css  js  c++  java
  • ln: creating hard link 问题

    其实很简单:

    chattr -R -i xxxxx           #xxxxx为你需要修改的文件,这样就可以了。。。

    下面全不是重点,扯淡。。。。

    ln: creating hard link `xxx' => `/opt/xx': Operation not permitted

    摘自http://www.windowslinuxosx.com/q/answers-how-do-i-remove-a-possible-hard-link-directory-to-root-625072.html

    Solution

    The files and directories in the .linktorootdir directory are copied from the root directory. You can simply delete them using for example rm -rf /volume1/usbcopy/USBCopy_1303012145/.linktohomedir.

    The explanation is below.

    Hardlinks of directories

    Hardlinks to directories are theoretically possible but because of multiple reasons they are disabled in many systems including Linux. This also means that you will not be able to remove a hardlink to directory as the unlink() syscall will not allow it.

    Demonstration

    root@x:~/testdir# ln -F dir1 dir1link
    ln: failed to create hard link `dir1link' => `dir1': Operation not permitted
    root@x:~/testdir# unlink dir1
    unlink: cannot unlink `dir1': Is a directory
    

    The shown denial is hardwired in the Linux kernel (fs/namei.c). Here are the results of syscalls:

    linkat(AT_FDCWD, "dir1", AT_FDCWD, "dir1link", 0) = -1 EPERM (Operation not permitted)
    unlink("dir1")                          = -1 EISDIR (Is a directory)
    

    Recognizing the two types of links

    • softlink - ls -l shows l as the first character of the type/permission field. stat output shows symbolic link.
    • hardlink - Hardlinks are mutually indistinguishable. Both the original file and newly created hardlink look exactly the same except the path/filename. Hardlinks cannot point from one filesystem to another. ls -i shows the same inode number for all files hardlinked to the same data (represented by inode). The second column of ls -l shows the number of hardlinks to the inode.
    user1@x:~/testdir$ ls -li
    total 12
    6865008 drwxrwxr-x 2 user1 user1 4096 Jul 30 00:50 dir1
    6822146 lrwxrwxrwx 1 user1 user1    4 Jul 30 01:44 dir1symlink -> dir1
    6822155 -rw-rw-r-- 2 user1 user1   64 Jul 30 01:44 file1
    6822155 -rw-rw-r-- 2 user1 user1   64 Jul 30 01:44 file1hardlink
    
    user1@x:~/testdir$ stat * | grep -E '((File)|(Size)|(Device)):'
      File: `dir1'
      Size: 4096        Blocks: 8          IO Block: 4096   directory
    Device: 807h/2055d  Inode: 6865008     Links: 2
      File: `dir1symlink' -> `dir1'
      Size: 4           Blocks: 0          IO Block: 4096   symbolic link
    Device: 807h/2055d  Inode: 6822146     Links: 1
      File: `file1'
      Size: 64          Blocks: 8          IO Block: 4096   regular file
    Device: 807h/2055d  Inode: 6822155     Links: 2
      File: `file1hardlink'
      Size: 64          Blocks: 8          IO Block: 4096   regular file
    Device: 807h/2055d  Inode: 6822155     Links: 2
    

    Origin of .linktorootdir

    In the .dfmdesk directory DFM creates some links during the first start. These links will be shown as icons on the desktop. Between the links there will be two links to directories:.linktorootdir as a symlink to the root directory of the system DFM is running on and also.linktohomedir. See the DFM documentation and the DFM source.

    In your case the directories / and /volume1/usbcopy/USBCopy_1303012145/.linktohomedirare on different filesystems (/dev/root and /dev/vg1000/lv) so they cannot be hardlinks to the same inode. (Hardlinks can point just in the scope of a single filesystem.)

    We can guess how the problem you describe emerged. Most probably the backup to NTFS was able to keep the symlink as NTFS has this capability. Later when you copied the backup from the USB drive the copying tool did not handle symlinks as expected. Instead of copying just the symbolic link itself, the tool followed the symbolic links on the source drive and copied the content of them (root directory in the case of .linktorootdir). The similar problem is describe also in the Synology forum: USBCopy cought in infinity loop while copying HDD.

    The solution is described at the beginning.

    A hard link is a directory entry that references the same inode as another directory entry (only working in the same file system). One should therefore avoid very sparingly and use only with good reason. If possible you should SymLinks favor, because hard links are difficult to understand something as symlinks, and are also not all programs be supported and you may want / would imagine it. Absolutely common for the uninitiated copy (not!) way, is something like:

    Code:
    chown root.root / home/user1/.profile
    ln / home/user1/.profile / home/user2/.profile
    ln / home/user1/.profile / home/user3/.profile
    ... (For all users)
    This is all well all user profiles a par "(what the user personally, but not good and perhaps not even find the meaning of. profile equivalent), but an outsiders' Admin occurs as rapidly in a faux pas when he says, local what to change, its change in a magical way (via hard link) globally to all user s impact. And it is particularly bad if the setting happens to a terminal and then you see nothing more )
    Hello,
    I do not understand the following lines 

    Code:
    linux: / usr / lib / openoffice / share / fonts # ln-v-d / usr/X11R6/lib/X11/fonts/TT /
    create hard link `. / dd 'to` / usr/X11R6/lib/X11/fonts/TT'
    Ln: creating hard link `. / Dd 'to `/ usr/X11R6/lib/X11/fonts/TT ': Operation not permitted
    linux: / usr / lib / openoffice / share / fonts #
    How can i make a hard link to that directory? Also what exact is the work of a hard link in linux. Thank you for your help.

    Reply With Quote
      #2  
    Old 20-08-2010
    Member
     
    Join Date: Mar 2010
    Posts: 162
     
    Re: How to create Hard Link in Linux

    A hard link is a directory entry that references the same inode as another directory entry (only working in the same file system). One should therefore avoid very sparingly and use only with good reason. If possible you should SymLinks favor, because hard links are difficult to understand something as symlinks, and are also not all programs be supported and you may want / would imagine it. Absolutely common for the uninitiated copy (not!) way, is something like:

    Code:
    chown root.root / home/user1/.profile
    ln / home/user1/.profile / home/user2/.profile
    ln / home/user1/.profile / home/user3/.profile
    ... (For all users)
    This is all well all user profiles a par "(what the user personally, but not good and perhaps not even find the meaning of. profile equivalent), but an outsiders' Admin occurs as rapidly in a faux pas when he says, local what to change, its change in a magical way (via hard link) globally to all user s impact. And it is particularly bad if the setting happens to a terminal and then you see nothing more )
    Re: How to create Hard Link in Linux

    See this 
    Code:
    > Ln-v-d / usr/X11R6/lib/X11/fonts/TT /
    And
    Code:
    ln one
    ln [OPTION] ... OBJECTIVE [command name]
    Code:
    -D,-F, - directory
    Directories to link hard. (Only super-user)
  • 相关阅读:
    VMware下桥接设置
    Silverlight 样式的灵活使用
    Silverlight网页打开后马上崩溃,“白屏”,而且毫无提示
    Silverlight中字典的使用
    WEBGIS网页崩溃问题分析
    MDB数据类型注意事项
    使用浏览器开发着工具查看地图或影响的请求信息
    ArcGIS出图调整
    启动aspx文件错误
    hdu3555(数位DP dfs/递推)
  • 原文地址:https://www.cnblogs.com/kernel0815/p/3643823.html
Copyright © 2011-2022 走看看