[Tutorial - Outdated] RPi: - Move the filesystem to a USB Drive

Hey guys,

I was just wondering if it is possible to boot dietpi from a USB drive? I’ve been reading that this massively increases speed/performance of the Pi and would love to be able to do so with the already amazing Dietpi. Currently have a B+ as well as a Pi3 running Dietpi and would love to give the Pi3 even more performance power for Owncloud

I have a 128GB USB3 drive.

I hope you can help,

thanks,
P

Hi jedisha,

Yes, you can run your DietPi system and all installed software from USB drive.
But to boot your RPi, you must have insert SD-Card any time. Without RPi will not boot. ( /boot/… must be on /dev/mmcblk0p1)

I would suggest, before you will change your root device, to Benchmarks your new Filesystem. Only read/write speed have a significant difference, it will have effect.

To do this, insert only one USB drive and reboot.

root@oDroid-C1-Plus-Test:~# df -h
Dateisystem    Größe Benutzt Verf. Verw% Eingehängt auf
/dev/mmcblk0p2  7,1G    579M  6,5G    9% /
udev             10M       0   10M    0% /dev
tmpfs           190M    5,4M  185M    3% /run
tmpfs           475M       0  475M    0% /dev/shm
tmpfs           5,0M       0  5,0M    0% /run/lock
tmpfs           475M       0  475M    0% /sys/fs/cgroup
tmpfs            10M    1,1M  9,0M   11% /DietPi
tmpfs            20M     12K   20M    1% /var/log
tmpfs           475M       0  475M    0% /tmp
/dev/mmcblk0p1  129M     25M  104M   20% /boot
/dev/sda1        57G    2,4G   52G    5% /mnt/usb_1

/dev/sda1 => is the new and only USB drive, mounted on: /mnt/usb_1

root@oDroid-C1-Plus-Test:~# /DietPi/dietpi/dietpi-external_drive_setup



 --------------------------------
 D I E T - P I
 External Drive Setup
 --------------------------------
 An Existing ext4 Drive has Been Found

Dateisystem    Größe Benutzt Verf. Verw% Eingehängt auf
/dev/sda1        57G    2,4G   52G    5% /mnt/usb_1

 Would you like to format this drive? [y/N]

WARNING: if you answer “y” all data on USB drive will be lost.
160422-0002.gif

root@oDroid-C1-Plus-Test:~# dietpi-config

10 Tools => Benchmarks Filesystem and RAM benchmarks => Flash Storage, USB Drive => Benchmark IO performance.
160422-0001.gif
If the result is like you expect, we can guide you through the necessary changes.

cu
k-plan

Hi,

edit by k-plan:

This Tutorial is outdated!
You can now use DietPi-Drive Manager.
It’s more simple and do all the steps for you with more options.




System:
DietPi V116 | Raspberry Pi B+ (e.g. in my case a fresh installation)
Micro SD-Card: Verbatim 8GB Class 10 Micro SDHC
USB Device: Patriot 32GB USB 3.0 drive
Boot up time: ca. 40 sec

Note:
Why to use this "extended version"? (only 25 easy steps :open_mouth: )
Because it’s possible to use more than only one drive attached to your RPi.

# Preparation

  • Make sure, " max_usb_current=1 " is proper set:
root@RPi-B-Plus:~# dietpi-config

4 Advanced Options => 3 Max USB Current : Enabled
160424-0001.gif

  • Install some tools we’ll need later:
root@RPi-B-Plus:~# apt-get install gdisk rsync
  • Insert USB drive and check to see if usb is recognized:
root@RPi-B-Plus:~# lsusb
Bus 001 Device 005: ID 13fe:5000 Kingston Technology Company Inc.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  • Locate the USB device name ( /dev/sdx ):
rroot@RPi-B-Plus:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1 29.5G  0 disk
└─sda1        8:1    1 29.5G  0 part
mmcblk0     179:0    0  7.4G  0 disk
├─mmcblk0p1 179:1    0   60M  0 part /boot
└─mmcblk0p2 179:2    0  7.4G  0 part /

In this example, USB device is on sda. From this point on we use /dev/sda for the USB drive.

  • Writing partition table to USB drive:
root@RPi-B-Plus:~# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************

Warning! Main partition table overlaps the first partition by 32 blocks!
You will need to delete this partition or resize it in another utility.

Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.

