Tutorial  Updated

How to boot Linux on your Switch

THIS GUIDE IS DEPRECATED
THIS IS BETTER https://github.com/natinusala/painless-linux


I've successfully booted ArchLinux using ShofEL2. Here is a quick guide on how to do it - I'll assume you're computer literate and know how to use a terminal / Linux commands / git.
Everything is taken from the README of the ShofEL2 repo so if you want to go even faster, go read that instead.

Thanks to NightHammer1000 and Y2K-x for the help !

There is a simplified and faster version of this tutorial available here, with precompiled binaries so you don't have to build everything : https://github.com/SoulCipher/shofel2_linux

The result

Without a SD card ("waiting for root device mmcblk0p2") : https://photos.app.goo.gl/7y6ut5ObuHMUIMZg2
Stock Arch Linux : https://photos.app.goo.gl/yALqe3zMZRe2dSQf1
Arch Linux with LXDE : https://photos.app.goo.gl/xaEgRqeSi8jvAwpz5
RetroArch running : https://photos.app.goo.gl/vBLPo5wiBto1qiUH3
Arch Linux with GNOME : https://gbatemp.net/attachments/img_0005-jpg.121608/
Arch Linux with KDE : https://gbatemp.net/attachments/img_20180427_121605-jpg.121666/

What works / what doesn't
  • Desktop environment : Gnome, LXDE, KDE
  • Wi-Fi : works
    • You will need to reboot your Switch and run the exploit again to make the Wi-Fi work (it never works on the first boot)
    • Then enter the Network Manager Application and add your network from there
    • If it doesn't work, you will need to edit the configuration on the host computer (see the additional notes at the end of this post)
    • With LXDE : Can cause a kernel panic if used at the same time as Bluetooth
  • Bluetooth : works but Joy-Cons can't be paired
  • Touch screen : works, although LXDE is not very touch-friendly
  • Audio : doesn't work yet
  • GPU acceleration : works (via mesa), with OpenGL (and maybe Vulkan too ?)
  • Joy-Cons : not recognized
  • Volume buttons : working with Gnome but not doing anything since there is no audio device
  • Power button : doesn't do anything, no sleep mode, no graceful shutdown
  • USB : doesn't work
  • Dock : not tested yet, but I bet it doesn't do anything besides charging the battery
  • Power management / battery level : working with Gnome
