Enable adoptable storage for the J5 J500H (3G)

Allowing Adoptable storage on the Samsung J5 20165 – J500H

There are a few tricks for this particular phone
1- We need to replace the recovery system with TWRP

Enable phone developer mode, then USB debugging and OEM override (Disable protection)
Download ODEN
Download the TWRP .TAR file for your device, for the Samsung J5 2016 (J500H), you should find i here
https://twrp.me/samsung/j53gxx.html

reboot your system into bootloader mode (Vol down, Home and power at the same time for 3 seconds to start the phone)

Open ODEN, chose the tar file for AP, and upload the TWRP

Now, don’t let the phone reboot into the system or it will overwrite the bootloader with the original one, instead
once the phone starts rebooting, hit, Volume UP and home button and power at the same time, and TWRP will patch the
system once it opens in recovery mode so that it won’t overwrite the new TWRP

Reboot system, and boot with Power, Home, And volume down button for bootloader change

From this point on, you can enter into TWRP with the Home, Vol UP and Power button combination at boot time

Now download the patch to enable adoptable storage and store it to the SD card (adoptable_storage_enabler_ashyx) from here https://forum.xda-developers.com/galaxy-tab-a/how-to/patch-adoptable-storage-enabler-t3507387

Start the recovery mode (TWRP mode)

Hit install and chose the file you have downloaded

That’s all you need

Now, next thing you will need to do is to format the SD card using the guide here

http://www.tech-g.com/2019/12/01/storing-whatsapp-video-and-photo-to-sd-card-with-no-compromise/

Backup or move an LXC container

You can not just copy an LXC container, wat you need to do is among the lines of

cd /var/lib/lxc
tar --numeric-owner -cf container_125_fs.tar vm125

The magic is mainly about maintaining the numeric owner of files, which is lost when you copy the files using the host machine 😉

you can untar it the same way you untar any other tar file.

for example, to untar it to a different location, you can use the command

tar -xf container_125_fs.tar -C /target/directory

This whole thing is very useful in moving a container to a different directory, then modifying the config file to point to that directory, as well as moving it to a different machine, the reason you can’t just move it is that moving will cause some issues as the move command does not take the ownership differences between host and guest into account.

Storing whatsapp media (video, photo, etc) to SD card.

To have android treat an SD card like internal storage, you will need to format it as internal storage, a feature of android disabled by most manufacturers, so here is how to do it even when the button is missing.

After you get a RELIABLE big SD card, let us get the procedure out of the way, Read below about reliability and dangers etc.. before you decide on getting a cheaper SD card

This feature of android is called Adoptable Storage.

1- On your windows PC (Or mac): Download adb.exe, there are many places to download it on the internet, but for convenience, here is a 64 bit download of the adb.exe file, in my case, it came with Android Stdio, and i found it in C:\Users\yazeed\AppData\Local\Android\Sdk\platform-tools, obviously you will have your username in place of yazeed in the path above

2- On your phone: Open your phone, Go to Settings, About, Software information, And tap repeatedly on Build Number until it informs you that you are now a developer

3- On your phone: A new developer options Menu should appear, Open it and enable USB debugging

4- Connect the phone to the computer via USB cable

5- On your windows PC (Or mac): Open the command prompt (CMD/Shell), I ran it as administrator to avoid any surprises, and run the following commands, obviously, you will need to change the directory to wherever you put the adb.exe file

cd C:\Users\yazeed\AppData\Local\Android\Sdk\platform-tools
adb shell
sm list-disks
** disk:179,64 <= as you can see, this handle/identifier is our SD card inside the phone
sm partition disk:179,64 private

6- Disconnect the wire.

7- Go to settings => storage => sd card (where yo normally format an SD card), then from the three button menu on the top right, select Migrate data, this will move the existing data from internal to SD card.

So right now, We have formatted the SD card as internal storage, the way this works is that the SD card is overlayed over the existing storage, so whatever you already have on your internal memory is not masked by mounting a new SD card in it’s place, but whatever you save from this point on will be saved to the SD card.

ProsCons
* The SD card size is added to the internal phone storage so you can install apps on the SD card and have apps store data on SD card when they don’t offer the option to do that natively

