장치가 읽기 전용으로 마운트되었지만 여전히 쓸 수 있습니다(CentOS 6.8).

장치가 읽기 전용으로 마운트되었지만 여전히 쓸 수 있습니다(CentOS 6.8).

플래시 드라이브에 CentOS 6.8이 설치되어 있고 제한된 수명 주기(쓰기 100,000회(각 섹터에 대해 오류가 발생하기까지의 평균 시간))로 인해 읽기 전용으로 마운트하고 싶습니다.

커널은 ro로 시작되는 것으로 추정됩니다. 적어도 결과는 cat /proc/cmdline"ro ..."로 시작됩니다.

/etc/fstab읽기 전용으로 마운트하도록 설정했습니다 .

UUID=4addd4a7-97f6-4399-89e4-6d3728bd2979 /     ext4    defaults,noatime,ro        1 1
UUID=21a81149-6534-4313-8696-e203896d5881 /boot ext4    defaults,noatime,ro        1 2
UUID=D64B-DD9C          /boot/efi               vfat    noatime,ro,umask=0077,shortname=winnt 0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
tmpfs                   /var/log                tmpfs   defaults        0 0

을 실행하면 mount의 사양이 /etc/fstab준수된 것을 볼 수 있습니다. 그럼에도 불구하고 나는 여전히 파일을 수정하고 새 파일을 쓸 수 있습니다. 쓰기 가능한 마운트에 대한 추가 증거가 실행 중입니다 lsof(다음에 따라).이 게시물). 결과에는 대부분 /home에 쓰기 위해 열려 있는 몇 개의 파일이 표시됩니다. (여기까지 오려면 /var/log로 마운트해야 했습니다 tmpfs.)

CentOS 6.8의 버그입니까? 해결 방법이 있나요?

답변1

아마도 매뉴얼 페이지에서 장치를 읽기 전용으로 만들려면 장치를 다시 마운트해야 한다는 일종의 버그가 있다는 내용을 읽은 기억이 납니다.

mount -o remount,ro ...

fstab의 다른 항목 뒤에 다시 마운트를 추가해 보십시오. ps 마운트는 fstab의 파일 시스템 "없음"을 제공할 수 있습니다.

업데이트:

관련 man 항목을 찾았습니다.

   mount(8) since v2.27 allows to change the mount options by passing the relevant options along with --bind.  For example:

          mount --bind,ro foo foo

   This feature is not supported by the Linux kernel; it is implemented in userspace by an additional mount(2) remounting syscall.  This solution is not atomic.

   The alternative (classic) way to create a read-only bind mount is to use the remount operation, for example:

          mount --bind olddir newdir
          mount -o remount,ro,bind olddir newdir

   Note that a read-only bind will create a read-only mountpoint (VFS entry), but the original filesystem superblock will  still  be  writable,  meaning  that  the  olddir  will  be
   writable, but the newdir will be read-only.

   It's impossible to change mount options recursively (for example with -o rbind,ro).

이를 기반으로 fstab 옵션을 사용해 볼 수 있습니다.

default,rbind,ro

실패하면 다시 마운트할 항목을 추가하세요.

업데이트 2(man 8 마운트 / man 8 마운트 blockdev);

   -r, --read-only
          Mount the filesystem read-only.  A synonym is -o ro.

          Note  that,  depending  on the filesystem type, state and kernel behavior, the system may still write to the device.  For example, ext3 and ext4 will replay the journal if
          the filesystem is dirty.  To prevent this kind of write access, you may want to mount an ext3 or ext4 filesystem with the ro,noload mount options or set the  block  device
          itself to read-only mode, see the blockdev(8) command.

이는 다음과 같은 옵션이 있음을 의미합니다.

ro,noload

또는 사용;

blockdev --setro /dev/...

관련 정보