Cloning an Atmosphere microSD using basic Linux tools

This time something completely different!

Cloning my Atmosphere-NX SD with one emuMMC partition on it to a larger one. Obviously with simple, cli linux tools.

First insert the old SD. In my case it is 200GB large. In the log I find:

Dec 20 16:02:43 casa kernel: sd 6:0:0:0: Attached scsi generic sg4 type 0
Dec 20 16:02:43 casa kernel: sd 6:0:0:0: [sde] 384503808 512-byte logical blocks: (197 GB/183 GiB)
Dec 20 16:02:43 casa kernel: sd 6:0:0:0: [sde] Write Protect is off
Dec 20 16:02:43 casa kernel: sd 6:0:0:0: [sde] No Caching mode page found
Dec 20 16:02:43 casa kernel: sd 6:0:0:0: [sde] Assuming drive cache: write through
Dec 20 16:02:43 casa kernel: sde: sde1 sde2
Dec 20 16:02:43 casa kernel: sd 6:0:0:0: [sde] Attached SCSI removable disk

Remember, sde will be our source device. It has two partitions on it, sde1 and sde2. One is the emuMMC partition, I think.

Let’s have a look to /proc/partitions:

# cat /proc/partitions
major minor #blocks name
...
8 64 192251904 sde
8 65 161678336 sde1
8 66 30572544 sde2

I remember the emuMMC partition is about 30 GB, it has to be sde2. Since it is the last partition, we’ll have to copy it at the end of our new SD card.

Let’s also look at fdisk, which will give us all that numbers we need to deal with:

# fdisk -l /dev/sde
Disk /dev/sde: 183.4 GiB, 196865949696 bytes, 384503808 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9fc2b2b2

Device Boot Start End Sectors Size Id Type
/dev/sde1 2048 323358719 323356672 154.2G b W95 FAT32
/dev/sde2 323358720 384503807 61145088 29.2G e0 unknown

Ok. A larger FAT32 partition, and then the “hidden” sde2 partition.

Let’s insert the new SD card, a 512GB one. In the logs I find:

Dec 20 16:30:42 casa kernel: sd 7:0:0:0: Attached scsi generic sg5 type 0
Dec 20 16:30:42 casa kernel: sd 7:0:0:0: [sdf] 1001390080 512-byte logical blocks: (513 GB/478 GiB)
Dec 20 16:30:42 casa kernel: sd 7:0:0:0: [sdf] Write Protect is off
Dec 20 16:30:42 casa kernel: sd 7:0:0:0: [sdf] No Caching mode page found
Dec 20 16:30:42 casa kernel: sd 7:0:0:0: [sdf] Assuming drive cache: write through
Dec 20 16:30:42 casa kernel: sdf: sdf1
Dec 20 16:30:42 casa kernel: sd 7:0:0:0: [sdf] Attached SCSI removable disk

in partitions:

# cat /proc/partitions
major minor #blocks name
...
8 64 192251904 sde
8 65 161678336 sde1
8 66 30572544 sde2
8 80 500695040 sdf
8 81 500662272 sdf

and fdisk:

# fdisk -l /dev/sdf
Disk /dev/sdf: 477.5 GiB, 512711720960 bytes, 1001390080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdf1 65536 1001390079 1001324544 477.5G 7 HPFS/NTFS/exFAT

So, the old card is 384503808 sectors long, and the new one is 1001390080. These are sectors of 512 bytes. Wee need the difference, since we’re going to shift the emuMMC partition to the end of the new device. This difference is 616886272 sectors.

So let’s repartition the new SD card, sdf. I did not record all the fdisk session, but use d to delete the original partitionn. Then n to create the new partition n. 1. It should start al sector 2048 like on the old one, and end on sector 323358719 + 616886272 = 940244991. Type of the partition will be b, just as it used to be. Next, create the second partition, the one for emuMMC. It will start on sector 940244992 and end on the last sector, 1001390079. Type e0.

The final layout is:

# fdisk -l /dev/sdf
Disk /dev/sdf: 477.5 GiB, 512711720960 bytes, 1001390080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdf1 2048 940244991 940242944 448.4G b W95 FAT32
/dev/sdf2 940244992 1001390079 61145088 29.2G e0 unknown

Now let’s copy the emuMMC partition.

dd if=/dev/sde2 of=/dev/sdf2 bs=64k

Then for the FAT32 data partition, we don’t need to raw copy it. We can just mount them and copy the files. Before mounting the new partition, we need to format it.


# mkfs.vfat /dev/sdf1
# cd /mnt
# mkdir {sde,sdf}1
# mount -r /dev/sde1 /mnt/sde1
# mount /dev/sdf1 /mnt/sdf1

Then I used rsync, just because I don’t know exactly how much time this is going to take. And with some incremental copy tool, I can stop and then restart more or less where I gave up. But this was not necessary: the copy took about three hours, something like that.

# rsync -av sde1/ sdf1

The slash at the end of sde1 is important: it tells to copy the _content_ of sde1 into sdf1.

While the copy is being performed, let’s take a look into a config file in the old SD card:

# cat /mnt/sde1/emummc/amummc.ini
[emummc]
enabled=1
sector=0x13469000
path=emuMMC/RAW1
id=0x0000
nintendo_path=emuMMC/RAW1/Nintendo

See the sector where emuMMC begins. We’ll have to update it, incrementing of the same number we used before. It’s going to be: 0x13469000 + 616886272 = 0x380B8000.

When the copy ends, we’ll update the sector= line in the target emummc.ini with this value. CTCaer, Hekate author, also states that if you forgot to update this setting, you can run “emuMMC migration” in hekate. It will find it and set it.

Finished. This worked for me.

Comments are closed.