RPi: - Move the filesystem to a USB Drive

Guides and tutorials for various stuff. Posted by DietPi users.

RPi: - Move the filesystem to a USB Drive

Postby jedisha » Wed Apr 20, 2016 10:24 pm

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
jedisha
 
Posts: 5
Joined: Thu Apr 14, 2016 9:14 am

Re: Boot Dietpi from USB?

Postby k-plan » Thu Apr 21, 2016 11:00 pm

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.

Code: Select all
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

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


Code: Select all
 --------------------------------
 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
Dedicated Drive Completed


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


10 Tools => Benchmarks Filesystem and RAM benchmarks => Flash Storage, USB Drive => Benchmark IO performance.

160422-0001.gif
Result Benchmarks Filesystem and RAM benchmarks


If the result is like you expect, we can guide you through the necessary changes.

cu
k-plan
Last edited by k-plan on Sun Apr 24, 2016 4:47 pm, edited 1 time in total.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.
User avatar
k-plan
 
Posts: 235
Joined: Sun Feb 28, 2016 4:28 pm

Re: Boot Dietpi from USB?

Postby k-plan » Sun Apr 24, 2016 1:25 pm

Hi,

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 :shock: )
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:
Code: Select all
root@RPi-B-Plus:~# dietpi-config

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


- Install some tools we’ll need later:
Code: Select all
root@RPi-B-Plus:~# apt-get install gdisk rsync


- Insert USB drive and check to see if usb is recognized:
Code: Select all
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 ):
Code: Select all
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:
Code: Select all
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 :
Code: Select all
Command (? for help): d
Using 1


- Make your new partition with n , when prompted to enter information hit Enter to use defaults:
Code: Select all
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 :
Code: Select all
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 :
Code: Select all
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:
Code: Select all
root@RPi-B-Plus:~# mount /dev/sda1 /mnt/usb_1/


- Benchmark Filesystem and RAM IO performance
Code: Select all
root@RPi-B-Plus:~# dietpi-config

10 Tools => Benchmarks Filesystem and RAM benchmarks => Flash Storage, USB Drive, RAM => Benchmark IO performance.
160423-0005.gif
DietPi - Filesystem benchmarks



# Preparing to change root device (system)

- Now we need Partition unique GUID (PARTUUID) of the USB device:
Code: Select all
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
Code: Select all
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:
Code: Select all
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)
Code: Select all
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:
Code: Select all
root@RPi-B-Plus:~# /DietPi/dietpi/dietpi-services stop


- Copy the filesystem over to your new partition:
Code: Select all
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:
Code: Select all
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:
Code: Select all
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.
Code: Select all
#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 :
Code: Select all
#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:
Code: Select all
root@RPi-B-Plus:~# umount /dev/sda1


- Cross the fingers and reboot your RPi:
Code: Select all
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:
Code: Select all
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):
Code: Select all
root@RPi-B-Plus:~# dietpi-config

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


- Now benchmark filesystem and RAM IO performance again:
160424-0002.gif
NEW - DietPi - Filesystem benchmarks

.. 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/view ... 29&t=44177
http://www.kupply.com/move-your-raspber ... -10-steps/
Last edited by k-plan on Sun May 08, 2016 8:57 am, edited 2 times in total.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.
User avatar
k-plan
 
Posts: 235
Joined: Sun Feb 28, 2016 4:28 pm

Re: Boot Dietpi from USB?

Postby Fourdee » Tue Apr 26, 2016 10:42 am

EXcellent write-up k-plan. Thanks for sharing :)
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.
User avatar
Fourdee
Site Admin
 
Posts: 2453
Joined: Tue Feb 06, 2007 12:36 pm

Re: Boot Dietpi from USB?

Postby mike175de » Tue May 03, 2016 2:29 pm

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
mike175de
 
Posts: 61
Joined: Sat Sep 05, 2015 2:39 pm

Re: Boot Dietpi from USB?

Postby k-plan » Tue May 03, 2016 9:54 pm

Hi mike,

mike175de wrote: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?


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.


mike175de wrote: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?


On Odroid XU4, XU3, C1, C1+, C0 and C2 you have to edit the "boot.ini" file:
Code: Select all
/DietPi/boot.ini


Sorry, but for now it's to late for writing a guide. Will do it later.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.
User avatar
k-plan
 
Posts: 235
Joined: Sun Feb 28, 2016 4:28 pm

Re: Boot Dietpi from USB?

Postby k-plan » Thu May 05, 2016 3:34 pm

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: viewtopic.php?f=9&t=396&p=1720#p1720

Let us know, if it will work for you.

cu
k-plan
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.
User avatar
k-plan
 
Posts: 235
Joined: Sun Feb 28, 2016 4:28 pm

Re: Boot Dietpi from USB?

Postby mike175de » Thu May 05, 2016 7:48 pm

Hey k-plan,

yes it did :D

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

mike175de
mike175de
 
Posts: 61
Joined: Sat Sep 05, 2015 2:39 pm

Re: Boot Dietpi from USB?

Postby jedisha » Wed Jun 08, 2016 2:33 pm

Wow, k-plan thank you so much! :D
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
jedisha
 
Posts: 5
Joined: Thu Apr 14, 2016 9:14 am

DietPi Boot RPi from USB

Postby WesleyfuhPP » Sun Dec 25, 2016 6:58 pm

can it be the boot problem if i use some repair disc?or it will make it worst?
WesleyfuhPP
 
Posts: 1
Joined: Sun Dec 18, 2016 5:44 pm
Location: Moldova

Next

Return to Community Tutorials

Who is online

Users browsing this forum: Alexa [Bot] and 1 guest