* The internal phone flash memory is not consumed as fast due to flash wear, even though phones usually fail for other reasons before the flash failiure occures, it is mentioned here for completeness

* You can not plug this SD card into your computer, in fact, you are expected to never ever remove it from your phone, this is to avoid catastrophic failiure and data loss

* If your SD card fails or otherwise goes bad, data loss will not only affect the data, but also afects your applications and settings, making the damage much worse

* A slow SD card might affect your phone’s performance.

There are a few things to keep in mind, I ordered them by importance, most important first.

  • ADB.EXE is a file from google, part of the development tools, and not a third party tool, it’s for android debugging by the people who make android
  • *RELIABLE: The SD card you chose must be super reliable as failure of the card will result in loss of your data, applications, settings, and your phone’s functionality in general, making it much worse than when using the SD card as external storage, Get an SD card with wear leveling, as the ext2/ext4 file system that android uses is not too good with flash memory, I personally use sandisk, some sandisk models explicitly state that they have wear leveling, get those, and beware, there are many many fake SD cards on the market, so get it from a reliable source.
  • *FAST: The SD card you chose needs to be fast, the faster the better, even though at some point, the speed of the SD card hits the phone’s limit (the speed the phone can access the SD card), having a very fast SD card will ensure fastest possible operation of your favorite apps
  • *One partition: I have seen people online split the SD card into some internal storage, and some external, but they provide no justification to the benefits of this, as windows will only read the first partition of the disk, My advice is to use the whole SD card as internal, as ther benefit of having part of it as external storage is debatable at best.In case you are wondering how that is done, in place of the line where it says
    sm partition disk:179,64 private

    You will need to use

    sm partition disk:179,64 mixed 20

    The alternative line you see above will create an internal storage partition of 80% and leave 20% as external SD storage

  • *WHATSAPP: The main reason i did this to my phone is that my whatsapp messenger is bombarded with gigabytes of video all the time, and whatsapp does not natively allow for storing media files such as video to external SD cards, in this solution, there is no compromise as the solution is invisible to whatsapp, whatsapp now stores media to the SD card with no real compromise.
  • Why is it disabled in most phones: This is a good question, The official reason, which is a valid, legitimate reason, why companies like samsung asus and others disable this feature is reliability, manufacturers can’t guarantee that yo did your homework and got a reliable and fast SD card, they also can not guarantee you will not accidentally switch the phone on after removing the card, or even remove the card while the phone is running, so in short, leaving this feature in is unwise for the average user, a great side effect (To them) from this legitimate reason is that they can sell larger capacity phones at a higher price and a higher profit margin, but that is irrelevant as the first reason is very legitimate.
  • *Learn: To learn more about the technology, you can visit the Adoptable tech page on the official android website, https://source.android.com/devices/storage/adoptable
  • * Temporarily taking it out: Most phones these days come with Dual SIM, and in most cases, an SD card slot that takes the place of the second SIM card, the issue here is that if you ever need to use the second SIM card slot for a SIM card, you can not just temporarily pull the SD card out without causing massive damage to your apps and data, god knows how the system and it’s sb systems will react to missing data and applications, probably by recreating them blank again, and when you insert the SD card again, there will be a clash of file names.

Searching for text within file contents

Searching for text within file contents in Linux

When you want to do this, odds are, you know what kind of file you are looking for, My first guess would be you would not be looking in zip, mp4, flv, etc… those are huge files, where in the unlikely event they do contain your string, it’s still not the file you are looking for…

So, you would probably want to look at the problem as, search the contents of text files for a certain text string

the best way to acheive that is to start by allowing the find command to find text files that may contain that string, then passing the “candidate for searching” files to the grep command

So if I am looking for a config file that contains a config named living-room, I would use a search such as this one

find /hds -name '*.conf' -exec grep -i 'living-room' {} \; -print

What is nice about this is that you can also look at both separately, so the find command has plenty of documentation online, and so does grep

Now, there are other ways to do this, the most popular of which is using grep on it’s own, here are some examples

The directives are as follows

i stands for ignore case (Slows things down, but sometimes necessary).
R stands for recursive. (Look inside inner folders depth first)
l stands for "show the file name, not the result itself".
e look for things matching a patern
--include Include files that match this pattern
--exclude Exclude files that match this pattern
--exclude-dir exclude directories listed
Examples
grep -Ril "text-to-find-here" /
grep --include=*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
grep --exclude=.o -rnw '/path/to/somewhere/' -e "pattern" grep --exclude-dir={dir1,dir2,.dst} -rnw '/path/to/somewhere/' -e "pattern"




