Error while attaching a disk as readonly mode to multiple instances

680 views
Skip to first unread message

Vikram Singh Saggu

unread,
Aug 12, 2014, 9:59:14 AM8/12/14
to gce-dis...@googlegroups.com
We are attaching a disk (readonly-pipeline) as readonly mode to multiple instances. Some times it gives error while attaching to instances.

I am using a startup script to attach the "readonly-pipeline" disk as readonly mode to newly created instances

"readonly-pipeline" disk was already attached to 4 instances. On new instance bootup in my startupscript i am using a command to attach "readonly-pipeline" disk as readonly to multiple instances where it gave the below error message

Error Message
ERROR: RESOURCE_IN_USE_BY_ANOTHER_RESOURCE: The disk resource 'projects/XXXX/zones/us-central1-a/disk
s/readonly-pipeline' is already being used by 'projects/XXXX/zones/us-central1-a/instances/yg-as-sortedbam123'

Omar KAMMOUN

unread,
Feb 8, 2016, 8:34:41 AM2/8/16
to gce-discussion
I have the same issue

gcloud compute instances attach-disk cp300-05-bis --disk cp-300-05-data --device-name data --mode ro

- The disk resource '******disks/cp-300-05-data' is already being used by '*****instances/cp300-05' 

Vikram Singh Saggu

unread,
Feb 8, 2016, 8:46:36 AM2/8/16
to Omar KAMMOUN, gce-discussion
Hi,

But now i do not get the error on attaching disk as read-only to multiple disk. Try below script.

#!/bin/bash
gcloud compute instances attach-disk instance-2 --disk example-disk-readonly --mode ro --zone europe-west1-c
sudo mkdir /mnt/sdb1
mount /dev/sda1 /mnt/sdb1

--
© 2014 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to a topic in the Google Groups "gce-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gce-discussion/z8E-tYK1u4A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gce-discussio...@googlegroups.com.
To post to this group, send email to gce-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/535fb7e3-f7bb-4bae-ba65-288e521d55be%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Thanks ,
Vikram

Omar KAMMOUN

unread,
Feb 9, 2016, 6:08:11 AM2/9/16
to gce-discussion, omarka...@gmail.com
Thank you for your replay

I misunderstand the doc
I thought one can write and all other can read,
but it's actually, if one write no one read,
but if no one write, all can read

few test
#i already have an instance name instance-1 in us-central1-a zone

#default config so i don't have to set --zone evry time
#gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a

#create disk my-ro-disk
gcloud compute disks create my-ro-disk --size 10GB

#attach disk my-ro-disk in read write mode
gcloud compute instances attach-disk instance-1 --disk my-ro-disk --device-name ro-disk

#SSH to instance-1 
gcloud compute ssh instance-1

# /!\ Prepare and FORMAT!!! disk for the first time, all data will be lost!
kammoun.o@instance-1:~$ sudo mkfs.ext4 -F /dev/disk/by-id/google-ro-disk

#Mount disk && create some content
kammoun.o@instance-1:~$ sudo mkdir /mnt/ro-disk
kammoun.o@instance-1:~$ sudo mount /dev/disk/by-id/google-ro-disk /mnt/ro-disk/
kammoun.o@instance-1:~$ sudo chmod 777 /mnt/ro-disk
kammoun.o@instance-1:~$ echo "Hello" > /mnt/ro-disk/hello.txt

#Unmount disk
kammoun.o@instance-1:~$ sudo umount /dev/disk/by-id/google-ro-disk
kammoun.o@instance-1:~$ exit

#Switch mode from rw to ro
gcloud compute instances detach-disk instance-1 --disk my-ro-disk
gcloud compute instances attach-disk instance-1 --disk my-ro-disk --device-name ro-disk --mode ro

#create new instance : instance-2
gcloud compute instances create instance-2 --machine-type f1-micro --image debian-8

#Attach disk in ro mode
gcloud compute instances attach-disk instance-2 --disk my-ro-disk --device-name ro-disk --mode ro

#SSH to instance-1 then Mount disk && check content
gcloud compute ssh instance-1
kammoun.o@instance-1:~$ sudo mount /dev/disk/by-id/google-ro-disk /mnt/ro-disk/
mount: /dev/sdb is write-protected, mounting read-only
kammoun.o@instance-1:~$ cat /mnt/ro-disk/hello.txt
Hello
kammoun.o@instance-1:~$ exit

#SSH to instance-2 then Mount disk && check content
gcloud compute ssh instance-2
kammoun.o@instance-1:~$ sudo mkdir /mnt/ro-disk
kammoun.o@instance-1:~$ sudo mount /dev/disk/by-id/google-ro-disk /mnt/ro-disk/
mount: /dev/sdb is write-protected, mounting read-only
kammoun.o@instance-1:~$ sudo chmod 777 /mnt/ro-disk
chmod: changing permissions of ‘/mnt/ro-disk’: Read-only file system
kammoun.o@instance-1:~$ cat /mnt/ro-disk/hello.txt
Hello
kammoun.o@instance-1:~$ exit
Reply all
Reply to author
Forward
0 new messages