Following the suggestion of @rikoshak, here is small tutorial how to move an existing openhabian installation from a SD-card to an usb-SSD on a RaspI 1 or 2.
Because openhabian is based on raspbian, this tutorial is also supposed to work with raspbian.
First of all, why should one move the root-system from the SD-card to an usb-SSD?
The problem is, that the SD-card gets corrupted over time and your system will fail then.
As many people I used to think that it would be sufficient to use a large card from a premium manufacturer to not face this problem, but that has been proved wrong.
Probably the frequent persistence writes kill the card. SSDs have large ram caches and a sophisticated wear management to cope with that.
What you need
An external usb-case and a fitting ssd. A usb stick will also work, but I’m not convinced that it would be an improvement over using an SD-card.
MAKE A BACKUP OF YOUR SD-card ( … just in case …)
Step 1: More power for usb hub of the Raspi
This this change enables that the USB hub of the Raspi delivers 1A, so you will have around 5W of power for your ssd. I’m using an old Samsung 64GB ssd that runs without an external power supply, but that depends on the ssd.
Edit the config.txt of your system
sudo nano /boot/config.txt
append the line
and plug in your ssd.
Step 2: Partition the ssd and put a filesystem on it
Figure out the device name of you usb-ssd. There are different methods to do that.
You can use lsblk
or read dmesg
I think that your ssd will most likely have the device name “sda”.
Partition your ssd drive with fdisk
sudo fdisk /dev/sda
After creating a partition, leave with w (write and exit)
Assuming you have created the partition “sda1”, name it and create a filesystem on it.
sudo mkfs.ext4 -L oh_ssd /dev/sda1
Step 3: Copy the root system from the SD-card to the ssd
Be warned that copying a running system is considered to be “dirty” for some reasons. It works for me, your mileage may vary : -)
First mount the ssd
sudo mount /dev/sda1 /mnt
Check if everything’s fine: If you
you should see the “lost+found” dir of your newly created ssd partition.
Stop openhab and copy the root system from the SD-Card to the ssd with tar. There are also other methods with rsync for example.
sudo systemctl stop openhab2 sudo tar cf - --one-file-system --exclude=/mnt/* --exclude=/proc/* --exclude=/lost+found/* --exclude=/sys/* --exclude=/media/* --exclude=/dev/* --exclude=/tmp/* --exclude=/boot/* --exclude=/run/* / | ( cd /mnt; sudo tar xfp -)
Step 4: Adjust cmdline.txt and fstab
sudo nano /mnt/etc/fstab
Change the line of the root filesystem (second line in the example below) to the partition that you’ve created on your ssd. It is important that /boot must stay on the SD-Card (mmcblk0p1)
/dev/mmcblk0p1 /boot vfat defaults 0 2 /dev/sda1 / ext4 errors=remount-ro,noatime 0 1 tmpfs /tmp tmpfs defaults,nodev,nosuid 0 0
Ok, now you’re nearly set. Last thing is to tell the kernel where the root filesystem resides in future.
sudo nano /boot/cmdline.txt
change the parameter root=/dev/mmcblk0p2 to your ssd partion (/dev/sda1)
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline net.ifnames=0 root=/dev/sda1 rootfstype=ext4 rootwait
Step 5: Try it out
First double check all changes that you have done. If you’ve made an error, your system will likely get stuck at boot …
If you can relogin after some seconds, check if your really running on your ssd.
Filesystem 1K-blocks Used Available Use% Mounted on udev 10240 0 10240 0% /dev tmpfs 199164 12828 186336 7% /run /dev/sda1 61407392 2244268 56020680 4% / tmpfs 497908 0 497908 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock tmpfs 497908 0 497908 0% /sys/fs/cgroup tmpfs 497908 32 497876 1% /tmp /dev/mmcblk0p1 130798 60150 70648 46% /boot tmpfs 99584 0 99584 0% /run/user/1000
If the line with your root system (mounted on == “/”) reads “/dev/sda1”, then congrats, you’ve made it!