Broken SD card, new install, external hdd with user data

Hi,

I recently had to setup Dietpi again as my SD card crashed.

I do have restored a backup from my external hdd using Dietpi backup.
On the the HDD I also have nextcloud data stored in a separate folder.

How do I use the user data folder from the HDD instead the one from the new SD?

How can I tell dietpi to look on the HDD without loosing any data and having my system run as with the old SD that broke?

Is there a tutorial of what to do if SD cards are changed to make the system run again without any reinstall ideally? I am a little lost and don’t want to lose any data or settings as all was running great before my SD card said good bye.

Thanks
T

Simply “move” them again to the external drive via dietpi-drive_manager. It does not remove anything from the target drive, but just copies the files from /mnt/dietpi_userdata over, which should be empty directories on a fresh DietPi install.

But verify this first. E.g. if you installed software already, and e.g. a MariaDB database is present in /mnt/dietpi_userdata/mysql, copying this over to the previous data drive would overwrite and break the database there. So at best move user data to a previous data drive always as very first step on a fresh DietPi image without any additional software installed.

Got ya.

So the order is:

Flash a new sd
Boot it
Copy mnt/dietpi_userdata over to the HDD
Restore backup from HDD

Is that correct and should that make everything work again without installing the same software as this gets restored (incl settings) during backup restore?

Theoretically the Restore should bring back all software installed.

