[英]Simulate mounted volume errors to cause read only
Few days ago we have encountered an unexpected error where one of the mounted drive on our RedHat linux machine became Read-Only. 几天前我们遇到了一个意外错误,其中我们的RedHat linux机器上的一个挂载驱动器变为只读。 The issue was cause by the network outage in the datacenter. 问题是由数据中心的网络中断引起的。
Now I need to see if I can reproduce the same behavior where drive will be re-mounted as Read-Only while application is running. 现在,我需要看看是否可以重现相同的行为,即在应用程序运行时将驱动器重新挂载为只读。
I tried to remounted it was read-only but that didn't work because there are files that are opened (logs being written). 我试图重新安装它是只读的但是没有用,因为有文件被打开(正在写日志)。
Is there a way to temporary cause the read-only if I have root access to the machine (but no access to the hypervisor). 如果我具有对计算机的root访问权限(但无法访问管理程序),是否有一种临时导致只读的方法。
That volume is mounted via /etc/fstab
. 该卷通过/etc/fstab
挂载。 Here is the record: 这是记录:
UUID=abfe2bbb-a8b6-4ae0-b8da-727cc788838f / ext4 defaults 1 1
UUID=8c828be6-bf54-4fe6-b68a-eec863d80133 /opt/sunapp ext4 rw 0 2
Here are the output of few commands that shows details about our mounted drive. 以下是几个命令的输出,显示有关已安装驱动器的详细信息。 I can add more details as needed. 我可以根据需要添加更多细节。
Output of fdisk -l
输出fdisk -l
Disk /dev/vda: 268.4 GB, 268435456000 bytes, 524288000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008ba5f
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 524287966 262142959+ 83 Linux
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Output of lsblk
command: 输出lsblk
命令:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 80G 0 disk
└─vda1 253:1 0 80G 0 part /
vdb 253:16 0 250G 0 disk /opt/sunup
Output of blkid
command: 输出blkid
命令:
/dev/vda1: UUID="abfe2bbb-a8b6-4ae0-b8da-727cc788838f" TYPE="ext4"
/dev/sr0: UUID="2017-11-13-13-33-07-00" LABEL="config-2" TYPE="iso9660"
/dev/vdb: UUID="8c828be6-bf54-4fe6-b68a-eec863d80133" TYPE="ext4"
Output of parted -l
command: parted -l
命令的输出:
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0
has been opened read-only.
Error: /dev/sr0: unrecognised disk label
Model: QEMU QEMU DVD-ROM (scsi)
Disk /dev/sr0: 461kB
Sector size (logical/physical): 2048B/2048B
Partition Table: unknown
Disk Flags:
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 268GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 268GB 268GB primary ext4 boot
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 42.9GB 42.9GB ext4
Yes, you can do it. 是的,你可以做到。 But the method proposed here may cause data loss, so use it only for testing. 但是这里提出的方法可能会导致数据丢失,因此仅将其用于测试。
Supposing you have /dev/vdb
mounted as /opt/sunapp
, do this: 假设您将/dev/vdb
挂载为/opt/sunapp
,请执行以下操作:
Configure a loop device to mirror the contents of /dev/vdb
: 配置循环设备以镜像/dev/vdb
的内容:
losetup /dev/loop0 /dev/vdb
Then, mount /dev/loop0
instead of /dev/vdb
: 然后,挂载/dev/loop0
而不是/dev/vdb
:
mount /dev/loop0 /opt/sunapp -o rw,errors=remount-ro
Now, you can run your application. 现在,您可以运行您的应用程序。 When it is time to make /opt/sunapp
read-only, use this command: 当需要将/opt/sunapp
只读时,请使用以下命令:
blockdev --setro /dev/vdb
After that, attempts to write to /dev/loop0
will result in I/O errors. 之后,尝试写入/dev/loop0
将导致I / O错误。 As soon as file system driver detects this, it will remount the file system as read-only. 一旦文件系统驱动程序检测到这一点,它就会将文件系统重新安装为只读。
To restore everything back, you will need to unmount /opt/sunapp
, detach the loop device, and make /dev/vdb
writable again: 要恢复所有内容,您需要卸载/opt/sunapp
,分离循环设备,并使/dev/vdb
再次可写:
umount /opt/sunapp
losetup -d /dev/loop0
blockdev --setrw /dev/vdb
When I had some issues like corrupted disks, I had used ntfsfix. 当我遇到像损坏的磁盘这样的问题时,我使用了ntfsfix。 Please see if these commands, solve the problem. 请查看这些命令是否解决了问题。
sudo ntfsfix /dev/vda
sudo ntfsfix /dev/vdb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.