BPI-M5 Howto install Ubuntu server on external USB-disk

Installing Ubuntu server running from USB-disk

It took me quite a while to find out how to run my M5 on USB-disk. The wiki is erroneous, so here my version:

Prepare

  • download Ubuntu server for the m5 and name it ubuntuserver-m5.img.zip
  • a SD-card of at least 16Gb
  • an USB-disk of for example 100G size
  • connect your M5 with a network cable (local network)
  • a Linux desktop computer
  • connect your M5 to a HDMI display

Phase 1 - Unpack and burn on SD

Attach the SD to your desktop and use lsblk to see where it is. In my case it is /dev/sdc (Be careful, using the wrong device will erase your system!)

unzip ubuntuserver-m5.img.zip
sudo dd if=ubuntuserver-m5.img of=/dev/sdc bs=10M status=progress
  • put this SD in the M5 and power the M5 up
  • See the messages appearing on your HDMI display
  • Log in as user pi password bananapi
  • Use lsblk to see the names of devices
    • The one with size 14.6Gb is the eMMc drive, mmcblk0
  • Use ip a show dev eth0: to see the M5 ip-address
  • On your desktop computer scp ubuntuserver-m5.img pi@<m5-ip-address>:
  • Then on the M5, type sudo dd if=ubuntuserver-m5.img of=/dev/mmcblk0 bs=10M status=progress which copies ubuntu-server to the eMMC
  • Now you need to expand the filesystem on the eMMC: sudo cfdisk /dev/mmcblk0
    • Do not change the /dev/mmcblk0p1, which is the boot partition of 256Mb, FAT
    • Resize /dev/mmcblk0p2 to maximum, 14.2Gb
    • Write and exit. Now you resized the partition
  • To expand the filesystem type: sudo resize2fs /dev/mmcblk0p2
    • (you probably have to type sudo e2fsck -f /dev/mmcblk0p2 before and after)
  • You are ready to boot from eMMC: sudo halt

Phase 2 - Prepare USB disk

  • Remove the SD-card and press the button between the micro-hdmi and hdmi entry
  • Sytem on eMMC is starting. A little after the green light goes off you can login from your desktop: ssh pi@<same_m5-ip-address>
  • type lsblk
  • You should see your mmcblk0 mounted on / and /boot
  • Plug in your external USB-drive en type lsblk, and see sda
  • From your desktop type: scp ubuntuserver-m5.img pi@<m5-ip-address>:
  • And after on your M5: sudo dd if=ubuntuserver-m5.img of=/dev/sda bs=10M status=progress
  • Then you need to alter the partitions on /dev/sda: sudo cfdisk /dev/sda
    • Resize /dev/sda2 (where root (/) will come) to something between 32G and 64G
    • Create a third partition covering the rest of the disk, where your data (/data) will come:
      • sudo resize2fs /dev/sda2
      • sudo mkfs.ext4 /dev/sda3
  • Now comes the tricky part, if this goes wrong, your M5 will go dead.
  • To make M5 boot to /dev/sda, you should remove boot.inion your eMMc
    • mv /boot/boot.ini /boot/boot.ini.orig
  • Cross your fingers and reboot: sudo reboot

Phase 3 - Configure your Ubuntu server on USB-disk

  • A little after the green light goes off you can login from your desktop:
    • ssh pi@<same_m5-ip-address>
    • log in with pi and bananapi
  • type lsblk
  • You should see your sda mounted on / and /boot
  • Modify your system:
    • Change password of user pi: passwd
    • Change timezone (to Berlin timezone): sudo timedatectl set-timezone Europe/Berlin && timedatectl
  • Check locale: locale -a
  • Change hostname: sudo hostname bpim5
  • Update software: sudo apt update && sudo apt -y upgrade
  • To mount the third partition:
    • obtain uuid: sudo blkid | grep sda3
    • sudo mkdir /data
    • sudo vim /etc/fstab and add the line: UUID=<UUID_here> /data ext4 noatime,defaults 0 2
    • sudo mount -a
  • Now /data will be your data directory, check with: lsblk

Turn it back

To boot from eMMC again, do the following:

sudo mount /dev/mmcblk0p1 /mnt
sudo mv /mnt/boot.ini.org /mnt/boot.ini
sudo reboot

Now your M5 boots from eMMC, and you can safely remove your USB-disk

(Corrections and additions welcome)

