A program for changing internal memory to external memory. How to make a flash drive as memory for an Android phone. How to swap memory on Android? What should be done

As promised in the comments to the post “Deployment Manager or where else can you deploy files,” I dug a little more into the file system (or rather, into the Directory Hierarchy). The basis for this article was a question from Dmitry Kuzmenko, I really hope that I was able to answer it to the required extent. Let's talk a little about the Android OS, manufacturers of devices running this operating system, and I will also show several options for obtaining a list of available storage devices.


Continuation for Android 4.4.* here: Android 4.4 and recording to an external memory card...

Upd (17.02.14). Based on the comments, changes were made to the appendices.
Upd2 (02/17/14). A false positive of the 3rd option was detected, the feature was fixed. Improved the search a bit.

Upd (30.03.14). The third method works on Android versions below 4.3. I won’t write code for versions higher than 4.3, because I don’t have devices with this version of Android to analyze the new structure.
Upd (21.04.14). Tested the code on Delphi XE6

Upd3 (07/15/14). Source code update, incorrect operation detected (AV error) on some devices

I will try to present the whole point briefly so that it does not turn out to be 10 pages of text.

Let's start with the basics.

The Android operating system is based on the Linux kernel. In Unix-like operating systems, there is only one root directory, and all other files and directories are nested under it. On most UNIX-like systems, removable disks, flash drives, and other external storage devices are mounted in the /mnt, /mount, or /media directory (in our case, the /mnt folder). UNIX-like operating systems also allow disks to be mounted automatically when the operating system boots.

We determine the list of available storage devices.

I must say right away that I did not find a method in the Android API that allows me to define such a list. Therefore, the first thing that comes to mind is checking possible paths on your own, and here the first “BUT” appears. Everything would be simple if it weren’t for device manufacturers who just want to change something in Android, and in this case they tried. I experimented and found out that the number of possible path options is quite large and it is almost impossible to find out all of them, unless you start collecting a common database of such options from all owners of Android devices.

Participants in my experiments (my only one is SGS2:):

  • Samsung Galaxy S Plus – Android 2.3.6
  • Samsung Galaxy S2 – Android 4.1.2
  • HTC Sensation Z710e – Android 4.0.3
  • HTC One X – Android 4.2.2
  • HTC Rhyme – Android 4.0.3

Now let's look at what paths are available on these devices, what is important to us is the path to the internal card (if any), external card (if any) and usb devices (if any).

As you can see, the paths are different everywhere.

Option 1.

We compose an array of possible values ​​and in a loop we check each one for availability using the usual check for the existence of a folder ( TDirectory.Exists), as well as the empty folder ( TDirectory.IsEmpty).

I compiled a general list for these devices and wrote a small application for testing.

My list (based on 5 popular devices):

  • /mnt/sdcard
  • /mnt/sdcard/external_sd
  • /mnt/extSdCard
  • /mnt/usb
  • /mnt/UsbDriveA
  • /mnt/UsbDriveB
  • /mnt/UsbDriveC
  • /mnt/UsbDriveD
  • /mnt/UsbDriveE
  • /mnt/UsbDriveF

Having searched for similar paths on the Internet, I found 3 more possible points:

  • /mnt/external_sd
  • /mnt/usb_storage
  • /mnt/external

Addition fromDmitry Kuzmenko:

Sony Xperia V - 4.1.2

  • /mnt/sdcard
  • /mnt/ext_card
  • /mnt/usbdisk

A bit more:
Sony Xperia Go - 4.1.2

  • /mnt/sdcard
  • /mnt/ext_card
  • /mnt/usbdisk
Samsung Galaxy S4 - 4.2.2
  • /mnt/sdcard
  • /mnt/extSdCard
  • /mnt/UsbDriveA
  • /mnt/UsbDriveB
  • /mnt/UsbDriveC
  • /mnt/UsbDriveD
  • /mnt/UsbDriveE
  • /mnt/UsbDriveF
You will find the finished array in the code below. You can leave in the comments information about the paths on your devices in the following form:

Device name – Android version

Direct path to internal memory

Direct path to external memory card

Direct paths to USB devices

All paths start from the /mnt/ folder.