Command (? for help): i
Using 1
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Microsoft basic data)
Partition unique GUID: FFEE1EB9-FE0D-4422-A3BE-5DEC4CB9F1DA
First sector: 2 (at 1024 bytes)
Last sector: 61800447 (at 29.5 GiB)
Partition size: 61800446 sectors (29.5 GiB)
Attribute flags: 0000000000000000
Partition name: 'Microsoft basic data'
  • Delete old partition(s) with d :
Command (? for help): d
Using 1
  • Make your new partition with n , when prompted to enter information hit Enter to use defaults:
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-61800414, default = 34) or {+-}size{KMGTP}:
Last sector (34-61800414, default = 61800414) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
  • Write the changes with w :
Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.
  • Continue with formatting :
root@RPi-B-Plus:~# mke2fs -t ext4 -L rootfs /dev/sda1
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 7725047 4k blocks and 1933312 inodes
Filesystem UUID: 2c35b4da-c18a-4277-9db4-2ba592475e26
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  • Mounting USB device:
root@RPi-B-Plus:~# mount /dev/sda1 /mnt/usb_1/
  • Benchmark Filesystem and RAM IO performance
root@RPi-B-Plus:~# dietpi-config

10 Tools => Benchmarks Filesystem and RAM benchmarks => Flash Storage, USB Drive, RAM => Benchmark IO performance.
160423-0005.gif
# Preparing to change root device (system)

  • Now we need Partition unique GUID (PARTUUID) of the USB device:
root@RPi-B-Plus:~# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
  • Get the Partition unique GUID information with i and finish with q
Command (? for help): i
Using 1
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 7D25B382-0D0F-4EDD-B044-E41ADE98A451
First sector: 34 (at 17.0 KiB)
Last sector: 61800414 (at 29.5 GiB)
Partition size: 61800381 sectors (29.5 GiB)
Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'

Command (? for help): q

e.g. Partition unique GUID: 7D25B382-0D0F-4EDD-B044-E41ADE98A451

  • Backup your cmdline.txt file and edit it to include your new partition:
root@RPi-B-Plus:~# cp /boot/cmdline.txt /boot/cmdline.txt.sdcard
root@RPi-B-Plus:~# nano /boot/cmdline.txt
  • Edit the file and change your “root=” to point to new filesystem partition with the find out Partition unique GUID (PARTUUID)
dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=7D25B382-0D0F-4EDD-B044-E41ADE98A451 rootfstype=ext4 elevator=noop fsck.repair=yes rootwait rootdelay=10

Watch for " rootdelay=10 " and save the file!

  • Stop the services:
root@RPi-B-Plus:~# /DietPi/dietpi/dietpi-services stop
  • Copy the filesystem over to your new partition:
root@RPi-B-Plus:~# rsync -axv / /mnt/usb_1/
...
sent 756,662,697 bytes  received 348,462 bytes  2,737,834.21 bytes/sec
total size is 755,276,856  speedup is 1.00

Be patient - this will take some time!

  • Get your partition UUID for fstab:
root@RPi-B-Plus:~# tune2fs -l /dev/sda1
tune2fs 1.42.12 (29-Aug-2014)
Filesystem volume name:   rootfs
Last mounted on:          /mnt/usb_1
Filesystem UUID:          2c35b4da-c18a-4277-9db4-2ba592475e26
...

e.g. UUID=2c35b4da-c18a-4277-9db4-2ba592475e26

  • Backup and edit the fstab file on your new filesystem:
root@RPi-B-Plus:~# cp /mnt/usb_1/etc/fstab /mnt/usb_1/etc/fstab.sdcard
root@RPi-B-Plus:~# nano /mnt/usb_1/etc/fstab
  • Comment out the old filesystem at /dev/mmcblk0p2 and add the new line pointing to your new filesystem and add your UUID as indicated.
