Linux

Old Macs - Linux Server 64bit on 32bit Boot

Introduction

Intel Core Solo and Core Duo processors are 32-bit and consequently Macs with these processors only are capable of booting in 32-bit mode as well as use 32-bit OSes.

Intel Core 2 Duo and Xeon processors are 64-bit, however most Macs with 64-bit processors released between 2006-2010 have a 32-bit EFI, and consequently, only are capable of booting in 32-bit mode. This is of particular disappointment , which despite having a powerful 64-bit processor no doubt has had its "working life" cut short by a 32-bit EFI. Looks like it is time for a life extension pill!

How to install a 64-bit OS on a 64-bit CPU with 32-bit Boot/EFI limited Macs? It requires some tweaks. But first let's check the specs of some of these old Macs. See if yours has a 64-bit CPU.

Check this page to see if your old Mac has a 32-bit CPU or a 64 one.

The Aim

We will be installing a 64-bit Linux distribution in one of these old Macs. The boot will done by a 3rd party boot firmware called rEFInd, that in turn will "call" a 32bit grub.efi that will boot our 64-bit Ubuntu Server distro. No UI will be needed, as this will run as a server. We can do anything we want in it over ssh. We will used a wired network, to make things simpler.

But we won't be covering any installation of software inside the system other the necessary daemons to share files (Apache/Samba). The main goal here is to get Ubuntu 64-bit going on this machine.

The Lab Rat

The lab rat for this will be a MacBook2,1 mid 2007, a.k.a. MB063LL/A. It has a Core2Duo 2.16 GHz Intel CPU with 4GB of DDR RAM (only 3GB is usable/available due to yet another firmware limitation - it is a pattern already), an average 500GB HDD 2.5", and some very well supported Intel ICH7/945GM Chipset/Video Card.

It will now be serving me audio and video as there is more than enough juice in it to run as a small server. Below is a picture of the handsome.

Requirements

  • An old Mac with a 64-bit CPU in it
  • Ubuntu's Net Install ISO (download the mini.iso)
  • rEFInd bootloader (download the binary zip file)
  • A CAT5 cable (with intrenets in it) - a.k.a wired connection
  • A 2GB USB flash drive (or bigger if you choose another ISO, like the DVD one)

We'll assume OSX is already installed in this machine, and it is the only system in it. We'll keep this OSX install as this will be a dual boot setup.

Partition Setup

This Mac's HDD is formatted with GUID Partition scheme, there is a hidden EFI partition of 200MB at the beginning of the disk (disk0s1/sda1). The rest of the HDD has the OSX's partition in it. There is no HD Recovery partition.

Add 1, 2 or 3 more partitions, depending on the desired scheme:

  1. One partition: a single linux partition without swap or data.
  2. Two partitions: Linux + swap (without data), or Linux + data (without swap)
  3. Three partitions: Linux + swap + data

We will go for #2, Linux + Data with no swap. For a small media server won't be a problem.

  • Boot up OSX and once it's done open Disk Utility.app located in /Applications/Utilities/

  • Select the OSX Partition in the left panel and click on Repair Disk, it will first check the file system integrity and if needed fix it.

  • Select the internal disk and click on the Partition tab

  • Add the partitions as needed. In the image below we've added two more. A small 20GB for the system, and the rest for the data partition where all the videos and audio will reside. For now set these new partitions as msdos type, we'll format them later during the system install.

  • Click Apply once you created the partitioning scheme.

Before

before

After

after

Preparing the USB flash drive

  • Insert the USB flash drive and using Disk Utility format the drive as GUID Partition Map and MSDOS (FAT) format

  • Copy the file mini.iso to the USB flash drive. We don't need to write the ISO to the USB with dd or anything. Grub will mount the ISO for us on the fly, so just copy the file to the USB flash drive.

Now lets mount the USB flash drive's EFI hidden partition and copy the contents of the file EFI32.zip in there. So place the EFI32.zip file on your desktop, open the Terminal.app and type the commands below.

diskutil list

Check first what partition needs to be mounted and in what disk this partition is on. In the example below the hidden EFI partition is disk1s1.

diskutil

cd ~/Desktop
mkdir usbefi
sudo mount -t msdos /dev/disk1s1 usbefi
unzip EFI32.zip
mv boot ~/Desktop/usbefi
mv EFI ~/Desktop/usbefi

The grub.conf located in the directory boot/grub has some 3 options on how to boot a Linux using rEFInd. You can edit this file as needed. We will use the first option, the Net Install .

