Skip to content

Commit a875aa4

Browse files
authored
Merge pull request #274 from NetApp/add_ubuntu_support
Added support for other Linux distributions
2 parents 7079332 + 968992e commit a875aa4

5 files changed

Lines changed: 736 additions & 424 deletions

File tree

Management-Utilities/ec2-user-data-iscsi-create-and-mount/EC2-cloud_formation.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Metadata:
6161
SvmName:
6262
default: "SVM Name"
6363
Username:
64-
default: "Username"
64+
default: "ONTAP Username"
6565
DriveLetter:
6666
default: "Drive Letter (Windows Only)"
6767
CidrIp:
@@ -115,14 +115,15 @@ Parameters:
115115
Description: SVM Name
116116
Username:
117117
Type: String
118-
Description: Username to run under
118+
Description: Username to run ONTAP APIs as.
119+
Default: fsxadmin
119120
DriveLetter:
120121
Type: String
121122
Default: d
122123
Description: Drive Letter - valid for Windows only
123124
CidrIp:
124125
Type: String
125-
Description: CIDR IP for SSH access to the instance
126+
Description: CIDR IP for SSH or RDP access to the instance. MUST be a CIDR!
126127
LinuxUserDataUrl:
127128
Type: String
128129
Default: https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/refs/heads/main/Management-Utilities/ec2-user-data-iscsi-create-and-mount/linux_userData.sh
@@ -219,4 +220,4 @@ Resources:
219220
Outputs:
220221
InstanceId:
221222
Description: EC2 Instance ID
222-
Value: !Ref MyEC2Instance
223+
Value: !Ref MyEC2Instance

