Hi Nicolas,
on https://discuss.moodlebox.net/d/312-install-a-cloning-program-into-the-moodlebox I wanted to get an easy to use cloning program for the MoodleBox. My idea is that teachers should be able to copy a fully installed MoodleBox to usb sticks or to an usb card reader with microSD cards. One copy should be a backup. And you can share other copies to other teachers and classes so they cab get their own MoodleBoxes.

In MoodleBox 4.5.0 you installed the program rpi-clone from https://github.com/billw2/rpi-clone.
On Github you wrote that you tested the program and you wrote that it works. Please tell us, how to use it.

In my first tests I use a fresh microSD card with MoodleBox 4.5.1. I start the Raspberry Pi and the Moodlebox runs fine. I change nothing and I try to get a copy an an usb stick. First I look for the device name of the usb stick.

moodlebox@moodlebox:~ $ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1 28.8G  0 disk 
└─sda1        8:1    1 28.8G  0 part /media/usb0
mmcblk0     179:0    0 14.8G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 14.6G  0 part /
moodlebox@moodlebox:~ $ 

Okay, my usb stick is sda and has one fat32 partition ... yes, it's a fresh formatted stick. The tutorial writes that I should use sudo rpi-clone sda to get a copy.

moodlebox@moodlebox:~ $ sudo rpi-clone sda

  Destination disk partition /dev/sda1 is mounted on /media/usb0.
  The clone cannot proceed unless it is unmounted.
Do you want to unmount /media/usb0?  (yes/no): yes

Booted disk: mmcblk0 15.9GB                Destination disk: sda 31.0GB
---------------------------------------------------------------------------
Part      Size    FS     Label             Part   Size    FS     Label  
1 /boot   256.0M  fat32  --                1      256.0M  fat32  --     
2 root     14.6G  ext4   MoodleBox by NMA  2       28.6G  --     --     
---------------------------------------------------------------------------
== Initialize: IMAGE partition table - FS types conflict ==
1 /boot               (31.0M used)   : MKFS  SYNC to sda1
2 root                (2.5G used)    : RESIZE  MKFS  SYNC to sda2
---------------------------------------------------------------------------
Run setup script       : no.
Verbose mode           : no.
-----------------------:
** WARNING **          : All destination disk sda data will be overwritten!
-----------------------:

Initialize and clone to the destination disk sda?  (yes/no): yes
Optional destination ext type file system label (16 chars max): 

Initializing
  Imaging past partition 1 start.
  => dd if=/dev/mmcblk0 of=/dev/sda bs=1M count=8 ...
  Resizing destination disk last partition ...
    Resize success.
  Changing destination Disk ID ...
  => mkfs -t vfat -F 32  /dev/sda1 ...
  => mkfs -t ext4  /dev/sda2 ...

Syncing file systems (can take a long time)
Syncing mounted partitions:
  Mounting /dev/sda2 on /mnt/clone
  => rsync // /mnt/clone with-root-excludes ...
  Mounting /dev/sda1 on /mnt/clone/boot
  => rsync /boot/ /mnt/clone/boot  ...

Editing /mnt/clone/boot/cmdline.txt PARTUUID to use 0407ed5f
Editing /mnt/clone/etc/fstab PARTUUID to use 0407ed5f
===============================
Done with clone to /dev/sda
   Start - 17:59:54    End - 18:02:12    Elapsed Time - 2:18

Cloned partitions are mounted on /mnt/clone for inspection or customizing. 

Hit Enter when ready to unmount the /dev/sda partitions ...
  unmounting /mnt/clone/boot
  unmounting /mnt/clone
===============================

moodlebox@moodlebox:~ $ 

The cloning works without an error. Now the MoodleBox should start with the usb stick. I remove the microSD card and switch the power on. I get the coloured start screen and a blinking green led but no boot process.

To get some ideas for the problem I look at the config.txt and the cmdline.txt. Both files are damaged so the Raspberry Pi can't boot from the copied usb stick. Do you have any idea?

