The Raspberry Pi family typically boots from an SD card plugged to the system. To avoid SD card lifetime issues, these systems can run from an connected USB resp. USB disk stick or – on some Pi derivatives – from an onboard eMMC flash memory.
Lifetime issues may occur from the fact that the number of write cycles to SD cards are much lower than to USB sticks/disks or eMMC. Additionally, systems often boot quicker from USB resp. eMMC compared to a plugged SD card.
At best, you can start with the USB device resp. a removable eMMC card) by flashing DietPi directly to this.
In case of an already running system, there may be the need of moving this running system to a different location: This blog post describes how to move your system to a USB stick/disk or to the onboard eMMC.
The description below is focused on a DietPi system, but – with minor changes – generally also works for other distributions.
Table of contents
- Step 1: Check filesystem size
- Step 2: Shrink filesystem size
- Step 3: Move operating system to USB stick resp. eMMC
- Step 4: Finalize
- Special hardware handling
DietPi supports various types of SBCs (see there), some of theses hardware variants contain onboard eMMC memory or a connector for an eMMC memory module.
These devices e.g. are:
- ODROID N2+, C2, C4, XU4(Q)
- NanoPi M4, M4B, M4v2, NEO4, K2, M1, M1+, R1
- NanoPC T4
- Pine A64, H64, ROCK64, ROCKPro64
- ROCK Pi 4, Radxa Zero
- Sparky SBC
- ASUS Tinker Board S
All these boards can boot from this eMMC, some boards, like the ODROID N2+, contain a switch to select the boot media (onboard, SD card).
In addition, most of the systems can boot from a USB connected device, like e.g.
- Raspberry Pi 4, 400
- Raspberry Pi 3B, 3B+ (maybe needed to be activated via
dietpi-config -> Advanced Options)
- Many derivates like ODROID C4, XU4, N2+, ASUS Tinker Board, many of the NanoPi boards
Therefore, it is a good practice to move the SBCs system to such an eMMC or USB device.
Basically, only the
dd command is needed to copy the SD cards contents to the USB device resp. eMMC and reboot. That’s all.
But life is not this easy in all cases…
The following preconditions must be checked to go on:
- A running DietPi system
- The size of the eMMC memory resp. USB memory stick/disk
The following procedures are given as the user ‘root’. If the shell runs without root privileges, the ‘sudo’ prefix shall be set in front of the given commands.
2.1 Running DietPi system
We assume a DietPi system running from an SD card which shall be moved completely (all SD card partitions) to the USB/eMMC.
To obtain a good performance, the USB device should be plugged into a USB3 connector. There are devices, like the Raspberry Pi 4, which have both USB2 and USB3 connectors onboard.
2.2 Size of the eMMC memory resp. USB memory device
The USB/eMMC memory must be larger than the actual needed storage on the SD card. Otherwise the SD card partitions need to be shrinked (e.g. using the gparted program, see below).
3. Step 1: Check filesystem size
Whether the USB/eMMC memory is larger than the actual needed storage on the SD card can be checked via
lsblk which may give (example 1):
root@Pi4:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 115.5G 0 disk mmcblk0 179:0 0 14.9G 0 disk ├─mmcblk0p1 179:1 0 256M 0 part /boot └─mmcblk0p2 179:2 0 14.6G 0 part /
The example 1 shows a 128 GB USB stick (
/dev/sda) and a 16 GB SD card (
A different situation may occur, if the size of the SD card used is larger than the USB device resp. eMMC capacity (example 2):
root@Pi4:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 3.9G 0 disk mmcblk0 179:0 0 14.9G 0 disk ├─mmcblk0p1 179:1 0 256M 0 part /boot └─mmcblk0p2 179:2 0 14.6G 0 part /
As can be seen in example 2, the size of the USB stick (
/dev/sda) is 4 GB and is smaller than the SD card (
/dev/mmcblk0) capacity of 16 GB. In this case, the SD card needs to be shrunk (e.g. using the
gparted program, see below).
In another example 3, the size of the eMMC is smaller than the SD card (example was done on a NanoPi M1+ with eMMC soldered onboard):
root@M1plus:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT mmcblk0 179:0 0 29.8G 0 disk └─mmcblk0p1 179:1 0 29.8G 0 part / mmcblk2 179:8 0 7.3G 0 disk └─mmcblk2p1 179:9 0 7.3G 0 part mmcblk2boot0 179:16 0 4M 1 disk mmcblk2boot1 179:24 0 4M 1 disk
As can be seen, there are two block devices:
mmcblk2. The device
mmcblk2 is the onboard eMMC flash (size 8 GiB), this can be deducted from the additional boot partitions
Additionally the output shows that the active root partition (SD card) is mounted to the mount point
In example 1 and 2, the final goal is to copy the SD card
mmcblk0 to the USB stick
In example 3, the final goal is to copy SD card
mmcblk0 to the onboard eMMC flash
4. Step 2: Shrink filesystem size
This step 2 can be skipped in the case that the USB device / eMMC capacity is larger than the SD card size.
The example given below is based on the above example 3 which was a NanoPi M1+ with onboard eMMC.
See above example 3: As can be seen, the SD card on
/dev/mmcblk0 has a size of 29.8 GiB. This partition needs to be resized to a value smaller than the 7.3 GiB of the onboard eMMC.
As a requirement, the data on the SD card needs to be less than the 7.3 GiB. If this cannot be achieved, we won’t be able to clone the drive and hence won’t be able to boot from eMMC.
The resizing of the SD cards partition can be done with various tools. One of them is the graphical tool GParted. It can be run on a (different) Linux system with an X11 desktop or may be run on a PC as an USB booted live system (see GParted Live on USB from gparted.org).
Before the partition is shrunk, the SD cards partitions are shown like this (select the appropriate device, here
The resizing is done via the Partition menu entry:
In the next dialog, drag the partition size quite near the minimum possible size:
Press the button Resize/Move, afterwards do an Edit->Apply All Operations. After the resizing is finished, the SD cards partitions looks like this:
You see that the partition is shrunk to 3.82 GiB. As next, eject the SD card, put it back to your system and boot. There the SD card
/dev/mmcblk0 may look like this:
root@M1plus:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT mmcblk0 179:0 0 29.8G 0 disk └─mmcblk0p1 179:1 0 3.8G 0 part / mmcblk2 179:8 0 7.3G 0 disk └─mmcblk2p1 179:9 0 4.7G 0 part mmcblk2boot0 179:16 0 4M 1 disk mmcblk2boot1 179:24 0 4M 1 disk
As can be seen the size of the partition
mmcblk0p1 was shrunk from 29.8 GiB down to 3.8 GiB which is less than the 7.3 GiB of the onboard eMMC.
5. Step 3: Move operating system to USB stick resp. eMMC
The basic command to do this is
To ensure that during the OS copy process no other processes change the filesystem, it is changed to read-only mode via:
dietpi-services stop swapoff -a mount -o remount,ro /
In case of an error message like “mount point is busy” at the mount command (last line), you need to manually set the root filesystem to read only. This can be achieved via
sed -i '\|[[:blank:]]/[[:blank:]]|s|,rw|,ro|' /etc/fstab reboot
which changes the root filesystem in the
/etc/fstab to read only and reboots the system.
Read only vs. read/write file system:
If you set the file system to read only, an access via SSH is not possible after the reboot, i.e. in this case you need access to the local console (via keyboard and monitor).
Alternatively, you might keep the system set to read/write and do the copying in this state. Due to the fact that this might lead to an inconsistent file state (e.g. if a different user or process writes files in parallel to the
ddcommand below), this should only be done if you are sure that no other users/processes use the file system during the copying process.
Then the SD card is copied to the USB device resp. eMMC.
For example 1 and 2 this is done via:
dd if=/dev/mmcblk0 of=/dev/sda bs=1M status=progress
For example 3 this is done via:
dd if=/dev/mmcblk0 of=/dev/mmcblk2 bs=1M status=progress
bs=1M speeds up by copying larger chunks. The option
status=progress gives an output at the command line to be able to track the operation. The copy process will take some time.
After the execution of the copy process, the next steps are:
- Shutdown the system
- Remove the SD card (Important!)
- Reboot the system
As a final step, you need to change the root filesystem back to read/write via:
mount -o remount,rw / sed -i '\|[[:blank:]]/[[:blank:]]|s|,ro|,rw|' /etc/fstab
Another options to move the SD card contents to your target device may be to use
- balenaEtcher or Rufus (graphical user interface option)
gnome-disks(graphical user interface option)
These are options which typically are executed on a different system.
6. Step 4: Finalize
If the system is booted from the USB device / eMMC, the system looks like this (example onboard eMMC from example 3):
root@M1plus:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT mmcblk2 179:0 0 7.3G 0 disk └─mmcblk2p1 179:1 0 4.7G 0 part / mmcblk2boot0 179:8 0 4M 1 disk mmcblk2boot1 179:16 0 4M 1 disk
The size of the partition
mmcblk2p1 (4.7 GiB) in this status is smaller than the whole onboard eMMC size (7.3 GiB). To be able to use the rest of the onboard flash, start the
dietpi-drive_manager to resize the partition to maximum size (Remark: The start of the
dietpi-drive_manager may take a longer time for this procedure).
Select the disk containing the root (
/) partition and press
In the following dialog select
Resize to go on:
After this procedure the disk partition sizes are:
root@M1plus:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT mmcblk2 179:0 0 7.3G 0 disk └─mmcblk2p1 179:1 0 7.3G 0 part / mmcblk2boot0 179:8 0 4M 1 disk mmcblk2boot1 179:16 0 4M 1 disk
Now, the partition size is now enlarged to 7.3 GiB and the complete operating system move is finished.
7. Special hardware handling
7.1 Special partitioning (e.g. NanoPi R6 series)
The NanoPi R6S has this complex partitioning, so it is important to not mess with this but shrink the last 8th partition only.
As an alternative, a base installation can be done directly to the onboard eMMC (also valid for USB devices). As a prerequisite, a running system (e.g. running from an SC card) need to be present.
The steps will be to download the DietPi image on the running system, extract it and flash it to the onboard eMMC.
7.1.1 Check system filename
First of all the needed image file name has to be determined. The downloadable DietPi images are located on the page https://dietpi.com/downloads/images/. The according filename needs to be determined from the present files (e.g. DietPi_NanoPi6-ARMv8-Bookworm.7z).
7.1.2 Download and flash file
This is achieved with these commands:
cd /tmp curl -O https://dietpi.com/downloads/images/DietPi_NanoPi6-ARMv8-Bookworm.img.xz 7zr x DietPi_NanoPi6-ARMv8-Bookworm.img.xz dd if=DietPi_NanoPi6-ARMv8-Bookworm.img of=/dev/mmcblk2 bs=1M status=progress
7.1.3 Remove SD card and reboot
The final step will be to remove the SC card and reboot to initialize the fresh DietPi installation from the eMMC.
If your Raspberry Pi does not boot from the USB stick you can also check this instruction: How to Boot Raspberry Pi 4 / 400 From a USB SSD or Flash Drive.
- LOGIN TechBlog, Holger: DietPi: System im laufenden Betrieb auf externe USB-Disk / Stick / SSD übertragen
- PiMyLifeUp, Gus: Raspberry Pi Boot from USB