- pb_log("remounting device %s read-only\n", dev->device_path);
- mount(dev->device_path, dev->mount_path, "",
- MS_REMOUNT | MS_RDONLY | MS_SILENT,
+ pb_log("remounting device %s read-only\n", device_path);
+
+ if (umount(dev->mount_path)) {
+ pb_log("Failed to unmount %s\n", dev->mount_path);
+ return;
+ }
+ dev->mounted_rw = dev->mounted = false;
+
+ if (dev->ramdisk) {
+ devmapper_merge_snapshot(dev);
+ /* device_path becomes stale after merge */
+ device_path = get_device_path(dev);
+ }
+
+ mount(device_path, dev->mount_path, fstype,
+ MS_RDONLY | MS_SILENT,