System configuration for OpenStack Infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.5KB

  1. #!/bin/bash
  2. # Copyright 2014 Hewlett-Packard Development Company, L.P.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. DEVICE=$1
  16. MOUNT_PATH=$2
  17. FS_LABEL=$3
  18. # Because images may not have all the things we need.
  19. if which apt-get ; then
  20. apt-get update && apt-get install -y lvm2
  21. elif which yum ; then
  22. yum -y install lvm2
  23. fi
  24. # Sanity check that we don't break anything that already has an fs.
  25. if ! blkid | grep $DEVICE ; then
  26. set -e
  27. parted --script $DEVICE mklabel msdos mkpart primary 0% 100% set 1 lvm on
  28. partprobe -s $DEVICE
  29. pvcreate ${DEVICE}1
  30. vgcreate main ${DEVICE}1
  31. lvcreate -l 100%FREE -n $FS_LABEL main
  32. mkfs.ext4 -m 0 -j -L $FS_LABEL /dev/main/$FS_LABEL
  33. tune2fs -i 0 -c 0 /dev/main/$FS_LABEL
  34. # Remove existing fstab entries for this device.
  35. perl -nle "m,/dev/main/$FS_LABEL, || print" -i /etc/fstab
  36. if [ ! -d $MOUNT_PATH ] ; then
  37. mkdir -p $MOUNT_PATH
  38. fi
  39. echo "/dev/main/$FS_LABEL $MOUNT_PATH ext4 errors=remount-ro,barrier=0 0 2" >> /etc/fstab
  40. mount -a
  41. else
  42. exit 1
  43. fi