Determining SSD Approximate Remaining Lifespan

I couldn’t find anything readily available that was trustworthy or free to determine the lifespan of an SSD. MTBF isn’t very useful as on-time doesn’t wear down like hard disks do. The next best thing is to get the total amount of bytes written to the drive and compare it with benchmark values, from torture tests (write until dead) in particular, that others have done and published.

The total bytes written is recorded within the SMART database of the drive. SmartMonTools is needed to read it. It is cross-platform and free.

Once installed, start CMD as an administrator (assuming Windows).

C:\WINDOWS\system32>smartctl -a /dev/sda
smartctl 6.5 2016-05-07 r4318 [x86_64-w64-mingw32-win10] (sf-6.5-1)
Copyright (C) 2002-16, Bruce Allen, Christian Franke,

Device Model: Crucial_CT525MX300SSD4
Serial Number: 16441483025B
LU WWN Device Id: 5 00a075 11483025b
Firmware Version: M0CR031
User Capacity: 525,112,713,216 bytes [525 GB]
Sector Size: 512 bytes logical/physical
Rotation Rate: Solid State Device
Form Factor: < 1.8 inches
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: ACS-3 T13/2161-D revision 5
SATA Version is: SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Tue Nov 29 23:36:05 2016 PST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

SMART overall-health self-assessment test result: PASSED


SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
 1 Raw_Read_Error_Rate 0x002f 100 100 000 Pre-fail Always - 0
 5 Reallocated_Sector_Ct 0x0032 100 100 010 Old_age Always - 0
 9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 3
 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 8
171 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0
172 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0
173 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 1
174 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 4
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always - 0
184 End-to-End_Error 0x0032 100 100 000 Old_age Always - 0
187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 0
194 Temperature_Celsius 0x0022 066 042 000 Old_age Always - 34 (Min/Max 28/58)
196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0
197 Current_Pending_Sector 0x0032 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0030 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x0032 100 100 000 Old_age Always - 0
202 Unknown_SSD_Attribute 0x0030 100 100 001 Old_age Offline - 0
206 Unknown_SSD_Attribute 0x000e 100 100 000 Old_age Always - 0
246 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 266902214
247 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 8350815
248 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 352002
180 Unused_Rsvd_Blk_Cnt_Tot 0x0033 000 000 000 Pre-fail Always - 1932
210 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0

We are concerned with three numbers:

  • reallocated sector count
  • sector size – 512
  • total LBA blocks written – 266902214 (in this case, it wasn’t labelled as such; in general, it’s the largest number)

If there are any reallocated sectors, that is bad news as it generally means the drive is on its last legs. Otherwise it can be considered a healthy drive. Multiplying the two numbers yields the total data written in bytes: 512 x 266902214 = 136653933568 bytes or about 127 GB

Referencing various sources on endurance testing, a TLC 240GB drive starts to degrade after 100-1000TB of writes depending on the make. There’s a wide range depending on the generation of technologies (SLC, MLC, TLC) and controllers used.

With the numbers from my SSD, pessimistically, its life is at 127GB / 100TB or 0.1%.

Posted in Uncategorized | Leave a comment

Sony Vaio Pro 13 Disassembled

There aren’t any high resolution images of the Sony Vaio Pro 13 internals, so I thought I would post them since the fan started making rattling noises. One of the reasons I discovered the fan developing the noise is that theĀ fan actually draws air from the air gaps in the keyboard – meaning it is game over if any liquids are spilled on it.

The repair itself was rather simple – disassemble the fan unit, vacuum all the dust, remove the rotor, lubricate the sleeve bearing, replace the thermal compound, and restore everything. The rotor can be forced off by carefully prying it from the back side through the intake openings.

The data sheet on the ram modules seems to have disappeared since Elpida merged with Micron. I emailed Micron and they sent back the PDF. Elpida J8416E6MB-GN-F (Courtesy of Micron)

img_20161028_1238399 img_20161028_1250588 img_20161028_1250534 img_20161028_1239003 img_20161028_1238486

Posted in Uncategorized | Leave a comment

Setting Up CKAN 2.5 on Ubuntu 14.04

Install root certificates for work https (optional, required if https is intercepted)

sudo mkdir /usr/share/ca-certificates/extra
sudo cp root.crt /usr/share/ca-certificates/extra/root.crt
sudo dpkg-reconfigure ca-certificates

Install CKAN Package

sudo apt-get install -y nginx apache2 libapache2-mod-wsgi libpq5
sudo dpkg -i wget python-ckan_2.5-trusty_amd64.deb
rm python-ckan_2.5-trusty_amd64.deb

Install PostgreSQL

sudo apt-get install -y postgresql solr-jetty


