I am using rsync to make backups of the boot and root file systems on my OpenWrt which is running on a Pi 4 (sd card). I want to script those backed up boot and root file systems back on to a raw image file that I created with dd and set up with a device block at /dev/loop0 then mounted to /mnt/boot and /mnt/root on another (Ubuntu) OS.
My question:
I got this working on Ubuntu and was using Parted there to create the OpenWrt partition layout for boot and root. But Parted is not in the opkg feed.
How should I make the partition layout on my raw image file when running the script on OpenWrt itself? I've tried gdisk but could not get the sd card to boot.
What partition type do I need for the boot partition? I tried EF00, but no joy. I formatted the bootfs as Fat 16 like: # mkfs.fat -F 16 /dev/loop0p1
When I view the OpenWrt Pi firmware in Gparted the first partition is fat 16 and has the partition labels - boot and lba.
I can reproduce that in a script on a system (Ubuntu) that has parted. But I want to run such a script on OpenWrt itself. I think my only option is to use gdisk or sgdisk which I'm not sure how to use.
This is the layout of an image file I made... when I dd it to an sd card it doesn't boot:
root@OpenWrt:/mnt/usb/openwrt/BackupOfImages# gdisk /dev/loop0
GPT fdisk (gdisk) version 1.0.6
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/loop0: 2457600 sectors, 1.2 GiB
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 5479C6D4-8D1D-4449-B797-95B35816C97C
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2457566
Partitions will be aligned on 2048-sector boundaries
Total free space is 16350 sectors (8.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 8192 139263 64.0 MiB EF00 EFI system partition
2 147456 2457566 1.1 GiB 8300 Linux filesystem
Command (? for help):
I formatted the boot Partition 1: # mkfs.fat -F 16 /dev/loop0p1
And the root Partition 2: # mkfs.ext4 /dev/loop0p2
I'll try with fat32 on Partition 1. Am I using the correct gdisk partition codes (EF00 & 8300)?
I create an image file like this: # dd if=/dev/zero of=loopbackfile.img bs=4M count=300
I create a loopback device for it (e.g: /dev/loop0): # losetup -fP loopbackfile.img
On Ubuntu I can partition this "drive"...
parted --script /dev/loop0 \
mklabel msdos \
mkpart primary fat16 4MiB 68MiB \
mkpart primary ext4 72MiB 100% \
set 1 lba on \
set 1 boot on
Then I can format those partitions, mount them etc.. I can then restore backed up OpenWrt boot and root file systems and write that image to an sd card and it boots in a Pi4.
Is it possible to do this all on OpenWrt? So far I think NO because Parted is not available. Fdisk can only make one primary partition and no ext partitions. That's the only reason I was working with gdisk and a GPT partition table.