Ralf

    Nicolas changed the title to Issue with rpi-clone .

    ralfkrause On Github you wrote that you tested the program and you wrote that it works. Please tell us, how to use it.

    Just like you, without issue. Testing again.

    ralfkrause In my first tests I use a fresh microSD card with MoodleBox 4.5.1.

    Please confirm that the image used is a fresh v4.5.1? (not only a fresh SD card).

      Nicolas Please confirm that the image used is a fresh v4.5.1? (not only a fresh SD card).

      Yes, it's a fresh installation with MoodleBox 4.5.1 on a 16GB microSD card and I change nothing. I start the MoodleBox. I connect to the MoodleBox wifi and I test the web server. Everything is running.

      Now I connect the terminal via ssh and I try to clone this running MoodleBox to a fat32 formatted usb stick with 32GB. My message https://discuss.moodlebox.net/d/363-issue-with-rpi-clone/1 is showing the terminal text.

      It is very strange that the process took only 2:18 minutes (it should take around 20 minutes). This seems to mean that there was already something on the USB stick (and maybe corrupted data that weren't overwritten).

      I could reproduce such a scenario, and removing corrupted data before cloning fixed the problem.

      I control that the usb stick is completely empty. And I test it once more. This time I do it directly at the MoodleBox with a monitor and a keyboard. I must change the keyboard language to de with raspi-config.

      sudo su 
      rpi-clone sda

      The process runs 2:04 minutes. I got a lot of error messages. I send a screen foto.

      I can reproduce the initial problem (corrupted /boot/config.txt file), but not reliably, it's kind of random.

      I suspect a conflict between the cloning process (that needs unmounting target device) and the automatic mounting of USB devices.

      I've reliably done a clone via the following sequence:

      1. Edit /etc/usbmount/usbmount.conf, changing ENABLED=1 to ENABLED=0, then save
      2. Run sudo umount /dev/sda*
      3. Run sudo mkfs.vfat -I /dev/sda to be sure everything on target device is deleted
      4. Run sudo rpi-clone -f sda to be sure again to format the partitions

      Please test using exactly the same sequence and commands.

      Hi Nicolas,
      I test exactly what you wrote.

      moodlebox@moodlebox:~ $ sudo su
      root@moodlebox:/home/moodlebox# nano /etc/usbmount/usbmount.conf
      root@moodlebox:/home/moodlebox# umount /dev/sda1; sudo umount /dev/sda2
      umount: /dev/sda1: not mounted.
      umount: /dev/sda2: no mount point specified.
      root@moodlebox:/home/moodlebox# sudo mkfs.vfat -I /dev/sda
      mkfs.fat 4.2 (2021-01-31)
      root@moodlebox:/home/moodlebox# sudo rpi-clone -f sda
      
      Booted disk: mmcblk0 15.9GB                Destination disk: sda 31.0GB
      ---------------------------------------------------------------------------
      Part      Size    FS     Label             Part   Size    FS     Label  
      1 /boot   256.0M  fat32  --                1       28.9G  fat32  --     
      2 root     14.6G  ext4   MoodleBox by NMA                               
      ---------------------------------------------------------------------------
      == Initialize: IMAGE partition table - forced by option ==
      1 /boot               (31.0M used)   : MKFS  SYNC to sda1
      2 root                (2.3G used)    : RESIZE  MKFS  SYNC to sda2
      ---------------------------------------------------------------------------
      Run setup script       : no.
      Verbose mode           : no.
      -----------------------:
      ** WARNING **          : All destination disk sda data will be overwritten!
      -----------------------:
      
      Initialize and clone to the destination disk sda?  (yes/no): yea
      Aborting!
      
      root@moodlebox:/home/moodlebox# sudo rpi-clone -f sda
      
      Booted disk: mmcblk0 15.9GB                Destination disk: sda 31.0GB
      ---------------------------------------------------------------------------
      Part      Size    FS     Label             Part   Size    FS     Label  
      1 /boot   256.0M  fat32  --                1       28.9G  fat32  --     
      2 root     14.6G  ext4   MoodleBox by NMA                               
      ---------------------------------------------------------------------------
      == Initialize: IMAGE partition table - forced by option ==
      1 /boot               (31.0M used)   : MKFS  SYNC to sda1
      2 root                (2.3G used)    : RESIZE  MKFS  SYNC to sda2
      ---------------------------------------------------------------------------
      Run setup script       : no.
      Verbose mode           : no.
      -----------------------:
      ** WARNING **          : All destination disk sda data will be overwritten!
      -----------------------:
      
      Initialize and clone to the destination disk sda?  (yes/no): yes
      Optional destination ext type file system label (16 chars max): 
      
      Initializing
        Imaging past partition 1 start.
        => dd if=/dev/mmcblk0 of=/dev/sda bs=1M count=8 ...
        Resizing destination disk last partition ...
          Resize success.
        Changing destination Disk ID ...
        => mkfs -t vfat -F 32  /dev/sda1 ...
        => mkfs -t ext4  /dev/sda2 ...
      
      Syncing file systems (can take a long time)
      Syncing mounted partitions:
        Mounting /dev/sda2 on /mnt/clone
        => rsync // /mnt/clone with-root-excludes ...
        Mounting /dev/sda1 on /mnt/clone/boot
        => rsync /boot/ /mnt/clone/boot  ...
      
      Editing /mnt/clone/boot/cmdline.txt PARTUUID to use 0ba945b4
      Editing /mnt/clone/etc/fstab PARTUUID to use 0ba945b4
      ===============================
      Done with clone to /dev/sda
         Start - 08:52:17    End - 09:48:43    Elapsed Time - 56:26
      
      Cloned partitions are mounted on /mnt/clone for inspection or customizing. 
      
      Hit Enter when ready to unmount the /dev/sda partitions ...
        unmounting /mnt/clone/boot
        unmounting /mnt/clone
      ===============================
      
      root@moodlebox:/home/moodlebox# 

      Now the process needed 56:26 minutes ... yes, more than 20 minutes.

      Now I start the MoodleBox from the cloned usb stick. Yes, it starts bit it's very slow. No, it can't be the usb stick. I used it with the Raspberry Pi Imager before to make a stick for MoodleBox 4.5.1. This stick started normally and very fast. I formatted the stick with FAT32 and then I started the current test with rpi-clone.

      Purging the caches takes a very long time.

      Could there be a problem that the MoodleBox was cloned fron the microSD card and should now run from the usb slot? I can't believe this because the MoodleBox normally starts fine from the usb slot with the same settings.

      moodlebox@moodlebox:~ $ lsblk
      NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
      sda      8:0    1 28.9G  0 disk 
      ├─sda1   8:1    1  256M  0 part /boot
      └─sda2   8:2    1 28.6G  0 part /
      moodlebox@moodlebox:~ $ 

      Or could there be a problem with the database. The database was running while the cloning process run.

      root@moodlebox:/#  /usr/bin/php7.4 /var/www/moodle/admin/cli/check_database_schema.php 
      Database structure is ok.
      root@moodlebox:/# 

      I have the idea to install the plugin report_benchmark but there seems to be no chance with this processing speed. Yes, the installation of the plugin needs a very long time but it's finished ... and also the execution.

      At least the clone is not corrupted, so this procedure is OK, thanks for the test.

      The fact that the clone lasted so long would plead though for a problem with the USB device. Try please to change the USB port (did you use a USB3 one, with the blue plastic inside?). I just re-run the whole thing, same result, same duration (this time 19:01 minutes).

      Yes, I'm using a blue coloured usb3 port for the stick.

      23 days later

      Bonjour Krause,
      Avez-vous terminé vos tests de clonage ?
      Et si oui, la procédure donnée ci-dessus peut-elle être appliquée pas à pas précisément ?
      J'aimerais trouver un logiciel qui éviterait de lancer des instructions dans un terminal. Je ne suis pas à l'aise car je n'y comprends rien !
      Sur Mac on trouve Apple Pi Baker (gratuit) ou SDclone (Très bien mais payant).
      Or je suis à présent 100% sur Linux (Ubuntu).
      Daniel

        methot J'aimerais trouver un logiciel qui éviterait de lancer des instructions dans un terminal.

        L'idée de Ralf est de faire l'opération à partir de la MoodleBox (qui n'a pas d'interface graphique), donc uniquement possible en ligne de commande.

        methot la procédure donnée ci-dessus peut-elle être appliquée pas à pas précisément ?

        Si c'est celle-ci (https://discuss.moodlebox.net/d/363-issue-with-rpi-clone/7): évidemment, sinon je ne la donnerais pas 😃