#Internal Drives---------------------------------------------------
proc            /proc           proc    defaults                                                                        0 0
/dev/mmcblk0p1  /boot           vfat    defaults,noatime,discard                                                        0 2
## root on SD-card
### /dev/mmcblk0p2  /               ext4    defaults,noatime,discard                                                    0 1
## root on USB device
/dev/disk/by-uuid/2c35b4da-c18a-4277-9db4-2ba592475e26     /          ext4    defaults,noatime,nodiratime               0 1
tmpfs                   /tmp                    tmpfs   defaults,noatime,nodev,nosuid,mode=1777                         0 0
tmpfs                   /var/log                tmpfs   defaults,size=20m,noatime,nodev,nosuid,mode=1777                        0 0
tmpfs                   /DietPi                 tmpfs   defaults,size=10m,noatime,nodev,nosuid,mode=1777                0 0
  • Comment out External Drives at /dev/sda1 ___ /mnt/usb_1 :
#External Drives---------------------------------------------------
# - Try and use only ext4 for USB drives
# - Faster performance than NTFS, espically on RPi v1
## /dev/sda1       /mnt/usb_1      ext4    defaults,noatime,nofail                    0       0
#/dev/sda1       /mnt/usb_1      ntfs-3g    defaults,permissions,noatime,nofail       0       0

and save the file!

  • Unmount your USB device:
root@RPi-B-Plus:~# umount /dev/sda1
  • Cross the fingers and reboot your RPi:
root@RPi-B-Plus:~# reboot

Note that you will not see much activity on the ACT LED anymore. This LED only shows R/W activity on the SD card.
If your USB device have a activity LED, you can check here R/W activity.
Boot up time is now: ca. 30 sec

  • After the RPi has booted, check the filesystem:
root@RPi-B-Plus:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  813M   27G   3% /
devtmpfs        238M     0  238M   0% /dev
tmpfs           242M     0  242M   0% /dev/shm
tmpfs           242M  4.4M  237M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           242M     0  242M   0% /sys/fs/cgroup
tmpfs            10M  1.1M  9.0M  11% /DietPi
tmpfs            20M   12K   20M   1% /var/log
tmpfs           242M     0  242M   0% /tmp
/dev/mmcblk0p1   60M   22M   39M  36% /boot
  • Create a new swap file (e.g. 101 MB):
root@RPi-B-Plus:~# dietpi-config

dietpi-config => 4 Advanced Options => 1 Swapfile Size
160424-0005.gif

  • Now benchmark filesystem and RAM IO performance again:
    160424-0002.gif
    … and reboot.


    Note:
  • To boot your RPi, you must have insert SD-Card at any time. Without RPi will not boot.
  • If somethings goes wrong or your RPi doesn’t boot, power off your RPi, put RPI SD-Card into your PC and restore " cmdline.txt.sdcard " to " cmdline.txt " on the DOS (FAT) partition named “boot
    Put edited SD-Card back into your RPi and power on. It will boot and run the system (DietPi) now from SD-Card like before your modifications.

Some useful Links, which have aided to make this howto:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=44177
http://www.kupply.com/move-your-raspberry-pi-system-to-usb-in-10-steps/

1 Like

EXcellent write-up k-plan. Thanks for sharing :slight_smile:

Hey k-plan,

thx for your guide.

1 question in front:
On a fresh installation should I answer the question if I want to use an USB-Drive with yes or no?

I tried to use it on my Adroid-C2, but there is no /boot/cmdline.txt there only a boot.ini and this file looks different than your cmdline.txt.

So what do I have to put in there, if it is the right file.

Any hint?

Thx in adavance,

mike175de

Hi mike,

If you want to swap over the hole system to your USB-Drive, I will prefer to answer “NO” at this point.

If you want to only Data and Applications on the USB-Drive, but keep system and boot files on SD-Card, then answer “yes”.
The rest will do DietPi for you.


On Odroid XU4, XU3, C1, C1+, C0 and C2 you have to edit the “boot.ini” file:

/DietPi/boot.ini

Sorry, but for now it’s to late for writing a guide. Will do it later.

Hi mike,

Sorry, but for now it’s to late for writing a guide. Will do it later.

Done and I have put the guide in here: [Tutorial - Outdated] Odroid: - Move the filesystem to a USB Drive - #3 by k-plan

Let us know, if it will work for you.

cu
k-plan

Hey k-plan,

yes it did :smiley:

Thx a lot for your tut again! (as thanked already in the other post)!

mike175de

Wow, k-plan thank you so much! :smiley:
I’ve not been able to check back in on this for a wahile… just read through your comprehensive tut and will try and find time to implement soon!

thx, jedisha

can it be the boot problem if i use some repair disc?or it will make it worst?

Hi.

which “boot problem” do you mean?

