Monday, February 14, 2022

How to use automount in your iMac Monterey OS

 macOS Version: Monterey 12.1


Below are the steps if you want to use your iMac Automount functionality to auto mount remote file systems using SMB.


1. Login as one of your administrators in your iMac

2. Open its terminal and sudo to root

MyImac:~ MyAdminUser$ sudo -i

Password:

MyImac:~ root# 

3. Go to /etc directory and open a file called auto_master in vi

MyImac:etc root# cd /etc
MyImac:etc root# vi auto_master

4.   Add the bolded yellow line below in your auto_master file. You can change mysmb to any name you want, just make sure you use the same name as filename in step 5.

#

# Automounter master map

#

+auto_master            # Use directory service

#/net                   -hosts          -nobrowse,hidefromfinder,nosuid

/home                   auto_home       -nobrowse,hidefromfinder

/Network/Servers        -fstab

/-                      -static

/-                      mysmb    -nosuid,noowners

Save and exit vi once the line above is added. 

5. In /etc directory create a file called mysmb in vi.

   MyImac:etc root# vi mysmb

6. Now this is where things get a bit complex and very specific to Monterey in terms of syntax. After you upgrade to Monterey, you will only be able to mount inside /System/Volumes/Data/. Hence you should use the following syntax:

/System/Volumes/Data/./<mountpoint> -fstype=smbfs,<other options> ://<yournas_user>:<password>@<nashostname>.local/<nas_share>  

mountpoint: this can be just one directory level or you can have something like dir1/dir2/mountpoint

         for example:

/System/Volumes/Data/./mnt/mynas/locaFS1 -fstype=smbfs,soft,noowners,nosuid,rw ://mynasuser:password@mynas.local/nasShareFS1

/System/Volumes/Data/./mnt/mynas/locaFS2 -fstype=smbfs,soft,noowners,nosuid,rw ://mynasuser:password@mynas.local/nasShareFS2

Save and exit vi once you've added the entries you need. Given that you put the password in this file, you may need to secure it so that only root users can read it by changing its permission to 640

7.  Edit  your /etc/hosts and add your nas share hostname on it. Yes for some reason, Monterey automount doesnt work with IP addresses.

MyImac:etc root# vi hosts

8. Add your nas server IP address and hostname on it. Make sure that the hostname you used in this is the same as the one you used in step 6 above. 

For this example, add this line on your /etc/hosts

<yourNAS IP ADDRESS> mynas

 Save and exit.

9. Restart your automount daemon process

MyImac:etc root# automount -vc

automount: /System/Volumes/Data/home updated (/home -> /System/Volumes/Data/home)

automount: /System/Volumes/Data/mnt/mynas/locaFS1 updated

automount: /System/Volumes/Data/mnt/mynas/locaFS2 updated

automount: no unmounts

MyImac:etc root# 


To verify if things are working:

Goto  /System/Volumes/Data/mnt/mynas/locaFS1  and see if you can see the remote NAS contents and its getting mounted

MyImac:etc root# cd /System/Volumes/Data/mnt/mynas/locaFS1

MyImac:etc root# ls


Issuing df -k command will should show you these that shows automount was able to mount your remote file system by just going into the above directory:    

map du30                                                 0          0          0   100%          0          0  100%   /System/Volumes/Data/mnt/mynas/locaFS1

map du30                                                 0          0          0   100%          0          0  100%   /System/Volumes/Data/mnt/mynas/locaFS2

//mynasuser@mynas.local/nasShareFS1            1870324040  765511232 1104812808    41%  765511230 1104812808   41%   /System/Volumes/Data/mnt/mynas/locaFS1







 

 

Wednesday, April 1, 2020

Manually Scheduling your Mac Backups
(for macOS Sierra and later)

This will enable you to have flexibility to schedule and run your backups for your mac.


1.      Disable the automatic backups you have in your time machine preference window by unticking the Back Up Automatically checkbox.





2.     We need to configure Time Jobs using launchd, it’s the cron of MacOS for those that are familiar with Unix.  For more information on how to configure such jobs, see the man pages of launchd.plist.

To add a new backup job using launchd:

a.      Open a terminal session and switch to root user

sudo -i

<use your user admin password here that you used to login to your mac session)

b.      Go to /Library/LaunchDaemons and open a vi session and create your backup plist file with the contents below.

The below job will run every Sunday at 23:33 local time. You can adjust the date and time as per your preference.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
   <dict>
<key>Label</key>
<string>com.myimac.backup</string>
<key>ProgramArguments</key>
<array>
               <string>/usr/bin/tmutil</string>
               <string>startbackup</string>
               <string>--auto</string>
               <string>--block</string>
</array>
<key>StandardErrorPath</key>
<string>/var/root/timemachinebackup_err.log</string>
<key>StandardOutPath</key>
<string>/var/root/timemachine.log</string>
<key>StartCalendarInterval</key>
<dict>
               <key>Hour</key>
               <integer>23</integer>
               <key>Minute</key>
               <integer>33</integer>
                <key>Weekday</key>
                <integer>7</integer>
</dict>
   </dict>
</plist>