Or copy and send me the file "/etc/vold.fstab" to infocean @ gmail.com or in the comments (don't forget to indicate the device model and Android version). Please also indicate all the folders that are in the /mnt directory /, it is very important.

Application:

UsesSystem.IOUtils; const pathmnt: Array of String = ("/mnt/sdcard", "/mnt/sdcard/external_sd", "/mnt/extSdCard", "/mnt/usb", "/mnt/UsbDriveA", "/mnt/UsbDriveB ", "/mnt/UsbDriveC", "/mnt/UsbDriveD", "/mnt/UsbDriveE", "/mnt/UsbDriveF", "/mnt/external_sd", "/mnt/usb_storage", "/mnt/external" , "/mnt/ext_card", "/mnt/usbdisk"); procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin Memo1.Lines.Clear;

Memo2.Lines.Clear;

for i:= 0 to Length(pathmnt) - 1 do begin if TDirectory.Exists(pathmnt[i]) AND not TDirectory.IsEmpty(pathmnt[i]) then begin Memo1.Lines.Add(pathmnt[i]);

Memo2.Lines.Add("True"); end else begin Memo1.Lines.Add(pathmnt[i]); Memo2.Lines.Add("False");

end; end; end; Option #2.

The first option has both pros and cons (the main one is the incompleteness of the list of possible paths), so let’s try to solve this problem in a different way.

  1. There is such a file " end else begin Memo1.Lines.Add(pathmnt[i]);»
  2. vold.fstab end; end;", lies here "/etc/"("/system/etc/"). This is one of the configuration files in UNIX-like systems that contains information about various file systems and storage devices. Describes how the disk (partition) will be used or integrated into the system.

And there is a file "


mounts

", lies here "/proc/". Contains information about all mount points used in the device. It is important to understand that if the memory card is not mentioned in this file, then it is not connected. This means that the file is constantly updated. end else begin Memo1.Lines.Add(pathmnt[i]); Step by step: end; end; Reading the file "

The first option has both pros and cons (the main one is the incompleteness of the list of possible paths), so let’s try to solve this problem in a different way.

  1. There is such a file " end else begin Memo1.Lines.Add(pathmnt[i]);»
  2. We check each device for accessibility by reading the file “
  3. » and search for the required string in it. TDirectory.Exists There will be no code in this version yet, because... For some reason unknown to me, I can't read the "mounts" file. In this regard, I propose a third option. TDirectory.IsEmpty»
  4. Option #3.

We combine the first and second options. We will take the list from the file "", and check it yourself, without opening the file "

" Why bother with two files every time when you can work with only one. In the file "/etc/vold.fstab" there are sometimes (on some devices) commented lines that are very similar to those found in my code, and therefore a false positive occurred. I fixed this feature in the new version of the code.
I also fixed the search for the required lines, now it is more universal!

In general, the code should now work fine on different devices. Try it, write in the comments, attach your file “/etc/vold.fstab” (don’t forget to indicate your device model and Android version).

Update3 - 07/15/14:
Blog reader Sergey Yakimenko discovered that the third option (file reading) did not work correctly on devices Huawei Ascend P6 And Reellex TAB-07, as reported in the comments.

After personal correspondence and some analysis, I found out what problems were interfering with the work.

Issues found and fixed:

  1. Spaces at the beginning of each found line. Fixed with "Trim"
  2. The found lines use tabs instead of spaces. Fixed by replacing tab characters with spaces.
The code has been updated. Thank you very much to Sergei.

Application:

Uses System.StrUtils, System.IOUtils; procedure TForm1.Button1Click(Sender: TObject); var OpenFileVold: TStringList;<>i: Integer;<>pathtemp: TStringDynArray; begin OpenFileVold:= TStringList.Create;

try // Read the file OpenFileVold.LoadFromFile("/etc/vold.fstab"); for i:= 0 to OpenFileVold.Count - 1 do begin if (Pos("dev_mount", OpenFileVold.Strings[i]) > 0) OR (Pos("fuse_mount", OpenFileVold.Strings[i]) > 0) then begin // Update(07/15/14) // 1 - Remove spaces at the beginning and end of the line (get rid of AV) // 2 - Replace tab characters with spaces pathtemp:= SplitString(StringReplace(Trim(OpenFileVold.Strings[i] ), #9, " ", ), " "); // Check the first character of the line to see if it matches the character "#" or "##", // so that there are no false positives if (pathtemp "#") AND (pathtemp

"##") then begin if TDirectory.Exists(pathtemp) AND not TDirectory.IsEmpty(pathtemp) then begin Memo1.Lines.Add(pathtemp);

