Archive:HOW-TO:Install Gentoo and XBMC on Apple TV 1: Difference between revisions
>Xett |
>Xett |
||
Line 341: | Line 341: | ||
===Chroot in and Edit Environment === | ===Chroot in and Edit Environment === | ||
With /proc and (hopefully) /dev successfully mounted, chroot into and update your new env: | |||
chroot /mnt/gentoo /bin/bash | |||
env-update | |||
source /etc/profile | |||
export PS1="(atvchroot) $PS1" | |||
Set your root password: | |||
passwd | |||
'''Remember it!''' | |||
==== Make.conf options ==== | ==== Make.conf options ==== |
Revision as of 15:19, 23 September 2010
Install Gentoo and XBMC on the AppleTV
These instructions will help you on your way to getting Gentoo intalled on your Apple TV. This guide is for a total ATV overhaul -- which is to say replacing the OSX-lite ATV OS with Gentoo. As such it has the possibility of totally toasting your pretty silver box. These steps do NOT require you to crack open your ATV and slave up its disk to an existing pc. This is of course an option, but IMHO, totally unnecessary.
Most of this guide was stolen right off http://code.google.com/p/atv-bootloader. I give full praise and credit to these guys. atv-bootloader is a truely awesome little bit of work. This guide assumes you are comfortable with a gentoo command-line installation and kernel configuration, telnet/ssh connections, network basics, partition/disk schemes, etc. If terms like "dd", "mbr", "efi" and "parted" don't mean anything to you, you should probably close this document and go grab a Ubuntu ISO. Not that I don't love Ubuntu :-)
You will also need an existing linux machine (or, yes, OSX would work too). This linux machine will be used to build the initial ATV-Bootloader USB stick, as well as telnet into your atv during the process. I used a gentoo box, and thus these instructions will be geared in that direction. Keep in mind some part may deviate, depending on your distro.
Your ATV and linux machine will need to be on the same lan with dhcp setup (should be a no brainer)
Herrrrrreeee we go...
Create an AppleTV Patchstick
(not to be confused with the atv-bootloader stick)
Head on over to http://code.google.com/p/atvusb-creator/ and download whatever flavor of the patchstick tool suites your OS. Extract it to a directory and run it. It will download a new version of the ATV firmware for you, put it in a juicer and pop out a nice little .img file for you to put on a USB drive. It will also produce you your very own boot.efi file. Hold on to this file, it will be important later.
Create an ATV-Bootloader USB Stick
All the linux commands I've listed here should be run as root, unless otherwise noted
On your linux machine, get your distros copy of GNU Parted. On gentoo, the package is called parted, so;
emerge -v parted
You will also need HFS+ tools. Portage has got a package called sys-fs/hfsplusutils, but I found it to suck. Your best bet is to grab the tar off the atv-bootloader site, do the following as your root;
cd ~ wget http://atv-bootloader.googlecode.com/files/hfs_support-1.0.tar.gz tar -xzf hfs_support-1.0.tar.gz cd hfs_support/ ./build_diskdev_cmds.sh
You'll now have your own copies of various hfsp utilities you will need moving forward. Get an empty usb drive of at least 512mb and plug it into your linux machine, lets assume it gets assigned to device node /dev/sdb The following commands zero out the device then create and format the usb partitions:
dd if=/dev/zero of=/dev/sdb bs=4096 count=1M partprobe /dev/sdb parted -s /dev/sdb mklabel gpt parted -s /dev/sdb mkpart primary HFS 40s 69671s parted -s /dev/sdb set 1 atvrecv on partprobe /dev/sdb mkfs.hfsplus -v Recovery /dev/sdb1 cd ~ mkdir atvbootloader mount /dev/sdb1 atvbootloader/
Now download and copy over the atv-bootloader files;
wget http://atv-bootloader.googlecode.com/files/recovery-0.6.tar.gz tar -xzf recovery-0.6.tar.gz cp -arp recovery/* atvbootloader/
That disk is now set up, so copy over that handy boot.efi that the Patchstick util found for you. If you created the patchstick on windows you'll need to copy the boot.efi file over to your linux machine, then copy it to the bootloader stick. You can use PSCP, ftp, or another flash disk, whatever you want. Just make sure it ends up on your atv-bootloader disk:
cp -ap boot.efi atvbootloader/
Now edit the boot.plist file from the recovery software to drop you to a command prompt. I'm a vi-guy, but you can use nano or whatever you want:
vi atvbootloader/penboot/com.apple.Boot.plist
Change one of the last lines in that file to read:
<string>atv-boot=none video=vsesafb</string>
Save and quit vi (:wq [enter]), unmount your usb atv-bootloader.
You've now got an awesome little usb drive that will boot your appletv to a live linux installation. W00t.
Backup your internal ATV Hard Drive
Boot your AppleTV to your new atv-bootloader usb drive. You may need to hold down the remote's [-] and [Menu] buttons at boot to force it to scan for usb devices.
atv-bootloader should load up after a minute or so and drop you at a login prompt.
You can login with root/root and do everything locally with a USB keyboard if you wish, but using telnet is much easier.
Gentoo does not 'ship' with telnet tools, so emerge them:
emerge -v netkit-telnetd
Then connect to your atv (this does not have to be done as root on your client machine):
telnet [your ATV's IP]
Again, root/root for passwords.
Figure out which of the device nodes represents your LOCAL disk on the ATV. I've had it map as both sda and sdb on occations, so I can't definitivly tell you which is will be. I assume that your local disk has detected as /dev/sda for the ballance of this guide.
At this point, you have two options: Lazy and Correct.
The Lazy (and slow) way to take a backup of your ATV is to plug in an external hard disk (lets assume its partition is /dev/sdc1) and run
mkdir /mnt/backup/ mount /dev/sdc1 /mnt/backup/ dd if=/dev/sda | gzip > /mnt/backup/atv-backup.dd.img
That will take a complete bit-for-bit backup of your disk. It will pipe it through gzip, so you will get good compression if most of your disk is empty, but if you have your local disk full of media, make sure your target external drive is at LEAST the size of your ATV's internal drive.
The far more 'correct' way to do an ATV backup is detailed on the atv-bootloader site.
Its best to just follow the official guide on this page, as I have zero customization to add:
http://code.google.com/p/atv-bootloader/wiki/ATVBackup#Backup
When you are done with the Backup section of that page, come back here and continue on...
Partition your internal ATV Hard Drive
Now that everything is backed up, you can create the new partition structure for your linux installation. This may seem confusing, but it is sort of straight forward when you understand what is going on under the hood. On your local ATV disk you are essentially creating a partition structure to support two separate OS installations; One for a local copy of the atv-bootloader to live in, the other for your gentoo installation. When your ATV boots, its EFI needs to talk to the atv-bootloader kernel/os. After this pow-wow is done, atv-bootloader hands the machine off to your gentoo installation. Makes sense, right? Good.
Again, make sure /dev/sda is your local ATV hard drive.
Zero out /dev/sda so its guid changes...
dd if=/dev/zero of=/dev/sda bs=4096 count=1M
create initial gpt structures
parted -s /dev/sda mklabel gpt
We need to find out how large our disk is, run this:
parted -s /dev/sda print
This should spit out something like below:
Model: ATA WDC WD1600BEVE-4 (scsi) Disk /dev/sda: 160GB
Here it tells me my local disk (/dev/sda) is 160GB, hurrah for me. This makes 160GB the end of our disk, remember this.
You're now going to create the three partitions required for the atv-bootloader.
parted -s /dev/sda mkpart primary fat32 40s 25M parted -s /dev/sda set 1 boot on parted -s /dev/sda mkpart primary HFS 25M 50M parted -s /dev/sda set 2 atvrecv on parted -s /dev/sda mkpart primary HFS 50M 75M
At this point you've created the partitions nessesary for installing the local copy of the atv-bootloader. The next could partitions you make will be for gentoo and can be whatever sizes you like, though I recomend at least 1gig of swap.
I've made my root partition about 16GB and swap 1000MB, create those now:
parted -s /dev/sda mkpart primary ext3 75M 16GB parted -s /dev/sda mkpart primary linux-swap 16GB 17GB
You'll notice that yes, this leaves a ton of my disk unused. I stream everything, so this doesn't bother me. You can always format the remain space and mount it up as a storage partition:
#Optional: parted -s /dev/sda mkpart primary ext3 17GB 160GB
Sync up your partition tables
partprobe /dev/sda
Get everything formatted:
mkfs.msdos -F 32 -n EFI /dev/sda1 mkfs.hfsplus -v Recovery /dev/sda2 mkfs.hfsplus -v OSBoot /dev/sda3 mkfs.ext3 -b 4096 -L Linux /dev/sda4 mkswap /dev/sda5 sync
Time to see if we got everything correct:
parted -s /dev/sda print
This should spit out something very similar to this:
Model: ATA WDC WD1600BEVE-4 (scsi) Disk /dev/sda: 160GB Sector size (logical/physical): 512B/512B Partition Table: gpt
Number Start End Size File system Name Flags 1 20.5kB 25.0MB 25.0MB fat32 primary boot 2 25.0MB 50.0MB 25.0MB hfs+ primary atvrecv 3 50.0MB 75.0MB 25.0MB hfs+ primary 4 75.0MB 16.0GB 15.9GB ext3 primary 5 16.0GB 17.0GB 1000MB linux-swap(v1) primary
Ensure the 'Flags' section is the same as above and that your first three partitions (at least) match mine.
That concludes all the partition setup that is needed. The next step is to install a LOCAL copy of the atv-bootloader magic on to the ATV's hard disk (remember, up until now we've been opperating in the live environment)
Install the atv-bootloader onto the internal disk
This should all look somewhat familiar as we did close to the same procedure earlier when creating the initial ATV-bootloader USB stick. This installation will be the OS the ATV actually boots to initially. Once it succeeds, then it hands things over to Gentoo.
Pull the atv-bootloader recovery files off of the repo:
cd ~ wget http://atv-bootloader.googlecode.com/files/recovery-0.6.tar.gz tar -xzf recovery-0.6.tar.gz
Create a mount points for the recovery stuff and mount everything up:
mkdir /mnt/osboot mkdir /mnt/recovery fsck.hfsplus /dev/sda2 mount /dev/sda2 /mnt/recovery fsck.hfsplus /dev/sda3 mount /dev/sda3 /mnt/osboot
Copy the atv-bootloader files over
cp -arp recovery/* /mnt/osboot/ cp -arp recovery/* /mnt/recovery/
Copy over the boot.efi file which should still be on the atv-bootloader USB flash disk:
mkdir /mnt/bootloader mount /dev/sdb1 /mnt/bootloader cp -ap /mnt/bootloader/boot.efi /mnt/osboot cp -ap /mnt/bootloader/boot.efi /mnt/recovery
Unmount everything:
cd ~ umount -a
Wham Bam! You now have an AppleTV with the atv-bootloader installed on it. At this point you can continue on to installing Gentoo from within the usb-live enviornment. OR, you can reboot, pop out your atv-bootloader live usb stick and let the ATV boot from its internal copy of atv-bootloader. I'd recomend rebooting and using the now-onboard copy of atv-bootloader. This prevents any more device node confusion as well as double checking that your partition/boot structure is set up correctly.
When you reboot, you should get dumped to the familiar atv-bootloader login prompt. root/root to log in, or shoot in via telnet from your existing linux machine. If you did not get sent to a login prompt, something went screwy somewhere. Boot back to the atv-bootloader live stick and double check all the partitions and files to make sure everything got created and copied where it is supposed it be.
If it booted correctly, you can move on to.....
Installing Gentoo
At this point there are a few directions you can go for the install env.
You pop in a gentoo live-usb stick and kexec over to the liveusb kernel. Or you can simply build your gentoo installation within the existing atv-bootloader env. I recomend the latter as it is less work, and all the tools you need are available in this live-usb. I may gloss over some of the more basic gentoo setup aspects here, so I recomend you head over to http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1 and give the handbook a quick look over to get the general refresher on whats going on. The atv-bootloader is solid and should detect and set up all the basics (network, etc).
Basic Gentoo Environment
All read up? Awesome! Away we go.
atv-bootloader should detect your local disk as /dev/sda, so go ahead and create your mount point:
mkdir /mnt/gentoo
You've already partitioned/formatted everything so you can go ahead and mount up your gentoo root partition:
mount /dev/sda4 /mnt/gentoo mkswap /dev/sda5 swapon /dev/sda5
Hop into your install directory:
cd /mnt/gentoo
I don't know about anybody else, but for whatever reason DNS does not work for me from the atv-bootloader env. Maybe I'm crazy. Who knows. All this means is that when you need to grab a source somewhere, you need to do it via IP.
http://www.gentoo.org/main/en/mirrors2.xml has a list of all current gentoo mirrors. Pick your favorite and the lookup its IP address. Write it on your forearm for future reference.
Check the date:
date
If it isn't right, fix it with: (Month, Day, hour, minute and Year)
date MMDDhhmmYYYY
Grab the gentoo installation stage3:
links http://the.ip.of.your.mirror.here/gentoo/releases/x86/current-stage3/
Note: Download the three files named "stage3-i686-########" there should be a tar.bz2, a .CONTENTS and a .DIGESTS. Download ALL THREE.
Get the latest Gentoo Portage tree and its hash... you can use wget here since the latest portage tree is uniformly named across mirrors:
wget http://the.ip.of.your.mirror.here/gentoo/snapshots/portage-latest.tar.bz2 wget http://the.ip.of.your.mirror.here/gentoo/snapshots/portage-latest.tar.bz2.md5sum
Check the hashes of your two files
md5sum -c stage3-i686-########.tar.bz2.DIGESTS
It should spit back verification like this:
stage3-i686-20100921.tar.bz2: OK stage3-i686-20100921.tar.bz2.CONTENTS: OK
Check your portage tar:
md5sum -c portage-latest.tar.bz2.md5sum
Which should come back with:
portage-latest.tar.bz2: OK
Note: During my install I could not, for the life of me get a solid copy of the current stage3. It just wouldn't verify against its hash. After hours of pulling from diff mirriors, I made the executive decsion to try and procede anyway. It turned out fine. If you have the same problem, you may be able to safely use what you've downloaded. However, it is ALWAYS SAFER to use a stage3 and portage tree that have checked out against their respective hashes.
Ehem...back to the show:
Extract your Stage3: (make sure you are in /mnt/gentoo)
tar -xvjpf stage3-i686*.tar.bz2
It will take a minute, when it is done, extract portage:
tar -xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr
This will take a longer minute. Get a juice box.
Copy your broken resolve.conf into gentoo:
cp -L /etc/resolv.conf /mnt/gentoo/etc/
Mount up the dev and proc systems.
mount -t proc none /mnt/gentoo/proc mount -o bind /dev /mnt/gentoo/dev
Funny story: It seems that, for reasons unknown, binding /dev doesn't like to work for most people, myself included. It barks back with:
mount: mounting /dev on /mnt/gentoo/dev failed: Invalid argument
Thankfully, because the stage3 contains basically every device node you could ever need, you -shouldn't- need this for a successful installation.
Chroot in and Edit Environment
With /proc and (hopefully) /dev successfully mounted, chroot into and update your new env:
chroot /mnt/gentoo /bin/bash env-update source /etc/profile export PS1="(atvchroot) $PS1"
Set your root password:
passwd
Remember it!