Save your file to a file ending in plist. It would help if it has the same as the Label string highlighted above.

com.myimac.backup.plist

c.      To schedule the above plist file  or backup job issue the following commands as root:

launchctl load /Library/LaunchDaemons/com.myimac.backup.plist

To check if it has been scheduled:

launchctl list | grep 'myimac'

Output:
-     0            com.giaimac.backup

To start your first backup job execution

launchctl start com.giaimac.backup

To check if its running

launchctl list | grep 'myimac'

Output:
94990        0            com.myimac.backup

       Or Open your Time Machine Preference and you will see there that the backup is running.

To Stop the said job from running in its scheduled time:

launchctl unload /Library/LaunchDaemons/com.myimac.backup.plist

You can further check the following sites for detailed information on  how to use schedule jobs in mac or use the launchctl command


Monday, March 30, 2020

How to compress your Time Machine backups that is on a network shared drive?

Compacting Time Machine File that is on a network shared drive. Do this after deleting the old backups from your time machine backups to reclaim the space the previous backups occupied.


  1. Dismount your time machine disk from Time Machine preference by selecting Remove Disk under Select Disk menu.

This is important to ensure nothing is accessing your time machine backup file. Else you will receive the "hdiutil resource temporarily unavailable" error when running the compact command. 

  1. To avoid the “hdiutil compact internal” error, ensure that the sparsebundle or your MAC backup file is not being accessed by anyone or anything. To do this, access the sparsebundle file in your NAS drive via Finder and mount it by clicking on it. Once it appears in your Finder  under Devices eject it manually. 

Sometimes it takes quite a few minutes (20-30 mins) for the sparsebundle file to be mounted after you click on it before you can eject it. If this happens, check the /var/log/fsck_hfs.log file and see if the mac is running fsck on the disk. Once its done, a window might appear saying nothing to be mounted, don’t worry and perform step 2  again.


3.     Using your user administrator account in your mac, open your Terminal Application and switch to root.

sudo -i

<enter your admin password when asked for password>

4.     Run the command below in your MAC Terminal screen after step 3 above. You can also run 'df -k' before you run the below command to compare your file system utilisation of your mac backup drive or location.

            hdiutil compact <fullpath of your sparesebundle file>

            Example:

               hdiutil compact /Volumes/MacBackup/MyImac.sparsebundle

            If you receive a “hdiutil resource temporarily unavailable”,
·       Make sure you have done step 1 above.
·       Make sure no processes is accessing the sparsebundle file even in your NAS storage.
·       Make sure you have the location of your sparsebundle file mounted in your MAC. For the case of the above example, make sure /Volumes/Macbackup is mounted in your MAC. To check this, issue “df -k” command.

      If you receive “hdiutil compact internal error”
·       Make sure you have done step 2 above properly.

       Once that is complete, you can issue 'df -k' and you'll see that the available space in your NAS Drive has increased. Now its time to attach back the newly compacted backup back to your time machine.

1. Open your finder and access the remote location where your sparsebundle is located. DO NOT mount or click at this time the sparsebundle. This step will ensure that you have mounted properly the remote file system where your sparsebundle backup file is located.     
2.  As the user administrator of your Mac, Open your Time Machine Preference and add back the remote disk you used previously. (Select Backup Disk)
3.     Quickly stop the impending backup by unchecking the Back Up Automatically check box.

4.     Open a terminal window and switch to root via 'sudo -i' command and issue this command once you are root

tmutil inheritbackup <your sparsebundle  full path file location>


For example:
           tmutil inheritbackup  /Volumes/MacBackup/MyMac.sparsebundle
           Attaching disk image...
           ** /dev/rdisk3s2 (NO WRITE)
           Executing fsck_hfs (version hfs-407.50.6).
           QUICKCHECK ONLY; FILESYSTEM CLEAN
          Claiming disk image for machine...
          Ejecting disk image...


5.     Go back to your finder in step 1 and Click on the sparsebundle file in Finder to mount it as a Time Machine drive. Normally MacOS will mount it under /Volumes/Time Machine Backups file system


6.     Issue the commands below (modify the associated command parameter to the latest backup)

tmutil associatedisk -a / <location of your latest backup in /Volumes/Time Machine Backups>

For example:

(take note of the spaces and the “\” before them, this is to “escape” them in mac os command line. To easily paste the below location to your Terminal window, from your Finder window, drag whe Macintosh HD folder in the Terminal window and it will give you the path naming convention below with "\")

tmutil associatedisk -a / /Volumes/Time\ Machine\ Backups/Backups.backupdb/MyImac/2020-03-30-010714/Macintosh\ HD 

(you can use alternatively the quoted version of the command above)

tmutil associatedisk -a / “/Volumes/Time Machine Backups/Backups.backupdb/MyImac/2020-03-30-010714/Macintosh HD”


7.     Wait for a few minutes then issue this command to check if your backups are now associated back to your time machine or restart your MAC

tmutil listbackups


8.     Reboot your mac so that you’ll see the updated information (without the -1 in their volume names)

9.     Run your Time Machine Backup to update your backup information in the Time Machine Preference window.