Storage - charlesfg/TPCx-V_setup GitHub Wiki
# First create the volume (raw has better performance over qcow2)
# but if qcow2 needed use -f qcow2 -o preallocation=metadata (https://kashyapc.com/2011/09/24/creating-a-qcow2-virtual-machine/)
qemu-img create -f raw /var/lib/libvirt/images/tpc-flatfiles.img 61G
# Attach the disk to the VM
virsh attach-disk tpc0 --source /var/lib/libvirt/images/tpc-flatfiles.img --target vdb --persistent
# Setup
# Partittion the disk
fdisk /dev/vdb
# Format
mkfs.ext4 -F -v -t ext4 -T largefile4 -m 0 -j -O extent -O dir_index /dev/vdb1
# create the directory and mount
mkdir /vgenstore
mount /dev/vdb1 /vgenstore
# Persist on fstab
echo -e "/dev/vdb1\t/vgenstore\text4\tdefaults\t0\t1" >> /etc/fstab
virsh detach-disk tpc0 --target /var/lib/libvirt/images/tpc-flatfiles.img --persistent
- All Tier B VMs use the same flat files for populating the databases so we will use it mounted as a separated disk
# As root on the Xen host
lvcreate -L60G -n tpc-flatfiles oxum-vg
# Stop the guest tpc 0
# Change the config adding the new partition
# Log on Guest
# - Create the partition
# For simplicity we will emulate the interactive interation with fdisk.
# Each echo cmd is an option to fdisk, in order we:
# o -> Create an clear the in memory partition table
# n -> new partition
# p -> primary partition
# 1 -> partition number 1
# -> default - start at beginning of disk
# -> default, extend partition to end of disk
# w -> write the partition table
# Source http://superuser.com/questions/332252/creating-and-formating-a-partition-using-a-bash-script
(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdc
# List the block devices to check if everything went ok
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,UUID,LABEL
mkfs.ext4 -F -v -t ext4 -T largefile4 -m 0 -j -O extent -O dir_index /dev/xvdc1
# Persist on fstab
echo -e "/dev/xvdc1\t/vgenstore\text4\tdefaults\t0\t1" >> /etc/fstab
# create the directory and mount
mkdir /vgenstore
mount /dev/xvdc1 /vgenstore
df -h
# Generate the files following the section 2.5.3 Create the Flat Files on User's Guide
For simplicity I decided to create all the disks at first then format
#!/bin/bash
# create_dbstores.sh
declare -A STORE_SIZE # Create an associative array
# Size of the dbstore in Gb (based on db + backup )
STORE_SIZE[tpc_g1]=43
STORE_SIZE[tpc_g2]=81
STORE_SIZE[tpc_g3]=121
STORE_SIZE[tpc_g4]=159
for i in `seq 1 4`; do
for j in 1 2; do
L=tpc_g${i}b${j}
S=${STORE_SIZE[tpc_g${i}]}
echo "Creating disk for the vm $L with $S GB"
qemu-img create -f raw /var/lib/libvirt/images/${L}-dbstore.img ${S}G
done
done
#!/bin/bash
# create_dbstores_lvm.sh
declare -A STORE_SIZE # Create an associative array
# Size of the dbstore in Gb (based on db + backup )
STORE_SIZE[tpc_g1]=43
STORE_SIZE[tpc_g2]=81
STORE_SIZE[tpc_g3]=121
STORE_SIZE[tpc_g4]=159
for i in `seq 1 4`; do
for j in 1 2; do
L=tpc_g${i}b${j}
S=${STORE_SIZE[tpc_g${i}]}
echo "Creating disk for the vm $L with $S GB"
lvcreate -L${S}G -n ${L}-dbstore oxum-vg
done
done
- Certainly, there is an easier and a more direct way, but this approach is safe and generates a backup
Do not need to copy the block, just perform the fdisk before resize2fs
# Create a NEW extended disk
lvcreate -L30G -n tpc-drive_extended-disk oxum-vg
# Clone the old data
dd if=/dev/oxum-vg/tpc-drive-disk of=/dev/oxum-vg/tpc-drive_extended-disk bs=512MB oflag=dsync
pv < /dev/sda > /dev/sdb
# I do not exactly know if this is needed but....
partprobe
kpartx -al /dev/oxum-vg/tpc-drive_extended-disk
# Perform an fdiks
fdisk /dev/oxum-vg/tpc-drive_extended-disk
d -Delete Partition
n -New create new partition
p -Primary
1- Partition number
Default values for size
w -Write changes
(echo d; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdc
# Change configuration on VM.cfg and boot it
# on the Guest
resize2fs /dev/xvda1
# Check everything
To this happen I've setup a user with ssh access to a VM without password (to be able to run commands inside the vm without interactively login in) and add it to the libvirt group (so it can be abble to run virsh commands).
For all drives we will mount it in the
sudo adduser `id -un` libvirtd
# Then relogin
#!/bin/bash
for i in `seq 1 4`; do
for j in 1 2; do
L=tpc_g${i}b${j}
DISK=/var/lib/libvirt/images/${L}-dbstore.img
# Attach the disk image
virsh attach-disk tpc0 --source ${DISK} --target vdb
# Create the partition
# For simplicity we will emulate the interactive interation with fdisk.
# Each echo cmd is an option to fdisk, in order we:
# o -> Create an clear the in memory partition table
# n -> new partition
# p -> primary partition
# 1 -> partition number 1
# -> default - start at beginning of disk
# -> default, extend partition to end of disk
# w -> write the partition table
# Source http://superuser.com/questions/332252/creating-and-formating-a-partition-using-a-bash-script
ssh [email protected] "(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/vdb"
# Format
ssh [email protected] "mkfs.ext4 -F -v -t ext4 -T largefile4 -m 0 -j -O extent -O dir_index /dev/vdb1"
# List Information
ssh [email protected] "lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL"
# Detach disk
virsh detach-disk tpc0 --target ${DISK}
done
done
#!/bin/bash
for i in `seq 1 4`; do
for j in 1 2; do
L=tpc_g${i}b${j}
DISK=phy:/dev/oxum-vg/${L}-dbstore
# Attach the disk image
xl block-attach tpc0 ${DISK} xvdd rw
# Create the partition
# For simplicity we will emulate the interactive interation with fdisk.
# Each echo cmd is an option to fdisk, in order we:
# o -> Create an clear the in memory partition table
# n -> new partition
# p -> primary partition
# 1 -> partition number 1
# -> default - start at beginning of disk
# -> default, extend partition to end of disk
# w -> write the partition table
# Source http://superuser.com/questions/332252/creating-and-formating-a-partition-using-a-bash-script
ssh [email protected] "(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdd"
# Format
ssh [email protected] "mkfs.ext4 -F -v -t ext4 -T largefile4 -m 0 -j -O extent -O dir_index /dev/xvdd1"
# List Information
ssh [email protected] "lsblk -f"
# Detach disk
xl block-detach tpc0 xvdd
done
done
-
List the disk devices information
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
tpc_g1b1 tpc_g1b2 tpc_g2b1 tpc_g2b2 tpc_g3b1 tpc_g3b2 tpc_g4b1 tpc_g4b2
tpc_g1a tpc_g1b1 tpc_g1b2 tpc_g2a tpc_g2b1 tpc_g2b2 tpc_g3a tpc_g3b1 tpc_g3b2 tpc_g4a tpc_g4b1 tpc_g4b2
sed -e 's/\s*([+0-9a-zA-Z])./\1/' << EOF | grep -hn n o # clear the in memory partition table n # new partition p # primary partition 1 # partition number 1 # default - start at beginning of disk +100M # 100 MB boot parttion n # new partition p # primary partition 2 # partion number 2 # default, start immediately after preceding partition # default, extend partition to end of disk a # make a partition bootable 1 # bootable partition is partition 1 -- /dev/sda1 p # print the in-memory partition table w # write the partition table q # and we're done EOF
mount -o nofail,noatime,nodiratime,nobarrier /dev/vdc1 /dbstore