Skip to content

Commit d99ba64

Browse files
committed
Set up a VM_IMAGE_DIR environment variable to override default storage location for VMs.
1 parent 2d260a6 commit d99ba64

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ documentation on for cloud-init.
8282

8383
`create-vm` stores files as follows:
8484

85-
* `${HOME}/vms/base/` - Place to store your base Linux cloud images.
86-
* `${HOME}/vms/images/` - `your-vm-name.img` and `your-vm-name-cidata.img` files.
87-
* `${HOME}/vms/init/` - `user-data` and `meta-data`.
88-
* `${HOME}/vms/xml/` - Backup copies of your VMs' XML definition files.
85+
* `${VM_IMAGE_DIR}` - Directory used for for VM storage. Defaults to `${HOME}/vms`.
86+
* `${VM_IMAGE_DIR}/base/` - Place to store your base Linux cloud images.
87+
* `${VM_IMAGE_DIR}/images/` - `your-vm-name.img` and `your-vm-name-cidata.img` files.
88+
* `${VM_IMAGE_DIR}/init/` - `user-data` and `meta-data`.
89+
* `${VM_IMAGE_DIR}/xml/` - Backup copies of your VMs' XML definition files.
8990

9091
QCOW2 filesystems allocate space as needed, so if you create a VM with 100GB of storage, the initial
9192
size of the `your-vm-name.img` and `your-vm-name-cidata.img` files is only about **700K total**. The
@@ -128,8 +129,8 @@ If you're not using Ansible just `apt-get install` the above packages.
128129
## Permissions
129130

130131
The `libvirtd` daemon runs under the `libvirt-qemu` user service account. The `libvirt-qemu` user
131-
must be able to read the files in `${HOME}/vms/`. If your ${HOME} directory has permissions set to
132-
`0x750` then `libvirt-qemu` won't be able to read the `${HOME}/vms/` directory.
132+
must be able to read the files in `${VM_IMAGE_DIR}`. If your ${HOME} directory has permissions set to
133+
`0x750` then `libvirt-qemu` won't be able to read the `${VM_IMAGE_DIR}` directory.
133134

134135
You could open up your home directory, e.g.:
135136

create-vm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# distributed under the License is distributed on an "AS IS" BASIS,
1515
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
# See the License for the specific language governing permissions and
17-
# limitations under the License.
17+
18+
# Set VM_IMAGE_DIR environment variable to override default storage location for VMs
19+
VM_IMAGE_DIR=${VM_IMAGE_DIR:-"${HOME}/vms"}
1820

1921
HOSTNAME=
2022
IMG_FQN=
@@ -25,7 +27,6 @@ STORAGE=80
2527
BRIDGE=virbr0
2628
MAC=
2729
VERBOSE=
28-
VM_IMAGE_DIR="${HOME}/vms"
2930

3031
usage()
3132
{
@@ -48,7 +49,7 @@ OPTIONS:
4849
EOF
4950
}
5051

51-
while getopts "h:n:i:k:r:c:s:b:m:v:d" option; do
52+
while getopts "h:n:i:k:r:c:s:b:m:v" option; do
5253
case "${option}"
5354
in
5455
h)

delete-vm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
# limitations under the License.
1818

1919
VM=$1
20-
VM_IMAGE_DIR="${HOME}/vms"
20+
21+
# Set VM_IMAGE_DIR environment variable to override default storage location for VMs
22+
VM_IMAGE_DIR=${VM_IMAGE_DIR:-"${HOME}/vms"}
23+
2124
VM_IMAGE="${VM_IMAGE_DIR}/images/$VM.img"
2225
CI_IMAGE="${VM_IMAGE_DIR}/images/$VM-cidata.img"
2326

0 commit comments

Comments
 (0)