After you're done editing grub.conf (if needed) unmount the EFI partition, either using Finder or in the Terminal:

sudo umount usbefi

If fails to unmount with umount, try:

diskutil unmount disk1s1

The USB flash drive is ready. The last step before the actual Ubuntu Server installation is to install rEFInd in order to boot the grubia32.efi present in the USB flash drive. This grub EFI file is the one that will start the 64-bit installation's kernel.

Installing rEFInd

The easiest way to install rEFInd is to install it to the root / of the Mac partition.

  • Extract the rEFInd zip file

  • Open the newly created folder and move the refind directory to the root.

  • Open this /refind folder and delete the 64-bit unnecessary files. drivers_aa64 drivers_x64 tools_aa64 refind_aa64.efi and refind_x64.efi

  • Rename the file refind.conf-sample to refind.conf

Open the refind.conf file and read it. It is well commented. For now the default config will do.

When you finish setting up the /refind folder it will look like this:

/refind

drivers_x32/

icons/

refind_ia32.efi

refind.conf

tools_ia32/

Now it is time to bless rEFInd's bootloader, so on the next boot instead of booting right into OS X we will get a boot menu, from which we can select the gruia32.efi that we copied to the USB flash drive.

So open Terminal.app and type:

sudo bless --setBoot --folder /refind --file /refind/refind_ia32.efi --shortform

Booting up the installation

Seems that we are done setting up things! Insert the USB flash drive into the old Macbook, and reboot/power-on.

The rEFInd menu will show up. Select an option by using the left or right arrows.

If you see more than one Linux boot option, it is ok. The one we want is the grubia32.efi one. Select an option and press F2, look for EFI/grubia32.efi. Esc to go back. Enter to boot.

Installing

  • Select Language Country Layout etc

  • Select the wired network device

  • Choose a hostname mirror username password etc. These are pretty standard installation things so etc will suffice. :o)

  • Best not to encrypt the home directory, it's a home media server.

Partitioning Disks

  • Select Manual and press Enter

  • The internal HDD should now be sdb. So scroll down to the 20GB partition we've created earlier and press Enter

  • Press Enter and type a name for it

  • In Use as select Etx4

  • In Mount Point select /

  • Scroll down to Done setting up the partition and press Enter