end;
end;
p.s.3. In the next article, I will show you how to get rid of the database update problem when updating an application manually.

By default, all applications are installed on the internal memory of the Android device. It is also used to store their cache. But even the memory of modern smartphones is sometimes not enough to download all the necessary software. It's good that there are memory cards with enough capacity for this. We will look further at how to use them to offload main memory.

How to switch Android phone memory to memory card

Let us clarify that in this case we are considering a situation where the user needs to ensure that downloaded files and programs are saved on microSD. By default, Android settings are set to automatically download to internal memory. So we will try to change this.

First, let's look at options for transferring already installed programs, and then - ways to change the internal memory to flash drive memory.

On a note: The flash drive itself must have not only a large amount of memory, but also a sufficient speed class, because the quality of the games and applications located on it will depend on this.

Method 1: Link2SD

This is one of the best options among similar programs. Link2SD allows you to do the same things you can do manually, but a little faster. In addition, you can forcefully move games and applications that are not moved in the standard way.

You can download Link2SD

Instructions for working with Link2SD are as follows:

  1. The main window will display a list of all applications. Select the one you need.
  2. Scroll down the app information and tap " Transfer to SD card».

Please note that those applications that are not transferred in the standard way may reduce their functionality. For example, widgets will stop working.

Method 2: Setting up memory

Let's return to system tools again. On Android, you can specify the SD card as the default installation location for applications. Again, this doesn't always work.

In any case, try the following:

1. While in the settings, open the “ Memory».

2. Click on " Preferred installation location" and select " SD card».

3. You can also designate storage to save other files by designating the SD card as " Default Memory».

The location of elements on your device may differ from the examples given.

Method 3: Replacing internal memory with external memory

And this method allows you to deceive Android so that it perceives the memory card as system memory. From the toolkit you will need any file manager. The example will use Root Explorer.

Attention! You perform the procedure described below at your own peril and risk. There is always a chance that this will cause problems with Android, which can only be corrected by flashing it.

The procedure is as follows:

1. In the system root, open the folder “etc" To do this, open your file manager.

2. Find the file " end else begin Memo1.Lines.Add(pathmnt[i]);" and open it with a text editor.

3. Wednesday and the entire text, find 2 lines starting with “ dev_mount"without a grid at the beginning. They should be followed by the following values:

  • « sdcard /mnt/sdcard»;
  • « extsd /mnt/extsd».

4. You need to swap the words after “ mnt/", so that it becomes like this:

  • « sdcard/mnt/extsd»;
  • « extsd/mnt/sdcard».

5. Different devices may have different symbols after “ mnt/»: « sdcard», « sdcard0», « sdcard1», « sdcard2" The main thing is to swap them.

6. Save the changes and restart your smartphone.

As for the file manager, it is worth saying that not all such programs allow you to see the above-mentioned files. We recommend using ES Explorer.

Method 4: Transfer applications in the standard way

Starting from Android 4.0, you can transfer some applications from internal memory to an SD card without using third-party tools.

To do this you will need to do the following:

1. Open " Settings».

2. Go to the section "Applications».

3. Tap (touch with your finger) the desired program.

4. Click the button Move to SD card».


The disadvantage of this method is that it does not work for all applications.

In these ways you can use SD card memory for games and applications.



The problem of lack of memory is one of the fundamental ones for both PCs and mobile devices. With a small amount of free memory, the system usually begins to slow down, freeze, and is unstable and unreliable. This is especially true for Android devices, many of which initially have a rather small amount of main memory (the so-called “Internal Storage”). In such a situation, some users may have the idea of ​​trying to use an external SD card as the main memory on their Android device. In this material, I will tell you how to make an SD card the main memory on Android gadgets, and what methods will help us with this.

Let's look at how to make an SD card the main memory on Android