solr_url =
ckan.site_url = http://opendata.test


NO_START=0            # (line 4)
JETTY_PORT=8983       # (line 19)

Add DB User and Init DB

sudo -u postgres createuser -S -D -R -P ckan_default
sudo -u postgres createdb -O ckan_default ckan_default -E utf-8
sudo ckan db init

You should see the CKAN landing page when going to http://localhost


Create an admin user.

Create a user through the web interface, then use the CLI to promote the user.

sudo ckan sysadmin add yournewusername
Posted in Uncategorized | Leave a comment

Cecilio CEVN-1NA Electric Silent Violin Internal Electronics

I got this relatively cheap electric violin by Cecilio (model CEVN-1NA) and wanted to see what was under the hood. Performance-wise, using a Sony MD 7505 headset, the sound was quite noisy and rather muddled. Tone adjustment just maded the sound even more so and appeared to crackle when turned to the max. Perhaps I may have gotten a defective unit, but the volume was rather minute. I tried several headphones including the stock ones without improvement. Putting the volume adjustment knob to max still yielded under acceptable levels.

Looking at the PCB, there are two main ICs in the built-in amp – one for tone, one for volume.





Here’s a rough schematic of how all the components are connected.


Posted in Uncategorized | Leave a comment

Strongswan PSK IPsec IKEv2 VPN on Ubuntu 14.04 with Blackberry

This is a short guide on configuring Strongswan on Ubuntu 14.04 with pre-shared keys (PSK) for a Blackberry 10 device to connect with. Setting this up requires in-depth knowledge of networking and routing.

Install and configuring Strongswan:

sudo apt-get install strongswan


conn %default

config setup

conn default


%any %any : PSK "yourGatewayPassword"

%any %any : PSK "yourUserPassword"

My server has one network interface connected to LAN and one interface connected directly to the internet. Both have internet routable gateways with the LAN gateway being the default. However, I will use the second interface for VPN connections so a second routing table is required for “same source routing” – allow internet traffic to respond through itself instead of routing through the LAN gateway by default. This may or may not be needed depending on the setup. The easier solution is to use the other gateway as default.

Configure same source routing:

sudo echo 2 ext >> /etc/iproute2/rt_tables


# eth0/br0 config 
# ...
auto eth1
iface eth1 inet dhcp
   # automatically set up routing table and rules on up and down
   post-up ip route add default via `grep routers /var/lib/dhcp/dhclient.eth1.leases | tail -1 | awk '/routers/ {print $3}' | sed 's/;//'` dev eth1 table ext
   post-up ip rule add from `grep fixed-address /var/lib/dhcp/dhclient.eth1.leases | tail -1 | awk '/fixed-address/ {print $2}' | sed 's/;//'` lookup ext
   post-down ip rule del lookup ext
   metric 10
sudo ifdown eth1
sudo ifup eth1

Configure Blackberry VPN profile:

Select General IKEv2 VPN server.


1. Advanced routing –
2. Strongswan setup –
3. Strongswan Forwarding and Split Tunnelling –

Posted in Uncategorized | Tagged , , , | Leave a comment

Running Ghost with cPanel on Shared Host via Rails

I have been looking to migrate my WordPress-driven blog over to Ghost but I don’t want to use a VPS since that would require me to configure and maintain every detail. Shared hosting is great in that it is essentially a managed instance – always updated, backed up, and available (depending on the quality of the host, of course). Most importantly, it’s someone else’s problem if there’s downtime.

