Question

Best practices using block storage on DO?

Hi, I am currently a Beta User of the Block Storage option on DO.

I would like to know how do I save something on a Block Storage drive.

Specifically I would like to set up OwnCloud to use a block storage drive exceeding the 20gb on a 512 mb sever. I have confirmed that this server is properly configured to use Block Storage, just don’t know how to change storage drive.

I would ultimately like to know (if possible) how to move the drive with all of the data to a different sever.

Thanks In Advance.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello,

Thanks for participating on our Block Storage Beta. To replicate your use case I used DigitalOcean’s One-Click OwnCloud install, which set up the droplet for me, the next step was to add a drive.

After creating and attaching a drive to your droplet, which you said you already did, you need to format and mount it, as explained on the beta tutorial, lets see how it would work on our one-click OwnCloud setup.

SSH into your droplet and find out the block device name that was given to the drive with the command lsblk, like so:

root@owncloud-512mb-nyc1-01:~# lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda      8:0    0  11G  0 disk 
vda    253:0    0  20G  0 disk 
└─vda1 253:1    0  20G  0 part /

In my case I have a 11GB drive, it got named sda. Now that I know its name, I can format and mount it. Formating will erase all the data in it (I’m assuming this is a brand new drive and doesn’t contain your data) and prepare the filesystem on it. I’ll do that with the command mkfs and I’ll use the ext4 filesystem, which is the default on most Linux distros:

mkfs -t ext4 /dev/sda

Now I need to mount it on a folder, so it will be visible to the droplet filesystem and I can put files on it. To do that first I need to create a folder, in my case it will be on /mnt/owncloud_data.

mkdir -p /mnt/owncloud_data

It’s common practice to create a folder inside /mnt to mount your block devices, but you could choose other folders. Now that I have my folder I can mount the block device on it, like so:

mount -o discard,defaults /dev/sda /mnt/owncloud_data

If I run lsblk again I’ll see that it’s name on the mountpoint for sda:

root@owncloud-512mb-nyc1-01:~# lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda      8:0    0  11G  0 disk /mnt/owncloud_data
vda    253:0    0  20G  0 disk 
└─vda1 253:1    0  20G  0 part /

Now I’m ready to use my drive to store my OwnCloud files. I’m not an OwnCloud expert, so I used the instructions on this YouTube video to change it’s configuration (thanks locslikes). Remember their recommendation about backing up your files before you do this kind of change.

By default, the OwnCloud one-click droplet will use the folder /var/www/owncloud/data to store files, I need to move it to my drive. To do so I’ll stop Apache and them move the folder, like so:

service apache2 stop
mv /var/www/owncloud/data /mnt/owncloud_data

You should see a new folder inside /mnt/owncloud_data like so:

root@owncloud-512mb-nyc1-01:~# ls -l /mnt/owncloud_data/
total 20
drwxrwx--- 4 www-data www-data  4096 Apr 27 19:43 data
drwx------ 2 root     root     16384 Apr 27 19:53 lost+found

Now we change OwnCloud’s configuration to point to the new folder, modifying the file /var/www/owncloud/config/config.php. Open it with your favorite editor and change the line:

  'datadirectory' => '/var/www/owncloud/data',

To:

  'datadirectory' => '/mnt/owncloud_data/data',

Save the file and restart Apache:

service apache2 start

Access your droplet IP, log into OwnCloud and the files you upload will be stored on your new block storage drive instead of the droplet local storage.

In the future I could detach the drive from this droplet, attach it to another OwnCloud droplet, mount it without formatting, changing the config just like we did above and my data would be available on the new droplet. The steps are pretty much the same, just make sure you don’t format the drive :)

Just remember that Block Storage is still in beta, some details might change when we make updates and we don’t provide a SLA for your data, so you should not use it for production applications yet. Also, we are aware that the process of formating and mouting is cumbersome and not user friendly, we are working to make it easier in the near future.

I hope this was helpful.

Best regards, Rafael