Hope this helps, good luck

3.3V Power supply – Linear Voltage Regulator

As usual i will start with the main points / the lowdown

1- Car voltage can (Depending on car) can go up to 15.3 when bulk charging the battery, the maximum voltage for the LD1117AV33 is 15V, so it is a no go.

2- My DoIt esp12F devkit came fitted with the AMS1117.

The regulator that shipped with my DoIT esp12F devkit is the AMS1117, which seems to be an excellent choice providing up to 1A of current, and accepting input voltages of up to 18V ! Yet, the voltage regulator is not fitted with a heat sink, hence, it will provide nowhere close to 1A reliably

the three liniar regulators I will be comparing in this post are

 

 ld1117v33  lf33abv  TC1262
Maximum Input Voltage 15V 16V 6V
Minimum input voltage (Based on dropout voltage) 4.3V 4.3V 4.3V
Can we change the input voltage while application is switched on  Yes   Yes   Yes
Maximum current draw (Is it enough for my application)
Higher is better
800 500 500
Quiescent current
Current drawn with no load (Not too relevant to cars)
Lower is better
5.5 mA  0.5 mA  0.070 mA

 

Even though i have always used the LD1117AV33 Linear Voltage Regulator in IOT projects, simply because it can provide up to 800 MA of current at 3.3V, I had to look at other voltage regulators for this particular project because it involves a vehice, Now, you may want to skip to the comparison table if your IOT project is not for a car, but

 

As usual, I post my research in this blog for my own use and so that others can benefit from it, so sometimes it looks as though it is not well written, but it could spare you a long time of research

First thing you need to know, is that not all cars have the same voltage, the  12V car battery voltage is nominal, a car battery is usually full and in good health when it’s voltage is around 12.8 or even 12.9 (while the car is off), and because the charging circuit differs from car to car,  A car alternator might step up the voltage to up to 15.3 when it is bulk charging the battery, and float charge a car battery at 14.2 or 14.3 when it considers it full, so bottom line, a linear voltage regulator needs to tolerate at least 15.5V

 

Even though i have always been using the LD1117AV33 step down, and indeed it is a reliable thing, I can not find any document that states that going above the maximum input voltage of 15V is okay, hence, the regulator is disqualified from the word go

 

 

 

Godaddy / Wild west domains, reseller examples

Godaddy / Wild west domains, reseller examples (List is work in progress)

fxdomains.com
polodomains.com
hostingdude.com
cheap-domainnames.com

Super resellers (Sells reseller accounts)
DomainResellerDirect.com

 

The main purpose of this list is for my own reference, as I try to make my own reseller account work for me, as i investigate how they are making it happen, i will probably learn a bit from them.

GPS / u-blox and Adafruit-Mediatek

The things i add here are primarily for my reference, but they could save you a lot of time, so here i am only covering the practical side, wikipedia can help you with the theory. things here are sort of in random order, so feel free to use your browser’s search facility.

I have the following positioning systems/chips/boards, so most of the stuff you will find here will relate to them

* V.KEL VK2828U7G5LF TTL Ublox GPS module with antenna: supports GPS, GALILEO, SBAS (WAAS, EGNOS, MSAS, GAGAN)
* K-172 USB GPS USB Receiver Dongle Adapter Smart Antenna Module For Gmouse Glonass, also running u-blox, Support NMEA 0183 and ublox binary protocol.
* The ADAFRUIT ultimate breakout board with the MTK3339 chip (Not U-BLOX), but rather mediatek

A-GPS and AssistNow:

The long story short: A-GPS seems to be when the satellite data is available in advance, whether you allow your system to download it from the internet as it goes, or you download it in advance and make it available to the system, it boils down to telling your system where the satellites are and their relevant data rather than wait for your device to download that data from the satellites at very low speeds (Sat data is downloaded at a maximum of 50 bits per second, so getting the data over the internet or from the SD card in your raspberry pi or arduino etc is much much faster).

AssistNow is how the U-Blox A-GPS works