Done with the root partition. Now let's configure the media one.

  • Select the other bigger Data media partition we created earlier and press Enter

  • Type in a name for it, and in Use as select Ext4 (if you want to access from OS X select MSDOS or HFS, not really my case.

  • In Mounting point select Enter manually and type in /mnt/media

  • Scroll down to Done setting up the partition and press Enter

  • Scroll down to Finished partitioning and write changes to disk and press Enter

  • Next question is about the "missing" swap partition, just say No to it, then Yes to write to the disk.

The actual installation will now begin.

Updates

Automatic updates is a personal thing. I rather update the system manually.

  • If you want to setup and forget best to check Install security updates automatically

Software Selection

No need to install Basic Ubuntu Server LAMP or change anything, other than sshd. We'll use it to control and maintain the server remotely.

  • Select OpenSSH Server press spacebar to check it. Press TAB and then Continue

Finish the Installation

If you plan booting back and forth between Linux and OSX select No to UTC clock, if Linux 24/7 is the intention select Yes

Fixing Up Grub and rEFInd

Because we booted the install from the ISO file sda and sdb got switched during the install, and grub was actually installed to "sda" the USB flash drive. So reboot the machine but do not remove the flash drive.

You'll get the grub menu, and boot into Ubuntu. The frame buffer was misbehaving with this machine, freezing. If so press FN + OPTION + F2 to switch to another TTY and then back to FN + OPTION + F1, or simply stay at TTY2.

Login with the username and password you choose in the installation and at the prompt type:

grub-install /dev/sda
update-grub2

Now reboot and remove the USB flash drive. The system will not show rEFInd menu because we just reinstalled grub to the drive.

If you wish to use it as a server only, no need for rEFInd anymore, proceed to the next step.

If you wish to dual-boot with rEFInd reboot the Mac and press OPTION right away. A HDD with name EFI Boot will be the only option, press enter.

  • The rEFInd menu will show, boot into OS X

  • Open System Preferences and go to Startup Disk

  • Select the hard disk and click Restart

  • Now it will boot directly into OS X. When finishes to boot open the Terminal.app and rebless the rEFInd efi file. Type:

    sudo bless --setBoot --folder /refind --file /refind refind_ia32.efi --shortform
    sudo reboot
    

Now everything is starting to look good. The rEFInd bootloader is the default one and there are 3 options, 2 Ubuntu and one OS X. We'll fix that dupe soon

Just bewared that if you reset the NVRAM it will revert back to grub. You can always press OPTION at boot redo the steps above to revert it back to rEFInd.

Daemons and Tweaking

The system is installed, and the proposed task was accomplished: a 64-bit OS running on a 32-bit Boot old Mac.

I'll simply go on to install a simple SMB (samba) server so I can access the videos and audios from the network. I'll also setup a HTTP server, in case I want to access any data from outside my network.

I'll also fix some other things. So let's star with these minor little tweaks.

Setting Up Static IP

It is best to set a static IP address to the server, this way the server's IP won't change when other devices connect to the network.

I'll do this remotely over SSH, you can do it locally (logging and using the physical Mac). First let's login into the Mac and find out what IP it is using. So login with your password and:

ifconfig

So we can see the the IP 192.168.1.22 below in the output, and we also can see the interface name enp1s0.

enp1s0    Link encap:Ethernet  HWaddr 00:1b:63:36:5f:62  
          inet addr:192.168.1.22  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21b:63ff:fe36:5f62/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:234 errors:0 dropped:0 overruns:0 frame:0
          TX packets:109 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:25153 (25.1 KB)  TX bytes:16849 (16.8 KB)
          Interrupt:16

You can go to your other Mac, Linux or Windoze and connect to that IP via SSH:

e.g. ssh the_user@the_IP

ssh user@192.168.1.22

Now lets edit the config file and setup a static IP. Type:

sudo nano /etc/network/interfaces

The file should have something like this for primary interface:

# The primary network interface
auto enp1s0
iface enp1s0 inet dhcp

Edit the file and add something like:

# The primary network interface
auto enp1s0
iface enp1s0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4

The above settings may be different for you, all depends on how your network is setup, but this should provide a basic template from where to start.

The dns-nameservers is required to resolve dns names. These above are Google's nameservers.

Onde you're done editing the file press CTRL + O to write to the file and CTRL + X to exit.

Reset the interface with:

sudo ifdown enp1s0 && sudo ifup enp1s0

It will lag a bit while the network interface is reseting, after that exit the SSH shell with:

exit

And reconnect to the new IP:

ssh user@192.168.1.100

If works, hooray, now the IP will be always the same. If did not work, login locally and check the settings, try the settings by reseting the iface down and up again with ifdown and ifup.

Removing Ubuntu Splash Screen

By default when the Ubuntu system boots it shows a nice graphic called Plymouth. I don't want nor need that. I want to see all the info about the system booting up and about the daemons.

To remove the splash screen we'll need to edit the grub file that resides inside the /etc/default/ directory. To edit type:

nano /etc/default/grub

Find this line:

GRUB_CMDLINE_LINUX_DEFAULT="splash quiet"

And change it to:

GRUB_CMDLINE_LINUX_DEFAULT=""

Press CTRL + O to write and CTRL + X to quit. Update grub with:

update-grub2

Next boot we will see the output from the kernel and modules, not the Plymouth splash screen. Also no more TTY freezing bugs. Boots right to ubuntu login:.

Brightness of The Screen

Its my guess that this server will sit in a room, or living room and not in a hack hidden in a little room. So the brightness of the screen can be annoying sometimes.

It is not possible to change the time it takes to shutdown the screen without recompiling the kernel, as this value is baked into the kernel. But we can dim the brightness of the screen up and down.

List this directory:

/sys/class/backlight/

Should be one directory inside with the name of your video card, list that one and look for a file called brightness. Mine is located at:

/sys/class/backlight/intel_backlight/brightness

I also have a:

/sys/class/backlight/intel_backlight/max-brightness

148 is the max brightness this Mac and by trial 20 is the last step before it shuts down. Just echo any number from 0 to the max into the brightness file:

echo "20" > /sys/class/backlight/intel_backlight/brightness

Setting Up The Media Partition

First let's change the mounting point for the data partition. /mnt/media is ok, but we could change that. So let's make it /media. Create the directory and set its permissions so we can write in it.

sudo mkdir /media
sudo chmod -R g+rw /media
sudo chown -R :1000 /media

1000 is my user's group id, you can find what id your user/group has by issuing a command id. Now we should be able to write to it. Now unmount the partition so we can edit the /etc/fstab file and change the mounting point:

sudo umount /mnt/media

Now let's edit the /etc/fstab file.

sudo nano /etc/fstab

Change this line:

UUID=e93b2d68-2d83-4700-aefe-fd1a5c96c1e0 /mnt/media      ext4    defaults      0       2

To this:

UUID=e93b2d68-2d83-4700-aefe-fd1a5c96c1e0 /media      ext4    defaults      0       2

Save it with CTRL + O and exit nano with CTRL + X, and remount the partition:

sudo mount /media

Installing Samba

To Access /media From Another PC we'll install samba, that provides smb access. Update the apt packages and then install samba:

sudo apt-get update
sudo apt-get install samba

samba uses it's own set of passwords, so set a password for your user by entering the command below. To make it simpler, just use the same password you've set to your linux user account. Change YOU to your username:

sudo smbpasswd -a YOU

We need to configure the share. To do that edit the following file:

sudo nano /etc/samba/smb.conf

The file is full of comments, that I advise you to read it and try to understand them. But to make things easier below is my configuration file:

[global]
workgroup = WORKGROUP
server string = %h server (samba, Ubuntu)
wins support = yes
security = user
log file = /var/log/samba/log.%m
max log size = 1000
panic action = /usr/share/samba/panic-action %d
server role = standalone server
obey pam restrictions = yes
unix password sync = yes
pam password change = yes
map to guest = bad user
usershare allow guests = no

[Media]
comment = Media Server
available = yes
path = /media/
browsable = yes
writable = yes
guest ok = no
read only = no
valid users = YOU
force group = users
create mask = 0660
directory mask = 0771

This alone should make the share work. Remember to change "YOU" and type your linux username. But it best to take a look at the rest of options inside this file. Now save it, quit nano and restart samba:

sudo service smbd restart

Check samba's configuration file integrity by issuing a:

testparm

The samba (SMB) share should now be operational. Test it connecting either from a Mac, Windoze or another Linux.

Testing Samba Connectivity

Connect using your Linux's username and the password we've just set for samba's user.

To connect using Windoze open any Windows Explorer window and type in the address bar:

\\192.168.1.100\media

To connect using Macs, with Finder active press CMD + K and enter:

smb://192.168.1.100/media

Linux users will have to install a samba client. I'll not cover this.

Now you can copy your media files to the /media directory in the server. And access them from other smb capable devices.

Installing Apache

This is our final step. By installing Apache, you can easily access the media folder from outside your local network. To make this happen you need to be able to forward some router port to the server's apache port (80). We'll not cover that, google for your router's name and "port forwarding".

We won't be installing SQL or PHP. All we want is to access the files inside /media.

Some internet providers block the default port 80, also this port is a target for scanners looking for vulnerabilities. So the safest way is to forward another higher port to the server's default 80. Ports go up to 65535, for this exercise we'll use port 40404.

The layout will be:

Internet ---> Router's port 40404 ---> Server's port 80

From outside the home network you can connect forcing the browser to connect to a non-default port, like this:

http://your.ip:40404

Install Apache2:

sudo apt install apache2

Test the install by accessing http://192.168.1.100 or whatever IP you have set for the server. It should be working already, but let's configure a few things, so edit the config:

sudo nano /etc/apache2/apache2.conf

Change this:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

To this:

<Directory /media/>
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    AllowOverride None
    Require all granted
</Directory>

CRTL + O to write to the file and CTRL + X to quit. Now lets edit the 000-default.conf file:

sudo nano /etc/apache2/sites-enabled/000-default.conf

Delete everything and paste this inside:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /media
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory "/media">
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/htpasswd.conf
    Require valid-user
    </Directory>
</VirtualHost>

CRTL + O to write to the file and CTRL + X to quit. Reload the apache2 daemon:

sudo service apache2 restart

Reload the http://192.168.1.100 to check if you are listing the /media directory.

Setup HT Access Security

Lets setup a .htaccess file to provide some sort of security verification to access files. Type:

sudo htpasswd -c /etc/apache2/htpasswd.conf A-USER-NAME

If you don't want a password skip the command above and remove the following lines from the 000-default.conf:

<Directory "/media">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/htpasswd.conf
Require valid-user
</Directory>

Finish!

Well this is it. Now we've turn that old Mac into a home server. Enjoy your new server!

If you have any questions, you are welcome to Google it. All these are vastly covered subjects. Here are some links that might help: