One place for hosting & domains

      October 2018

      How to Deploy a Symfony 4 Application to Production with LEMP on Ubuntu 18.04


      The author selected Software in the Public Interest Inc to receive a donation as part of the Write for DOnations program.

      Introduction

      Symfony is an open-source PHP framework with an elegant structure and a reputation for being a suitable framework to kick-start any project irrespective of its size. As a set of reusable components, its flexibility, architecture, and high performance make it a top choice for building a highly complex enterprise application.

      In this tutorial, you will deploy an existing, standard Symfony 4 application to production with a LEMP stack (Nginx, MySQL, and PHP) on Ubuntu 18.04, which will help you get started configuring the server and the structure of the framework. Nginx is a popular open-source, high-performance HTTP server with additional features including reverse proxy support. It has a good reputation and hosts some of the largest and highest traffic sites on the internet. If you choose to deploy your own Symfony application instead, you might have to implement extra steps depending on the existing structure of your application.

      Prerequisites

      To complete this tutorial, you will need:

      Step 1 — Creating a User and Database for the Application

      By following the instructions in the Prerequisites, you now have all the basic server dependencies required for the application installation. As every dynamic web application requires a database, you will create a user and properly configure a database for the application in this section.

      To create a MySQL database for our application and a user associated with it, you need to access the MySQL client using the MySQL root account:

      Enter the appropriate password, which should be the same password used when running mysql_secure_installation.

      Next, create the application database with:

      You will see the following output in the console:

      Output

      Query OK, 1 row affected (0.00 sec)

      You have successfully created your application database. You can now create a MySQL user and grant them access to the newly created database.

      Execute the following command to create a MySQL user and password. You can change the username and password to something more secure if you wish:

      • CREATE USER 'blog-admin'@'localhost' IDENTIFIED BY 'password';

      You will see the following output:

      Output

      Query OK, 0 rows affected (0.00 sec)

      Currently, the user blog-admin does not have the right permission over the application database. In fact, even if blog-admin tries to log-in with their password, they will not be able to reach the MySQL shell.

      A user needs the right permission before accessing or carrying out a specific action on a database. Use the following command to allow complete access to the blog database for the blog-admin user:

      • GRANT ALL PRIVILEGES ON blog.* TO 'blog-admin'@'localhost';

      You will see the following output:

      Output

      Query OK, 0 rows affected (0.00 sec)

      The blog-admin now has all privileges on all the tables inside the blog database. To reload the grant tables and apply changes, you need to perform a flush-privilege operation using the flush statement:

      You will see the following output:

      Output

      Query OK, 0 rows affected (0.00 sec)

      You are done creating a new user and granting privileges. To test if you’re on track, exit the MySQL client:

      And log in again, using the credentials of the MySQL user you just created and enter the password when prompted:

      Check that the database can be accessed by the user with:

      You'll see the blog table in the output:

      Output

      +--------------------+ | Database | +--------------------+ | information_schema | | blog | +--------------------+ 2 rows in set (0.00 sec)

      Finally, exit the MySQL client:

      You have successfully created a database, a user for the demo application, and granted the newly created user the right privileges to access the database. You are now ready to set up the demo application.

      Step 2 — Setting Up the Demo Application

      To keep this tutorial simple, you will deploy a blog application built with Symfony. This application will allow an authenticated user to create a blog post and store it in the database. In addition, the application user can view all the posts and details associated with an author.

      The source code of the blog application you will deploy in this tutorial is on GitHub. You will use Git to pull the source code of the application from GitHub and save it in a new directory.

      First, create a directory that will serve as the root directory for your application. So, run the following command from the console to create a new directory named symfony-blog:

      • sudo mkdir -p /var/www/symfony-blog

      In order to work with the project files using a non-root user account, you’ll need to change the folder owner and group by running:

      • sudo chown sammy:sammy /var/www/symfony-blog

      Replace sammy with your sudo non-root username.

      Now, you can change into the parent directory and clone the application on GitHub:

      • cd /var/www
      • git clone https://github.com/yemiwebby/symfony-blog.git symfony-blog

      You'll see the following output:

      Output

      Cloning into 'symfony-blog'... remote: Counting objects: 180, done. remote: Compressing objects: 100% (122/122), done. remote: Total 180 (delta 57), reused 164 (delta 41), pack-reused 0 Receiving objects: 100% (180/180), 167.01 KiB | 11.13 MiB/s, done. Resolving deltas: 100% (57/57), done.

      The demo application is now set. In the next step, you will configure the environment variables and install the required dependencies for the project.

      Step 3 — Configuring your Environment Variables for the Application

      To completely set up the application, you need to install the project dependencies and properly configure the application parameters.

      By default, the Symfony application runs in a development mode, which gives it a very detailed log for the purposes of debugging. This is not applicable to what you are doing in this tutorial, and not good practice for a production environment, as it can slow things down and create very large log files.

      Symfony needs to be aware that you’re running the application in a production environment. You can set this up by either creating a .env file containing variable declarations, or creating environment variables directly. Since you can also use the .env file to configure your database credentials for this application, it makes more sense for you to do this. Change your working directory to the cloned project and create the .env file with:

      • cd symfony-blog
      • sudo nano .env

      Add the following lines to the file to configure the production application environment:

      .env

      APP_ENV=prod
      APP_DEBUG=0
      

      APP_ENV is an environment variable that specifies that the application is in production, while APP_DEBUG is an environment variable that specifies if the application should run in debug mode or not. You have set it to false for now.

      Save the file and exit the editor.

      Next, install a PHP extension that Symfony apps use to handle XML:

      • sudo apt install php7.2-xml

      Next, you need to install the project dependencies, run composer install:

      • cd /var/www/symfony-blog
      • composer install

      You have successfully configured the environment variables and installed the required dependencies for the project. Next, you will set up the database credentials.

      Step 4 — Setting Up Database Credentials

      In order to retrieve data from the application’s database you created earlier, you will need to set up and configure the required database credentials from within the Symfony application.

      Open the .env file again:

      Add the following content to the file, which will allow you to easily connect and interact properly with the database. You can add it right after the APP_DEBUG=0 line within the .env file:

      .env

      ...
      DATABASE_URL=mysql://blog-admin:password@localhost:3306/blog
      

      The Symfony framework uses a third-party library called Doctrine to communicate with databases. Doctrine gives you useful tools to make interactions with databases easy and flexible.

      You can now use Doctrine to update your database with the tables from the cloned Github application. Run this command to do that:

      • php bin/console doctrine:schema:update --force

      You'll see the following output:

      Output

      Updating database schema... 4 queries were executed [OK] Database schema updated successfully!

      After setting up the required credentials and updating the database schema, you can now easily interact with the database. In order to start the application with some data, you will load a set of dummy data into the database in the next section.

      Step 5 — Populating your Database Using Doctrine-Fixtures

      At the moment, the newly created tables are empty. You will populate it using doctrine-fixtures. Using Doctrine-Fixtures is not a prerequisite for Symfony applications, it is only used to provide dummy data for your application.

      Run the following command to automatically load testing data that contains the details of an author and a sample post into the database table created for the blog:

      • php bin/console doctrine:fixtures:load

      You will get a warning about the database getting purged. You can go ahead and type Y:

      Output

      Careful, database will be purged. Do you want to continue y/N ? y > purging database > loading AppDataFixturesORMFixtures

      In the next section you will clear and warm up you cache.

      Step 6 — Clearing and Warming Up your Cache

      To ensure your application loads faster when users make requests, it is good practice to warm the cache during the deployment. Warming up the cache generates pages and stores them for faster responses later rather than building completely new pages. Fortunately, Symfony has a command to clear the cache that also triggers a warm up. Run the following command for that purpose:

      • php bin/console cache:clear

      You will see the following output:

      Output

      Clearing the cache for the prod environment with debug false [OK] Cache for the "prod" environment (debug=false) was successfully cleared.

      You will conclude the set up in a bit. All that remains is to configure the web server. You will do that in the next section.

      Step 7 — Configuring the Web Server and Running the Application

      By now, you have Nginx installed to serve your pages and MySQL to store and manage your data. You will now configure the web server by creating a new application server block, instead of editing the default one.

      Open a new server block with:

      • sudo nano /etc/nginx/sites-available/blog

      Add the following content to the new server block configuration file. Ensure you replace the your_server_ip within the server block with your server IP address:

      /etc/nginx/sites-available/blog

      
      server {
          listen 80;
          listen [::]:80;
      
          server_name blog your_server_ip;
          root /var/www/symfony-blog/public;
          index index.php;
          client_max_body_size 100m;
      
          location / {
              try_files $uri $uri/ /index.php$is_args$args;
          }
      
          location ~ .php {
              try_files $uri /index.php =404;
              fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              fastcgi_param SCRIPT_NAME $fastcgi_script_name;
              fastcgi_split_path_info ^(.+.php)(/.+)$;
              fastcgi_index index.php;
              include fastcgi_params;
            }
      
          location ~ /.(?:ht|git|svn) {
              deny all;
          }
      }
      

      First, we specified the listen directives for Nginx, which is by default on port 80, and then set the server name to match requests for the server’s IP address. Next, we used the root directives to specify the document root for the project. The symfony-blog application is stored in /var/www/symfony-blog, but to comply with best practices, we set the web root to /var/www/symfony-blog/public as only the /public subdirectory should be exposed to the internet. Finally, we configured the location directive to handle PHP processing.

      After adding the content, save the file and exit the editor.

      Note: If you created the file example.com in the prerequisite article How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu 18.04, remove it from the sites-enabled directory with sudo rm /etc/nginx/sites-enabled/example.com so it doesn't conflict with this new file.

      To enable the newly created server block, we need to create a symbolic link from the new server block configuration file located in /etc/nginx/sites-available directory to the /etc/nginx/sites-enabled by using the following command:

      • sudo ln -s /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/

      Check the new configuration file for any syntax errors by running:

      This command will print errors to the console if there are any. Once there are no errors run this command to reload Nginx:

      • sudo systemctl reload nginx

      You just concluded the last step required to successfully deploy the Symfony 4 application. You configured the web server by creating a server block and properly set the web root in order to make the web application accessible.

      Finally, you can now run and test out the application. Visit http://your_server_ip in your favorite browser:

      The following image is the screenshot of the Symfony blog application that you should see at your server's IP address:

      Alt screenshot of the Symfony blog application

      Conclusion

      Symfony is a feature-rich PHP framework with an architecture that makes web development fun for the developer who builds software using it. Symfony is a feature-rich web development framework that provides developers powerful tools to build web applications. It's often considered a good choice for enterprise applications due to its flexibility. The steps to deploy a typical Symfony application vary—depending on the setup, complexity, and the requirements of the application.

      In this tutorial, you manually deployed a Symfony 4 application to production on an Ubuntu 18.04 server running LEMP. You can now apply this knowledge to deploying your own Symfony applications.



      Source link

      How to Create a DigitalOcean Droplet from an Ubuntu ISO Format Image


      Introduction

      DigitalOcean’s Custom Images feature allows you to bring your virtual disk images from an on-premise environment or another cloud platform to DigitalOcean and use them to start DigitalOcean Droplets.

      As described in the Custom Images documentation, the following image types are supported natively by the Custom Images upload tool:

      ISO is another popular image format which you may want to use with Custom Images. ISO images are frequently provided by Linux distributions as a convenient method for installing Linux. Unfortunately, ISO images aren’t currently supported by the upload tool, although support is planned for the end of 2018.

      In this tutorial, we’ll demonstrate how to use the free and open-source VirtualBox virtualization tool to create a DigitalOcean-compatible VDI image (VirtualBox Disk Image) from an Ubuntu 18.04 ISO. The steps in this guide can be adapted to work with your preferred distribution’s ISO images.

      Prerequisites

      Before you begin, you’ll need the following available to you:

      If you’re adapting these steps for another distribution’s ISO and your image does not have cloud-init installed and configured, you must install and configure it manually after installing the OS.

      Once you have these prerequisites available to you, you’re ready to begin with this guide.

      Step 1 — Installing VirtualBox and Creating a Virtual Machine

      The tool we’ll use to convert the ISO-format image in this guide is VirtualBox, a free and open-source virtualizer for x86 hardware. By default, VirtualBox uses a GUI, which we’ll use to create the VDI image in this guide.

      To begin, download and install VirtualBox from the downloads page. Follow the appropriate link in the VirtualBox 5.2.20 platform packages section depending on your host operating system. In this guide, we’ll be using an OSX system, so we’ll download and install VirtualBox using the provided DMG.

      Once you’ve installed VirtualBox, open the application.

      You should see the following welcome screen:

      VirtualBox Welcome Screen

      Click on New to begin creating your Ubuntu virtual machine.

      The following window should pop up, allowing you to name your virtual machine (VM) and select its OS:

      Name Virtual Machine Window

      In this tutorial, we’ll name our VM Ubuntu 18.04, but feel free to give the VM a more descriptive name.

      For Type, select Linux, and for Version, select Ubuntu (64-bit). Then, hit Continue.

      The following screen should appear, allowing you to specify how much memory to allocate to your virtual machine:

      Allocate Memory Window

      Unless you have a more complex use case, 1024 MB should be enough memory for your virtual machine. If you need to adjust memory size, enter the amount of memory to be allocated to the VM, then hit Continue.

      You should see the following screen:

      Create Hard Disk Window

      This window allows you to create a virtual hard disk for your VM. This virtual hard disk is the image that you’ll upload to DigitalOcean in a later step. The Ubuntu operating system will be installed from the ISO you downloaded to this virtual hard disk. Make sure Create a virtual hard disk now is selected, and hit Create.

      The following Hard disk file type window should appear, allowing you to select the format you’d like to use for your image:

      Select Hard Disk Type Window

      All three types are supported by DigitalOcean Custom Images, so unless you have a strong preference, select VDI (VirtualBox Disk Image). Hit Continue.

      You should then see the following window:

      Hard Disk Options

      This window allows you to choose between a Dynamically allocated or Fixed size hard disk file. We’ll use the default Dynamically allocated option and allow the file to grow as we install the Ubuntu OS and packages. Hit Continue.

      The next window allows you to name your hard disk file (as well as choose the path to which it will be saved), and specify its maximum size:

      Hard Disk Size

      Be sure to give yourself enough disk space to install the operating system as well as additional packages you may need. The default 10 GB should be fine for most purposes, but if you anticipate installing a large number of packages or storing a lot of data in the image, you should bump this up to your anticipated disk usage.

      Once you’ve selected the size of the virtual hard disk, hit Create.

      At this point, you’ll be returned to the initial welcome screen, where you’ll see the virtual machine you just created:

      VM Welcome Screen

      We can now begin installing Ubuntu onto the virtual machine.

      Step 2 — Installing Ubuntu 18.04 onto the Virtual Machine

      In this step we’ll install and configure the Ubuntu operating system onto our virtual machine.

      To begin, from the VirtualBox welcome screen, select your virtual machine, and hit the Start button in the toolbar.

      You should see the following virtual machine window, prompting you to select the ISO file from which you’ll boot the system:

      Select ISO

      Select the Ubuntu 18.04 Server ISO you downloaded, and hit Start.

      In the VM, the Ubuntu installer will begin booting from the ISO, and you should be brought to the following menu:

      Ubuntu Select Language

      Choose your preferred language using the arrow keys, and hit ENTER to continue.

      You should then see the following Keyboard configuration screen:

      Ubuntu Keyboard Config

      Choose your preferred keyboard configuration, select Done, and hit ENTER.

      Next, you’ll be brought to the following installer selection screen:

      Ubuntu Installer Selection

      Select Install Ubuntu, and hit ENTER.

      The following Network connections screen should appear:

      Ubuntu Network connections

      This screen allows you to configure the network interfaces for your Ubuntu server. Since we’re performing the installation on a virtual machine, we’ll just use the default option as the configured interface will be overwritten when we launch the image on the DigitalOcean platform.

      Select Done and hit ENTER.

      You’ll then be brought to the following Configure proxy screen:

      Ubuntu Configure Proxy

      If you require a proxy, enter it here. Then, select Done, and hit ENTER.

      The next screen will allow you to choose an Ubuntu archive mirror:

      Ubuntu Archive Mirror

      Unless you require a specific mirror, the default should be fine here. Select Done and hit ENTER.

      Next, you’ll be prompted to partition your virtual disk:

      Ubuntu Partition Disk

      Unless you’d like to set up Logical Volume Manager (LVM) or manually partition the virtual disk, select Use An Entire Disk to use the entire attached virtual disk, and hit ENTER.

      The following screen allows you to select the virtual disk that will be partitioned:

      Ubuntu Filesystem setup

      As described in the prompt text, the installer will create a partition for the bootloader, and use the remaining virtual disk space to create an ext4 partition to which the Ubuntu OS will be installed.

      Select the attached virtual disk and hit ENTER.

      The following screen displays a summary of the filesystem installer options before partitioning:

      Ubuntu Filesystem Summary

      The ext4 partition will be mounted to /, and a second partition (1 MB) will be created for the GRUB bootloader. Once you’ve gone over and confirmed the partitioning scheme for your virtual disk, select Done and hit ENTER.

      In the confirmation screen that appears, select Continue and hit ENTER.

      The next screen will allow you to configure the system hostname, as well as an Ubuntu user:

      Ubuntu Create User

      Note that as you fill out this screen, the installer will continue copying files to the virtual disk in the background.

      In this tutorial, we’ll create a user named sammy and call our server ubuntu. The server name will likely be overwritten when this image is run on the DigitalOcean platform, so feel free to give it a temporary name here.

      You can upload your SSH keys to DigitalOcean and automatically embed them into created Droplets, so for now we won’t Import SSH identity. To learn how to upload your SSH keys to DigitalOcean, consult the Droplet Product Documentation.

      Once you’ve filled in all the required fields, the prompt should look something like this:

      Ubuntu Profile Complete

      Select Done and hit ENTER.

      The next screen will prompt you to select popular snaps for your Ubuntu server. Snaps are prepackaged bundles of software that contain an application, its dependencies, and configuration. To learn more about snaps, consult the Snap Documentation.

      Ubuntu Select Snaps

      In this guide we won’t install any snaps and will manually install packages in a later step. If you’d like to install a snap, select or deselect it using SPACE and scroll down to Done. Then, hit ENTER.

      Regardless of your selection in the snap screen, you’ll then be brought to an installation progress and summary screen:

      Ubuntu Install Progress

      Once the installation completes, select Reboot Now and hit ENTER.

      The installer will shut down and prompt you to remove the installation medium (in this case this is the ISO image we selected earlier). In most cases, the ISO will be detached automatically upon reboot, so you can simply hit ENTER.

      To double check, in the VirtualBox GUI menu, navigate to Devices, and then Optical Drives. If the Remove disk from virtual drive option is available to you, click on it to detach the ISO from the virtual machine. Then, back in the virtual machine window, hit ENTER.

      The system will reboot in the virtual machine, this time from the virtual disk to which we installed Ubuntu.

      Since cloud-init is installed by default on Ubuntu 18.04 Server, the first time Ubuntu boots, cloud-init will run and configure itself. In the virtual machine window, you should see some cloud-init log items and have a prompt available to you. Hit ENTER.

      You can then log in to your Ubuntu server using the user you created in the installer.

      Enter your username and hit ENTER, then enter your password and hit ENTER.

      You should now have access to a command prompt, indicating that you’ve successfully completed the Ubuntu 18.04 installation, and are now logged in as the user you created previously.

      In the next step of this guide, we’ll reconfigure cloud-init and set it up to run when the Ubuntu image is launched as a Droplet on the DigitalOcean platform.

      Step 3 — Reconfiguring cloud-init

      Now that we’ve installed Ubuntu 18.04 to a virtual disk and have the system up and running, we need to reconfigure cloud-init to use the appropriate datasource for the DigitalOcean platform. A cloud-init datasource is a source of config data for cloud-init that typically consists of userdata (like shell scripts) or server metadata, like hostname, instance-id, etc. To learn more about cloud-init datasources, consult the official cloud-init docs.

      By default, on Ubuntu 18.04, cloud-init configures itself to use the DataSourceNoCloud datasource. This will cause problems when running the image on DigitalOcean, so we need to reconfigure cloud-init to use the ConfigDrive datasource and ensure that cloud-init reruns when the image is launched on DigitalOcean.

      To begin, ensure that you’ve started your Ubuntu 18.04 virtual machine and have logged in as the user you created earlier.

      From the command line, navigate to the /etc/cloud/cloud.cfg.d directory:

      • cd /etc/cloud/cloud.cfg.d

      Use the ls command to list the cloud-init config files present in the directory:

      Output

      05_logging.cfg 50-curtin-networking.cfg 90_dpkg.cfg curtin-preserve-sources.cfg README

      First, delete the 50-curtin-networking.cfg file, which configures networking interfaces for your Ubuntu server. When the image is launched on DigitalOcean, cloud-init will run and reconfigure these interfaces automatically. If this file is not deleted, the DigitalOcean Droplet created from this Ubuntu image will have its interfaces misconfigured and won't be accessible from the internet.

      • sudo rm 50-curtin-networking.cfg

      Next, we'll run dpkg-reconfigure cloud-init to remove the NoCloud datasource, ensuring that cloud-init searches for and finds the ConfigDrive datasource used on DigitalOcean:

      • sudo dpkg-reconfigure cloud-init

      You should see the following graphical menu:

      Cloud Init dpkg Menu

      The NoCloud datasource is initially highlighted. Press SPACE to unselect it, then hit ENTER.

      Finally, navigate to /etc/netplan:

      Remove the 50-cloud-init.yaml file (this was generated from the cloud-init networking file we removed earlier):

      • sudo rm 50-cloud-init.yaml

      The final step is ensuring that we clean up configuration from the initial cloud-init run so that it reruns when the image is launched on DigitalOcean.

      To do this, run cloud-init clean:

      At this point, your image is ready to be launched on the DigitalOcean platform. You can install additional packages and software into your image. Once you're done, shutdown your virtual machine:

      We can now move on to uploading and launching this custom image on the DigitalOcean platform.

      Step 4 — Uploading Custom Image and Creating Droplet

      Now that we've created an Ubuntu 18.04 VDI image and configured it for use on DigitalOcean, we can upload it using the Custom Images upload tool.

      On macOS, the Ubuntu virtual disk image we created and configured will be located by default at ~/VirtualBox VMs/your_VM_name/your_virtual_disk_name.vdi. This path may vary slightly depending on the OS you're using with VirtualBox.

      Before we upload the image, we'll compress it to speed up the file transfer to DigitalOcean.

      On your host OS (not inside the virtual machine), navigate to the directory containing your VDI image file:

      • cd ~/VirtualBox VMs/Ubuntu 18.04/

      Now, use gzip to compress the file:

      • gzip < Ubuntu 18.04.vdi > Ubuntu 18.04.gz

      In this command we pipe the source Ubuntu 18.04.vdi file into gzip, specifying as output the Ubuntu 18.04.gz compressed file.

      Once gzip finishes compressing your file, upload the .gz file to DigitalOcean, following instructions in the Custom Images Quickstart.

      You should now be able to create and use Droplets from your custom Ubuntu 18.04 Server image.

      Conclusion

      In this tutorial, we learned how to create a custom VDI image from a vanilla Ubuntu 18.04 ISO using the VirtualBox virtualization tool. We adjusted cloud-init so it can properly configure Droplet networking on DigitalOcean, and finally compressed and uploaded the image using the Custom Images upload tool.

      You can adjust the steps in this tutorial to work with your preferred Linux distribution’s ISO images. Ensure that you have an SSH server installed and configured to start on boot, and that cloud-init has been installed and properly configured to use the ConfigDrive datasource. Finally, ensure that any stale networking configuration files have been purged.

      You may also wish to use a tool like Packer to automate the creation of your machine images.

      To learn more about DigitalOcean Custom Images, consult the Custom Images product docs and launch blog post.



      Source link

      How to Use Block Storage with Your Linode


      Updated by Linode

      Written by Linode


      Use promo code DOCS10 for $10 credit on a new account.

      How to Use Block Storage with Your Linode

      Linode’s Block Storage service allows you to attach additional storage volumes to your Linode. A single volume can range from 10 GiB to 10,000 GiB in size and costs $0.10/GiB per month. They can be partitioned however you like and can accommodate any filesystem type you choose. Up to eight volumes can be attached to a single Linode, be it new or already existing, so you do not need to recreate your server to add a Block Storage Volume.

      The Block Storage service is currently available in the Dallas, Fremont, Frankfurt, London, Newark, and Singapore data centers.

      Caution

      • Linode’s backup services do not cover Block Storage Volumes. You must execute your own backups for this data.

      • Your Linode must be running in Paravirtualization mode. Block storage currently does not support Full-virtualization.

      How to Add a Block Storage Volume to a Linode

      This guide assumes a Linode with the root disk mounted as /dev/sda and swap space mounted as /dev/sdb. In this scenario, the Block Storage Volume will be available to the operating system as /dev/disk/by-id/scsi-0Linode_Volume_EXAMPLE, where EXAMPLE is a label you assign the volume in the Linode Manager. Storage volumes can be added when your Linode is already running, and will show immediately in /dev/disk/by-id/.

      Add a Volume from the Linode Dashboard

      1. Go to the page of the Linode to which you want to attach a Block Storage Volume.

        Select a Linode from the Manager

      2. Click on the Volumes tab, then click Add a Volume:

        Click Add a Volume

      3. Assign the Block Storage Volume a label and size. The label can be up to 32 characters long and consist only of ASCII characters a-z; 0-9.-_. The maximum volume size is 10,000 GiB. When finished, click Submit:

        Create a Volume with a label.

        Note

        There is currently a soft limit of 100 TB of Block Storage Volume per account.

      4. Once you add a volume it will appear under Attached Volumes with the new volume’s label, size, and file system path.

        A Volume has been created

      5. You’ll need to create a filesystem in your new volume. If your Linode is not already running, boot then SSH into your Linode and execute the following command, where FILE_SYSTEM_PATH is your volume’s file system path:

        mkfs.ext4 FILE_SYSTEM_PATH
        
      6. Once the volume has a filesystem, you can create a mountpoint for it:

        mkdir /mnt/BlockStorage1
        
      7. You can then mount the new volume:

        mount FILE_SYSTEM_PATH /mnt/BlockStorage1
        
      8. If you want to mount the new volume automatically every time your Linode boots, you’ll want to add the following line to your /etc/fstab file:

        FILE_SYSTEM_PATH /mnt/BlockStorage1 ext4 defaults 0 2
        

      Attach a Volume from Your Account’s Volume List

      1. Click on the Volumes page of the Linode Manager to see your account’s volume list:

        View your available Volumes

      2. Click the menu option (three dots) for the volume you want to attach to a Linode and select Attach:

        Open volume menu.

      3. Select the label of the Linode you want to attach the volume to from the dropdown menu, then click Save:

        Attach a Volume to a Linode

        Note

        The Linodes available in this dropdown menu all share the same region as your volume.

      4. You’ll need to create a filesystem in your new volume. If your Linode is not already running, boot then SSH into your Linode and execute the following command, where FILE_SYSTEM_PATH is your volume’s file system path:

        mkfs.ext4 FILE_SYSTEM_PATH
        
      5. Once the volume has a filesystem, you can create a mountpoint for it:

        mkdir /mnt/BlockStorage1
        
      6. You can then mount the new volume, where FILE_SYSTEM_PATH is your volume’s file system path:

        mount FILE_SYSTEM_PATH /mnt/BlockStorage1
        
      7. If you want to mount the new volume automatically every time your Linode boots, you’ll want to add the following line to your /etc/fstab file:

        FILE_SYSTEM_PATH /mnt/BlockStorage1
        

      How to Detach a Block Storage Volume from a Linode

      1. Go back to the page of the Linode which the volume is attached to. Shut down the Linode.

      2. When the Linode is powered off, click on the Volumes tab, then click Detach under the volume’s menu (three dots):

        Detach a Volume from a Linode from the Volume menu.

      3. A confirmation screen appears and explains that the volume will be detached from the Linode. Click Detach to confirm:

        Linode Manager detach volume confirmation

        The Linode’s dashboard does not show the volume present anymore:

        The Linode's Volumes tab shows no attached volumes.

        The volume still exists on your account and you can see it if you view the Volumes page:

        Volume not attached, but still exists.

      How to Delete a Block Storage Volume

      Caution

      The removal process is irreversible, and the data will be permanently deleted.

      1. Shut down the attached Linode.

      2. Detach the volume as described above.

      3. Click the volume’s Delete option on the Volumes page.

        Delete a Volume

      How to Resize a Block Storage Volume

      Storage volumes cannot be sized down, only up. Keep this in mind when sizing your volumes.

      1. Shut down your Linode.

      2. Click the Resize option for the volume you want to resize.

        Select Resize from the Volume menu.

      3. Enter the new volume size. The minimum size is 10 GiB and maximum is 10,000 GiB. Then click Submit.

        Resize Volume menu.

      4. You’ll be returned to the volume list and the notification bell in the top right of the page will notify you when the resizing is complete.

        Notification bell shows the Volume has been resized.

      5. Reboot your Linode.

      6. Once your Linode has restarted, make sure the volume is unmounted for safety:

        umount /dev/disk/by-id/scsi-0Linode_Volume_BlockStorage1
        
      7. Assuming you have an ext2, ext3, or ext4 partition, resize it to fill the new volume size:

        resize2fs /dev/disk/by-id/scsi-0Linode_Volume_BlockStorage1
        
      8. Mount it back onto the filesystem:

        mount /dev/disk/by-id/scsi-0Linode_Volume_BlockStorage1 /mnt/BlockStorage1
        

      Where to Go From Here?

      Need ideas for what to do with space? We have several guides which walk you through installing software that would make a great pairing with large storage volumes:

      Install Seafile with NGINX on Ubuntu 16.04

      Install Plex Media Server on Ubuntu 16.04

      Big Data in the Linode Cloud: Streaming Data Processing with Apache Storm

      Using Subsonic to Stream Media From Your Linode

      Install GitLab on Ubuntu 14.04

      Join our Community

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link