Gih's Blog

只言片语
Posts tagged as mac

Speeding up fsck on the disk of TimeMachine

2014-09-06 by gihnius, tagged as mac

Why fsck?

Sometimes the file system get corrupted and hence you may unable to boot your system. In such case you will need to repair the corrupted file system. In Linux you can repair it using fsck command. In windows we have command chkdsk. In OSX we have "fsck", "fsck_hfs".

There are several reasons behind the file system corruption. For example, improper shutdown, suddenly cut off the power supply, a storage device was removed when system is in process to write the data on it, accidental system file deletion and viruses can cause file corruption and unstable system. Some file corruptions are less harmful and user can continue working. However it is important to run a “fsck” once in a while as a practice.

Why time machine?

Time Machine is Apple's built-in backup solution for OS X that creates hourly backups of all files on the system. It takes many snapshots of your local drive, copies many millions of files to the backup disk volume.  By default, Checking the time machine disk volumes with Disk Utility,  can be painfully slow, taking many hours or days to complete, if it completes at all.

How?

Find the time machine disk, open Terminal.app, type diskutils list, find the line contains Apple_HFS YOUR_DISK_NAME, get the device name from the last column below IDENTIFIER, for example, disk3, disk4...

Run fsck_hfs with 2G memory cache:(adjust less than the system memory)

sudo fsck_hfs -f -y -c 2g /dev/disk3

The key is to increase the size of the cache used by fsck_hfs. see more from manual:

-c size Specify the size of the cache used by fsck_hfs internally.  Bigger size
        can result in better performance but can result in deadlock when used
        with -l option.  Size can be specified as a decimal, octal, or hexadec-
        imal number.  If the number ends with a ``k'', ``m'', or ``g'', the
        number is multiplied by 1024 (1K), 1048576 (1M), or 1073741824 (1G),
        respectively.

Learn about using Disk Utility to verify or repair disks.

A custom power management settings

2014-08-14 by gihnius, tagged as mac

pmset is a command line tool that apple has bundled in their OS X operating system. Its purpose is to display and/or modify the power management settings. Here is a modified settings in order to: 1. Save battery power as much as possible; 2. let you return to work as soon as possible.

battery mode (pmset -b)

Write the hibernation image to disk and powering off memory for Standby after 6 hours.

pmset -b standbydelay 21600

Sleep after 10 minutes idle.

pmset -b sleep 10

Spindown disk after 30 minutes idle.

pmset -b disksleep 30 

Set hibernatemode to 3. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from disk image.

pmset -b hibernatemode 3

Turn down display after 5 minutes idle.

pmset -b displaysleep 5

Poweroff after 8 hours to save power.

pmset -b autopoweroffdelay 28800

charger mode (pmset -c)

In charger mode, I would like to change hibernatemode to 0.  So that the system can be waked up quickly. In this mode, the system will not back memory up to persistent storage. The system must wake from the contents of memory, the system will lose context on power loss. 

pmset -c hibernatemode 0

Standby, the manual said, standby only works if hibernation is turned on to hibernatemode 3 or 25. Here I set it the same as battery mode

pmset -c standbydelay 21600

Sleep after 10 minutes idle.

pmset -c sleep 30

Turn down display after 10 minutes idle.

pmset -c displaysleep 10

Spindown disk after 60 minutes idle.

pmset -c disksleep 60

Poweroff after 12 hours to save power.

pmset -c autopoweroffdelay 43200

Show custom settings for all power sources (pmset -g)

pmset -g custom

Put together and save to a script.

#!/bin/sh

## battery mode
pmset -b standbydelay 21600
pmset -b sleep 10
pmset -b disksleep 30
pmset -b hibernatemode 3
pmset -b displaysleep 5
pmset -b autopoweroffdelay 28800
## charger mode
pmset -c standbydelay 21600
pmset -c sleep 30 
pmset -c hibernatemode 0
pmset -c displaysleep 10
pmset -c disksleep 60
pmset -c autopoweroffdelay 43200

pmset -g custom

for more detail about pmset, please check out the manual page of pmset by man pmset.

tested on osx 10.8 - 10.9.4