This post is to document my steps to run Ghost or any other nodejs applications on a cPanel shared web host. While ssh is not required, it makes debugging and testing a little easier. At the time of writing, cPanel does not support nodejs apps natively ( However, they do support Rails 2 apps, so we can leverage Rails to bootstrap our nodejs app. Note, we cannot just run nodejs applications via command line because port(s) need to be mapped on the account such that will be redirected correctly.

For the sake of completeness, I also looked at an alternative method ( that uses PHP to proxy requests to a node app. That sounds incredibly dirty, though my method is also hacky but arguably less so. Anyway, here it goes.

Outline of steps:
1. Create 2 Rails Applications in cPanel
– one will be used to bootstrap
– second will not be used; we use the assigned port in Ghost or nodejs app
2. Modify Rails app #1 for bootstrapping
3. Install nodejs and npm
4. Upload and configure Ghost
5. Run it and setup redirects as needed
6. …
7. Profit!

1. Create 2 Rails Applications in cPanel
– one will be used to bootstrap
– second will not be used; we use the assigned port in Ghost or nodejs app
2. Modify Rails app #1 for bootstrapping

In the bootstrap Rails app ./config/boot.rb, append to the bottom:

pid = Process.fork
if pid.nil? then
  sleep 5
  exec '(cd ~/node_apps/ghost && npm install)'
  exec '/home/YOURUSERNAME/bin/node /home/YOURUSERNAME/node_apps/ghost/index.js'

note: you may want to immediately exit from the Rails app
note2: screenshot application names maybe different from the commands shown here

3. Install nodejs and npm

tar xvf node-v0.12.3-linux-x64.tar.gz
mkdir -p ~/local/bin
cp node-v0.12.3-linux-x64/bin/node ~/local/bin/
rm -rf node-v0.12.3*
echo prefix = ~/local >> ~/.npmrc
chmod o+x
rm -rf

note: npm from the node package seems to be statically linked to /usr/local which you won’t have access to, so we install it directly with the prefix option

4. Upload and configure Ghost
– start the bootstrap Rails app from cPanel

5. Run it and setup redirects as needed

Posted in Uncategorized | Tagged , , , | Leave a comment

Installing Grub2 on Both GPT HD in Software RAID1 on Ubuntu 14.04

I installed Ubuntu 14.04 on 2x 3TB mdadm raid 1 and wanted both drives to be bootable in case one fails. This took a rather long time to figure out but this is how you do it. Below was tested on a vm.

GPT Partition Layout
1MB bios_grub
256MB /boot
3TB mdadm raid1 / lvm

1. Set labels on the /boot
2. Modify fstab to mount by label
3. Copy /boot to /boot of second drive
4. Update grub on the second drive

Ubuntu Test-2014-11-16-16-46-10

Ubuntu Test-2014-11-16-16-26-58

Ubuntu Test-2014-11-16-16-31-14
note: missing from the screenshot, but “grub-install /dev/sdb” might be needed

Posted in Uncategorized | Tagged | Leave a comment

PXE/Network ISO Boot with Ubuntu on Beagleboard and Tomato WRT54G

This is a short guide on configuring Ubuntu linux to provide network boot services to a local network. It works like this: DHCP responds with dhcp-boot option that tells the client to fetch the boot image from a certain computer. I have DHCP running on a WRT54G with the Tomato firmware and a Beagleboard running Ubuntu 12.04 to serve the boot images.

Image server:

sudo apt-get install syslinux
sudo apt-get install tftpd-hpa
sudo vim /etc/default/tftpd-hpa 
sudo cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/
sudo cp /usr/lib/syslinux/menu.c32 /var/lib/tftpboot/
sudo cp /usr/lib/syslinux/memdisk /var/lib/tftpboot/
sudo vim /var/lib/tftpboot/pxelinux.cfg/default
ls /var/lib/tftpboot/
images  memdisk  menu.c32  pxelinux.0  pxelinux.cfg 

* note: might be missing some simple steps (mkdir, etc~

Content of /etc/default/tftpd-hpa:

# /etc/default/tftpd-hpa


Content of /var/lib/tftpboot/pxelinu.cfg/default:

default menu.c32
prompt 0
timeout 30
ontimeout BootLocal
noescape 1
allowoptions 0
menu title PXE Boot Server
label BootLocal
  localboot 0
label Clonezilla
  kernel memdisk
  append iso initrd=images/clonezilla-live-20140630-trusty-amd64.iso raw
label SystemRescueCD
  kernel memdisk
  append iso initrd=images/systemrescuecd-x86-4.3.0.iso

Setting in Tomato (Advanced DHCP):


After that, set your bios to boot via network and you should see a menu for boot options at boot.


Posted in Uncategorized | Tagged , , | Leave a comment

Amazon Elasticbeanstalk Nginx Https Redirect

I force all traffic to use https. It is much simpler to do the redirect at the application layer but it should really be done at the proxy before hitting the application. Here is the eb.config I use:

Note: This CANNOT be done with just one line in container_commands as the bootstrap script doesn’t like the escaped slashes in the return statement; it will error.

    mode: "000755"
    content: |
      sed -i 's/8080;/8080;\n    if ($http_x_forwarded_proto != https) {\n      return 301 https:\/\/$http_host$request_uri;\n    }/' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf

    command: "/tmp/deployment/"
Posted in Uncategorized | Tagged , | Leave a comment

Installing NodeJS on CentOS 5 without Compiling

The EPEL repo for CentOS 5.x doesn’t include node. So it’s either compile or grab the precompiled executable. The latter is a lot faster.

1. Download the tar file from


2. extract

tar xvf node-v0.10.26-linux-x64.tar.gz

3. remove files and copy

cd node-v0.10.26-linux-x64
rm ChangeLog && rm LICENSE && rm
cp -r . /usr/
Posted in Uncategorized | Leave a comment