ZXNext vhd editing

Thedad
Posts: 25
Joined: Tue Sep 07, 2021 9:28 am
Has thanked: 8 times
Been thanked: 6 times

ZXNext vhd editing

Unread post by Thedad »

Hi,

A low-level issue which I wonder if anybody has an answer to.

In the ZXNext Core, I load the OS/Data from a .vhd file. Pretty common AFAIK.

I want to upgrade the core with the latest version ZXNext OS, so does anybody have any decent/easy way of mounting a .vhd in Linux as there are a bunch of instructions lying about on how to do it, but would welcome any recommendations here.

TIA.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZXNext vhd editing

Unread post by JamesH »

Long story short,

Code: Select all

man -s 8 losetup

:) Also, I believe all modern DEs are able to handle partitioned disk images out of the box, but I assume you want to do it on the MiSTer itself to avoid copying large image files (works with any Linux system with any supported partition/filesystem).

Updated 2023-08-13 to reflect important remarks from pgimeno.

In other words:

  1. Set up loopback devices reflecting image partitions:

    Code: Select all

    /media/fat/games/ZXNext# losetup --show -Pf boot.vhd
  2. If necessary (or if you get distracted :)), double check that everything was detected properly (you can this any time):

    Code: Select all

    /media/fat/games/ZXNext# losetup -a
    /dev/loop0: 0 /media/fat/linux/bluetooth
    /dev/loop1: 0 boot.vhd
    /dev/loop8: 0 
    
  3. Just mount it and do whatever you like (NOTE: you mount partition device loop1p1, not the entire loop device)

    Code: Select all

    /media/fat/games/ZXNext# mount /dev/loop1p1 /mnt/
    /media/fat/games/ZXNext# ls /mnt/
    demos  dot     games	 nextzxos  sys	      TBBLUE.TBU  tools
    docs   extras  machines  rpi	   TBBLUE.FW  tmp
    
  4. PROFIT. But NEVER start the core when the image partition is mounted!!!
  5. When done, unmount the partition:

    Code: Select all

    /media/fat/games/ZXNext# umount /mnt/
  6. And do not forget to release allocated loop device:

    Code: Select all

    /media/fat/games/ZXNext# losetup -a
    /dev/loop0: 0 /media/fat/linux/bluetooth
    /dev/loop1: 0 boot.vhd
    /dev/loop8: 0 
    /media/fat/games/ZXNext# losetup -d /dev/loop1
    

There are technically correct, but completely obsolete guides on those internetz, suggesting to calculate partition(s) offset(s) and explicitly specify it when calling losetup. That's no longer necessary for many years.

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: ZXNext vhd editing

Unread post by pgimeno »

JamesH wrote: Wed Aug 09, 2023 3:47 pm

Double check that everything was detected properly (and you need to know the assigned device anyway):

That's what the --show flag is for. Passing --show to losetup in the first step would void the need for the second step.

Oh, and very important, don't forget to unmount the partition before booting the core, or you risk serious corruption!

Thedad
Posts: 25
Joined: Tue Sep 07, 2021 9:28 am
Has thanked: 8 times
Been thanked: 6 times

Re: ZXNext vhd editing

Unread post by Thedad »

JamesH wrote: Wed Aug 09, 2023 3:47 pm

Long story short,

Code: Select all

man -s 8 losetup

:) Also, I believe all modern DEs are able to handle partitioned disk images out of the box, but I assume you want to do it on the MiSTer itself to avoid copying large image files (works with any Linux system with any supported partition/filesystem).

Updated 2023-08-13 to reflect important remarks from pgimeno.

In other words:

  1. Set up loopback devices reflecting image partitions:

    Code: Select all

    /media/fat/games/ZXNext# losetup --show -Pf boot.vhd
  2. If necessary (or if you get distracted :)), double check that everything was detected properly (you can this any time):

    Code: Select all

    /media/fat/games/ZXNext# losetup -a
    /dev/loop0: 0 /media/fat/linux/bluetooth
    /dev/loop1: 0 boot.vhd
    /dev/loop8: 0 
    
  3. Just mount it and do whatever you like (NOTE: you mount partition device loop1p1, not the entire loop device)

    Code: Select all

    /media/fat/games/ZXNext# mount /dev/loop1p1 /mnt/
    /media/fat/games/ZXNext# ls /mnt/
    demos  dot     games	 nextzxos  sys	      TBBLUE.TBU  tools
    docs   extras  machines  rpi	   TBBLUE.FW  tmp
    
  4. PROFIT. But NEVER start the core when the image partition is mounted!!!
  5. When done, unmount the partition:

    Code: Select all

    /media/fat/games/ZXNext# umount /mnt/
  6. And do not forget to release allocated loop device:

    Code: Select all

    /media/fat/games/ZXNext# losetup -a
    /dev/loop0: 0 /media/fat/linux/bluetooth
    /dev/loop1: 0 boot.vhd
    /dev/loop8: 0 
    /media/fat/games/ZXNext# losetup -d /dev/loop1
    

There are technically correct, but completely obsolete guides on those internetz, suggesting to calculate partition(s) offset(s) and explicitly specify it when calling losetup. That's no longer necessary for many years.

Completely forgot to respond. Thanks for that. Very useful and something I thought was possible, I'm just too busy atm.

Post Reply