Management-Utilities/ec2-user-data-iscsi-create-and-mount/README.md

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ These sample scripts provide a way to launch an AWS EC2 instance with `user data
55
volume and LUN, mount it to the instance, while installing all the needed libraries and resources.
66

77
## Notes
8-
- LUN size will be set to 90% of the volume size, the remain space is needed for the the LUN managment operation.
9-
This means that usuable volume size is 90% of the requestd size.
10-
- The process might take several minutes to be compleetd.
8+
- LUN size will be set to 90% of the volume size, the remaining space is needed for the LUN management operation.
9+
This means that usable volume size is 90% of the requested size.
10+
- The process might take several minutes to be complete.
1111

12-
## Set Up
13-
1. Create an AWS SecretsManager secret to hold the password of the account you plan to use to authenicate to the FSxN file system with.
12+
## Preperation
13+
14+
1. Create an AWS SecretsManager secret to hold the password of the account you plan to use to authenticate to the FSxN file system with.
1415
The secret should be of type `other` with value set to `Plain Text` that holds just the password.
1516
2. Create an AWS IAM role that has EC2 as the trusted entity and has permissions to read the secret value. Here is an example policy that will do that:
1617
```json
@@ -30,41 +31,55 @@ The secret should be of type `other` with value set to `Plain Text` that holds j
3031
```
3132
Replace the "Resource" ARN with the ARN of your secret.
3233

33-
3. Download the needed script according to the instance type you want to run (Linux or Windows).
34+
## Deployment Options
35+
36+
There are two ways to deploy an EC2 instance with the needed user data script:
37+
1. Copy the CloudFormation template found in the repo [EC2-cloud_formation.yaml](EC2-cloud_formation.yaml) to you local machine and deploy a CloudFormation stack using it. CloudFormation will prompt you for all the required parameters.
38+
2. Follow the instruction below to deploy an EC2 instance from the AWS console.
39+
40+
## AWS console deployment
41+
42+
1. Download the needed script according to the instance type you want to run. Either [linux_userData.sh](linux_userData.sh)
43+
for a Linux distribution or [windows_userData.ps1](windows_userData.ps1) for Windows. The Linux script has been tested
44+
with `Amazon Linux 2023`, `Ubuntu 24.04`, `Red Hat Enterprise Linux 10` and `Debian 13` distributions,
45+
while the Windows script is designed for `Windows Server 2025 Base`.
46+
47+
Note that since AWS has a 16KB limit for the user data the linux_userData.sh script is made up of the variable
48+
assignment noted below, and a compressed, base64 encoded version of the `linux_userData_real.sh` script. When the
49+
`linux_userData.sh` script is run, it will decode and uncompress what was the `linux_userData_real.sh` script
50+
and run it.
51+
52+
Once you have downloaded the script, open it in a text editor and set the required values as noted below.
3453

3554
For the Linux version of the script, set the following values at the top of it:
36-
- SECRET_NAME - Secret name has has the password for the `ONTAP-USER`.
37-
- AWS_REGION - AWS secret manager region.
55+
- SECRET_ARN - The ARN of the secret that has the password for the `ONTAP-USER`.
3856
- FSXN_ADMIN_IP - IP address, or hostname, of the FSxN management endpoint.
3957
- VOLUME_NAME - The name of the volume you want to create in your FSxN.
40-
- VOLUME_SIZE - The size of the volume you want to create in GB e.g [100g]
58+
- VOLUME_SIZE - The size of the volume you want to create in GB e.g [100]
4159
- SVM_NAME - The name of the SVM where the volume is to be created.
42-
- ONTAP_USER - The ONTAP user id you wish to authenicate with.
60+
- ONTAP_USER - The ONTAP user id you wish to authenticate with.
4361

4462
For the Windows version of the script, set the following values at the top of it:
4563
- $secretId - secret ARN that holds the password for the `$user`.
4664
- $ip - IP address, or hostname, of the FSxN management endpoint.
4765
- $volName - The name of the volume you want to create in your FSxN.
4866
- $volSize - The size of the volume you want to create in GB e.g [100]
4967
- $drive_letter - The drive letter to assign to the volume.
50-
- $user - The ONTAP user id you wish to authenicate with.
68+
- $user - The ONTAP user id you wish to authenticate with.
5169
- $svm_name - The name of the SVM where the volume is to be created.
5270

53-
4. Save the script file.
71+
2. Save the script file.
5472

55-
## On AWS console EC2
56-
5773
### For Linux installation:
5874
<ol>
5975
<li>Launch new instance
6076
<ol>
6177
<li>Fill in the server name.</li>
62-
<li>Select 'Amazon Linux'.</li>
63-
<li>Under Amazon Machine Image select 'Amazon Linux 2023 AMI'.</li>
78+
<li>Under the Quick Start tab select the Linux distribution of your choice. The supported distributions are: `Amazon Linux 2023`, `Ubuntu 24.04`, `Red Hat Enterprise Linux 10` and `Debian 13`</li>
6479
<li>Fill in the other settings based on your networking and business needs.</li>
6580
<li>Under 'Advanced details':
6681
<ol>
67-
<li>Set the 'IAM instance profile' to the policy you created in the steps above.</li>
82+
<li>Set the 'IAM instance profile' to the policy you created in the preperation step above.</li>
6883
<li>At the bottom, under the 'User data' section, press 'choose file' and select the script saved above.</li>
6984
</ol>
7085
</li>
@@ -73,7 +88,7 @@ The secret should be of type `other` with value set to `Plain Text` that holds j
7388
<li>Launch the instance.</li>
7489
</ol>
7590

76-
The installation log file can be found at: `/home/ec2-user/install.log`.
91+
The installation log file can be found at: `/var/log/iscsi-install.log`.
7792
If an error occurs while the installation is running, the script will terminate and all installations and setup will roll back.
7893

7994
### For Windows installation:
@@ -96,6 +111,24 @@ If an error occurs while the installation is running, the script will terminate
96111
</ol>
97112

98113
The installation log file can be found at: `C:\Users\Administrator\install.log`.
99-
If an error occurs while the installation is running, a message will be inserted into the installation log file, it will attempt to roll back any work that it preformed, finally the script will terminate.
114+
If an error occurs while the installation is running, a message will be inserted into the
115+
installation log file, it will attempt to roll back any work that it preformed, finally the script will terminate.
116+
117+
**Note:** It can take 10 to 15 minutes for the script to complete. Check the installation log file to confirm it is done.
118+
The line `Uninstall script removed` should be at the bottom of the file when the script has finished.
119+
120+
## Author Information
121+
122+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
123+
124+
## License
125+
126+
Licensed under the Apache License, Version 2.0 (the "License").
127+
128+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
129+
130+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an _"AS IS"_ basis, without WARRANTIES or conditions of any kind, either express or implied.
131+
132+
See the License for the specific language governing permissions and limitations under the License.
100133

101-
**Note:** It can take 20 to 30 minutes for the script to compplete. Check the installation log file to confirm it is done. The line `Uninstall script removed` should be at the bottom of the file when the script has finished.
134+
© 2026 NetApp, Inc. All Rights Reserved.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
#
3+
# Since, for some reason, the maximum size of a EC2 User Data script is
4+
# 16KB we have to compress the real script, with some logic to uncompress
5+
# it on the EC2 instance when it is deployed, and then pass that as the
6+
# user data content.
7+
#
8+
# This script is used to create the linux_userData.sh script from the
9+
# linux_userData_real.sh file.
10+
################################################################################
11+
12+
cat <<'EOF' > linux_userData.sh
13+
#!/bin/bash
14+
#
15+
# Set the ARN of the secret that should contain just the password for the ONTAP admin user set below.
16+
SECRET_ARN=""
17+
#
18+
# Set the FSx admin IP.
19+
FSXN_ADMIN_IP=""
20+
#
21+
# Set the name of the volume to be created on the FSx for ONTAP file system. Note, volume names cannot have dashes in them.
22+
VOLUME_NAME=""
23+
#
24+
# Set the volume size in GB. It should just be a number, without the 'GB' suffix.
25+
VOLUME_SIZE=
26+
#
27+
# Set the SVM name. The default is 'fsx'.
28+
SVM_NAME="fsx"
29+
#
30+
# Set the ONTAP admin user. The default is fsxadmin.
31+
ONTAP_USER="fsxadmin"
32+
#
33+
################################################################################
34+
# **** You should not need to edit anything below this line ****
35+
################################################################################
36+
#
37+
# When called from the CloudFormation template, the parameters are passsed as
38+
# arguments.
39+
SECRET_ARN="${SECRET_ARN:=$1}"
40+
FSXN_ADMIN_IP="${FSXN_ADMIN_IP:=$2}"
41+
VOLUME_NAME="${VOLUME_NAME:=$3}"
42+
VOLUME_SIZE="${VOLUME_SIZE:=$4}"
43+
SVM_NAME="${5:-$SVM_NAME}"
44+
ONTAP_USER="${6:-$ONTAP_USER}"
45+
#
46+
# Since AWS only allows up to 16KB for the user data script, the rest of this script
47+
# will be the compressed version of the linux_userData_real.sh file, which will be
48+
# uncompressed and executed on the EC2 instance when it is deployed.
49+
cat <<EOF2 > /tmp/linux_userData.sh
50+
#!/bin/bash
51+
export SECRET_ARN="$SECRET_ARN"
52+
export FSXN_ADMIN_IP="$FSXN_ADMIN_IP"
53+
export VOLUME_NAME="$VOLUME_NAME"
54+
export VOLUME_SIZE="$VOLUME_SIZE"
55+
export SVM_NAME="$SVM_NAME"
56+
export ONTAP_USER="$ONTAP_USER"
57+
EOF2
58+
59+
cat <<EOF3 | base64 -d | gunzip >> /tmp/linux_userData.sh
60+
EOF
61+
62+
cat linux_userData_real.sh | gzip -c | base64 >> linux_userData.sh
63+
64+
cat <<EOF4 >> linux_userData.sh
65+
EOF3
66+
67+
chmod +x /tmp/linux_userData.sh
68+
/tmp/linux_userData.sh
69+
EOF4

0 commit comments

Comments
 (0)