1- A-GPS only work out of the box with u-center, the software by u-blox, on your raspberry PI or arduino, it will not work out of the box , to make it work you need to look online for software that does that (It’s on github)

the online edition is when the data is downloaded from the internet in real time (when it is needed), the AssistNow  offline is when you download “AlmanacPlus® Differential Almanac Correction Data” from the internet and store it with your device (On whatever is driving the device, be it a PC, laptop, raspberry pi, arduino etc…)

2- The adafruit GPS raspberry pi board does A-GPS in a different way, which works out of the box, they add a battery to the board, and once data is downloaded once, it stays on the board for as long as there is a battery 😉

 

 

Finding duplicate files on NAS storage

I have this bad habit of copying things so many times when modifying them, when that is a large database, we talking many gigas, so here is a script to find those duplicate files among many hard drives and telling you which ones are duplicates, moving and deleting and symbolic linking is done manually after.

1- this script is PHP-CLI, so make sure that is installed on your computer
2- this script runs the find command, make sure it can execute that program
3- you run the script with the path parameter, but will need to edit the script to change the 1GB size i have hard coded

What this script does is

1- find files with size greater than 1GB (find /hds -size +1G)
2- Store the files in database with size
3- retrieve the files ordered by size
4- if 2 files have exactly the same size, calculates MD5sum for the first MB of the file
5- If the MD5 of the first MB of the files are the same, calculate the whole MD5
6- If they turn out to be duplicates, they are printed to the command line

BCACHE – how to setup

About this tutorial

Despite being lengthy, this tutorial is in fact easy and fast, I have split it to parts so that you can get down to business instantly if you need to.

Worth mentioning is that i think this simple procedure presents itself as rocket science, it is not, so advise you to dive in (experimenting on a separate computer first may be a good idea), again i assure you it is VERY STRAIGHT FORWARD, the length is because i am elaborating to make it easy.

Disclaimer

This is an effort to put all the information i need about bcache in one place for my referance and your benefit, but please beware, bcache should be run with backup (You will have to come up with things as raid will render the cache redundant for example and rsync for big files might make your CPU do a lot of work), in any case, i am not responsible and will not be held liable for any damage you may endure.

SSDs are the future

When it comes to SSDs, I would say they have come a long way in terms of price, and one day they will be replacing hard drives, I have no doubt about that, there is no advantage in a hard drive that an SSD can’t eventually match (You might argue that TBs written, maybe, but have you tried to check the reliability of a hard drive stressed to the level needed to achieve those TBs written ?).

What is bcache for

Spinning hard drives are fast beasts when it comes to sequential reads, but when it comes to random reads where the head has to go seek the data, they become very very slow, you can be reading at 200MB/s and suddenly drop to 2MB/s, While SSDs do not suffer this much from random reads, slower than sequential, yes, but nothing close to the gap you see in spinning disks, in a spinning disk, the speed difference can be 100 fold OR MORE.

History (Windows)

The earliest attempt that i can remember was Intel robson (2005), Intel robson or intel turbo memory was a feature in the Core 2 CPUs, but i don’t think it made it up to the Core I, it was not very popular and for a good reason, at the extra cost, OEMs could add more ram, not only would it be better for marketing, it also made more sense, as Windows was already introducing memory cache for disks with windows Vista.

Some time later, microsoft came up with Microsoft ReadyBoost (With windows Vista), readyboost relied on fast pen drives to cache the data from the spinning disk, it was not a very popular feature at the time for many reasons, the drawbacks is that they had to design it to be pulled out without affecting data integrity, making restrictions on the writing speed (Writethrough, can’t writeback), and still it was doing the stuff that RAM did perfectly. not to mention that affordable pen drives were not that fast to begin with.

Caching today.

As it is today, caching still makes sense, I would argue it makes more sense than ever, spinning hard disk drives are still much cheaper than SSDs, A good SSD, A 1 TB SSD from samsung is at around $340 for the EVO, and 460 for the pro (Jul 2017), compare that to the spinning disk, with a price tag averaging $40, and you will know that the difference is still around 10 fold, even more if you go up in size, So what do we do ?

The answer is cache the disk. now is a better time to use caching with super fast SSDs that employ wear leveling and are connected in a more stable and persistant connection (SATA inside the computer).

