Table of content
Introduction
Every new compute instance comes with a pre-defined size of virtual disk space.
Imagine you already have a compute instance in data center Rot DC1 where you want to install a Hana database. The database data should be stored on an extra virtual disk. The following section will guide you step-by-step through the process from creating a raw virtual disk to finally write to and read from the new filesystem.
Linux
Basics
LVM stands for Logical Volume Manager and is a method to manage disk space dynamically on multiple harddrives. It adds an addional layer of abstraction between the filesystem and the harddrives.
Before starting with the creation of a new volume under Linux some terms needed to be explained.
Physical volume
A physical volume is the real data storage of a LVM. It could be a partition or a whole harddrive.
Volume group
A volume group is a container for at least one physical volume.
Logical volume
A logical volume is like a partition inside a volume group. The logical volume can be used like a normal partition, meaning that filesystems can be created and it can be mounted.
Scalability
LVM allows to resize physical volume, volume group and logical volume on the fly without reboot the system.
Note The filesystem inside the the logical volume needs to be resized as well.
Step 1: Create a new volume
In the Monsoon Dashboard navigate to the project where the compute instance resides and click on the tab Volume.
Perform the following steps to create a new virtual disk in the same Availability Zone as the compute instance:
- Click on on the button New Volume.
- Give the volume a short description.
- Select the availability zone.
- Select the size of the virtual disk from 1 to 1024 GB.
The newly created volume has the type vmdk, which is an open container format for virtual hard disk drives to be used in virtual machines. By clicking on the name of the volume more detailed information including the compute instances the volume is attached to are being displayed.
Step 2: Attach volume to the compute instance
Once the the virtual disk is available you can attach the volume to your compute instances. Open the tool box of the volume and then click on ‘Attach’.
On the following screen select the server to which you want to attach the new volume. You can attach the volume only to servers within your project. When the volume is attached it appears in the operating system of the instance as a raw disk.
- On Linux under /dev/monsoon/<volume-id>. Additionally, it is also sensible to set an alias /dev/ under which the volume should also appear.
Important When setting an alias, you cannot choose a kernel reserved name like /dev/sda.
Note Please be aware that you have created in this step a raw virtual disk only.
Note On Linux you can scan for all storage devices available on your machine with the command lvmdiskscan.
Step 3: Create physical volume
Instead of applying the manual steps described below you can also use the sap-lvm cookbook to create and mount a Logical Volume.
Create physical volume
In order to use the raw virtual disk in Linux you have to intialize the device as an LVM physical volume. The following command pvcreate initializes your device as an LVM physical volume for later use as part of an LVM logical volume.
The path to the virtual disk is /dev/monsoon/<volume-id>
or if an alias was set it can also be accessed via /dev/<alias>
.
Note This example will only use /dev/monsoon/<volume-id>
.
sudo pvcreate /dev/monsoon/<volume-id>
List physical volumes
You can view all physical volumes on your instance with the pvdisplay command.
sudo pvdisplay
Example output:
--- Physical volume --- PV Name /dev/sda6 VG Name osvg PV Size 68.27 GiB / not usable 1.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 17477 Free PE 5821 Allocated PE 11656 PV UUID qb8pns-Zj94-JFWl-HpQ6-BRBQ-V2RO-WPCeD9
Alternatively you can also use pvs command.
sudo pvs
Example output:
PV VG Fmt Attr PSize PFree /dev/sda2 main lvm2 a- 465,57G 311,57G
Step 4: Create/Extend volume group
Create volume group
Create an LVM volume group <group>
with vgcreate command from the physical volume /dev/monsoon/<volume-id>
.
sudo vgcreate <group> /dev/monsoon/<volume-id>
Extend volume group
Expand an existing LVM volume group <group>
with vgextend command by the physical volume /dev/monsoon/<volume-id>
.
sudo vgextend <group> /dev/monsoon/<volume-id>
List volume groups
You can view all volume groups on your instance with the vgdisplay command.
sudo vgdisplay
Example output:
--- Volume group --- VG Name osvg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 68.27 GiB PE Size 4.00 MiB Total PE 17477 Alloc PE / Size 11656 / 45.53 GiB Free PE / Size 5821 / 22.74 GiB VG UUID GY8Uou-MFzC-JkWf-ZP1g-JATj-9NUd-mlHcqK
Alternatively use the vgs command.
sudo vgs
Example output:
VG #PV #LV #SN Attr VSize VFree main 1 6 0 wz--n- 465,57G 311,57G
Note Use the vgscan command to verify the LVM configuration of the volume group .
Step 5: Create/Extend logical volume
Create logical volume
Use the lvcreate command to create the appropriate logical volume <volume>
that uses all of the unallocated space within the volume group <group>
.
sudo lvcreate -l 100%FREE -n <volume> <group>
Extend logical volume
To extend an existing logical volume /dev/<group>/<volum>
use the lvextend command that uses all of the unallocated space of the volume /dev/monsoon/<volume-id>
.
sudo lvextend /dev/<group>/<volum> /dev/monsoon/<volume-id>
List logical volumes
You can view all volume groups on your instance with the lvdisplay command.
sudo lvdisplay
Example output:
--- Logical volume --- LV Name /dev/osvg/lvroot VG Name osvg LV UUID F9hXgF-gj8B-Rdgh-efVD-p1Er-SkKN-qWx18U LV Write Access read/write LV Status available # open 1 LV Size 18.62 GiB Current LE 4768 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:1
Alternatively use the lvs command.
sudo lvs
Example output:
LV VG Attr LSize Origin Snap% Move Log Copy% home main -wi-ao 70,00G music main -wi-ao 20,00G root main -wi-ao 20,00G swap main -wi-ao 2,00G tmp main -wi-ao 2,00G virtualbox main -wi-ao 40,00G
Note Use the lvscan command to verify the LVM configuration of the logical volume.
Step 6: Create/Extend filesystem
Create filesystem
Without a file system nothing can be saved on a logical volume. Perform the mkfs command to format the logical volume.
sudo mkfs.ext3 /dev/<group>/<volume>
Extend filesystem
To extend an existing filesystem on the logical volume <volume>
with the volume group <group>
use the command resize2fs.
sudo resize2fs /dev/<group>/<volume>
Step 7: Mount logical volume
Before accessing a new filesystem it is necessary to mount it. First create the directory <directory>
and then mount the logical volume.
sudo mkdir <directory> sudo mount /dev/<group>/<volume> <directory>
Run the command df -h and you should see your logical volume in the output.
Example output:
Filesystem Size Used Avail Use% Mounted on /dev/mapper/packer--UBUNTU1204--BUILD--54--vg-root 137G 36G 96G 27% / udev 7.9G 12K 7.9G 1% /dev tmpfs 1.6G 268K 1.6G 1% /run none 5.0M 0 5.0M 0% /run/lock none 7.9G 0 7.9G 0% /run/shm /dev/sda1 228M 56M 161M 26% /boot
Step 8: Access the logical volume
Congratulations! You have set up the LVM volume on your compute instance. Now you can write to and read from <directory>
.
touch <directory>/hello.world ls <directory>
Note Use the commands chown and chmod if you need to change the owner or permissions of <directory>
.
Step 9: Automatically mount the logical volume
In order to mount the logical volume automatically when the instance boots, add the following line to the /etc/fstab file.
/dev/<group>/<volume> <directory> ext3 rw,noatime 0 0
After restarting the instance run the command df -h and you should see that the logical volume is mounted on <directory>
.
Create a simple or striped dynamic Volume/Drive on Windows
Step 1: Create a new volume
In the Monsoon Dashboard navigate to the project where the compute instance resides and click on the tab Volume.
Perform the following steps to create a new virtual disk in the same Availability Zone as the compute instance:
- Click on on the button New Volume.
- Give the volume a short description.
- Select the availability zone.
- Select the size of the virtual disk from 1 to 1024 GB.
The newly created volume has the type vmdk, which is an open container format for virtual hard disk drives to be used in virtual machines. By clicking on the name of the volume more detailed information including the compute instances the volume is attached to are being displayed.
Step 2: Attach volume to the compute instance
Once the the virtual disk is available you can attach the volume to your compute instances. Open the tool box of the volume and then click on ‘Attach’.
On the following screen select the server to which you want to attach the new volume. You can attach the volume only to servers within your project. When the volume is attached it appears in the operating system of the instance as a raw disk.
- On Windows Server in Disk Manager as Disk[1-n]. The Disk Manager can be found in All Programs -> Administrative Tools -> Server Manager -> Storage -> Disk Management.
Note Setting an alias affects only on Linux, on windows no alias/name is configurable at that time
Note Please be aware that you have created in this step a raw virtual disk only.
Step 3: Open disk manager
3.1 Connect to your Windows system via Remote Desktop Connection.
3.2 Open Server Manager
3.3 On navigation select Storage/Disk Management
3.3 On main window you should see your created disk in mode uninitialzed and unallocated
Step 4: Take disk online and initialize it
4.1 Right click on on disk and take it online
4.2 Right click on disk and initialize it
4.3 Also select partition style
Step 5A: Create a formatted simple Volume/Drive
5.1 Right click on new volume and select “New Simple Volume…”
5.2 Follow the steps of wizzard
5.3 Set size
5.4 Set drive letter
5.5 Set file system (NTFS is default)
5.6 Check summary and start formatting
5.7 You should now see your new created simple Volume/Drive
Step 5B: Create striped Volume
Note In order to create a dynamic/stripped volume on Windows you need to create at least 2 volumes on the Monsoon platform, attach to your instance and perform the steps 3 and 4 on both volumes.
5.1 Right click on on of your new Volumes and click on “New Sliced Volume…”
5.2 Follow the steps of Striped Volume Wizard
5.3 The first new Volume will be selected by default, you have to add at least one additional disk
5.4 Choose a drive letter
5.5 Choose file system (NTFS is default)
5.6 Check the summary and start volume formatting
5.7 Disks must be converted to dynamic mode - confirm, click on yes
5.8 You should now see your new Sliced Volume/Drive in diskmanager
转自: https://monsoon.mo.sap.corp/training/compute/create-volume/