Jeremy Ronquillo | 6be909e | 2020-08-24 09:36:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
Andy Bavier | 2c42773 | 2022-02-03 15:16:46 -0700 | [diff] [blame] | 5 | # SPDX-License-Identifier: Apache-2.0 |
Jeremy Ronquillo | 6be909e | 2020-08-24 09:36:13 -0700 | [diff] [blame] | 6 | |
| 7 | ############################################### |
| 8 | # Disk setup and symlinks for a CloudLab node # |
| 9 | ############################################### |
| 10 | |
| 11 | # Don't do anything if not a CloudLab node |
| 12 | [ ! -d /usr/local/etc/emulab ] && exit 0 |
| 13 | |
| 14 | # The watchdog will sometimes reset groups, turn it off |
| 15 | if [ -e /usr/local/etc/emulab/watchdog ] |
| 16 | then |
| 17 | sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop |
| 18 | sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled |
| 19 | fi |
| 20 | |
| 21 | # Mount extra space, if haven't already |
| 22 | if [ ! -d /mnt/extra ] |
| 23 | then |
| 24 | sudo mkdir -p /mnt/extra |
| 25 | |
| 26 | # for NVME SSD on Utah m510, not supported by mkextrafs |
| 27 | if df | grep -q nvme0n1p1 && [ -e /usr/testbed/bin/mkextrafs ] |
| 28 | then |
| 29 | # set partition type of 4th partition to Linux, ignore errors |
| 30 | echo -e "t\\n4\\n82\\np\\nw\\nq" | sudo fdisk /dev/nvme0n1 || true |
| 31 | |
| 32 | sudo mkfs.ext4 /dev/nvme0n1p4 |
| 33 | echo "/dev/nvme0n1p4 /mnt/extra/ ext4 defaults 0 0" | sudo tee -a /etc/fstab |
| 34 | sudo mount /mnt/extra |
| 35 | mount | grep nvme0n1p4 || (echo "ERROR: NVME mkfs/mount failed, exiting!" && exit 1) |
| 36 | |
| 37 | elif [ -e /usr/testbed/bin/mkextrafs ] && [ -b /dev/sdb ] # if on Clemson/Wisconsin Cloudlab |
| 38 | then |
| 39 | # Sometimes this command fails on the first try |
| 40 | 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/" |
| 41 | |
| 42 | # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted) |
| 43 | mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1) |
| 44 | |
| 45 | elif [ -e /usr/testbed/bin/mkextrafs ] && [ -b /dev/sda4 ] # if on Utah xl170 |
| 46 | then |
| 47 | # set partition type of 4th partition to Linux, ignore errors |
| 48 | printf "t\\n4\\n83\\np\\nw\\nq" | sudo fdisk /dev/sda || true |
| 49 | |
| 50 | sudo mkfs.ext4 /dev/sda4 |
| 51 | echo "/dev/sda4 /mnt/extra/ ext4 defaults 0 0" | sudo tee -a /etc/fstab |
| 52 | sudo mount /mnt/extra |
| 53 | mount | grep sda4 || (echo "ERROR: mkfs/mount failed, exiting!" && exit 1) |
| 54 | fi |
| 55 | fi |
| 56 | |
| 57 | # prepare for creating the libvirt/images symlink |
| 58 | sudo mkdir -p /var/lib/libvirt |
| 59 | sudo rm -rf /var/lib/libvirt/images |
| 60 | |
| 61 | # create symlinks to /mnt/extra partition |
| 62 | for DIR in docker kubelet openstack-helm nova libvirt/images |
| 63 | do |
| 64 | sudo mkdir -p "/mnt/extra/$DIR" |
| 65 | sudo chmod -R a+rwx "/mnt/extra/$DIR" |
| 66 | if [ ! -e "/var/lib/$DIR" ] |
| 67 | then |
| 68 | sudo ln -s "/mnt/extra/$DIR" "/var/lib/$DIR" |
| 69 | fi |
| 70 | done |