Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind mount /var/lib/kubelet to /var/lib/docker/kubelet #6

Draft
wants to merge 1 commit into
base: auditd-configs-05
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions scripts/partition-disks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,53 @@ migrate_and_mount_disk() {
fi
}

################################################################
# Migrate existing folder to a location
#
# Globals:
# None
# Arguments:
# 1 - the path to mount
# 2 - the folder path to migration
# 3 - the mount options to use.
# Outputs:
# None
################################################################
migrate_and_bind_dir() {
local dest_path=$1
local folder_path=$2
local mount_options=$3
local temp_path="/mnt/binds/${folder_path}"

# check if the folder already exists
if [ -d "${folder_path}" ]; then
FILE=$(ls -A ${folder_path})
>&2 echo $FILE
mkdir -p ${temp_path}
# Empty folder give error on /*
if [ ! -z "$FILE" ]; then
cp -Rax ${folder_path}/* ${temp_path}
fi
else # create the folder
mkdir -p ${folder_path}
fi

# add the mount point to fstab and mount
mkdir -p ${dest_path}
echo "${dest_path} ${folder_path} none ${mount_options} 0 0" >> /etc/fstab
mount -a

# check if the folder wasn't empty
if [ -d "${temp_path}" ]; then
cp -Rax ${temp_path}/* ${dest_path}
fi

# if selinux is enabled restore the objects on it
if selinuxenabled; then
restorecon -R ${folder_path}
fi
}

# migrate and mount the existing folders to dedicated EBS Volumes
migrate_and_mount_disk "/dev/sdf" "/home" defaults,nofail,nodev,nosuid
migrate_and_mount_disk "/dev/sdg" "/var" defaults,nofail,nodev
Expand All @@ -87,3 +134,6 @@ growpart "/dev/\$(readlink "/dev/sdj")" 1; xfs_growfs '/var/lib/docker'
df -Th | grep -E 'Filesystem|xfs'
EOF
chmod +x "$cloud_init_script"

# Bind mount /var/lib/kubelet -> /var/lib/docker/kubelet
migrate_and_bind_dir "/var/lib/docker/kubelet" "/var/lib/kubelet" defaults,bind