Thursday, January 17, 2019

Cannot Eject USB Drive on Windows

It has frustrated me a great deal that I sometimes cannot eject USB drives on Windows. What really worked for me is the answer this superuser thread. The answer for me isn't to use the Sysinternals tools, and questionable 3rd party tools like unlocker. Rather, the answer is to use the Windows Event Viewer as pointed out by an answer in the thread. In my case, what has prevent the USB drive from being ejected is the Windows Task Manager, and I am not alone!

Tuesday, January 15, 2019

Replacing Corrupt Hard Drive for FreeNAS

An ATA hard drive can fail without being detected by the SMART system in time. At a FreeNAS 11 system I observe when this happens, the drive disappears from the zpool disk list while FreeNAS reports an alert typically like the following,


The volume MyZpool state is DEGRADED: One or more devices has been taken offline 
by the administrator. Sufficient replicas exist for the pool to continue 
functioning in a degraded state.

Since the disk drive disappears from the zpool disk list, the method to replace the disk drive in the FreeNAS guide won't work -- after you replaced the corrupted hard disk drive, if you bring the disk drive online, the disk will be "UNAVAIL"; and if you attempt to replace it via the FreeNAS's Web interface, there will be no disk for you to choose from. If you run "zpool status", you will observe a long sequence of digits instead of the partition as the following example:

$ zpool status
  pool: MyZpool
 state: DEGRADED
status: One or more devices could not be opened.  Sufficient replicas exist for
        the pool to continue functioning in a degraded state.
action: Attach the missing device and online it using 'zpool online'.
   see: http://illumos.org/msg/ZFS-8000-2Q

config:

        NAME                                            STATE     READ WRITE CKSUM
        MyZpool                                         DEGRADED     0     0     0
          raidz2-0                                      DEGRADED     0     0     0
            gptid/11111111-2222-3333-4444-555555555555  ONLINE       0     0     0
            gptid/22222222-2222-3333-4444-555555555555  ONLINE       0     0     0
            99999999999999999999                        UNAVAIL      0     0     0  was /dev/ada2
            gptid/33333333-2222-3333-4444-555555555555  ONLINE       0     0     0
            gptid/44444444-2222-3333-4444-555555555555  ONLINE       0     0     0
            gptid/55555555-2222-3333-4444-555555555555  ONLINE       0     0     0

errors: No known data errors

  pool: freenas-boot
 state: ONLINE
  scan: scrub repaired 0 in 0 days 00:10:03 with 0 errors on Tue Jan 15 03:55:03 2019
config:

        NAME        STATE     READ WRITE CKSUM
        freenas-boot  ONLINE       0     0     0
          da0p2     ONLINE       0     0     0

errors: No known data errors


The method to resolve this is via command line. Below is the steps starting from replacing the physical hard drive.

  1. Replace the physical hard drive. For this, shutdown the machine if necessary. 
  2. Partition the hard drive. Following is an example where we assume the disk is /dev/ada2.
    
    # create gpt called ada2
    sudo gpart create -s gpt ada2
    # create a 2G swap partition (it will be ada2p1)
    sudo gpart add -i 1 -b 128 -t freebsd-swap -s 2G ada2
    # create a second partition using the rest of the space (it will be ada2p2)
    sudo gpart add -i 2 -t freebsd-zfs ada2
    # replace disk labeled "99999999999999999999" by ada2p2. See the error message example above. 
    sudo zpool replace MyZpool 99999999999999999999 ada2p2
    

Once the above is completed, FreeNAS will immediately start resilvering the zpool.

Wednesday, December 12, 2018

Pushing Git Repositories to Multiple Remotes

According to this post, we configure as follows,


git remote add all URL_1
git remote set-url --add --push all URL_1
git remote set-url --add --push all URL_2
...
git remote set-url --add --push all URL_N

To push to the N remotes, do,

git push all

Saturday, December 8, 2018

Windows Device Guard and Credential Guard

I enabled Windows Device Guard and Credential Guard at a windows 10 host. The result was that VMWare Player/Workstation and VirtualBox ceased to work. For instance, VMWare Player complains,


VMware Payer and Device/Credential Guard are not compatible. 
VMware Player can be run after disabling Device/Credential Guard.

The error message also provided a URL to a VMWare Knowledge Base article. Following the article, the best solution is actually to use the Windows Defender Device Guard and Windows Defender Credential Guard hardware readiness tool to disable the Device and Credential Guard. The tool is distributed as a zip archive. Having extracted it, we simply issue the following command in the PowerShell session,


DG_Readiness_Tool_v3.6.ps1 -Disable -AutoReboot

You may revise the above command to match the version of the tool downloaded.

Monday, December 3, 2018

Example of Using tcpdump for Capturing and Showing Frame Content

This is just a quick note on an example of using tcpdump.

To capture packets whose TCP or UDP port number is 112233 via interface eth0, and save the captured packets to file packet.cap, we run,

sudo tcpdump -i eth0 -w packet.cap port 112233

To examine the content of the captured the frames including full data-link layer header and payload in the packet.cap file, we run,

sudo tcpdump -nn -xx -XX -r packet.cap

Wednesday, November 28, 2018

CTRL-C Stopped Working on Linux Terminal

I remotely logged in a CentOS 7.5 box via PuTTY. However, somehow, CTRL-C stopped working. It turns out that CTRL-C was being trapped, which we could examine using the trap command, e.g.,


trap -- '' SIGINT
trap -- '' SIGQUIT
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU

To remove CTRL-C, i.e., SIGINT from this list, we can issue a command,

trap - SIGINT

which can be placed in the shell's profile, e.g., for bash, in $HOME/.bash_profile.

Installing pdftk in Ubuntu 18.04 Bionic

The pdftk package is reported missing from Ubuntu 18.04 Bionic. To me, the easiest way to install it out of a few suggested methods is as follows,



sudo snap install pdftk


Read more about snap here.