Partition based emuMMC and L4T Ubuntu on the same SD card

Discussion in 'Switch - Tutorials' started by lordelan, Jul 21, 2019.

  1. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    Wow this is really strange.
    Before I did all this I've had a big 400 GB single FAT32 partitioned SD card with 32 k cluster size which was working just fine in Horizon (stock, Atmo, SX OS).
    Then I just went through the steps from my guide and it really kinda worked "first try" (which still surprises me).
    As a side note: It seems that the SD card was MBR and that using Etcher with the L4T image turns the destination device into GPT. That's why I had to "destroy" the partition table with CloneZilla first so there's no mismatch that CloneZilla would complain about.
    Of course I destroyed it on the temporary flash drive I flashed the img to and not on my SD card I wanted to use in my Switch again as I didn't care about the flash drive anyway. Gladly that was enough for CloneZilla do to the partition cloning.
     
    ~~Tito~~ likes this.
  2. ~~Tito~~

    ~~Tito~~ GBAtemp Regular

    Member
    4
    Apr 7, 2009
    United States
    I’m going to try and confirm that resizing the partition isn’t the problem shortly. If thats the case then what I’m going to do is setup everything I need then image my SD without Ext4. This way I can simply restore the good image without having to set it all up again multiple times.
     
    lordelan likes this.
  3. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    Sounds like a plan. I really hope it turns out working for you at some point. Would be a shame if not.
    Good thing you're so obstinately. :P
     
    ~~Tito~~ likes this.
  4. ~~Tito~~

    ~~Tito~~ GBAtemp Regular

    Member
    4
    Apr 7, 2009
    United States
    Its the resize... I can't believe it. When I resize Fat in Gparted it breaks readability on the switch... Going to try and fix this in windows.
     
    lordelan likes this.
  5. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    Really?! What?! That's exactly what I did. Wow ...
    But at least you found the problem. Now you "only" need to try out countless resize methods until one works lol.
     
    ~~Tito~~ likes this.
  6. ~~Tito~~

    ~~Tito~~ GBAtemp Regular

    Member
    4
    Apr 7, 2009
    United States
    According to windows. GParted formats the FAT32 partition into a "RAW" format. I've already created an Ex4 partition. Going to verify that the switch reads the corrected Fat32 then try and restore 1.img. Based off of this mess. It seems like we can only use windows tools to format, resize, or edit the MBR boot table. After fixing the partition in windows. The SD is detectable again...

    New steps to take:
    • SXOS to create EmuNand
    • Resize FAT32 Partition using windows. Leave at least 10gb free AFTER the Fat32 partition.
    • Use Windows or Ubuntu to create ext4 on newly created space
    • Restore 1.img to ext4 using disks in ubuntu
    • Boot into every OS to confirm.

    So Linux has booted successfully as well...


    What a headache... Now that I know this works... I’m going to clean this up and experiment. I still want my Linux partition to reside before Fat32. Going to try that later on this week.

    For now I can confirm that this is working!!
     
    Last edited by ~~Tito~~, Jul 23, 2019
    lordelan and Cyan like this.
  7. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    22
    Oct 27, 2002
    France
    Engine room, learning
    Thank you for your finding :)
    that's strange that resizing FAT32 changes the MBR to raw. maybe the Linux's FAT32 code used by GParted is uncommon and used only by linux?


    let us know if it works fine with Linux partition before FAT partition.
    In case it doesn't, don't worry too much because there's a way to fix that. hacky way, but it works ! Edit the MBR in hexeditor to swap partition position. make the "first" seen in the table the FAT one, even if physically located after Linux partition. the table only has a "start + length" info, it doesn't number them. just swap the partition 1 and 2 in the table ;)
    managers and OS should be able to access the partition without problem, it'll just be reset back to real physical order if you ever edit the partitions in a partition manager.
     
    ~~Tito~~ and lordelan like this.
  8. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    As I wrote I definitely used GParted for resizing and it worked on my end (god knows why). This is so strange.
    But really cool that you got it working, @~~Tito~~ :)
    Now that's some smart workaround. :)
     
  9. ~~Tito~~

    ~~Tito~~ GBAtemp Regular

    Member
    4
    Apr 7, 2009
    United States
    I don't know why the format was off when using gparted, but I am glad that its working. lol

    @Cyan If I were to do that. Would I have to manually calculate the values used for the sectors? At this point I'm pretty lazy and I'm enjoying the switch lol.
     
    lordelan likes this.
  10. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    I know that feeling. :D :D :D
     
  11. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    22
    Oct 27, 2002
    France
    Engine room, learning
    Thanks for posting your partition hex values :)
    MBR is fine, and partitions start look good too.
    noo, not at all.
    create your two partitions (the unallocated MMC partitions is not a real partition, just nothing defined for it) using any tools you want.
    once done and you have your partitions set, the MBR already contains the starting sector and size of both the Ext4 and FAT32 partitions :


    4 MBR's primary partitions table :
    1 - 00 01 01 00 83 FE FF FF 02 20 A4 03 FE 07 40 01 (Type Linux (83), starts around 30GB from the start, at 0x03A42002, right after MMC)
    2 - 00 FE FF FF 0C FE FF FF 00 28 E4 04 00 D8 B8 36 (Type FAT32 (0C), starts around 38GB, after Linux)
    3- empty
    4- empty
    the MMC is not defined, it's not raw but unallocated, starts from sector 1 to 0x03A42001

    edit the MBR to swap the informations entirely, swap line 1 and 2 to have the FAT32 into the first slot of the table. keep all the same values
    1 - 00 FE FF FF 0C FE FF FF 00 28 E4 04 00 D8 B8 36 (Type FAT32 (0C), starts around 38GB, after Linux)
    2 - 00 01 01 00 83 FE FF FF 02 20 A4 03 FE 07 40 01 (Type Linux (83), starts around 30GB from the start, after MMC)
    3- empty
    4- empty

    see, the FAT32 still starts after linux, but it's listed first in the table. there's nothing to calculate, just swapt the partition in the table.
    it's like the table lists partition in reversed order, that's all, but their position and size are identical, you just swap the entire definition, no need to calculate anything.
    like I said, partition manager could have issues with this, thinking anything located "before the LBA Start of the first defined partition in the table" is unallocated (meaning the linux partition could be also part of the unallocation). it all depends how tools are dealing with random partition definition order.


    But, that's only if the switch works fine with FAT32 being listed first.
    if you manage to make the switch work with FAT32 being listed second, then don't bother doing it. it was just an idea based on what you reported on previous page.
     
    Last edited by Cyan, Jul 23, 2019
    lordelan and ~~Tito~~ like this.
  12. tabzer

    tabzer GBAtemp Fan

    Member
    3
    Feb 15, 2019
    Japan
    I can boot between LAKKA and L4T. I didn't run into any issues setting it up, and frankly I am confused what people are talking about. (OP and Cyan)

    I did it on Windows:

    Using OSFMount you can mount the L4T image. You can mount the boot partition and the ext4 partition.

    Using Diskgenius, I was able to create a 16GB partition followed by a 32GB partition at the end of my SD card. I was able to use Diskgenius to CLONE the ext4 partition from the image, to the 16 GB partition on my SD card. I was able to use the 32GB partition for emummc. Didn't need SXboot garbage. Did Tariq's method with DD -> https://gbatemp.net/threads/emummc-setup-win-linux-quadboot.541152/

    For the FAT32 partition of the L4T image, copied all those files to a temporary directory, as wanted to apply the patches first. Got the patch from the L4T and deleted the files as requested by the L4T thread and added patch files. Put the completed product into the main partition. Add Lakka to primary partition. Setup Hekate.

    I CAN boot between L4T, CFW, AND LAKKA with jig. I turned of autorcm for OFW and online play
     
    Last edited by tabzer, Jul 26, 2019
    ~~Tito~~ likes this.
  13. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    Interesting post. Thx for letting us know that it can be done way easier.

    But why did you turn off AutoRCM? I'm booting into stock (non CFW) sysNAND and playing online just fine with AutoRCM enabled.
     
  14. tabzer

    tabzer GBAtemp Fan

    Member
    3
    Feb 15, 2019
    Japan
    Frankly, I am not certain of how much information is being logged in the boot sequence, so I try go safe.

    Are you using fusee-secondary? Do you mind sharing a copy of the OFW configuration you use with hekate (5.0.1)? I might end up going back to autorcm, but I am not in a hurry.
     
  15. lordelan
    OP

    lordelan GBAtemp Psycho!

    Member
    11
    Jan 4, 2015
    Germany
    I'm really using absolute default config from Kosmos. Only added SX OS and L4T Ubuntu to it. :)
     
    tabzer likes this.
  16. tabzer

    tabzer GBAtemp Fan

    Member
    3
    Feb 15, 2019
    Japan
    Ah, I'll check that. They had an example of it on hekate's github, but I am reluctant because I know what I am doing is working.
     
  17. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    22
    Oct 27, 2002
    France
    Engine room, learning
    your setup is probably easier and working fine because you end with 3 partitions, with FAT32 first ?
    what he tried to do in this thread is make SXOS compatible setup (with mmc at the beginning), and using l4t image would overwrite each other.

    It's a guide for users with existing, or want to use, SXOS MMC.
    what he wanted to achieved is that order:
    MMC, FAT32, linux.

    What lordelan did is flash the l4t image to another device, mount it in clonezilla to dump individual partitions to new image to write them back to SD in the order he wanted. it's only overcomplicated because he didn't know how to extract single partition from the full device image.
    But fat32 and linux partitions can be read individually from the l4t image using dd (or diskgenius? or any other tools), no need to write them to a temporary device first. once you have the linux partition, you can write it to SD where you want and should be as easy as Tariq's guide.



    Most guides end up expanding the Linux partition to fill the SD card size. but isn't FAT32 better to be bigger than linux? when you buy/install games to SD, it goes to FAT32/exFAT partition, not ext4.
    Checking the MBR, I think FAT32 is 500MB? unless I miscalculated.
    I guess partitions can be moved after flashing the l4t image, but if linux was first it would be easier to expand the fat32, instead of expanding the ext4, or moving it to make space for fat32, without overlapping the mmc at the end of the card.

    the ext4 only contains linux's OS files, no homebrew and data right? these will go on FAT32?
    so what I suggested is put FAT32 at the end:
    32G MMC, 8G linux, remaining FAT32

    which is what tito tried.
    The issue Tito had is that he got no partition found on switch when doing it that way. I made a supposition that his MBR could be messed up, but it seems fine. only issue is that FAT32 is not listed first on the table. Maybe the switch doesn't mount the "first FAT32" but the "first listed" partition, because SD card for Switch are not supposed to have more than one, and Nintendo might have hardcoded the first partition. that's why I suggested to edit the MBR table to place FAT32 as first partition even if physically located farer.
    create 3 partitions, write bin to MMC and Linux, edit MBR to put FAT32 first, linux second. (MMC unallocated). This is yet to be tested.

    Edit:
    And we could even now do a 5-boot method, with Android partition:
    https://gbatemp.net/threads/experie...ly-released-version-of-lineageos-15-1.544519/
    just follow the same method to write android to any partition.
     
    Last edited by Cyan, Jul 28, 2019
    ~~Tito~~ likes this.
  18. tabzer

    tabzer GBAtemp Fan

    Member
    3
    Feb 15, 2019
    Japan
    You could do it in any order using the method I described, because hekate is reading from the FAT32 before it forwards boot.scr command to tell it to boot from the ext4 partition. The boot.scr might need decrypted/edited/reencrypted, to have the partition reference modified to point at the 3rd partition instead of the 2nd. Maybe it'll work without that step. I didn't test it.

    This is why I made my partitions first, and then cloned using diskgenius. Diskgenius will adapt to the size of the partition it is cloning to, so for the example of the ext4 partition, you don't have to tell linux to extend after the fact. Since I already have all my stuff on FAT32, I found it easier just to copy the files from the image, instead of "etching" or cloning the image.

    I'm using 400GB SD, and the bulk is dedicated to fat32 for typical Switch CFW stuff. I use about 16GB for l4t (maybe it's too much) and then 32GB for emummc. With SXOS, it might be possible that it looks at the second partition for FAT32 when its emunand is used.

    So tito might have to keep the EMUNAND/FAT32/L4T order if persisting with SXOS:

    And change the partition reference in boot.scr by decrypt-> edit -> reencrypt

    "dd if=boot.scr of=boot.txt bs=72 skip=1"
    Decrypts

    mkimage -A arm -T script -O linux -d boot.txt boot.scr
    Encrypts

    Don't exactly know the partition address layout. But it shouldn't be too hard to figure out once you have the boot.txt file opened.

    Except the complication is that the lineageos has like 5-7 partitions of wtfuckery.

    That doesn't sound right. ext4 needs to be ext4. There is a case with drivegenius, when cloning a ext4 image to a fat32 partition, it will convert the fat32 partition to ext4.
     
    Last edited by tabzer, Jul 28, 2019
    Cyan likes this.
  19. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    22
    Oct 27, 2002
    France
    Engine room, learning
    I meant : which file need to be on the ext4 ? only essential linux files, kernel, etc.

    All the homebrew and games data are not required to be on ext4 and can be located on FAT32?

    that's probably what we missed !
     
    Last edited by Cyan, Jul 28, 2019
  20. tabzer

    tabzer GBAtemp Fan

    Member
    3
    Feb 15, 2019
    Japan
    Yeah, homebrew and games data is useless on ext4. Switch CFW and OFW deosn't support it. What L4T can do, is access the FAT32 partition as storage just fine.
     
    ~~Tito~~ and Cyan like this.
Loading...