There is just one small exclusion. We exclude /mnt/* in general, but include /mnt/dietpi_userdata explicitly (as long as it is not a symbolic link).

Update:
I did as I described but the result is not as hoped.

The restore went through without error, but:
Maria DB service fails to start and
Within the banner it says:
df: /mnt/dietpi_userdata: Datei oder Verzeichnis nicht gefunden

There is just one small exclusion. We exclude /mnt/* in general, but include /mnt/dietpi_userdata explicitly (as long as it is not a symbolic link).

What does this mean for me and the update?

did you moved dietpi_userdata to your external disk before stating the restore?

can you share following

lsblk -o name,fstype,label,size,ro,type,mountpoint,partuuid,uuid
ls -la /mnt
cat /etc/fstab
df -h

did you moved dietpi_userdata to your external disk before stating the restore?

I did (hoping I did it correctly).

Not sure if relevant: My backup was based on 8.2.2, the image I used to start over is 8.1.2.

Also, if this all a little too much to solve, I don’t want to steal your time. I would be happy setting the PI up from scratch as long as I don’t lose my nextcloud data. If that is easier to achieve, let me know what needs to be done.

The output you asked for:

root@DietPi:~# lsblk -o name,fstype,label,size,ro,type,mountpoint,partuuid,uuid
NAME FSTYPE LABEL   SIZE RO TYPE MOUNTPOINT PARTUUID                             UUID
sda               931,5G  0 disk                                                
└─sda1
     ext4         931,5G  0 part            366d5803-dd04-4f0d-93db-6d429734eb8e d72ee951-aa1f-4edc-9e90-146132868e0d
sdb               931,5G  0 disk                                                
└─sdb1
     ext4         931,5G  0 part            1374f8db-5348-4faa-acfc-8635ec4d6d5b 72c2de50-ca98-4b36-b5c6-647485beff98
mmcblk0
│                  29,7G  0 disk                                                
├─mmcblk0p1
│    vfat           128M  0 part /boot      b458407c-01                          E342-0AA2
└─mmcblk0p2
     ext4          29,6G  0 part /          b458407c-02                          ec8d8e5e-1fb5-47c3-a1ef-542d5bc49b70
root@DietPi:~# ls -la /mnt
insgesamt 28
drwxr-xr-x  9 root   root   4096 Mär 17 13:02 .
drwxr-xr-x 24 root   root   4096 Mär  5 01:28 ..
drwxr-xr-x  2 root   root   4096 Mär 17 11:40 72c2de50-ca98-4b36-b5c6-647485beff98
drwxr-xr-x  2 root   root      0 Feb 14  2019 backup
drwxr-xr-x  2 root   root   4096 Mär 17 11:40 d72ee951-aa1f-4edc-9e90-146132868e0d
lrwxrwxrwx  1 root   root     57 Mär 17 11:41 dietpi_userdata -> /mnt/d72ee951-aa1f-4edc-9e90-146132868e0d/dietpi_userdata
drwxrwxr-x  2 dietpi dietpi 4096 Feb 21 20:03 ftp_client
drwxr-xr-x  2 root   root      0 Mär 17 13:31 media1
drwxrwxr-x  2 dietpi dietpi 4096 Feb 21 20:04 nfs_client
drwxrwxr-x  2 dietpi dietpi 4096 Feb 21 20:04 samba
root@DietPi:~# cat /etc/fstab
# You can use "dietpi-drive_manager" to setup mounts.
# NB: It overwrites and re-creates physical drive mount entries on use.
#----------------------------------------------------------------
# NETWORK
#----------------------------------------------------------------


#----------------------------------------------------------------
# TMPFS
#----------------------------------------------------------------
tmpfs /tmp tmpfs size=487M,noatime,lazytime,nodev,nosuid,mode=1777
tmpfs /var/log tmpfs size=50M,noatime,lazytime,nodev,nosuid,mode=1777

#----------------------------------------------------------------
# MISC: ecryptfs, vboxsf, glusterfs, bind, Btrfs subvolume mounts
#----------------------------------------------------------------


#----------------------------------------------------------------
# SWAP SPACE
#----------------------------------------------------------------


#----------------------------------------------------------------
# PHYSICAL DRIVES
#----------------------------------------------------------------
PARTUUID=b458407c-02 / ext4 noatime,lazytime,rw 0 1
PARTUUID=b458407c-01 /boot vfat noatime,lazytime,rw 0 2
UUID=72c2de50-ca98-4b36-b5c6-647485beff98 /mnt/media1 ext4 noatime,lazytime,rw,nofail,noauto,x-systemd.automount
UUID=d72ee951-aa1f-4edc-9e90-146132868e0d /mnt/backup ext4 noatime,lazytime,rw,nofail,noauto,x-systemd.automount
root@DietPi:~# df -h
Dateisystem    Größe Benutzt Verf. Verw% Eingehängt auf
/dev/root        30G    3,2G   25G   12% /
devtmpfs        454M       0  454M    0% /dev
tmpfs           487M    1,1M  486M    1% /dev/shm
tmpfs           487M     13M  474M    3% /run
tmpfs           5,0M    4,0K  5,0M    1% /run/lock
tmpfs           487M       0  487M    0% /sys/fs/cgroup
tmpfs            50M     12K   50M    1% /var/log
tmpfs           487M       0  487M    0% /tmp
/dev/mmcblk0p1  127M     30M   97M   24% /boot
tmpfs            98M       0   98M    0% /run/user/999
tmpfs            98M       0   98M    0% /run/user/0
root@DietPi:~#

something is wrong with the way you are going to mount your disks.

You have 2 disk connected to your device. Each has 930GB disk space available

sdb1 - UUID - 72c2de50-ca98-4b36-b5c6-647485beff98
sda1 - UUID - d72ee951-aa1f-4edc-9e90-146132868e0d

aktualy you are mounting both disk as follow

UUID=72c2de50-ca98-4b36-b5c6-647485beff98 > /mnt/media1 
UUID=d72ee951-aa1f-4edc-9e90-146132868e0d > /mnt/backup

however your /mnt/dietpi_userdata directory is linked to a mount point called /mnt/d72ee951-aa1f-4edc-9e90-146132868e0d/, which did not exist or is not correctly mounted

dietpi_userdata -> /mnt/d72ee951-aa1f-4edc-9e90-146132868e0d/dietpi_userdata

You would need to ensure dietpi_userdata is pointing to correct disk/mount point. Basically you have 2 options.

  • change symbolic linke for dietpi_userdata to pint to /mnt/backup
  • mount disk sda1 to /mnt/d72ee951-aa1f-4edc-9e90-146132868e0d/ instead of /mnt/backup

Thanks for the investigation.

change symbolic link for dietpi_userdata to point to /mnt/backup

How would I do that? Via the drive manager?

let’s have a look into /mnt/backup to check if all is available on this mount.

ls -la /mnt/backup

There you go:

root@DietPi:~# ls -la /mnt/backup
insgesamt 1101844
drwxr-xr-x  4 root   root         4096 Mär 17 12:42 .
drwxr-xr-x  9 root   root         4096 Mär 17 13:02 ..
drwxr-xr-x 11 root   root         4096 Mär 18 03:13 dietpi-sync
drwxrwxr-x  6 dietpi dietpi       4096 Mär 17 11:17 dietpi_userdata
-rw-------  1 root   root   1128267776 Mär 17 11:41 .swapfile
root@DietPi:~#

you can do following

cd /mnt
rm dietpi_userdata
ln -s /mnt/backup/dietpi_userdata dietpi_userdata

check if the link has been created correctly. If yes, restart all services

ls -la /mnt/
dietpi-services restart

I did change the symlink and it looked good.

root@DietPi:~# ls -la /mnt
insgesamt 36
drwxr-xr-x  9 root   root   4096 Mär 20 06:24 .
drwxr-xr-x 24 root   root   4096 Mär  5 01:28 ..
drwxr-xr-x  3 root   root   4096 Mär 18 01:25 72c2de50-ca98-4b36-b5c6-647485beff98
drwxr-xr-x  4 root   root   4096 Mär 17 12:42 backup
drwxr-xr-x  2 root   root   4096 Mär 17 11:40 d72ee951-aa1f-4edc-9e90-146132868e0d
lrwxrwxrwx  1 root   root     27 Mär 20 06:24 dietpi_userdata -> /mnt/backup/dietpi_userdata
drwxrwxr-x  2 dietpi dietpi 4096 Feb 21 20:03 ftp_client
drwxr-xr-x 11 root   root   4096 Mär 20 01:25 media1
drwxrwxr-x  2 dietpi dietpi 4096 Feb 21 20:04 nfs_client
drwxrwxr-x  2 dietpi dietpi 4096 Feb 21 20:04 samba

But Maria DB server still fails as before:

root@DietPi:~# dietpi-services restart

 DietPi-Services
─────────────────────────────────────────────────────
 Mode: restart

[  OK  ] DietPi-Services | restart : proftpd
[  OK  ] DietPi-Services | restart : redis-server
[FAILED] DietPi-Services | restart : mariadb
[  OK  ] DietPi-Services | restart : php7.3-fpm
[  OK  ] DietPi-Services | restart : lighttpd
[  OK  ] DietPi-Services | restart : cron

let’s have a look to MariaDB

systemctl restart mariadb.service
journalctl -u mariadb
cat /var/log/mysql/error.log
readlink /var/lib/mysql
readlink -f /var/lib/mysql

error.log file might not be available. You could try to activate it as follow

sed -i 's/#log_error/log_error/' /etc/mysql/mariadb.conf.d/50-server.cnf
systemctl restart mariadb.service

Let me know what you see…

root@DietPi:~# systemctl restart mariadb.service
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
root@DietPi:~# journalctl -u mariadb
-- Logs begin at Sun 2022-03-20 06:33:57 CET, end at Sun 2022-03-20 19:37:06 CET. --
Mär 20 06:34:07 DietPi systemd[1]: Starting MariaDB 10.3.31 database server...
Mär 20 06:34:08 DietPi mysqld[783]: 2022-03-20  6:34:08 0 [Note] /usr/sbin/mysqld (mysqld 10.3.31-MariaDB-0+deb10u1) starting as process 783 ...
Mär 20 06:34:08 DietPi mysqld[783]: 2022-03-20  6:34:08 0 [Warning] Can't create test file /var/lib/mysql/DietPi.lower-test
Mär 20 06:34:08 DietPi mysqld[783]: [97B blob data]
Mär 20 06:34:08 DietPi mysqld[783]: 2022-03-20  6:34:08 0 [ERROR] Aborting
Mär 20 06:34:08 DietPi systemd[1]: mariadb.service: Main
 process exited, code=exited, status=1/FAILURE
Mär 20 06:34:08 DietPi systemd[1]: mariadb.service: Fail
ed with result 'exit-code'.
Mär 20 06:34:08 DietPi systemd[1]: Failed to start Maria
DB 10.3.31 database server.
Mär 20 06:35:12 DietPi systemd[1]: Starting MariaDB 10.3.31 database server...
Mär 20 06:35:12 DietPi mysqld[1201]: 2022-03-20  6:35:12 0 [Note] /usr/sbin/mysqld (mysqld 10.3.31-MariaDB-0+deb10u1) starting as process 1201 ...
Mär 20 06:35:12 DietPi mysqld[1201]: 2022-03-20  6:35:12 0 [Warning] Can't create test file /var/lib/mysql/DietPi.lower-test
Mär 20 06:35:12 DietPi mysqld[1201]: [97B blob data]
Mär 20 06:35:12 DietPi mysqld[1201]: 2022-03-20  6:35:12 0 [ERROR] Aborting
Mär 20 06:35:12 DietPi systemd[1]: mariadb.service: Main
 process exited, code=exited, status=1/FAILURE
Mär 20 06:35:12 DietPi systemd[1]: mariadb.service: Fail
ed with result 'exit-code'.
Mär 20 06:35:12 DietPi systemd[1]: Failed to start Maria
DB 10.3.31 database server.
Mär 20 13:53:49 DietPi systemd[1]: Starting MariaDB 10.3.31 database server...
Mär 20 13:53:49 DietPi mysqld[26851]: 2022-03-20 13:53:49 0 [Note] /usr/sbin/mysqld (mysqld 10.3.31-MariaDB-0+deb10u1) starting as process 26851 ...
Mär 20 13:53:50 DietPi mysqld[26851]: 2022-03-20 13:53:50 0 [Warning] Can't create test file /var/lib/mysql/DietPi.lower-test
Mär 20 13:53:50 DietPi mysqld[26851]: [97B blob data]
Mär 20 13:53:50 DietPi mysqld[26851]: 2022-03-20 13:53:50 0 [ERROR] Aborting
Mär 20 13:53:50 DietPi systemd[1]: mariadb.service: Main
 process exited, code=exited, status=1/FAILURE
Mär 20 13:53:50 DietPi systemd[1]: mariadb.service: Fail
ed with result 'exit-code'.
Mär 20 13:53:50 DietPi systemd[1]: Failed to start Maria



root@DietPi:~# readlink /var/lib/mysql
/mnt/dietpi_userdata/mysql
root@DietPi:~# readlink -f /var/lib/mysql
/mnt/backup/dietpi_userdata/mysql

what about the error log file? There might be some more hint inside.

Maybe I am doing it wrong, but error log seems the be empty?

root@DietPi:~# sed -i 's/#log_error/log_error/' /etc/mysql/mariadb.conf.d/50-server.cnf
root@DietPi:~# systemctl restart mariadb.service
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
root@DietPi:~# cat /var/log/mysql/error.log
root@DietPi:~#

ok let’s see if this will give some more hints. The command will try to start the database manually

sudo -u mysql /usr/sbin/mariadbd

Well…that didn’t go as expected…

root@DietPi:~# sudo -u mysql /usr/sbin/mariadbd
sudo: /usr/sbin/mariadbd: Befehl nicht gefunden
root@DietPi:~#

hmm, can you share following

systemctl cat mariadb | grep "ExecStart="
which mariadbd