mount.sh
· 1.4 KiB · Bash
Raw
# Ubuntu install ISCSI Server
# Assuming the IP of the server is 10.0.0.1
# Mount a disk as /dev/sdb first
apt install tgt -y
# Edit /etc/tgt/conf.d/iscsi.conf
echo "
<target iqn.2024-03.iscsi.server:lun1>
backing-store /dev/sdb
initiator-address 10.0.0.2
initiator-address 10.0.0.3
initiator-address 10.0.0.4 # Add more if needed. These are the IPs of the clients
incominguser iscsi-user password
outgoinguser iscsi-target secretpass
</target>" | tee /etc/tgt/conf.d/iscsi.conf
systemctl restart tgt
tgtadm --mode target --op show
# Ubuntu install ISCSI Client
# Assuming the IP of the server is 10.0.0.2
apt install open-iscsi -y
iscsiadm -m discovery -t sendtargets -p 10.0.0.1 # This IP is the server IP
# You should see:
# 10.0.0.2:3260,1 iqn.2024-03.iscsi.server:lun1
# Edit /etc/iscsi/initiatorname.iscsi
echo "InitiatorName=iqn.2024-03.iscsi.server:lun1" | tee /etc/iscsi/initiatorname.iscsi
# Edit /etc/iscsi/nodes/iqn.2024-03.iscsi.server\:lun1/10.0.0.1\,3260\,1/default
echo "
node.session.auth.authmethod = CHAP
node.session.auth.username = iscsi-user
node.session.auth.password = password
node.session.auth.username_in = iscsi-target
node.session.auth.password_in = secretpass
node.startup = automatic" | tee /etc/iscsi/nodes/iqn.2024-03.iscsi.server\:lun1/10.0.0.1\,3260\,1/default
systemctl restart open-iscsi iscsid
iscsiadm -m session -o show
lsblk
| 1 | # Ubuntu install ISCSI Server |
| 2 | # Assuming the IP of the server is 10.0.0.1 |
| 3 | |
| 4 | # Mount a disk as /dev/sdb first |
| 5 | apt install tgt -y |
| 6 | |
| 7 | # Edit /etc/tgt/conf.d/iscsi.conf |
| 8 | echo " |
| 9 | <target iqn.2024-03.iscsi.server:lun1> |
| 10 | backing-store /dev/sdb |
| 11 | initiator-address 10.0.0.2 |
| 12 | initiator-address 10.0.0.3 |
| 13 | initiator-address 10.0.0.4 # Add more if needed. These are the IPs of the clients |
| 14 | incominguser iscsi-user password |
| 15 | outgoinguser iscsi-target secretpass |
| 16 | </target>" | tee /etc/tgt/conf.d/iscsi.conf |
| 17 | |
| 18 | systemctl restart tgt |
| 19 | tgtadm --mode target --op show |
| 20 | |
| 21 | # Ubuntu install ISCSI Client |
| 22 | # Assuming the IP of the server is 10.0.0.2 |
| 23 | |
| 24 | apt install open-iscsi -y |
| 25 | iscsiadm -m discovery -t sendtargets -p 10.0.0.1 # This IP is the server IP |
| 26 | # You should see: |
| 27 | # 10.0.0.2:3260,1 iqn.2024-03.iscsi.server:lun1 |
| 28 | |
| 29 | # Edit /etc/iscsi/initiatorname.iscsi |
| 30 | echo "InitiatorName=iqn.2024-03.iscsi.server:lun1" | tee /etc/iscsi/initiatorname.iscsi |
| 31 | |
| 32 | # Edit /etc/iscsi/nodes/iqn.2024-03.iscsi.server\:lun1/10.0.0.1\,3260\,1/default |
| 33 | echo " |
| 34 | node.session.auth.authmethod = CHAP |
| 35 | node.session.auth.username = iscsi-user |
| 36 | node.session.auth.password = password |
| 37 | node.session.auth.username_in = iscsi-target |
| 38 | node.session.auth.password_in = secretpass |
| 39 | node.startup = automatic" | tee /etc/iscsi/nodes/iqn.2024-03.iscsi.server\:lun1/10.0.0.1\,3260\,1/default |
| 40 | systemctl restart open-iscsi iscsid |
| 41 | iscsiadm -m session -o show |
| 42 | lsblk |