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 )
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
- 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
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.
# 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!
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!
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
- Now benchmark filesystem and RAM IO performance again:
… 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/