Linux

Old Macs - Linux Server 64bit on 32bit Boot

Introduction

Some 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 such a disappointment! Despite having a powerful 64-bit processor no doubt has had its "working life" cut short by a 32-bit EFI.

How to install a 64-bit OS on a 64-bit CPU with 32-bit Boot/EFI Mac? It requires some tweaks.

First check these old Macs specs and see if yours has a 64-bit CPU: Old Intel Macs CPU/EFI Specs

The Aim

Install a 64-bit Linux distribution in one of these old Macs and turn it into a home media server. We'll use a 3rd party boot firmware called rEFInd. rEFInd will then load 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. To make things simpler and faster we'll setup a wired network.

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 are available due to yet another firmware limitation), an average 500GB HDD, and a very well supported Intel ICH7/945GM Chipset/Video Card.

There is more than enough juice in it to run as a small server and t will now be serving me audio and video.

Requirements

We're assuming OSX is already installed in this machine and it is the only system in it. We'll keep this OSX install.

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 audios will reside. For now set these new partitions as MSDOS type, we'll format them later.

  • Click Apply once you created the partitioning scheme.

Before

before

After

after

Preparing the USB drive

  • Insert the USB drive in and using Disk Utility format the disk MSDOS (FAT) format. Click on the Options button and change it to GUID Partition Map. Apply!

  • Copy the file mini.iso to the USB 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 drive.

Mount the USB drive's EFI hidden partition and copy the contents of the file efi32.zip in there. We need to identify the EFI partition , so open the Terminal.app and list the devices attached to the computer:

diskutil list

In the example below the hidden EFI partition is disk1s1.

diskutil

Now extract and copy the efi32.zip contents in the EFI partition

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

The grub.conf located in the directory boot/grub has 3 options. You can edit this file as needed. We will use the Install ISO Net-Install option. That will mount and boot the mini.iso.

After you're done editing grub.conf (if needed) unmount the EFI partition:

sudo umount usbefi

If fails to unmount with umount try:

diskutil unmount disk1s1

The USB 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 drive.

Installing rEFInd

The easiest way to install rEFInd is copy the program folder to the root / of the Mac's system 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 well commented refind.conf file and read it. I've set mine booting the Ubuntu as default with 0s timeout. But for now the default config will do.

If you're interested in rEFInd theming take a look at these exquisite rEFInd themes.

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

/refind

drivers_x32/
icons/
refind_ia32.efi
refind.conf
tools_ia32/

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

Open Terminal.app and type:

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

Booting up the installation

Insert the USB drive into the old Macbook, and reboot/power-on.

rEFInd menu will show up, select an option by using the keyboard's left/right arrows.

It is ok if more than one Linux boot option shows up. The one we want is the grubia32.efi one, so select an option and press F2, look for EFI/grubia32.efi. Press Esc to go back and Enter to boot.

Installing

  • Select Language, Country, Layout, etc

  • Select the wired network device

  • Choose a hostname, mirror, username, password, etc.

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

Partitioning Disks

  • Select Manual and press Enter
Root Partition
  • 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

Media Partition
  • 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.

  • 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

Select only sshd. No need to install Basic Ubuntu Server LAMP or change anything else now. Just 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 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 update grub. At the prompt type:

sudo grub-install /dev/sda
sudo update-grub2

Shutdown the system by typing:

sudo shutdown -h now

Remove the USB drive and turn the Macbook back on. 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, jump to Daemons and Tweaking.

If you wish to dual-boot with rEFInd do this:

  1. Reboot the Mac and press OPTION right away. A HDD with name EFI Boot will be the only option, press enter.

  2. The rEFInd menu will show, boot into OS X

  3. Open System Preferences and go to Startup Disk

  4. Select the hard disk and click Restart

  5. It will boot directly into OS X. When finishes to boot open the Terminal.app and rebless the rEFInd efi file by typing:

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

Finally, the rEFInd bootloader is the default one and there are 3 options, 2 Ubuntus and one OS X. We'll fix that dupe soon

Note Bewared that if you reset the NVRAM it will revert back to grub. You can always press OPTION at boot and rebless rEFInd's efi.

Setting Up Static IP

Edit the interfaces file:

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.

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

And try to connect to the new IP from another machine:

ssh user@192.168.1.100

If works the network is setup. If not, review the settings!

Removing Ubuntu Splash Screen

By default when the Ubuntu system boots it shows a nice graphic called Plymouth. We don't want nor need that.

If you like to remove the splash screen edit the grub file that resides inside the /etc/default/ directory:

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 nano. Update grub with:

update-grub2

Next boot we will see the output from the kernel and modules, not the Plymouth splash screen.

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 for this Mac and 20 is the lowest value 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 match 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 should make the share work, so press CTRL+O to save the file and CTRL+X to quit nano, then restart samba:

sudo service smbd restart

Check samba's configuration file integrity by issuing:

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 it.

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

    \192.168.1.100\media

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

    smb://192.168.1.100/media

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

You can copy your media files to the server's /media directory and access them from any smb capable device.

Installing Apache

Installing Apache we can easily access the media folder from outside the 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".

It will also be possible to access these files from any browser inside the intranet.

We won't be installing SQL or PHP. All we want is access to the files inside /media and SMB and HTTP are more than enough.

Note that some internet providers block the default http port 80, also this port is a target for scanners looking for vulnerabilities. The safest way to go is to forward another port to apache's port. Ports go from 1 up to 65535. For this exercise we'll use port 40404.

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

Connect to a non-default portlike this:

http://myservers.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 lets edit the Apache's 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
</VirtualHost>

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

sudo service apache2 restart

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

Setup Apache's HT Access Security

If you want a password authentication over http then edit the 000-default.conf file like this:

<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>

Create a htaccess user and password authentication by typing:

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

Finished!

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:

 

© 2019 Mteam7 Network. All rights reserved.