SSD caching On Windows.

On windows, the answer may be ISR (Intel Smart Responce), I have not tried it myself, but i have heard many good things about it, you get into your bios and set the disks are R.A.I.D, then use the Intel Management Engine software to cahce the spinning disk on the SSD, that simple.

I could almost swear INTEL had a software solution for this that was a bit pricy, but i can’t seem to find it, i remember watching a video about it many years ago.

In any case, I am not very experienced with windows, so I will just leave it here.

SSD disk caching on Linux

On Linux, there are many solutions, the one that i will be showing you how to use right now is bcache, because it is fast, efficient, and works on block devices.

So, I am assuming you have installed debian stretch (9), and you have logged in, and you have networking et al running, now, let us get to installing bcache, mind you, bcache has been part of the linux kernel since jessie or even before, so all you need is bcache-tools, in Jessie, you had to compile those with a few lines, in stretch, there is a package for it.

** BCACHE **

To help avoid the confusion, you can use your big hard disk before attaching an SSD, you can then, whenever you want, attach an SSD to it to start the performance gain.

Installing bcache tools in Debian Jessie (8)

** IF YOU ARE INSTALLING ON JESSIE, BCACHE TOOLS WERE NOT PACKAGED FOR JESSIE**

apt-get install git make gcc pkg-config uuid openssl util-linux uuid-dev libblkid-dev

git clone https://github.com/g2p/bcache-tools.git
cd /usr/src
cd bcache-tools
make
make install

** END OF FOR JESSIE **

Installing bcache tools in Debian Stretch (9)

apt-get install bcache-tools

Planning how to setup the drives

In this article, i will be setting up 2 separate disks that are not system disks, one is a 4TB spinning disk, the other is a 1TB SSD, there are a few rules that you need to be aware of though

1- You can cache as many backing devices as you wish with one SSD
2- You can not cache one backing device with more than one SSD

3- There are memory requirements for bcache, so for example dropping the disks in a 486 computer with 256mb ram and using iscsi is not a good idea .

My setup

The backing device is your large spinning disk, the caching device is the SSD

My backing device is a 4TB hard drive that is connected as /dev/sde
My caching device is a 1TB samsung 850evo (alignment considerations here since it is a tlc disk (the pro is MLC, works like a regular with no alignment issues)), connected as /dev/sdc

Setting up the backing device (sde), mounting and populating it with data

You may want to start with the following command to clear any existing filesystem from the drives (Change SDE with your own drive designation)

wipefs -a /dev/sde

Now, let’s format SDE as backing, and SDC as caching

1- Run parted for backing device

parted /dev/sde
mklabel gpt
mkpart primary ext4 0% 100%

2- Make it a bcache backing partition

Using make-bcache, you will use the -B switch to tell the system that this is the backing device, meaning the spinning disk

make-bcache -B /dev/sde1

output from the above will be something like

UUID:                   19d92bc8-8f49-479a-9480-33ca659b91b2
Set UUID:               0e3f386a-ec62-42b9-b0f3-025a09253946
version:                1
block_size:             1
data_offset:            16

3- Format it as ext4 or whatever filesystem you fancy

mkfs.ext4 /dev/bcache0

4- Mounting it like you would mount any other partition

mount /dev/bcache0 /hds/bcache0

5- If you like, you can now copy your data to it and get things ready before installing the caching device (before attaching the SSD as cache).

as i prefer to copy all the files to the spinning disk before attaching the SSD, since when we copy sequential, the SSD does not cache anyway, but the things it does cache are not the things we will use frequently, So i copy my files to it first, then i attach the SSD.

Setting up the caching device (sdc), then attaching it to the backing device

1- Create a partition on caching device (you chose the size you want to use as cache), but i would recommend that if you want to use the whole disk that you leave 10% unpartitioned for over-provisioning.

wipefs -a /dev/sdc

parted /dev/sdc
mklabel gpt
mkpart primary ext4 0% 90%

Using make-bcache, you will use the -C switch to tell the system that this is the caching device, meaning the solid state disk (SSD)

make-bcache -C /dev/sdc1

output from the above will be something like

