/mnt/에서 'mkdir'을 실행할 수 없으며 'chmod'를 실행할 수 없습니다.

/mnt/에서 'mkdir'을 실행할 수 없으며 'chmod'를 실행할 수 없습니다.

나는 후속 조치를 취하고 있다이 가이드내 Ubuntu Azure 호스팅 VM에서는 /mnt/. 실행할 때 다음 오류 메시지가 계속 나타납니다 sudo mkdir /mnt/test/.

mkdir: cannot create directory ‘/mnt/test/’: Operation not permitted

이것을 시도했을 때 약간 다른 오류 메시지가 나타났습니다 cd /mnt/.

-bash: cd: /mnt/: Permission denied

다음 단계는 디렉토리의 권한을 확인하는 것이었으므로 실행하여 sudo stat /mnt/다음을 얻었습니다.

File: /mnt/
Size: 4096          Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d  Inode: 2           Links: 6
Access: (0444/dr--r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-02-17 14:19:48.658231668 +0000
Modify: 2021-02-08 12:34:19.906967600 +0000
Change: 2021-02-09 09:40:12.287101300 +0000
Birth: -

쓰기 권한이 없다는 것을 알고 실행했지만 sudo chmod 664 /mnt/다음 오류 메시지를 받았습니다.

chmod: changing permissions of '/mnt/': Operation not permitted

저는 Unix를 처음 접했기 때문에 어떻게 진행해야 할지 잘 모르겠습니다. 추가 문제 해결 단계나 해결 방법을 알려주시면 감사하겠습니다.

의견에 대한 응답:

df /mnt산출:

Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/sda1       32894736 49192  31151544   1% /mnt

grep | '/mnt'일부 편집 정보가 포함된 출력:

/dev/sda1 on /mnt type ext4 (rw,relatime,x-systemd.requires=cloud-init.service)
/dev/sda1 on /mnt/sdc1 type ext4 (rw,relatime)
/dev/sdc on /mnt/sdc type ext4 (rw,relatime)
//<azure storage account name>.file.core.windows.net/sih-workspace on /mnt/sih-workspace type cifs (rw,relatime,vers=3.0,cache=strict,username=**********,uid=0,noforceuid,gid=0,noforcegid,addr=<azure data centre IP>,file_mode=0777,dir_mode=0777,soft,persistenthandles,nounix,serverino,mapposix,rsize=1048576,wsize=1048576,bsize=1048576,echo_interval=60,actimeo=1)

답변1

ephemeral-disk-warning.dll을 통해 파일을 생성하는 어리석은 시스템 장치를 사용하십시오 ./mnt/DATALOSS_WARNING_README.txtsystemctl disable ephemeral-disk-warning.service

이유:

@chris-davies 덕분에 같은 상황에 직면했습니다.논평:

/mnt 자체의 다른 마운트에 의해 숨겨진 /mnt의 하위 디렉토리에 여러 마운트가 있는 것으로 보입니다. 당신이 원하는 것과 기대하지 않는 것을 결정해야합니다. 내 제안은 첫 번째 작업은 /mnt를 마운트 해제하여 다른 작업에 다시 노출되도록 하는 것입니다. 하지만 저는 귀하가 사용하고 있는 Azure 파일 시스템 유틸리티에 대해 잘 알지 못하므로 이것이 완전한 답변은 아닙니다.

$ cat /etc/rc.local
mkdir /mnt/tmp
mount --bind /mnt/tmp /tmp
chmod 1777 /tmp
# shortly after booted
$ l /mnt
total 37K
drwxr-xr-x  5 root  root  4.0K Jan 14 08:46 .
drwxr-xr-x 19 root  root    26 Jan 14 01:22 ..
drwx------  2 root  root   16K Jan 14 08:46 lost+found
drwxrwxrwt  5 root  root  4.0K Jan 14 08:46 tmp
# just after systemd unit `ephemeral-disk-warning.service` started and failed
$ l /mnt
ls: cannot access '/mnt/.': Permission denied
ls: cannot access '/mnt/..': Permission denied
ls: cannot access '/mnt/lost+found': Permission denied
ls: cannot access '/mnt/tmp': Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
d????????? ? ? ? ?            ? lost+found
d????????? ? ? ? ?            ? tmp

조사:

$ journalctl --no-pager --boot -g ephemeral
Jan 14 08:46:48 azure systemd[1]: Starting Write warning to Azure ephemeral disk...
Jan 14 08:46:48 azure ephemeral-disk-warning[3758]: /usr/sbin/ephemeral-disk-warning: 7: cannot create /mnt
Jan 14 08:46:48 azure audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=unconfined msg='unit=ephemeral-disk-warning comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jan 14 08:46:48 azure root[3763]: Added ephemeral disk warning to /mnt
                                  /tmp/DATALOSS_WARNING_README.txt
Jan 14 08:46:48 azure systemd[1]: Finished Write warning to Azure ephemeral disk.
$ journalctl --no-pager --boot -u ephemeral-disk-warning
Jan 14 08:46:48 azure systemd[1]: Starting Write warning to Azure ephemeral disk...
Jan 14 08:46:48 azure ephemeral-disk-warning[3758]: /usr/sbin/ephemeral-disk-warning: 7: cannot create /mnt
Jan 14 08:46:48 azure ephemeral-disk-warning[3758]: /tmp/DATALOSS_WARNING_README.txt: Directory nonexistent
Jan 14 08:46:48 azure systemd[1]: Finished Write warning to Azure ephemeral disk.
Jan 14 08:46:48 azure ephemeral-disk-warning[3761]: chmod: cannot access '/tmp/DATALOSS_WARNING_README.txt': No such file or directory
Jan 14 08:46:48 azure ephemeral-disk-warning[3762]: chattr: No such file or directory while trying to stat /tmp/DATALOSS_WARNING_README.txt
$ systemctl cat ephemeral-disk-warning.service
[Unit]
Description=Write warning to Azure ephemeral disk
After=cloud-config.service
ConditionVirtualization=microsoft
ConditionPathIsMountPoint=/mnt
ConditionPathExists=/dev/disk/azure/resource-part1

[Service]
Type=oneshot
ExecStart=/usr/sbin/ephemeral-disk-warning
RemainAfterExit=yes
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
$ cat /usr/sbin/ephemeral-disk-warning
#!/bin/sh
dev_resource=$(readlink -f /dev/disk/azure/resource-part1)
dev_resource_mp=$(awk '$1==R {print$2}' "R=${dev_resource}" /proc/mounts)
warn_file="${dev_resource_mp}/DATALOSS_WARNING_README.txt"

if [ ! -f "${warn_file}" ]; then
    cat > ${warn_file} <<EOM
WARNING: THIS IS A TEMPORARY DISK.

Any data stored on this drive is SUBJECT TO LOSS and THERE IS NO WAY TO
RECOVER IT.

Please do not use this disk for storing any personal or application data.

For additional details to please refer to the MSDN documentation at:
http://msdn.microsoft.com/en-us/library/windowsazure/jj672979.aspx

To remove this warning run:
    sudo chattr -i $warn_file
    sudo rm $warn_file

This warning is written each boot; to disable it:
    echo "manual" | sudo tee /etc/init/ephemeral-disk-warning.override
    sudo systemctl disable ephemeral-disk-warning.service

EOM

    chmod 0444 ${warn_file}
    chattr +i ${warn_file}
    logger "Added ephemeral disk warning to ${warn_file}"
fi
$ source <(head -n 4 /usr/sbin/ephemeral-disk-warning)
$ echo $warn_file
/mnt
/tmp/DATALOSS_WARNING_README.txt
$ echo chattr +i ${warn_file}
chattr +i /mnt
/tmp/DATALOSS_WARNING_README.txt

그래서 이건 또 다른 거야개행 트랩결과적으로 전체가 다음 /mnt과 같이 표시됩니다.불변, 마지막으로 /etc/rc.local이전 스타일의 자동 실행 스크립트를 다음으로 변환했습니다.시스템 장치:

# https://unix.stackexchange.com/questions/471824/what-is-the-correct-substitute-for-rc-local-in-systemd-instead-of-re-creating-rc
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/path/to/the/script.sh
StandardOutput=journal+console
StandardOutput=journal+console

[Unit]
# https://unix.stackexchange.com/questions/635165/unable-to-mkdir-in-mnt-and-cannot-chmod/766859#766859
After=ephemeral-disk-warning.service

After=mnt.mount
Requires=mnt.mount
RequiredBy=anything-requiring-mnt.service
Before=anything-requiring-mnt.service

[Install]
WantedBy=multi-user.target

답변2

/mnt에 파일 시스템을 마운트하면 그 아래에 아무것도 생성할 수 없습니다. "$df -h /mnt"를 실행하여 이를 테스트할 수 있으며 다음과 같은 자동 지도가 표시될 것이라고 가정할 수 있습니다.

마운트된 %를 사용하여 사용 가능한 파일 시스템 크기 사용 가능

/etc/auto.toybox 0 0 0 - /mnt

그렇다면 자동 마운트는 자동 매퍼의 마운트 지점으로 /mnt를 선언했으며 /mnt 아래에 생성하려는 모든 항목은 작동하지 않습니다. 그렇기 때문에 허가가 거부되었습니다.

위와 같은 자동 마운트가 표시되면 자동 마운트에 대한 직접 매핑이 잘못되었을 수 있습니다. autofs, ypbind man 및 systemctl 출력을 봅니다. ypcat -k 명령을 사용하여 auto.master 매핑이 수행하는 작업을 확인하세요.

ypcat -k auto.master 또는 ypcat -k auto.home 등을 사용하면 매핑을 알 수 있습니다.
auto.master는 redhat 변형 및 ypbind를 사용하는 경우 /etc/ypsrc/ 디렉토리에 있을 수 있는 auto.home과 같은 매핑을 사용한다는 점을 기억하십시오. 매핑을 보려면 "automount -m" 또는 "sudo automount -m"을 사용하세요. NIS 서버의 매핑을 변경하려면 /var/yp/에서 "make"를 실행해야 합니다.

/etc/ypsrc/auto.home을 사용하면 자동 매퍼가 디렉토리를 client:/home 디렉토리에 마운트할 수 있습니다. 따라서 /mnt에서 "정말로" mkdir이 필요한 경우 마운트 지점을 /home으로 이동하고 이제 허용해야 합니다. 끔찍한 "권한 거부" 오류가 발생하지 않고 /mnt에서 mkdir을 수행할 수 있지만 실제로 /mnt를 사용하여 임의의 디렉터리를 생성하면 안 됩니다. IMHO. 요약하자면, 이미 사용 중인 마운트 지점에서는 mkdir을 수행할 수 없습니다. 이는 /autofs를 자동 마운트하거나 /mnt<에 잘못된 소유자/그룹을 할당하는 데 문제가 있을 수 있으며 이는 쉽게 알아차리고 수정할 수 있습니다.

관련 정보