Boot from iSCSI / LUN
Posted: Tuesday 23 July 2019 16:03
Below a description how to boot from iSCSI on a Synology NAS or other NAS with iSCSI/LUN.
THIS IS EXPERIMENTAL!!! If you do not exactly know what is being explained then STOP.
There might be typo's. I will fix them here when I find them.
Everything is based on a fixed IPaddress for the Raspberry Pi, make sure that you have ssh access.
Step 1. Take a normal SD-card and put the latest Raspbian Buster Lite on it.
Update and upgrade, you should be on: Linux raspberry 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux
or higher, currently (25-7-2019) on Linux raspberry 4.19.58-v7+ #1245 SMP Fri Jul 12 17:25:51 BST 2019 armv7l GNU/Linux
Step 2. Create a iSCSI target and LUN on your Synology. Mark your IQN. I made a LUN of 16Gb.
Step 3. Install iSCSI on the Raspberry Pi, make sure it is running and discover the Target. Try to login and find the device with dmesg.
Create an empty file iscsi.initramfs. Actually there are 2 ways: One is empty file and everything concerning iSCSI on the commandline in /boot/cmdline.txt or Second, everything concerning iSCSI in this file and not in the /boot/cmdline.txt. I choose the first option (empty file).
Step 4. Suppose you found with dmesg that the device is "/dev/sdb". I call it /dev/sdX . Give that device a filesystem ext4, and mark the UUID. Please be careful that you have the right device. Mount that device.
Step 5. Copy the filesystem from the SD-card to the new LUN, and skip a view dirs. I mount my USB sticks on /media so I skip that one too. Wait some time until everything is copied. Then make some empty dirs.
Step 6. Goto /boot and copy some files and place the script below also on /boot. This is needed to switch between normal SD-card boot and LUN boot.
Script: nano /boot/switch_boot_setup.sh and make the file executable.
You might have to install initramfs-tools with:
Edit config.txt.lun and add at the end of the file with the name of the file just created:
Find the INITIATOR iqn from /etc/iscsi/initiatorname.iscsi
Edit cmdline.txt.lun. Replace the complete content with (everything on 1 line!!!):
Step 8. Fix fstab on the LUN device. Remove the line with mmcblk0p2 (not the mmcblk0p1). If that line is not present, delete the line with
Most important is that there should be no line with a root (/) mount, because that is been replace with the line below.
Add a new line for the /dev/sdX device. Edit: nano /mnt/iscsi/etc/fstab
Step 9. Execute and reboot:
Step 10. After the reboot you should be on the LUN. Verify with:
If you want to go back to the original SD-card boot, execute:
I hope I did not miss something, else this post will be edited.
If everything is stable I will post some scripts to keep the LUN and SD-card synchronized (almost done).
Enjoy.
Step 11.
Normal upgrading op packages can be done the normal way followed by sync of the files with the appropriate script.
When needed here is a logrotate file for both sd-card and lun the same file:
Content:
Step 12. Upgrading the kernel.
Make sure that switching back and forth between lun and org works fine.
Also make sure that synchronising between lun and org is working fine too. There should be no errors.
Now switch back to org, synchronize and reboot to org.
If you like, make a exact copy of your SD-card and make a snaphot of the LUN, just in case something goes wrong.
Now issue the following commands in exactly this order.
Ignore possible errors about 'update-initramfs', those will be handled after the reboot.
Once up again issue this command
Mark the new 'initrd.img-4.xx.yy-zz' filename. Edit the last line of config.txt.lun with this new filename and synchronize the files to lun.
Now switch back to the lun and reboot.
Check after the reboot if you are on the new kernel with.
Remove the OLDER 'initrd.img-4.xx.yy-zz' file from /boot
THIS IS EXPERIMENTAL!!! If you do not exactly know what is being explained then STOP.
There might be typo's. I will fix them here when I find them.
Everything is based on a fixed IPaddress for the Raspberry Pi, make sure that you have ssh access.
Step 1. Take a normal SD-card and put the latest Raspbian Buster Lite on it.
Update and upgrade, you should be on: Linux raspberry 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux
or higher, currently (25-7-2019) on Linux raspberry 4.19.58-v7+ #1245 SMP Fri Jul 12 17:25:51 BST 2019 armv7l GNU/Linux
Step 2. Create a iSCSI target and LUN on your Synology. Mark your IQN. I made a LUN of 16Gb.
Step 3. Install iSCSI on the Raspberry Pi, make sure it is running and discover the Target. Try to login and find the device with dmesg.
Create an empty file iscsi.initramfs. Actually there are 2 ways: One is empty file and everything concerning iSCSI on the commandline in /boot/cmdline.txt or Second, everything concerning iSCSI in this file and not in the /boot/cmdline.txt. I choose the first option (empty file).
Code: Select all
sudo apt-get install open-iscsi
sudo systemctl restart iscsi.service
sudo iscsiadm -m discovery -t sendtargets -p <IP of Synology>
sudo iscsiadm --portal <IP of Synology> -T <IQN of Target on Synology> --mode node --login
dmesg
sudo touch /etc/iscsi/iscsi.initramfsCode: Select all
sudo mkfs.ext4 -m0 /dev/sdX
sudo blkid /dev/sdX ----> Mark this /dev/sdX UUID
sudo mkdir /mnt/iscsi
sudo mount /dev/sdX /mnt/iscsiCode: Select all
sudo rsync -avhP --exclude /boot --exclude /proc --exclude /run --exclude /sys --exclude /mnt --exclude /media / /mnt/iscsi/
sudo mkdir /mnt/iscsi/{proc,run,sys,boot,mnt,media}Code: Select all
sudo cp /boot/cmdline.txt /boot/cmdline.txt.org
sudo cp /boot/cmdline.txt /boot/cmdline.txt.lun
sudo cp /boot/config.txt /boot/config.txt.org
sudo cp /boot/config.txt /boot/config.txt.lun- Spoiler: show
You might have to install initramfs-tools with:
Code: Select all
sudo apt-get install initramfs-toolsCode: Select all
cd /boot
sudo update-initramfs -v -k `uname -r` -c > /home/pi/initramfs.txtCode: Select all
initramfs initrd.img-4.19.yy-xxx followkernelEdit cmdline.txt.lun. Replace the complete content with (everything on 1 line!!!):
Code: Select all
dwc_otg.lpm_enable=0 ip=<Raspberry IPaddress>:<Synology IPaddress>:<Gateway IP>:255.255.255.0:<Raspberry hostname>:eth0:off
ISCSI_INITIATOR=<IQN from /etc/iscsi/initiatorname.iscsi>
ISCSI_TARGET_NAME=<IQN from Synology> ISCSI_TARGET_IP=<Synology IPaddress>
ISCSI_TARGET_PORT=3260 ISCSI_TARGET_GROUP=1 rw rootfs=ext4 root=UUID=<UUID from the /dev/sdX device>
fsck.repair=yes elevator=deadline rootwait panic=15Code: Select all
PARTUUID=xxxxxxxxxx / ext4 defaults,noatime 0 1Add a new line for the /dev/sdX device. Edit: nano /mnt/iscsi/etc/fstab
Code: Select all
UUID=<UUID from the /dev/sdX device> / ext4 defaults 1 1Code: Select all
sudo /boot/switch_boot_setup.sh lun
sudo rebootCode: Select all
sudo df -H
There should be a line like:
/dev/sdX 17G 2.2G 15G 14% /
Code: Select all
sudo /boot/switch_boot_setup.sh org
sudo rebootIf everything is stable I will post some scripts to keep the LUN and SD-card synchronized (almost done).
Enjoy.
Step 11.
Normal upgrading op packages can be done the normal way followed by sync of the files with the appropriate script.
When needed here is a logrotate file for both sd-card and lun the same file:
Code: Select all
sudo nano /etc/logrotate.d/sync_lun_and_sd-cardCode: Select all
/var/log/sync_lun_2_sd-card.log {
rotate 1
weekly
compress
missingok
}
/var/log/sync_sd-card_2_lun.log {
rotate 1
weekly
compress
missingok
}Make sure that switching back and forth between lun and org works fine.
Also make sure that synchronising between lun and org is working fine too. There should be no errors.
Now switch back to org, synchronize and reboot to org.
Code: Select all
sudo /boot/switch_boot_setup.sh orgNow issue the following commands in exactly this order.
Code: Select all
sudo apt-get update
sudo apt-get upgrade
sudo rebootOnce up again issue this command
Code: Select all
cd /boot
sudo update-initramfs -v -k `uname -r` -c > /home/pi/initramfs.txtCode: Select all
sudo /root/scripts/sync_sd-card_2_lun.shCode: Select all
sudo /boot/switch_boot_setup.sh lunCode: Select all
uname -a