Hacking Ubuntu 18.04 on a Switch

cmsj

Well-Known Member
OP
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
44
XP
203
Country
United Kingdom
Current version: 2.0
Download pre-built images: https://github.com/cmsj/switch_linux_kit/releases/tag/2.0

There are download/install instructions on the download page :)

This is now being distributed as a pre-built exploit chain, and a pre-built SD card image, so it should be a lot easier to install/run than before. You can still build it all from scratch of course, if you want to (https://github.com/cmsj/switch_linux_kit is the repo and there are instructions in the README.md)

Old post content below:

I've written a script to build a full Ubuntu Desktop image for the Switch (see a screenshot below). There are some instructions here, but be aware that you'll need a Linux machine to both build and run the boot exploit, and to build the Ubuntu image if you don't want to download my image.

First of all, you need to get the fail0verflow exploit/boot chain working. There's a good tutorial for doing the whole thing here or there is a good Docker image you can run that will do the work for you (but you still need the tegra_mtc.bin file (download here courtest of @CptPotato ). This is non-optional whether you want to use a pre-built Ubuntu image or not.

Next, either clone my git repo and run ./build-image.sh or download the bionic.tgz tarball from here. As with all the other systems, you need a micro SD card that is partitioned with one small (formatted) FAT32 partition, and a large (formatted) ext4 partition. Once you have the SD card ready, extract bionic.tgz to it with something like: tar xvf /path/to/bionic.tgz -C /mountpoint/of/SDcard

Then boot the Switch with the exploit as in other tutorials, or if you used the Docker image linked above, run bash -x 02_exploit.sh wait a few seconds then run bash -x 03_uboot.sh and the Switch should boot Linux and after a few seconds, switch to a graphical interface. At the first boot it'll be in portrait mode. Tap on the icon at the very top right of the screen, open the preferences window and you can change the rotation in the display settings.

What works:
  • 3D acceleration (although it seems slower than it should be, but this code only landed in Mesa *very* recently)
  • WiFi (but you need to tell Ubuntu to reboot and when the screen goes black, re-run the full exploit chain)
  • touchscreen
  • Bluetooth (somewhat, it seems to be a bit unreliable)
  • Light sensor (but you'll probably want to turn that off in the system preferences, because it's very annoying!)
What doesn't work:
  • Audio
  • Joycons
One final note, if you tell Linux to shut down, it will do so, but doesn't actually power the Switch off completely, so when the screen goes black, hold down the Switch's power button for ~15 seconds and then press it again to make sure it boots into the Nintendo OS.

IMG_0502.JPG
 
Last edited by cmsj,

cmsj

Well-Known Member
OP
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
44
XP
203
Country
United Kingdom
Care to share an image of your SD card? Is WiFi, HW acceleration etc working?

This is the bare bones so far. No WiFi (although there seems to be a general problem there anyway) and no HW acceleration. No bluetooth. Volume buttons work out of the box, the ambient light sensor works (annoyingly, it keeps massively over-reacting the screen brightness). It's almost unusuably slow, but I'm going to keep chipping away at it, and I'll post an image somewhere when it's at least vaguely usable.
 

blinkzane

Panic at your moms house
Member
Joined
Jul 24, 2012
Messages
944
Trophies
0
Location
Florida
XP
1,624
Country
United States
This is the bare bones so far. No WiFi (although there seems to be a general problem there anyway) and no HW acceleration. No bluetooth. Volume buttons work out of the box, the ambient light sensor works (annoyingly, it keeps massively over-reacting the screen brightness). It's almost unusuably slow, but I'm going to keep chipping away at it, and I'll post an image somewhere when it's at least vaguely usable.
let me know if you need help, I have a decent background in linux and ubuntu.
 
  • Like
Reactions: MeowMeowMeow

ShroomKing

Somebody
Member
Joined
Mar 3, 2017
Messages
470
Trophies
0
Age
27
Location
in bed
XP
1,720
Country
United States
FYI:

this: https://gist.github.com/ChristophHaag/11f6e7ef577d6f35a2debd64963fdbdf is for hardware acceleration on the tegra x1. I'm using it with arch and team f0f seem to be using it with debian, i'm not very familiar with ubuntu but it *probably* works on there too.

and this: https://chromium.googlesource.com/c...e28cabf8d658bcb52b/brcm/brcmfmac4356-pcie.txt is for wifi. When using wget on that link the file will come encoded as base64 for whatever reason, make sure you decode it or it won't work.

Just a quick heads up =)
 
D

Deleted User

Guest
This is the bare bones so far. No WiFi (although there seems to be a general problem there anyway) and no HW acceleration. No bluetooth. Volume buttons work out of the box, the ambient light sensor works (annoyingly, it keeps massively over-reacting the screen brightness). It's almost unusuably slow, but I'm going to keep chipping away at it, and I'll post an image somewhere when it's at least vaguely usable.

maybe try to install mesa about the HW thing
 

cmsj

Well-Known Member
OP
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
44
XP
203
Country
United Kingdom
FYI:

this: https://gist.github.com/ChristophHaag/11f6e7ef577d6f35a2debd64963fdbdf is for hardware acceleration on the tegra x1. I'm using it with arch and team f0f seem to be using it with debian, i'm not very familiar with ubuntu but it *probably* works on there too.

and this: https://chromium.googlesource.com/c...e28cabf8d658bcb52b/brcm/brcmfmac4356-pcie.txt is for wifi. When using wget on that link the file will come encoded as base64 for whatever reason, make sure you decode it or it won't work.

