1
1
#! /bin/bash
2
- sleep 60
3
- DEVICE=/dev/$( lsblk -n | awk ' $NF != "/" {print $1}' | tail -n 1 )
4
- exec > >( tee /var/log/user-data.log| logger -t user-data -s 2> /dev/console) 2>&1
5
- FS_TYPE=$( file -s $DEVICE | awk ' {print $2}' )
6
- MOUNT_POINT=/data
7
2
8
- # If no FS, then this output contains "data"
9
- if [ " $FS_TYPE " = " data" ]
10
- then
11
- echo " Creating file system on $DEVICE "
12
- mkfs -t ext4 $DEVICE
13
- fi
3
+ # ## Mountig ebs volume
14
4
15
- mkdir $MOUNT_POINT
16
- mount $DEVICE $MOUNT_POINT
5
+ # Specify the target directory where you want to mount the devices
6
+ mount_point=" /data"
7
+
8
+ # Device to skip
9
+ device_to_skip=" xvda"
10
+
11
+ # Filesystem type
12
+ filesystem_type=" ext4" # Change this to the appropriate filesystem type
13
+
14
+ # Create the mount point directory if it doesn't exist
15
+ sudo mkdir -p " $mount_point "
16
+
17
+ # Use lsblk to list block devices, filter by type "disk" (whole disks)
18
+ # and exclude read-only filesystems (ro)
19
+ block_devices=$( lsblk -o NAME,TYPE,RO -r -n | awk ' $2 == "disk" && $3 == "0" {print $1}' )
20
+
21
+ # Iterate through the block devices, skip the specified device, and attempt to mount the rest
22
+ for device in $block_devices ; do
23
+ if [ " $device " != " $device_to_skip " ]; then
24
+ echo " Mounting $device at $mount_point /$device "
25
+ sudo mkdir -p " $mount_point /$device "
26
+ sudo mkfs -t " $filesystem_type " " /dev/$device " # Format the device with the specified filesystem
27
+ sudo mount " /dev/$device " " $mount_point /$device "
28
+ if [ $? -eq 0 ]; then
29
+ echo " Mounting successful."
30
+ else
31
+ echo " Failed to mount $device ."
32
+ fi
33
+ else
34
+ echo " Skipping $device ."
35
+ fi
36
+ done
37
+ echo " Mounting complete."
0 commit comments