Zack Williams | 31f631f | 2019-01-15 14:29:40 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | ############################################### |
| 18 | # Disk setup and symlinks for a CloudLab node # |
| 19 | ############################################### |
| 20 | |
| 21 | # Don't do anything if not a CloudLab node |
Hyunsun Moon | 1f0a005 | 2019-08-05 19:49:13 -0500 | [diff] [blame] | 22 | [ ! -d /usr/local/etc/emulab ] && exit 0 |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 23 | |
Zack Williams | fab1045 | 2019-08-15 15:50:29 -0700 | [diff] [blame] | 24 | # The watchdog will sometimes reset groups, turn it off |
| 25 | if [ -e /usr/local/etc/emulab/watchdog ] |
| 26 | then |
| 27 | sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop |
| 28 | sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled |
| 29 | fi |
| 30 | |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 31 | # Mount extra space, if haven't already |
| 32 | if [ ! -d /mnt/extra ] |
| 33 | then |
| 34 | sudo mkdir -p /mnt/extra |
| 35 | |
Zack Williams | 31f631f | 2019-01-15 14:29:40 -0700 | [diff] [blame] | 36 | # for NVME SSD on Utah m510, not supported by mkextrafs |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 37 | if df | grep -q nvme0n1p1 && [ -e /usr/testbed/bin/mkextrafs ] |
| 38 | then |
| 39 | # set partition type of 4th partition to Linux, ignore errors |
| 40 | echo -e "t\\n4\\n82\\np\\nw\\nq" | sudo fdisk /dev/nvme0n1 || true |
| 41 | |
| 42 | sudo mkfs.ext4 /dev/nvme0n1p4 |
| 43 | echo "/dev/nvme0n1p4 /mnt/extra/ ext4 defaults 0 0" | sudo tee -a /etc/fstab |
| 44 | sudo mount /mnt/extra |
| 45 | mount | grep nvme0n1p4 || (echo "ERROR: NVME mkfs/mount failed, exiting!" && exit 1) |
| 46 | |
Zack Williams | 31f631f | 2019-01-15 14:29:40 -0700 | [diff] [blame] | 47 | elif [ -e /usr/testbed/bin/mkextrafs ] && [ -b /dev/sdb ] # if on Clemson/Wisconsin Cloudlab |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 48 | then |
| 49 | # Sometimes this command fails on the first try |
| 50 | sudo /usr/testbed/bin/mkextrafs -s 1 -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -s 1 -r /dev/sdb -qf "/mnt/extra/" |
| 51 | |
| 52 | # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted) |
| 53 | mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1) |
Zack Williams | 31f631f | 2019-01-15 14:29:40 -0700 | [diff] [blame] | 54 | |
| 55 | elif [ -e /usr/testbed/bin/mkextrafs ] && [ -b /dev/sda4 ] # if on Utah xl170 |
| 56 | then |
| 57 | # set partition type of 4th partition to Linux, ignore errors |
| 58 | printf "t\\n4\\n83\\np\\nw\\nq" | sudo fdisk /dev/sda || true |
| 59 | |
| 60 | sudo mkfs.ext4 /dev/sda4 |
| 61 | echo "/dev/sda4 /mnt/extra/ ext4 defaults 0 0" | sudo tee -a /etc/fstab |
| 62 | sudo mount /mnt/extra |
| 63 | mount | grep sda4 || (echo "ERROR: mkfs/mount failed, exiting!" && exit 1) |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 64 | fi |
| 65 | fi |
| 66 | |
Zack Williams | fab1045 | 2019-08-15 15:50:29 -0700 | [diff] [blame] | 67 | # prepare for creating the libvirt/images symlink |
| 68 | sudo mkdir -p /var/lib/libvirt |
| 69 | sudo rm -rf /var/lib/libvirt/images |
| 70 | |
| 71 | # create symlinks to /mnt/extra partition |
| 72 | for DIR in docker kubelet openstack-helm nova libvirt/images |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 73 | do |
Zack Williams | 31f631f | 2019-01-15 14:29:40 -0700 | [diff] [blame] | 74 | sudo mkdir -p "/mnt/extra/$DIR" |
| 75 | sudo chmod -R a+rwx "/mnt/extra/$DIR" |
| 76 | if [ ! -e "/var/lib/$DIR" ] |
Andy Bavier | 9958885 | 2018-06-05 12:59:51 -0700 | [diff] [blame] | 77 | then |
Zack Williams | 31f631f | 2019-01-15 14:29:40 -0700 | [diff] [blame] | 78 | sudo ln -s "/mnt/extra/$DIR" "/var/lib/$DIR" |
Andy Bavier | 9958885 | 2018-06-05 12:59:51 -0700 | [diff] [blame] | 79 | fi |
Andy Bavier | 188aff1 | 2018-05-18 05:43:55 -0700 | [diff] [blame] | 80 | done |