To accomplish this task, you will need a high-speed SD card (preferably class 10 or faster). Cards of 6, and especially 4 and 2 classes are not suitable for such purposes; your system, due to their use, will significantly slow down its operation, which is unlikely to please any of the users.

It is also important to understand that the lifespan of such an SD card due to the active load on it will be significantly less than if the load on the card was in standard mode.


Method No. 1. Changing the contents of the Vold.fstab file

The first of the described methods involves changing the contents of the system settings file “Vold.fstab”. After making these changes, the Android OS will consider your SD card as the internal memory of the device, but keep in mind that a number of previously installed applications may stop working.

It is important to know that this method only works on rooted devices running Android OS below (!) than version 4.4.2. In Android OS versions 4.4.2 and higher, most likely you simply will not find the specified file.

Also keep in mind that an error in the implementation of this method (in particular, adding extra characters to the required lines) can have a tragic effect on the performance of your device. Therefore, carefully weigh the possible risks, and if, after all, you have made a decision, then proceed to implement it.

So, to implement this method, do the following:

For example, these could be lines like this:

  • dev_mount sdcard/storage/sdcard0 emmc@xxxxxx
  • dev_mount sdcard2/storage/sdcard1 auto/xxxxxx

To make the necessary changes, we need to swap the path in the specified lines, that is, simply put, instead of 0, put a 1 in the first line, and in the second, instead of 1, put a 0.

After the changes, these lines will look like:

  • dev_mount sdcard/storage/sdcard1 emmc@xxxxxx
  • dev_mount sdcard2/storage/sdcard0 auto/xxxxx

Save the changes you have made, and then reboot the gadget.

Another option on how to make a memory card the main one on Android:


Method No. 2. We use the settings of Android OS 6.0 and higher

In addition to the first method, in which I looked at how to switch the phone's memory to a memory card, there is another method that works only on the settings of Android OS 6.0 (Marshmallow) or higher, and allows you to use the SD card as the main one for saving files and working with them . To implement it, I recommend making a copy of the data from your SD card (if any on it), since this card will be formatted by the system.

The capabilities of the device can be seriously expanded if you replace the internal Android memory with a memory card. This will allow you to install many more applications on your tablet or other gadget, but the main requirement for performing this update is to have root rights on the device. Let's look at ways to use an SD card as the device's system memory, as well as the conditions associated with this.

Risks and conditions for replacing the gadget’s internal memory with an SD card

Before repeating the steps below, the user should consider several important points:

  1. The lifespan of the SD card will be greatly reduced due to frequent read/write cycles when running applications.
  2. The speed of the gadget may drop noticeably if you use a low-end MicroSD card.
  3. If you make a mistake when editing a system file, the phone may not boot next time - you will have to reflash it.

In general, the procedure (especially for inexperienced users) is quite risky, so it makes sense to carry it out exclusively for old gadgets with a small amount of their own memory.

Using the Root Browser utility and editing the vold.fstab file

To swap memory, you will need to install Root Browser from Google Play.

Let us repeat that you can only fully work with it on rooted devices. After running the above application:


In Android, sdcard stands for internal memory, and extsd stands for external memory, i.e. SD card. By replacing these lines, we actually swapped these types of memory. On some systems these pieces of code may look different, for example like this:

They need to be replaced as follows:

After completing the described procedure, reboot the gadget. Before doing this, be sure to check that there are no errors in the modified code, so that in the future there will be no need to reflash it.

The second way to increase memory using Link2SD

The application is available on the Play Market and only works on devices with root rights. This file manager does not physically replace the device’s internal memory with an external drive, but it is capable of transferring any utilities to an SD card, significantly saving the gadget’s resources.

The peculiarity of the application in question is that the MicroSD itself will have to be split and properly formatted. Therefore, copy everything valuable from your card to your computer and start dividing the drive into sections.

Dividing the device card into sections if there is a custom Recovery

Every Android device has a recovery mode, but the method described below is only suitable for devices with . If you've never heard of CWM, move on to the second drive partitioning option. Next, we’ll tell you how to solve the problem if your device recovery mode has the Partition SD Card item:

Partitioning a MicroSD card via a computer

Connect the card to your laptop or PC. To do this, you can use a card reader or other equipment, the main thing is that it should be defined as a drive and not an MTP media device. Further: