-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." |