Just a quick heads up =)

Thanks. Building mesa from git is on the roadmap, I'm just trying to get some other things nailed down first (having gotten it to boot into X, I'm now trying to work out why my touchscreen configs aren't being applied properly :)
(also thanks for the reminder about the pcie.txt. I had seen that discussed before, but forgot to include it in my image)

Edit: even with that broadcom textfile, wifi still doesn't appear without a warm reboot, and even with the file the firmware load errors are still in dmesg. It's not really changed anything AFAICS.
 
Last edited by cmsj,

EclipseSin

Ignorant Wizard
Member
Joined
Apr 1, 2015
Messages
2,063
Trophies
0
Age
33
Location
221b Baker Street
XP
1,705
Country
United Kingdom
Is the wifi hardware detected on the first boot even though it's not working? Driver loaded? Restarting the network manager can fix that with some chips. I haven't setup linux yet.

sudo service network-manager restart
 

cmsj

Well-Known Member
OP
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
44
XP
203
Country
United Kingdom
Is the wifi hardware detected on the first boot even though it's not working? Driver loaded? Restarting the network manager can fix that with some chips. I haven't setup linux yet.

sudo service network-manager restart

It's nothing to do with network manager, the kernel just doesn't see the device. Presumably some quirk in the setup for the chip that happens to be right after a warm reboot.
 

Maufeat

Active Member
Newcomer
Joined
Sep 3, 2015
Messages
31
Trophies
0
Age
25
Location
WebDev
XP
226
Country
Germany
Cool! I've tried your build script but it didn't work.
I've formatted my first partiton to FAT32 and my second partition (rootfs) to ext4 and then I've put bionic.tgz which got generated by executing the script.
While booting it stucks here:
Selection_001.png
 
Last edited by Maufeat,

guily6669

GbaTemp is my Drug
Member
Joined
Jun 3, 2013
Messages
1,985
Trophies
0
Age
32
Location
Doomed Island
XP
1,556
Country
United States
Nice one there, but do you think Ubuntu distro would really be the best 4 it? It is kinda too much desktop mac like for my taste ;). But still looks awesome :grog:
 

cmsj

Well-Known Member
OP
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
44
XP
203
Country
United Kingdom
Cool! I've tried your build script but it didn't work.
I've formatted my first partiton to FAT32 and my second partition (rootfs) to ext4 and then I've put bionic.tgz which got generated by executing the script.
While booting it stucks here:

Did you just copy the bionic.tgz onto the ext4 partition? You need to extract it there: tar xvf /path/to/bionic.tgz -C /mountpoint/of/ext4/partition/
 

ry755

Well-Known Member
Member
Joined
Nov 29, 2017
Messages
535
Trophies
1
Age
18
Location
California
XP
1,415
Country
United States
Cool! I've tried your build script but it didn't work.
I've formatted my first partiton to FAT32 and my second partition (rootfs) to ext4 and then I've put bionic.tgz which got generated by executing the script.
While booting it stucks here:
Selection_001.png
It says "Exec format error" which means the programs are compiled for the wrong architecture
 

cmsj

Well-Known Member
OP
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
44
XP
203
Country
United Kingdom
It says "Exec format error" which means the programs are compiled for the wrong architecture

Yeah that's an odd error - there's no compiling in my build script, but I think it's mostly just that he/she copied bionic.tgz to the SD card without extracting it. What it's actually doing is far far cooler...
It installs qemu-user-static and debootstrap.

debootstrap is a very helpful old Debian tool that lets you download and install a complete Debian-like OS in a directory. But wait, you might say, how is that going to work on an x86_64 host?! All the little binaries in the packages are aarch64 so all the postinstall scripts will fail! Aha no, I say, qemu-user-static installs a qemu binary that emulates syscalls rather than spin up a whole ARM/PPC/MIPS/whatever VM, and configures the kernel's binfmt system to use it automatically when you run a foreign binary.

So what the script is actually doing is like a mini OS install by executing a load of ARM binaries in a chroot. It's very cool stuff :)

[email protected]:~# uname -p
x86_64
[email protected]:~# chroot /var/chroot/ubuntu_arm64_bionic/ uname -p
aarch64
[email protected]:~#

(Edit: I'd love to take credit for this cool hack, but if you look at my github repo, you'll see it's forked from a repo that is used to build multi-arch-multi-OS docker images. I've just stripped out all of the multi-arch stuff and the incomplete Debian support, and added in various extra bits needed by the Switch)
 
Last edited by cmsj,
  • Like
Reactions: ry755

Maufeat

Active Member
Newcomer
Joined
Sep 3, 2015
Messages
31
Trophies
0
Age
25
Location
WebDev
XP
226
Country
Germany
Maybe it helps to show the exact steps that I've done:

Code:
git clone https://github.com/cmsj/nintendo-switch-ubuntu-builder.git ubuntu
cd ubuntu
./make_build.sh
gparted ( Created a 300MB FAT32 partition then filled the rest of the sd card with a second ext4 partition labled "rootfs" )
mount /dev/sdn2 /mnt/sdcard
tar xvf bionic.tgz -C /mnt/sdcard
cp bionic.tgz /mnt/sdcard/root
 
  • Like
Reactions: Deleted User
General chit-chat
Help Users
  • No one is chatting at the moment.
    Veho @ Veho: Corporation is the new corporation.