diff --git a/_example/complete/user-data.sh b/_example/complete/user-data.sh index 3fe0961..3cbefc3 100644 --- a/_example/complete/user-data.sh +++ b/_example/complete/user-data.sh @@ -1,16 +1,37 @@ #!/bin/bash -sleep 60 -DEVICE=/dev/$(lsblk -n | awk '$NF != "/" {print $1}'| tail -n 1 ) -exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 -FS_TYPE=$(file -s $DEVICE | awk '{print $2}') -MOUNT_POINT=/data -# If no FS, then this output contains "data" -if [ "$FS_TYPE" = "data" ] -then - echo "Creating file system on $DEVICE" - mkfs -t ext4 $DEVICE -fi +### Mountig ebs volume -mkdir $MOUNT_POINT -mount $DEVICE $MOUNT_POINT +# Specify the target directory where you want to mount the devices +mount_point="/data" + +# Device to skip +device_to_skip="xvda" + +# Filesystem type +filesystem_type="ext4" # Change this to the appropriate filesystem type + +# Create the mount point directory if it doesn't exist +sudo mkdir -p "$mount_point" + +# Use lsblk to list block devices, filter by type "disk" (whole disks) +# and exclude read-only filesystems (ro) +block_devices=$(lsblk -o NAME,TYPE,RO -r -n | awk '$2 == "disk" && $3 == "0" {print $1}') + +# Iterate through the block devices, skip the specified device, and attempt to mount the rest +for device in $block_devices; do + if [ "$device" != "$device_to_skip" ]; then + echo "Mounting $device at $mount_point/$device" + sudo mkdir -p "$mount_point/$device" + sudo mkfs -t "$filesystem_type" "/dev/$device" # Format the device with the specified filesystem + sudo mount "/dev/$device" "$mount_point/$device" + if [ $? -eq 0 ]; then + echo "Mounting successful." + else + echo "Failed to mount $device." + fi + else + echo "Skipping $device." + fi +done +echo "Mounting complete." \ No newline at end of file