Skip to content

Commit

Permalink
Mount disk by disk path file
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiaoyuner committed Jul 18, 2023
1 parent 81ea690 commit 9fb8945
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=Setup k8s master services
Requires=rc-local.service
After=rc-local.service
Before=sonic.target

[Service]
Type=oneshot
Expand Down
26 changes: 25 additions & 1 deletion files/image_config/kubernetes/kubernetes_master_entrance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,39 @@ set -x

# mount disk from host
mount_point="/from_host"
disk="/dev/sdb1"
disk_by_path_dir="/dev/disk/by-path"
# We can't ensure the mounted disk name is sda or sdb
# But we can specify the disk logic unit number to 2
# We find the correct disk by the disk logic unit number from by-path directory
target_str="lun-2-part1"
disk_path_file=$(ls $disk_by_path_dir | grep $target_str)

# Check whether the disk path file exists
if [ -z "$disk_path_file" ]; then
echo "Error: Disk path file not found."
exit 1
fi

# Check the number of lines returned
line_count=$(echo "$disk_path_file" | wc -l)

# If there are multiple lines, exit with status 1
if [ "$line_count" -ne 1 ]; then
echo "Error: multiple disk path files found."
exit 1
fi

disk="${disk_by_path_dir}/${disk_path_file}"
mkdir -p $mount_point
mount $disk $mount_point

# check whether it is the first time to boot
first_boot_flag_file="/from_host/first_boot_flag"
if [ -f $first_boot_flag_file ]; then
exit 0
fi
touch $first_boot_flag_file

# execute entrance script
init_file_name="entrance.sh"
init_file=${mount_point}/${init_file_name}
Expand Down

0 comments on commit 9fb8945

Please sign in to comment.