Skip to content

Commit

Permalink
improve/document mount_offset_tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nmcclain committed Oct 4, 2019
1 parent 4031465 commit 259d503
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ With this image, you can run a custom script on first boot and:
1. Source image is obtained from the official Raspberry Pi [download page](https://www.raspberrypi.org/downloads/raspbian/).
1. Be sure to verify the SHA hash!
1. Mount the second partition of the source image - the `mount` command will require an `--offset` flag, [as described here](https://raspberrypi.stackexchange.com/questions/13137/how-can-i-mount-a-raspberry-pi-linux-distro-image).
* Note: the [mount_offset_tool](mount_offset_tool/) helps calculate the `--offset` on linux.
1. Install [firstboot.service](firstboot.service) in `/mnt/lib/systemd/system/firstboot.service`
1. Enable firstboot.service for systemd: `cd /mnt/etc/systemd/system/multi-user.target.wants && ln -s /lib/systemd/system/firstboot.service .`
1. Unmount the second partition of the source image.
Expand Down
17 changes: 8 additions & 9 deletions mount_offset_tool/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"
Expand All @@ -10,10 +11,10 @@ import (
)

func main() {
if err := doit(os.Args[1]); err != nil {
if err := getDevices(os.Args[1]); err != nil {
log.Fatal(err)
}
log.Printf("OK!")
// log.Printf("OK!")
}

type DevInfo struct {
Expand All @@ -22,7 +23,7 @@ type DevInfo struct {
Sectors int
}

func doit(img string) error {
func getDevices(img string) error {
raw, err := exec.Command("/sbin/fdisk", "-l", "-o", "Device,Start,Sectors", img).Output()
if err != nil {
return err
Expand Down Expand Up @@ -54,14 +55,12 @@ func doit(img string) error {
}

}
log.Printf("unitSz = %+v\n", unitSz)
log.Printf("devices = %+v\n", devices)
// log.Printf("unitSz = %+v\n", unitSz)
// log.Printf("devices = %+v\n", devices)
// calculate and print mount cmd for img2
for _, d := range devices {
if strings.HasSuffix(d.Device, ".img2") {
offset := unitSz * d.Start
log.Printf("img2 mount cmd:\nmount -v -o offset=%d,loop %s /mnt\n", offset, img)
}
offset := unitSz * d.Start
fmt.Printf("%s mount command:\n mount -v -o offset=%d,loop %s /mnt\n", d.Device, offset, img)
}

return nil
Expand Down

0 comments on commit 259d503

Please sign in to comment.