Create Patchstick in Leopard

From AwkwardTV
Revision as of 13:30, 14 July 2008 by Magu (talk | contribs) (Leopard Files)
Jump to: navigation, search

Creation of a Patchstick is possible on Leopard if you have access to your old Mac OS X Intel install disc, i.e. the one that got bundled with you pre-Leopard Intel Mac or whatever. If you've thrown it away or bought your mac post-Leopard there are several ways you can get a hold of it, out of which the least immoral one is to just borrow it from a friend.

Following is a guide to create a plain Patchstick which just installs ssh - nothing else. This guide includes all of the files needed to make it fully compatible with a stock updated Take 2 Apple TV.

Recommended to be used in conjunction with Take_2_Full_Update. Tested and used on a MacBook with Mac OS X Server Leopard 10.5.2.

Creation Guide

  1. In the folder where you unpacked patchstick.zip create a subfolder called Files.
    Note: Instead of manually copying files from various disks and dmg's in Steps 2-6 you can use the script in Leopard Files below.
  2. In the Files folder, create the following folder structure. (Not really necessary, but structure is always good. Also, my createPatchstick script relies on this structure.)
    System
    System/Library
    System/Library/Extensions
    System/Library/Frameworks
    sbin
    usr
    usr/lib
    usr/lib/system
    
  3. Create a temporary folder somewhere and put the following files there. (For the PKGs, use Pacifist and it's search function to extract only the needed files.)
    • From Essentials.pkg (found in System/Installation/Packages) on Mac OS X Install disc 1 get:
      AppleACPIPlatform.kext
      AppleAPIC.kext
      AppleEFIRuntime.kext
      AppleFileSystemDriver.kext
      AppleFlashNVRAM.kext
      AppleHDA.kext
      AppleHPET.kext
      AppleIRController.kext
      AppleRTC.kext
      AppleSMBIOS.kext
      AppleSMC.kext
      AudioIPCDriver.kext
      BootCache.kext
      GeForce.kext
      IO80211Family.kext
      IOACPIFamily.kext
      IOATAFamily.kext
      IOAudioFamily.kext
      IOGraphicsFamily.kext
      IOHIDFamily.kext
      IONDRVSupport.kext
      IONetworkingFamily.kext
      IOPCIFamily.kext
      IOPlatformPluginFamily.kext
      IOSCSIArchitectureModelFamily.kext
      IOStorageFamily.kext
      IOUSBFamily.kext
      IOUSBMassStorageClass.kext
      NVDANV40Hal.kext
      NVDAResman.kext
      OSvKernDSPLib.kext
      System.kext
      
      Kerberos.framework
      
      chown
      
    • From BaseSystem.pkg (found in System/Installation/Packages) on Mac OS X Install disc 1 get:
      CoreFoundation.framework
      IOKit.framework
      
      bash
      chmod
      cp
      sync
      sh
      ls
      bless
      mount
      mount_hfs
      mount_devfs
      sleep
      umount
      reboot
      
      dyld
      libSystem.B.dylib
      libncurses.5.4.dylib
      libgcc_s.1.dylib
      libmathCommon.A.dylib
      
    • From MacOSXUpdCombo10.4.9Intel.pkg in the MacOS X 10.4.9 Combo Updater get:
      AppleIntelCPUPowerManagement.kext 
      
    • From the AppleTV 2.0.2 Updater get:
      boot.efi
      
  4. Put those in the correct folders so the layout ends up as:
    boot.efi
    sbin
    sbin/bash
    sbin/bless
    sbin/chmod
    sbin/chown
    sbin/cp
    sbin/ls
    sbin/mount
    sbin/mount_devfs
    sbin/mount_hfs
    sbin/reboot
    sbin/sh
    sbin/sleep
    sbin/sync
    sbin/umount
    System
    System/Library
    System/Library/Extensions
    System/Library/Extensions/AppleACPIPlatform.kext
    System/Library/Extensions/AppleAPIC.kext
    System/Library/Extensions/AppleEFIRuntime.kext
    System/Library/Extensions/AppleFileSystemDriver.kext
    System/Library/Extensions/AppleFlashNVRAM.kext
    System/Library/Extensions/AppleHDA.kext
    System/Library/Extensions/AppleHPET.kext
    System/Library/Extensions/AppleIntelCPUPowerManagement.kext
    System/Library/Extensions/AppleIRController.kext
    System/Library/Extensions/AppleRTC.kext
    System/Library/Extensions/AppleSMBIOS.kext
    System/Library/Extensions/AppleSMC.kext
    System/Library/Extensions/AudioIPCDriver.kext
    System/Library/Extensions/BootCache.kext
    System/Library/Extensions/GeForce.kext
    System/Library/Extensions/IO80211Family.kext
    System/Library/Extensions/IOACPIFamily.kext
    System/Library/Extensions/IOATAFamily.kext
    System/Library/Extensions/IOAudioFamily.kext
    System/Library/Extensions/IOGraphicsFamily.kext
    System/Library/Extensions/IOHIDFamily.kext
    System/Library/Extensions/IONDRVSupport.kext
    System/Library/Extensions/IONetworkingFamily.kext
    System/Library/Extensions/IOPCIFamily.kext
    System/Library/Extensions/IOPlatformPluginFamily.kext
    System/Library/Extensions/IOSCSIArchitectureModelFamily.kext
    System/Library/Extensions/IOStorageFamily.kext
    System/Library/Extensions/IOUSBFamily.kext
    System/Library/Extensions/IOUSBMassStorageClass.kext
    System/Library/Extensions/NVDANV40Hal.kext
    System/Library/Extensions/NVDAResman.kext
    System/Library/Extensions/OSvKernDSPLib.kext
    System/Library/Extensions/System.kext
    System/Library/Frameworks
    System/Library/Frameworks/CoreFoundation.framework
    System/Library/Frameworks/IOKit.framework
    System/Library/Frameworks/Kerberos.framework
    usr
    usr/lib
    usr/lib/dyld
    usr/lib/libgcc_s.1.dylib
    usr/lib/libncurses.5.4.dylib
    usr/lib/libSystem.B.dylib
    usr/lib/system
    usr/lib/system/libmathCommon.A.dylib
    
  5. Prepare the Patchstick folder.
    • Get the following files. All except sshd can be found in Essentials.pkg on Mac OS X Install disc 1. Sshd is located in BSD.pkg on the same disc.
      ssh/scp
      ssh/sftp
      ssh/sftp-server
      ssh/ssh
      ssh/ssh-add
      ssh/ssh-agent
      ssh/ssh-keygen
      ssh/ssh-keyscan
      ssh/ssh-keysign
      ssh/sshd
      ssh/sshd-keygen-wrapper
      
    • Edit installer.d/ssh to:
      #!/sbin/bash
      
      # install ssh
      # (c) 2007 macTijn at awkwardtv dot org
      
      echo -n "        * Installing SSH daemon... "
      /sbin/cp /stuff/ssh/sshd /OSBoot/usr/sbin/sshd
      /sbin/cp /stuff/ssh/ssh /OSBoot/usr/bin/ssh
      /sbin/cp /stuff/ssh/ssh-add /OSBoot/usr/bin/ssh-add
      /sbin/cp /stuff/ssh/ssh-agent /OSBoot/usr/bin/ssh-agent
      /sbin/cp /stuff/ssh/ssh-keygen /OSBoot/usr/bin/ssh-keygen
      /sbin/cp /stuff/ssh/ssh-keyscan /OSBoot/usr/bin/ssh-keyscan
      /sbin/cp /stuff/ssh/scp /OSBoot/usr/bin/scp
      /sbin/cp /stuff/ssh/sftp-server /OSBoot/usr/libexec/sftp-server
      /sbin/cp /stuff/ssh/ssh-keysign /OSBoot/usr/libexec/ssh-keysign
      /sbin/cp /stuff/ssh/sshd-keygen-wrapper /OSBoot/usr/libexec/sshd-keygen-wrapper
      /sbin/cp /stuff/ssh/ssh.plist /OSBoot/System/Library/LaunchDaemons/ssh.plist
        
      /sbin/chmod 755 /OSBoot/usr/sbin/sshd
      /sbin/chmod 755 /OSBoot/usr/bin/ssh
      /sbin/chmod 755 /OSBoot/usr/bin/ssh-add
      /sbin/chmod 755 /OSBoot/usr/bin/ssh-agent
      /sbin/chmod 755 /OSBoot/usr/bin/ssh-keygen
      /sbin/chmod 755 /OSBoot/usr/bin/ssh-keyscan
      /sbin/chmod 755 /OSBoot/usr/bin/scp
      /sbin/chmod 755 /OSBoot/usr/libexec/sftp-server
      /sbin/chmod 4755 /OSBoot/usr/libexec/ssh-keysign
      /sbin/chmod 755 /OSBoot/usr/libexec/sshd-keygen-wrapper
      /sbin/chmod 755 /OSBoot/System/Library/LaunchDaemons/ssh.plist
      
      echo "        Adding Kerberos..."
      /sbin/cp -p -R /System/Library/Frameworks/OSXFrames/Kerberos.framework /OSBoot/System/Library/Frameworks/OSXFrames/
      /sbin/sed -i"" -e 's;^exec;DYLD_FRAMEWORK_PATH="/System/Library/Frameworks/OSXFrames" exec;' /OSBoot/usr/libexec/sshd-keygen-wrapper
      
    • Edit ssh/ssh.plist to:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
              <key>Label</key>
              <string>com.openssh.sshd</string>
              <key>Program</key>
              <string>/usr/libexec/sshd-keygen-wrapper</string>
              <key>ProgramArguments</key>
              <array>
                      <string>/usr/sbin/sshd</string>
                      <string>-i</string>
              </array>
              <key>SessionCreate</key>
              <true/>
              <key>Sockets</key>
              <dict>
                      <key>Listeners</key>
                      <dict>
                              <key>Bonjour</key>
                              <array>
                                      <string>ssh</string>
                                      <string>sftp-ssh</string>
                              </array>
                              <key>SockServiceName</key>
                              <string>ssh</string>
                      </dict>
              </dict>
              <key>StandardErrorPath</key>
              <string>/dev/null</string>
              <key>inetdCompatibility</key>
              <dict>
                      <key>Wait</key>
                      <false/>
              </dict>
      </dict>
      </plist>
      

  6. Edit createPatchstick to:
    #!/bin/bash
    #
    # Usage: createPatchstick /dev/diskX
    
    echo
    echo "--- Generation of Apple TV Patchstick ---"
    echo
    echo " Created by Marook."
    echo " Thanks to: MacTijn, Alan_Quatermain & ericIII"
    echo " Leopard remake by joda"
    echo
    echo "-----------------------------------------"
    echo
    
    if [ "$USER" != "root" ]
    then
    	echo "You need to run this script as ROOT. Exiting..."
    	echo
    	exit 1
    fi
    
    if [ $# -ne 1 ]
    then
    		echo
    		echo "Listing available disks:"
    		diskutil list
    		echo $'\a'
            echo "Please specify the disk to re-partition as argument one:"
            echo " ./createpatchstick /dev/diskX"
            echo
            echo " WARNING: The disk will be ERASED !!!"
            echo
            exit 1
    fi
    
    
    partition_disk() {
    	echo
    	echo " Partitioning $THEDISK:"
    	diskutil partitionDisk $THEDISK 2 GPTFormat HFS+ Patchstick-root 80M HFS+ Patchstick 40M
    	echo " Patitions done."
    	#sleep 2
    }
    
    basic_folders() {
    	echo "Creating System folders..."
    	mkdir /Volumes/Patchstick-root/sbin /Volumes/Patchstick-root/etc /Volumes/Patchstick-root/dev /Volumes/Patchstick-root/OSBoot /Volumes/Patchstick-root/stuff
    	mkdir -p /Volumes/Patchstick-root/usr/lib/system
    	mkdir -p /Volumes/Patchstick-root/System/Library/Extensions
    	mkdir -p /Volumes/Patchstick-root/System/Library/Frameworks
    	ln -s /Volumes/Patchstick-root/sbin /Volumes/Patchstick-root/bin
    	mkdir -p /Volumes/Patchstick-root/System/Library/Frameworks/OSXFrames/
    	mkdir -p /Volumes/Patchstick-root/usr/libexec
    }
    
    copy_system() {
    	echo "Copying System Extentions..."
    	cp -R Files/System/Library/Extensions/{AppleACPIPlatform,AppleAPIC,AppleEFIRuntime,AppleFileSystemDriver,AppleFlashNVRAM,AppleHDA,AppleHPET,AppleIRController,AppleRTC,AppleSMBIOS,AppleSMC,AudioIPCDriver,BootCache,GeForce,IO80211Family,IOACPIFamily,IOATAFamily,IOAudioFamily,IOGraphicsFamily,IOHIDFamily,IONDRVSupport,IONetworkingFamily,IOPCIFamily,IOPlatformPluginFamily,IOSCSIArchitectureModelFamily,IOStorageFamily,IOUSBFamily,IOUSBMassStorageClass,NVDANV40Hal,NVDAResman,OSvKernDSPLib,System,AppleIntelCPUPowerManagement}.kext /Volumes/Patchstick-root/System/Library/Extensions/
    	cp -R Files/System/Library/Frameworks/{CoreFoundation,IOKit}.framework /Volumes/Patchstick-root/System/Library/Frameworks
    	cp Files/sbin/{bash,chmod,chown,bless,cp,mount,mount_hfs,mount_devfs,sleep,umount,sync,sh,ls,reboot,sed} /Volumes/Patchstick-root/sbin/
    	cp Files/usr/lib/{dyld,libSystem.B.dylib,libncurses.5.4.dylib,libgcc_s.1.dylib} /Volumes/Patchstick-root/usr/lib/
    	cp Files/usr/lib/system/libmathCommon.A.dylib /Volumes/Patchstick-root/usr/lib/system/
    }
    
    copy_kernal() {
    	echo "Copying System files..."
    	cp root/mach_kernel /Volumes/Patchstick-root/
    	cp root/com.apple.Boot.plist /Volumes/Patchstick-root/
    	cp root/Info.plist /Volumes/Patchstick-root/System/Library/Extensions/AppleFileSystemDriver.kext/Contents/
    	cp root/launchd /Volumes/Patchstick-root/sbin/launchd
    	chmod 755 /Volumes/Patchstick-root/sbin/launchd
    	cp Files/boot.efi /Volumes/Patchstick-root/
    	
    	echo "Adding Kerberos..."
    	cp -p -R Files/System/Library/Frameworks/Kerberos.framework /Volumes/Patchstick-root/System/Library/Frameworks/OSXFrames/
    }
    
    copy_stuff() {
    	echo "Copying Patchstick files..."
    	
    	cp -R Patchstick/* /Volumes/Patchstick/
    }
    
    disk_atv_mode() {
    	echo "Changing Patchstick-root to Apple TV Mode..."
    	START=$(gpt -r show $THEDISK | grep '1  GPT part' | awk '{print $1}')
    	SIZE=$(gpt -r show $THEDISK | grep '1  GPT part' | awk '{print $2}')
    	diskutil unmountDisk $THEDISK
    	gpt remove -i 1 $THEDISK
    	diskutil unmountDisk $THEDISK
    	gpt add -b $START -s $SIZE -i 1 -t "5265636F-7665-11AA-AA11-00306543ECAC" $THEDISK
    	diskutil unmountDisk $THEDISK
    	echo
    	echo "Your disk $THEDISK is now unmounted and ready to patch your AppleTV."
    }
    
    
    if [ $# = 1 ]
    then
    
    	read -p "Are you sure you want to partition disk $1? [yes|no]" sure
    	echo
    	
    	THEDISK=$1
    	export THEDISK
    	
    	case "$sure" in
         yes)
         	echo
         	partition_disk
         	basic_folders
         	copy_system
         	copy_kernal
         	copy_stuff
         	disk_atv_mode
    		echo "Enjoy... :-)"
    		echo
    		;;
    
         *)
    		echo "You selected No. Aborting..."
    		exit
    		;;
    	esac   
    
    fi
    
  7. Create your Patchstick by running createPatchstick.

Leopard Files

You can use this script to collect various files from Steps 2-5 into Files directory under Leopard. However, you still need an original Mac OS X 10.4 disk.
Steps:

  • Create Files directory as in Step 1 above.
  • Place the script below into Files (eg., Files/script.sh)
  • Mount Mac OS X Install Disk 1, 10.4.9 Combo Update (MacOSXUpdCombo10.4.9Intel.dmg), and AppleTV 1.1 Update (2Z694-5248-45.dmg).
  • Run 'cd Files; sudo sh script.sh'.

All necessary files (including ssh) will now be in Files and you can continue from Step 5. Note that there is no need for Pacifier any more.

Script 'script.sh'.

#!/bin/bash

[ "$USER" != "root" ] && 
{
  echo "You need to run this script as ROOT. Exiting..."
  echo
  exit 1
}

OSDISK='/Volumes/Mac OS X Install Disc 1';
OSDMG='/Volumes/Mac OS X 10.4.9 Combined Update (Intel)';
ATVDMG='/Volumes/OSBoot';

# Check for mounted volumes
[ -d "$OSDISK" ] || 
{
  echo "You need to mount Mac OS X Install Disc 1. Exiting..."
  exit 1
}

[ -d "$OSDMG" ] ||    
{
  echo "You need to mount Mac OS X 10.4.9 Combo Update DMG. Exiting..."
  exit 1
}

[ -d "$ATVDMG" ] ||    
{
  echo "You need to mount AppleTV 1.1 Update DMG. Exiting..."
  exit 1
}


# Make necessary directories
mkdir ./sbin;
mkdir ./usr;
mkdir ./usr/lib;
mkdir ./usr/bin;
mkdir ./usr/lib/system;
mkdir ./ssh;

# Extract from 10.4.9 Update
pax -r -p e -z -f /Volumes/Mac\ OS\ X\ 10.4.9\ Combined\ Update\ \(Intel\)/MacOSXUpdCombo10.4.9Intel.pkg/Contents/Archive.pax.gz \
'./System/Library/Extensions/AppleIntelCPUPowerManagement.kext*' \
'./System/Library/Extensions/AppleACPIPlatform.kext*' \
'./System/Library/Extensions/AppleAPIC.kext*' \
'./System/Library/Extensions/AppleEFIRuntime.kext*' \
'./System/Library/Extensions/AppleFileSystemDriver.kext*' \
'./System/Library/Extensions/AppleHDA.kext*' \
'./System/Library/Extensions/AppleHPET.kext*' \
'./System/Library/Extensions/AppleIRController.kext*' \
'./System/Library/Extensions/AppleRTC.kext*' \
'./System/Library/Extensions/AppleSMBIOS.kext*' \
'./System/Library/Extensions/AppleSMC.kext*' \
'./System/Library/Extensions/BootCache.kext*' \
'./System/Library/Extensions/GeForce.kext*' \
'./System/Library/Extensions/IO80211Family.kext*' \
'./System/Library/Extensions/IOATAFamily.kext*' \
'./System/Library/Extensions/IOAudioFamily.kext*' \
'./System/Library/Extensions/IOGraphicsFamily.kext*' \
'./System/Library/Extensions/IOHIDFamily.kext*' \
'./System/Library/Extensions/IONDRVSupport.kext*' \
'./System/Library/Extensions/IONetworkingFamily.kext*' \
'./System/Library/Extensions/IOPCIFamily.kext*' \
'./System/Library/Extensions/IOPlatformPluginFamily.kext*' \
'./System/Library/Extensions/IOSCSIArchitectureModelFamily.kext*' \
'./System/Library/Extensions/IOStorageFamily.kext*' \
'./System/Library/Extensions/IOUSBFamily.kext*' \
'./System/Library/Extensions/IOUSBMassStorageClass.kext*' \
'./System/Library/Extensions/NVDANV40Hal.kext*' \
'./System/Library/Extensions/NVDAResman.kext*' \
'./System/Library/Extensions/System.kext*' \
'./System/Library/Frameworks/Kerberos.framework*' \
'./System/Library/Frameworks/CoreFoundation.framework*' \
'./System/Library/Frameworks/IOKit.framework*' ;

# Extract from OS Install disk, Essentials PKG
pax -r -p e -z -f /Volumes/Mac\ OS\ X\ Install\ Disc\ 1/System/Installation/Packages/Essentials.pkg/Contents/Archive.pax.gz \
'./System/Library/Extensions/AppleFlashNVRAM.kext*' \
'./System/Library/Extensions/AudioIPCDriver.kext*' \
'./System/Library/Extensions/IOACPIFamily.kext*' \
'./System/Library/Extensions/OSvKernDSPLib.kext*' \
'./usr/bin/chgrp' ;
mv ./usr/bin/chgrp ./sbin/chown;

# Extract from OS Install Disk, BaseSystem PKG
cp -p \
"$OSDISK/bin/bash" \
"$OSDISK/bin/chmod" \
"$OSDISK/bin/cp" \
"$OSDISK/bin/sync" \
"$OSDISK/bin/sh" \
"$OSDISK/bin/ls" \
"$OSDISK/usr/sbin/bless" \
"$OSDISK/sbin/mount" \
"$OSDISK/sbin/mount_hfs" \
"$OSDISK/sbin/mount_devfs" \
"$OSDISK/bin/sleep" \
"$OSDISK/sbin/umount" \
"$OSDISK/sbin/reboot" \
"$OSDISK/usr/bin/sed" \
./sbin/. ;

cp -p \
"$OSDISK/usr/lib/dyld" \
"$OSDISK/usr/lib/libgcc_s.1.dylib" \
"$OSDISK/usr/lib/libncurses.5.4.dylib" \
"$OSDISK/usr/lib/libSystem.B.dylib" \
"$OSDISK/usr/lib/system/libmathCommon.A.dylib" \
./usr/lib/. ;

cp -p \
"$OSDISK/usr/lib/system/libmathCommon.A.dylib" \
./usr/lib/system/.;

# BOOT.EFI
cp -p /Volumes/OSBoot//usr/standalone/i386/boot.efi .

# SSH

pax -r -p e -z -f /Volumes/Mac\ OS\ X\ Install\ Disc\ 1/System/Installation/Packages/Essentials.pkg/Contents/Archive.pax.gz \
'./usr/bin/ssh*' \
'./usr/bin/scp' \
'./usr/bin/sftp*' \
'./usr/libexec/sftp-server' \
'./usr/libexec/ssh-keysign' \
'./usr/libexec/sshd-keygen-wrapper' ;
mv ./usr/bin/* ../Patchstick/ssh/.;
mv ./usr/libexec/* ../Patchstick/ssh/.;

pax -r -p e -z -f /Volumes/Mac\ OS\ X\ Install\ Disc\ 1/System/Installation/Packages/BSD.pkg/Contents/Archive.pax.gz \
'./usr/sbin/sshd' ;
mv ./usr/sbin/* ../Patchstick/ssh/.;

# Remove empty directories
rmdir ./usr/bin ./usr/sbin ./usr/libexec;

# Change permissions
chown -R root:wheel ./sbin ./ssh ./usr ../Patchstick/ssh;
chmod -R 755 ./sbin ./ssh ./usr ../Patchstick/ssh;