Thanks @drdaan, great job.

As you asked, my addition. I used your tips and started my M5 from a spare microSD card 8GB. I come across many warnings about breaking emmc card into unbootable state, where you may need a special cable just to revive your pi. I recall other ssd idea - emmc one is more capable then a plain ssd, both in terms of speed and reliability, emmc should survive more RW cycles. One more thought - current Fedora Core uses trick to devide FS into readonly part and the rest into /var, where logs, home and other changing staff located. Finally, here my setup:

$ lsblk /dev/mmcblk0 /dev/mmcblk1
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 14.6G  0 disk /var
mmcblk1     179:128  0  7.4G  0 disk
├─mmcblk1p1 179:129  0  256M  0 part /boot
└─mmcblk1p2 179:130  0  6.9G  0 part /

$ df -Th|grep /dev/mmcblk
/dev/mmcblk1p2 ext4      6.9G  4.8G  1.7G  75% /
/dev/mmcblk1p1 vfat      253M   21M  232M   9% /boot
/dev/mmcblk0   ext4       15G  3.3G   11G  23% /var

$ ll -h /home /var
lrwxrwxrwx  1 root root    9 Aug 30 05:17 /home -> /var/home
/var:
total 80K
drwxr-xr-x 17 root root     4.0K Aug 27 12:08 .
drwxr-xr-x 19 root root     4.0K Aug 30 05:17 ..
drwxr-xr-x  2 root root     4.0K Sep  1 03:11 backups
drwxr-xr-x 20 root root     4.0K Aug 27 12:41 cache
drwxrwsrwt  2 root whoopsie 4.0K Aug 29 14:41 crash
drwxr-xr-x  3 root root     4.0K Aug 27 10:21 home
drwxr-xr-x 75 root root     4.0K Aug 29 11:22 lib
drwxrwsr-x  2 root staff    4.0K Apr 15  2020 local
drwxrwxrwt  3 root root     4.0K Dec 11  2020 lock
drwxrwxr-x 13 root syslog   4.0K Sep  1 03:30 log
drwx------  2 root root      16K Aug 27 11:56 lost+found
drwxrwsr-x  2 root mail     4.0K Jul 31  2020 mail
drwxrwsrwt  2 root whoopsie 4.0K Oct 27  2020 metrics
drwxr-xr-x  2 root root     4.0K Jul 31  2020 opt
lrwxrwxrwx  1 root root        4 Jul 31  2020 run -> /run
drwxr-xr-x 15 root root     4.0K Aug 30 05:05 snap
drwxr-xr-x  7 root root     4.0K Oct 27  2020 spool
drwxrwxrwt  7 root root     4.0K Sep  1 03:31 tmp

The IO speed also slightly better:

$ sudo ioping -L -c 2 /dev/mmcblk1
256 KiB <<< /dev/mmcblk1 (block device 7.42 GiB): request=1 time=7.62 ms (warmup)
256 KiB <<< /dev/mmcblk1 (block device 7.42 GiB): request=2 time=7.84 ms

--- /dev/mmcblk1 (block device 7.42 GiB) ioping statistics ---
1 requests completed in 7.84 ms, 256 KiB read, 127 iops, 31.9 MiB/s
generated 2 requests in 1.01 s, 512 KiB, 1 iops, 507.7 KiB/s
min/avg/max/mdev = 7.84 ms / 7.84 ms / 7.84 ms / 0 ns

$ sudo ioping -L -c 2 /dev/mmcblk0
256 KiB <<< /dev/mmcblk0 (block device 14.6 GiB): request=1 time=2.93 ms (warmup)
256 KiB <<< /dev/mmcblk0 (block device 14.6 GiB): request=2 time=2.93 ms

--- /dev/mmcblk0 (block device 14.6 GiB) ioping statistics ---
1 requests completed in 2.93 ms, 256 KiB read, 340 iops, 85.2 MiB/s
generated 2 requests in 1.00 s, 512 KiB, 1 iops, 510.2 KiB/s
min/avg/max/mdev = 2.93 ms / 2.93 ms / 2.93 ms / 0 ns

So, summary:

  1. leave the ssd card as root and bootable partition
  2. use emmc as separate partition, create on it ext4 (or btrfs) and mount it under /var
  3. you may need some efforts to cp current content of /var into new /dev/mmcblk0. I used a single user mode to minimize open files and add mount point /var into /etc/fstab for next boot