UUID: eeda3570-eb1b-4983-8c53-76322a654585
Set UUID: 92dbf6ca-0f0b-44d5-b70e-8f1e7919838d
version: 0
nbuckets: 1716964
block_size: 1
bucket_size: 1024
nr_in_set: 1
nr_this_dev: 0
first_bucket: 1

Now, even if this is not for a technical purpose, just to give you the feel of this, try running the command below, the command should result in “no cache” because we did not attach a cache to it yet

cat /sys/block/bcache0/bcache/state

DO NOT Format the caching partition as ext4

this time, we won’t be formatting it in ext4 like the backing device above (think about it, the OS should see the backing device, and at some abstraction layer not even know about this one, so why would it have a file system other than the one that bcache itself understands), we will simply be attaching it to the disk.

Attaching the caching device

If you take a look at the result from make-bcache -C command, you will notice a Set UUID, we will need this unique ID to tell bcache what SSD to connect to what cache, the only cache we have so far is bcache0 as you can see from above, here is how we attach it.

echo 92dbf6ca-0f0b-44d5-b70e-8f1e7919838d > /sys/block/bcache0/bcache/attach

Now, if we run the command above again

cat /sys/block/bcache0/bcache/state

It should read “Clean” or “Dirty” instead of “no cache” (I would bet it reads clean at this stage), Depending on whether something has been written to it and still not in the backing device, or clean otherwise.

Setup all done, unless you want to fine tune it for your purpose, then read on.

Tuning the cache.

1- Caching mode

to inspect what caching mode we are using now

cat /sys/block/bcache0/bcache/cache_mode

Which will probably result in

[writethrough] writeback writearound none

By default, the system uses writethrough (better data integrity), but if you are like me, and have made 100% sure the electric won’t ever go down, or if you backup the data in real time, you might want to switch to writeback, writeback gives much faster write operations which is not necessarily a requierment for all applications.

echo writeback > /sys/block/bcache0/bcache/cache_mode

2- sequential read cutoff

The other thing you might wish to tune is the size of the sequential read/write cutoff, we want a size short enough to be worth caching, by default, it is 4MB, so that everything under 4MB sequential will be cached, I personally like to take that down to 1MB judging by the fact that files larger than 1MB do read pretty fast directly from the disk ! but surely, this will depend on your application and on experimentation with your application.

cache 1 megabyte and smaller

echo 1M > /sys/block/bcache0/bcache/sequential_cutoff

cache everything (special value, not the same mathematical logic of less than)

echo 0 > /sys/block/bcache0/bcache/sequential_cutoff

back to caching 4 mega bytes and smaller (default)

echo 4M > /sys/block/bcache0/bcache/sequential_cutoff

3- Percentage of dirty data to allow on SSD.

I personally like it the way it is (10% of the SSD’s size), but you can change that, and sometimes you have to temporarily change that for certain purposes)

Flush all dirty data to disk as soon as you can

echo 0 > /sys/block/bcache0/bcache/writeback_percent

Allow 10% dirty data

echo 10 > /sys/block/bcache0/bcache/writeback_percent

the first (Value 0) is very usefull when you want to disconnect the cache, to disconnect you want the dirty_data to be 0 on the SSD, so you can start by issuing the first line above, then as soon as all the data is flushed to the backing device, you can disconnect the SSD like i will be showing you further down.

Manipulating the setup

Sometimes, you want to change your SSD with a larger or smaller or newer one, other times, you want to disconnect it and use the backing device without a cahce, other times, you want to use the same caching device to cache more disks, here i will show you how

Assuming you want to disconnect the SSD, for this to happen, you will need to go through a couple of steps, first, make sure there is no dirty data, and second, detach it from the backing device

For the first step, we should inform bcache that we don’t want any dirty data, by default, bcache allows for 10% of the size of the SSD to be dirty data, we need to make that ZERO percent

echo 0 > /sys/block/bcache0/bcache/writeback_percent

remember, if you reattach or otherwise, you should set it back to ten percent in the same way

echo 10 > /sys/block/bcache0/bcache/writeback_percent

Monitoring cache and cache performance

1- How much dirty data is on the SSD, Assuming that “/sys/block/bcache0/bcache/state” reads dirty, you can see how much data is dirty with the command.

cat /sys/block/bcache0/bcache/dirty_data

2- Caching statistics

tail /sys/block/bcache0/bcache/stats_total/*