blob: 08bb6d095ad135893c1acefd470959d0d68c7e3c [file] [log] [blame]
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07001#!/usr/bin/env bash
2
3# Copyright 2017-present Open Networking Foundation
4#
Andy Bavier2c427732022-02-03 15:16:46 -07005# SPDX-License-Identifier: Apache-2.0
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07006
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
15if [ -e /usr/local/etc/emulab/watchdog ]
16then
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
19fi
20
21# Mount extra space, if haven't already
22if [ ! -d /mnt/extra ]
23then
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
55fi
56
57# prepare for creating the libvirt/images symlink
58sudo mkdir -p /var/lib/libvirt
59sudo rm -rf /var/lib/libvirt/images
60
61# create symlinks to /mnt/extra partition
Fatemeh Rouzbeha0b26e22022-04-07 12:45:12 -070062for DIR in docker kubelet openstack-helm nova libvirt/images rancher
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -070063do
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
70done
Fatemeh Rouzbeha0b26e22022-04-07 12:45:12 -070071sudo mkdir -p "/mnt/extra/k3s"
72sudo chmod -R a+rwx "/mnt/extra/k3s"
73if [ ! -e "/run/k3s" ]; then sudo ln -s "/mnt/extra/k3s" "/run/k3s"; fi