What you'll need
  • A computer running Linux with a blue USB SuperSpeed port, or a Mac
    • A Linux VM can work in theory, but it depends on how the USB passthrough is implemented (apparently VMWare works, VirtualBox doesn't)
  • A USB A-to-C cable (with data support, obviously)
    • be careful as cheap cables were reported to work randomly / not work at all
  • Some time (you know, Linux is kinda large)

Prep work

First, you'll need to install the required toolchains. Open this link and download the tar.gz binaries for
  • aarch64-linux-gnu
  • arm-linux-gnueabi
Be careful to choose the right architecture for your PC (for me it was x86_64 so "gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz").

Once you have them, extract them somewhere nice and add the "bin" (not "lib" as I previously stated) folder of both toolchains to your PATH ("$ export PATH=$PATH:/path/to/toolchain1/lib:/path/to/toolchain2/lib"). The building process won't work otherwise.

Then, install those dependencies (how to install them and their name might depend on your distribution) :
  • build-essential (sorry I didn't add it it was obvious to me)
  • libssl-dev
  • swig
  • bison
  • pkg-config
  • flex
  • zlib1g-dev
  • python3
  • python-dev
  • python3-pip
  • pyusb 1.0.0 : "$ sudo pip3 install pyusb==1.0.0"
  • libusb-1.0-0-dev

Compiling

Clone each required repository :

Code:
$ git clone https://github.com/fail0verflow/shofel2.git
$ git clone --recursive --depth=1 https://github.com/fail0verflow/switch-coreboot.git coreboot
$ git clone https://github.com/fail0verflow/switch-u-boot.git u-boot
$ git clone --depth=1 https://github.com/fail0verflow/switch-linux.git linux
$ git clone https://github.com/boundarydevices/imx_usb_loader.git

You can grab a coffee or two because Linux has more than 5 million files to download.

Then, build everything :

Code:
$ cd shofel2/exploit
$ make

Code:
$ cd u-boot
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make nintendo-switch_defconfig
$ make

Code:
$ cd coreboot
$ make nintendo_switch_defconfig
$ make iasl
$ make

If you have a tegra_mtc.bin file error, you'll have to extract it from a Pixel C stock image :
"$ ./build/util/cbfstool/cbfstool bootloader-dragon-google_smaug.7900.97.0.img extract -n fallback/tegra_mtc -f tegra_mtc.bin"

Or you can download it directly from here : https://0w0.st/tegra_mtc.bin (thanks to @CptPotato for uploading this)

You'll have to put it in the "coreboot/src/soc/nvidia/tegra210" directory.

Code:
$ cd imx_usb_loader
$ git reset --hard 0a322b01cacf03e3be727e3e4c3d46d69f2e343e
$ make

The big one :

Code:
$ cd linux
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make nintendo-switch_defconfig
$ make

If you encounter issues about a missing rule "/lib/firmware/nvidia/tegra210/vic04_ucode.bin" for the target "firmware" you'll have to :
  • install the firmware-misc-nonfree package
  • if you can't install it, or if it still doesn't work, download the package manually from debian sid and extract the file "/lib/firmware/nvidia/tegra210/vic04_ucode.bin" (from the root of your PC, not on the cloned repo) from the DEB (and chmod it if needed)
If you encounter issues about a missing rule "/lib/firmware/brcm/brcmfmac4356-pcie.txt", download this file and put it in "/lib/firmware/brcm/" (from the root of your PC, not on the cloned repo)

Building the rootfs

This is the annoying part. Download the archive / image corresponding to the distribution you want to use :
If it's a tarball you just downloaded

While it's downloading, you'll have to take a microSD card and, using the software of your choice (I used GParted) :
  • remove every existing partition to only have unallocated space on it (do I need to tell you that you're going to loose everything on the card ?)
  • create a tiny FAT32 partition (I chose 200mb but it doesn't matter) - that'll be mmcbkl0p1, you can label it "garbage"
  • create an ext4 partition on the remaining part of the card - that'll be mmcblk0p2, you can label it "rootfs"
  • it's important that the FAT32 partition comes first and the ext4 one comes after - on the Switch, Linux will look for mmcblk0p2, the second partition, if you have scrolling boot logs and then back to RCM it means you did it wrong
Once the rootfs tarball is downloaded, you can simple extract it to the mounting point of the ext4 partition you just created :

Code:
$ tar xvf ArchLinuxARM-aarch64-latest.tar.gz -C /mounting/point/of/ext4/partition && sync
$ cp ArchLinuxARM-aarch64-latest.tar.gz /mounting/point/of/ext4/partition/root && sync

("/mounting/point/of/ext4/partition/root" is the "root" directory on the partition)

Don't forget to properly eject the SD Card !

If "tar xvf" doesn't work for you you can install "bsdtar" and use "bsdtar -xpf" instead

Then you can put the SD card in the console.

If it's a img / bin file you just downloaded

You can simply write it on your SD card using :
  • If you're on Windows, Ether or Win32DiskImager
  • If you're on Linux / Mac OS : "sudo dd if=yourimage.img of=/dev/sdX && sync" where /dev/sdX is the device of your SD card (unmounted)
You will probably want to open a partition manager to resize the ext4 partition once it's flashed, so that it fits your SD card.

Then you can put the SD card in the console.

Booting linux

Run the exploit :

Code:
$ cd shofel2/exploit
$ sudo ./shofel2.py cbfs.bin ../../coreboot/build/coreboot.rom

Your terminal should now be waiting for the Switch to enter RCM mode.

To do so : (I don't have pictures but that's the same method as fusée gelée, just look at some video tutorials)
  • plug the Switch on your PC using the USB A-to-C cable - use a blue SuperSpeed port if you have one
  • shut it down
  • remove the right joy-con
  • using a method of your choice, short the 10th pin of the right joy-con (the last pin on the right, away from the screen, closer to the back) with the ground : that can be pin 1, 2 or 7, that can also be a screw on the joy-con rack or the console's fan - I personnaly stick a RPi jumper wire in the fan and touch the 10th pin on the other side, works everytime (like this)
  • keep the pins shorted and power the Switch while pressing the volume UP button
If it worked, the console will show a black screen and you'll see the exploit running on your terminal. If you see the Nintendo logo, it has failed. You can power off the console and try again.

Then, run those last commands :

Code:
$ cd shofel2/usb_loader
$ ../../u-boot/tools/mkimage -A arm64 -T script -C none -n "boot.scr" -d switch.scr switch.scr.img
$ sudo ../../imx_usb_loader/imx_usb -c .

Linux should then boot on your console - first the boot logs with the penguins, and then an ArchLinux login prompt. Voilà !
Again, if you have the boot logs and then a black screen, it means you did the SD card part wrong.

Additional notes

Hardware graphics acceleration


The most recents image already contain this fix.

To add mesa drivers install this package using pacman :
https://0w0.st/mesa-full-tegra-r101876.bf5e0276b6-1-aarch64.pkg.tar.xz

You will need a working internet connection to do so.

Then, use this script to choose your power profile : https://0w0.st/power.sh

Full speed RAM


According to the blog post ("Linux on Switch boot chain" section), you need to extract a file from a Pixel C factory image in order to have the RAM working at full speed. I didn't do it so I won't cover it here.

Fixing calibration issues of the touch screen (thanks to @Wizardy)

To fix calibration issues of the touch screen, edit the file /usr/share/X11/xorg.conf.d/10-evdev.confg (of the rootfs)

And change the InputClass section to :

Code:
Section "InputClass"
        Identifier "evdev touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
        Option "InvertX" "no"
        Option "InvertY" "yes"
        Option "SwapAxes" "yes"
        Option "Calibration" "0 1279 0 719"
EndSection

Wi-Fi

To setup Wi-Fi, mount the rootfs partition on your host PC and edit the configuration for your network in the file "/etc/NetworkManager/system-connections" (if it doesn't exist, take Gigaspot).

To have a working Wi-Fi you must reboot your Switch and run the exploit again each time you power it off

Moving the rootfs to another partition

If you want to move the rootfs to another partition on your SD card, edit the "shofel2/usb_loader/switch.scr" file and replace "/dev/mmcblk0p2" by the partition you want to use.
 
Last edited by natinusala,

natinusala

Win32 error 31 is not an error
OP
Member
Joined
Dec 1, 2012
Messages
1,032
Trophies
0
Age
44
XP
2,914
Country
France
If it says waiting for root device /dev/mmcblk0p2 it means that your SD card is not recognized - putting an empty card will result in a kernel panic
 
Last edited by natinusala,

kombos

Well-Known Member
Member
Joined
Apr 24, 2018
Messages
140
Trophies
0
Location
Universe
XP
167
Country
Ukraine
So the KDE rootfs is done, this will most likely be my last rootfs.
My initial goal from the beginning was to make a simple rootfs that would enable people that couldn't do chroot+qemu-aarch64 to use linux as that can be quite a pain.
Anyways in this release i have installed KDE, added @kombos NAND script (in /opt) and added a very simple bash script that switches the gpu clock (switchpower).
To use it simple run sudo switchpower and you will be asked to pick a preset, low (307.2MHz), normal (768MHz) or high (998MHz). (high is not recommended for longer periods of time.)
The default clock is set by a systemctl service called defaultpower.
https://0w0.st/KDE_rootfs3.tar.bz2

Thanks mate !
 

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
So,

Ive installed ubuntu 16.04 onto my mac (not a VM this time)

make sure i have the following installed:

python3
python-dev
python3-pip
pyusb 1.0.0
libusb-1.0-0-dev

clone https://github.com/SoulCipher/shofel2_linux.git


erase the sd card
make a 200mb Fat32 partition using gparted
a second portion is made with the remaining space ~64gb, ext4 FS

For the instances where i’ve trend the gnome build, i’ve done the following:

browse to the directory where i downloaded the file and run the two commands:

Code:
tar xvf gome__rootfs.tar.bz2 -C /home/oumar/rootfs/
cp gome__rootfs.tar.bz2 /home/oumar/rootfs/root

they are successful and i’ve browsed the folder to see the folders/files are present and onto the correct partition.

pop in the sd card into the switch and do get into RCM mode

run the exploit and wait… penguins appear and linux starts loading until it just forever hangs at

Code:
waiting for root device /dev/mmcblk0p2
random: crng init done


For the arch lxde build, i’ve download the file and extracted it to get a bin file.

browse to the directory with the bin file and run:

Code:
sudo dd if=arch_lxde.bin of=/dev/mmcblk0 (i’ve also tried /dev/mmcblk0p2)


for both instances they caused terminal to freeze so used the Ubuntu Disk Image Writer to extract the bin on the sd card. browse the sd card cam can see the relevant folders/files present.

pop in the sd card into the switch and do get into RCM mode

run the exploit and wait… penguins appear and linux starts loading until it just forever hangs at

Code:
waiting for root device /dev/mmcblk0p2
random: crng init done


Cant see anything i'm doing wrong (really hope its not something obvious), appreciate any help :D thanks
I had same issue with 128GB SDXC card, thing stucks at random: crng
Swap to a 32GB and all works again.
SoulCipher had it work on a 64GB SDXC - if you check his NAND backup thread.

So I highly suspect that a bigger SD card >64GB wont work yet.

Cheers
 
  • Like
Reactions: kombos

KIT786

Well-Known Member
Newcomer
Joined
Nov 2, 2008
Messages
55
Trophies
0
Website
Visit site
XP
1,401
Country
If it says waiting for root device /dev/mmcblk0p2 it means that your SD card is not recognized - putting an empty card will result in a kernel panic

I had same issue with 128GB SDXC card, thing stucks at random: crng
Swap to a 32GB and all works again.
SoulCipher had it work on a 64GB SDXC - if you check his NAND backup thread.

So I highly suspect that a bigger SD card >64GB wont work yet.

Cheers

Cheers guys, might have to see if i can try another card even if mine is a 64gb card. also thinking it might have something to do with that link @Type_O_Dev posted, guess its worth trying the patch linked in the twitter post
 
  • Like
Reactions: Mittytoto

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
Cheers guys, might have to see if i can try another card even if mine is a 64gb card. also thinking it might have something to do with that link @Type_O_Dev posted, guess its worth trying the patch linked in the twitter post
Makes sense as high capa cards also higher speed. I think I still have the kernel source, will try the patch and report later.
 
Last edited by Mittytoto,

Gigaa

Well-Known Member
Member
Joined
Apr 25, 2018
Messages
108
Trophies
0
Age
26
Location
Norway
Website
giga.is
XP
130
Country
Norway
I had same issue with 128GB SDXC card, thing stucks at random: crng
Swap to a 32GB and all works again.
SoulCipher had it work on a 64GB SDXC - if you check his NAND backup thread.

So I highly suspect that a bigger SD card >64GB wont work yet.

Cheers
Personally i use a 128 GB card my self so card higher than 64 GB should work just fine. Not sure what is causing the problem for the other guys really.
 

KIT786

Well-Known Member
Newcomer
Joined
Nov 2, 2008
Messages
55
Trophies
0
Website
Visit site
XP
1,401
Country
so tried a no brand 8gb card and was able to get further in the boot process and then gets stuck at a black screen.. not a total win but making progress lol. the card i've been trying is a Samsung EVO, I do have a a sandisk 128gb, that i use for my switch games, might back that up and give it a try tomorrow.

appreciate all the help guys :)
 
  • Like
Reactions: Gigaa

Gigaa

Well-Known Member
Member
Joined
Apr 25, 2018
Messages
108
Trophies
0
Age
26
Location
Norway
Website
giga.is
XP
130
Country
Norway
  • Like
Reactions: Type_O_Dev

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
Personally i use a 128 GB card my self so card higher than 64 GB should work just fine. Not sure what is causing the problem for the other guys really.
It's all about card class I guess. Mine is Samsung EVO+ 128GB which is rated as UHS-1.

Btw, I have applied the mentioned fix and now it's working with my same Samsung card
Code:
https://github.com/perillamint/switch-linux/commit/ec2c0a0bbc388622e35aaa5f5038f6d899fcbbee
Yeah as the comment, this is a dirty hack as your high speed card now is forced to run slower.

I am not a kernel guy so obviously don't know how to really fix it yet...
So if you could @Gigaa, please have a look as many of us would want to use a high speed card really.
For now I just use my patched kernel just to have the big card to backup my NAND...

@kombos if you could, please apply this fix to your next kernel build? Could be more stable than apply and build directly from f0f's original kernel.

Cheers.
 
Last edited by Mittytoto,

Tigeris tiger

Well-Known Member
Newcomer
Joined
Jan 31, 2016
Messages
54
Trophies
0
Age
37
XP
1,069
Country
United States
Kind of an odd question. But how long does it normally take to boot into linux on the switch? It says "Done. You should see kernel booting on switch soon" It does look like it pushed all the data from the terminal window. Just wondering.
 

Gigaa

Well-Known Member
Member
Joined
Apr 25, 2018
Messages
108
Trophies
0
Age
26
Location
Norway
Website
giga.is
XP
130
Country
Norway
It's all about card class I guess. Mine is Samsung EVO+ 128GB which is rated as UHS-1.

Btw, I have apply the mentioned fixed and now it's working with my Samsung card
Code:
https://github.com/perillamint/switch-linux/commit/ec2c0a0bbc388622e35aaa5f5038f6d899fcbbee
Yeah as the comment, this is a dirty hack as your high speed card now is forced to run slower.

I am not a kernel guy so obviously don't know how to really fix it yet...
So if you could @Gigaa, please have a look as many of us would want to use a high speed card really.
For now I just use my patched kernel just to have the big card to backup my NAND...

@kombos if you could, please apply this fix to your next kernel build? Could be more stable than apply and build directly from f0f's original kernel.

Cheers.
Sadly i'm not really a kernel guy myself so your guess is as good as mine. My card is UHS-1 too btw.
Kind of an odd question. But how long does it normally take to boot into linux on the switch? It says "Done. You should see kernel booting on switch soon" It does look like it pushed all the data from the terminal window. Just wondering.
Shouldn't take more than 20 sec at worst. Is it not booting?
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • SylverReZ @ SylverReZ:
    @Materia_tofu, We do learn a lot from plenty of talented individuals.
  • Materia_tofu @ Materia_tofu:
    this is true! i learned how to make soundfont remixes from a friend back in 2021
    +1
  • BakerMan @ BakerMan:
    Update on my brother: He's home now, tired and hungry, obviously, but other than that, seems to be doing fine.
    +2
  • Veho @ Veho:
    That's a relief to hear. Do you know what happened?
  • SylverReZ @ SylverReZ:
    @BakerMan, Any idea what happened? I hope that your brother's doing good.
  • BakerMan @ BakerMan:
    Well, from what I've heard from my parents, he had a seizure last night, perhaps an epileptic episode, fucking died, had a near death experience, my dad called the paramedics, they showed up, took him to the hospital, and he woke up covered in tubes, and started complaining.
  • BakerMan @ BakerMan:
    He couldn't eat until after his MRI, when he had a bomb pop.
  • BakerMan @ BakerMan:
    What matters now is that he's doing alright.
  • Veho @ Veho:
    But you still don't know what it was?
  • Veho @ Veho:
    Has he had seizures before?
  • The Real Jdbye @ The Real Jdbye:
    apparently stress can cause seizures, my brother had one during a test once
  • The Real Jdbye @ The Real Jdbye:
    never had one before that, and never had one since
  • Redleviboy123 @ Redleviboy123:
    Question about game texture chanching Do i need an own game id?
  • The Real Jdbye @ The Real Jdbye:
    @Veho for those that want to
    experience being sonic the hedgehog
  • Veho @ Veho:
    Ah, you mean
    furries.
    +1
  • The Real Jdbye @ The Real Jdbye:
    well, sonic fans are a whole separate thing from furries
  • The Real Jdbye @ The Real Jdbye:
    like bronys
  • The Real Jdbye @ The Real Jdbye:
    sonic porn is too weird even for me
  • Dumpflam @ Dumpflam:
    bruh
  • Dumpflam @ Dumpflam:
    guys how do i delete a post
  • The Real Jdbye @ The Real Jdbye:
    you don't
  • The Real Jdbye @ The Real Jdbye:
    you can report it and request deletion
  • BakerMan @ BakerMan:
    Also, no, that was his first time having a seizure, and hopefully the last
    +1
    BakerMan @ BakerMan: Also, no, that was his first time having a seizure, and hopefully the last +1