repair disc” by what? By fsck ?

In your system need/want/make as filesystem check and repair, something is going wrong.
Storage medium is going to be faulty, or something witch power supply system is wrong.

The Pi3 can boot from USB drive without SD card - see this thread:

https://dietpi.com/forum/t/running-dietpi-on-a-usb-hdd-w-o-sd/546/1

This is for interest only as it does not create a stable system.

John

I’ve converted all my Pi’s to boot from hard drive or USB stick. Works flawlessly! Followed the official instructions here: ( https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md

I’ve had no issues so far. I am wondering if DietPi can be done using the same instructions. Has anyone tried? What is the take on official support for this from DietPi?

Thanks!

Yes.

https://github.com/Fourdee/DietPi/issues/509#issuecomment-246702824

Running DietPi on a USB HDD w/o SD

All Raspberry Pi’s ?!
I will say no.
What’s about Raspberry Pi-Zero, Raspberry Pi Zero W, Raspberry Pi B+ , Raspberry Pi B, Raspberry Pi A, Raspberry Pi 2, …?


I have: https://github.com/Fourdee/DietPi/issues/509#issuecomment-246734927

And, unfortunately seeing no advantage over moving filesystem to USB devices. Only drawback and rising boot up time. Sorry.
But you can do as you like.


https://github.com/Fourdee/DietPi/issues/509#issuecomment-258833304

[quote=“k-plan”]

Yes.

https://github.com/Fourdee/DietPi/issues/509#issuecomment-246702824

Running DietPi on a USB HDD w/o SD

[quote=“jsfrederick”]
I’ve converted all my Pi’s to boot from hard drive or USB stick.
[/quote]

All Raspberry Pi’s ?!
I will say no.
What’s about Raspberry Pi-Zero, Raspberry Pi Zero W, Raspberry Pi B+ , Raspberry Pi B, Raspberry Pi A, Raspberry Pi 2, …?
[/quote]

All the Pi’s I have are RPi 3’s so, yes, all mine are booting from hard disk.

[quote=“jsfrederick”]
I’ve had no issues so far.
[/quote]

I have: > https://github.com/Fourdee/DietPi/issues/509#issuecomment-246734927

And, unfortunately seeing no advantage over moving filesystem to USB devices. Only drawback and rising boot up time. Sorry.
But you can do as you like.

I do. It reduces the issues with booting and writing to SD cards and produces a more stable storage platform. Yes, it does increase the boot time, but that is something I will live with. It also allows for LARGE (>2TB) storage platforms. I am using them for Nextcloud and Netatalk.

[quote=“jsfrederick”]
What is the take on official support for this from DietPi?
[/quote]

https://github.com/Fourdee/DietPi/issues/509#issuecomment-258833304

I did see and read the other message about this process. I think that most folks had attempted USB boot before it was “Officially” supported by RPI Foundation. They just supported this in March (I think). So maybe it would work well now with DietPi. I may give it a try when I get a few minutes.[

Thanks for the info/i]

Curious,
I previously had tried to run diet pi off usb and it was not supported.
My pi is set up to boot from the USB without an issue. I currently run Raspbian stretch off a usb stick.
Does diet pi now support booting from the usb so i could download the image write the image to usb with etcher and get rolling?

I agree that for my two Pi 1B this tutorial is not outdated. It seems that they have to be booted from SD-card, in spite of the system runs on a usb-disk. K-plan’s tutorial worked fine though I had to modify it a bit:

Instead of the following line in /etc/fstab on usb-disk:

/dev/disk/by-uuid/2c35b4da-c18a-4277-9db4-2ba592475e26     /          ext4    defaults,noatime,nodiratime               0 1

I used:

/dev/sda1 / ext4 noatime,lazytime,rw 0 1

for the first boot to usb-disk. (After having checked the /dev/sda1 was the right device using lsblk.)

With this you are moving RootFS only. BootFS is still located on SD card. Anyway, theoretically this should be possible using dietpi-drive_manager if I’m not mistaken.

Maybe this blog post describes a different approach for running a system from USB (based on a system running on SD Card): Moving a running DietPi system to a USB stick/disk or an onboard eMMC.

Well, a Pi 1B did not support full boot from USB. Therefore, moving RootFS is the maximum you could do. Raspberry Pi Documentation - Raspberry Pi hardware