Notes‎ > ‎

Useful Linux Tricks on Macbook

posted Jul 19, 2011 8:33 AM by Amol Kolhe   [ updated Jul 20, 2011 6:59 PM ]
Parts of this section are specific to Ubuntu on a macbook. I have also used some of these tricks on a EEE netbook, but they might not work for others. Many of them are specific to the macbook hardware (mine is macbook 4,1) and the software used with specific versions of Ubuntu.

I do not like Ubuntu's GUI interface, it is too tightly coupled with Gnome and (is in my opinion quite sluggish and packs lot of junk which could be avoided/disabled), but Ubuntu remains my Linux Distro of choice, because it is well tested on a wide array of hardware and mostly works out of the box. In fact, on 11.04 (64 bit), every piece of hardware on my macbook worked beautifully including Wifi using WPA2. Similar experience with 10.10 on a EEE Netbook. If I start with a more minimal distro like Ubuntu Server or Debian or FreeBSD, it is a lot of work setting up each piece of hardware and software. So I like to start with a fresh install of Ubuntu and reverse-engineer it to my liking.


ng 

Disable X-windows from Startup

On Ubuntu, I've found it quite difficult to disable X-windows from startup. The simplest and guaranteed way of accomplishing this is by removing GDM. I dislike gdm the same reasons I dislike Gnome. I usually use linux as a lean-mean alternative to boot into and surf the net or boot into command line and run scripts. I don't need a full blown desktop in linux. Gnome and Gdm are overkill for that, and I feel they are sluggish (especially gnome). 

Following command will have horrible consequences on your Gnome setup so if you're unsure, then don't execute it.
sudo apt-get -y purge gdm

Installing Fluxbox

sudo apt-get -y install fluxbox

Using startx to start GUI

The startx script checks the user's home directory for the file .xinitrc, to determine what window manager to use. On a new install, this file is missing, and by default, the system wide default window manager will be started. And if you removed gdm, this might not go very well. To override this behavior and start Fluxbox for instance, following step is needed.

echo startfluxbox > ~/.xinitrc

Now to start X-windows, just run
startx


Allow non-root user to shutdown/restart

Add a group for shutdown/halt/reboot and add your user(s) to it. Allow this group to execute sudo reboot/halt/shutdown without typing password and then alias the restart commands with alternate versions with sudo built in.

sudo groupadd shutdown

sudo vi /etc/group                #Add your user to the grouping
shutdown:x:1001:amol

sudo vi /etc/sudoers            #Add the following lines
shutdown ALL=(ALL) NOPASSWD:/sbin/shutdown
shutdown ALL=(ALL) NOPASSWD:/sbin/halt
shutdown ALL=(ALL) NOPASSWD:/sbin/reboot

vi ~/.profile
alias reboot="sudo /sbin/reboot"
alias halt="sudo /sbin/halt"
alias shutdown="sudo /sbin/shutdown"

Once all of the steps are done, restart shell, and you should be able to restart your system without ever typing a password.

Changing Screen Brightness from Command line

On a macbook, this can be done by editing the file /sys/class/backlight/mbp_backlight/brightness and putting in a value between 1 and 15, 1 being the least bright and 15 being most bright. If you're trying this on any other hardware, you might need to find the correct path for yous.

I  wrote a script to quickly and easily do so from command line. You can grab it from the attachment section below. I use the same script from X-windows by assigning keyboard shortcuts (to match my laptop's brightness keys). 

Usage: sudo /sbin/brightness [+ - or a value between 1 and 15]
Example:
sudo /sbin/brightness +
sudo /sbin/brightness -
sudo /sbin/brightness 9

Getting Macbook's Brightness Keys to work in Fluxbox

Macbooks has F1 key mapped to decrease Brightness and F2 key mapped to increase Brightness (without pressing the Fn key). F1 and F2 (without Fn) corresponds to Key codes 232 and 233 respectively. You can find this by using the command xev and pressing each key.

Copy the brightness script mentioned above in /sbin or use your own script.

vi ~/.fluxbox/keys    # Add the following lines
232 :Exec sudo /sbin/brightness -
233 :Exec sudo /sbin/brightness +

There is one more thing before above keys will work. Sudo command promps for password, so the shortcut won't really work. To bypass this do the following
sudo groupadd brightness
sudo vi /etc/group            #Add your user to group brightness
brightness:x:1002:amol

sudo vi /etc/sudoers        #Add the following line
brightness ALL=(ALL) NOPASSWD:/sbin/brightness

Restart Fluxbox.

Samba/CIFS/Windows Share

Install samba/CIFS compatibility package
sudo apt-get -y install smbfs

Check if the mount works:
sudo mkdir -p /mnt/samba
sudo chown amol:amol /mnt/samba
sudo mount -t smbfs //MyBookWorld/public /mnt/samba

Where MyBookWorld is the Hostname/IP Address of the Sharing Server and public is the shared path.
Once above works, you should be able to browse, the remote file system from Terminal or File Browser. To auto-mount on system start-up add it to fstab
sudo vi /etc/fstab # Add the following line in the end
//MyBookWorld/public /mnt/samba smbfs username=guest,uid=amol,gid=amol 0 0


Č
ċ
ď
brightness
(1k)
Amol Kolhe,
Jul 19, 2011 9:06 AM