Switch to F2FS. Moving with HDD on SSD and F2FS

By 250GB and began to think how to transfer the system to it.

First of all, he was puzzled by choosing the file system most suitable for SSD. After a short google, I decided to put on a relatively fresh FS developed by Samsung specifically under FLESH F2FS (Flash Friendly File System) media.

F2FS is a fairly young FS, but nevertheless supported by the Linux core from version 3.8

The task was to have been identified:

  1. Teach the system to understand F2FS
  2. Post and format SSD in F2FS
  3. Copy the data
  4. Configure fstab and grub

Turn on F2FS support in Kubuntu

In Kubuntu 14.04 and 14.10, the F2FS support module is present, but not included. So, to enable support, it is enough to dial:

sudo Modprobe F2FS

Check that the module is connected

sudo lsmod | Grep F2fs.

Now the system can work with F2FS, but only before rebooting. What would the module be loaded automatically with each download, add the F2FS entry to the end of the file / etc / modules

sudo -i.
echo F2FS \u003e\u003e / etc / modules

Also teach the initramfs to support F2FS. To do this, add F2FS to the end of the file and update.

In Kubuntu 16.10, the kernel 4.8 also need to additionally add a module cRC32. Otherwise, the system will not boot.

sudo -i.
echo F2FS \u003e\u003e / etc / initramfs-tools / modules
echo CRC32 \u003e\u003e / etc / initramfs-tools / modules
update-Initramfs -u

To create F2FS Install F2FS-Tools and Gparted packages

sudo Apt-Get Install F2FS-Tools Gparted

The CDE section manager does not know how to create F2FS, but Gparted can.

For the upper 14.04, you also need to update the Util-Linux package to version 2.25 or higher.

sudo Add-APT-Repository PPA: Xeron-Oskom / Util-Linux && Sudo APT-Get Update && Sudo Apt-Get Dist-Upgrade -F

Connect SSD, create partitions and format in F2FS

Since my disposal was only a laptop without stationary computer SSD. I connected as an external disk via USB. To do this, I took the old outdoor HDDdisassembled and confused instead of the usual external disk Your SSD and connected all this business to USB.
Surprisingly neither the system neither the disk sections manager saw. But after loading from the installation flash drive with Kubuntu 14.04, the disk saw and I safely created a blank section after which the disc was visible in the main system in which I made a breakdown and formatting.

The breakdown was done in Gparted, since the F2FS CDE sections manager does not yet understand.

Personally, I stated like this:
/ Boot Ext2 768MB
/ Root f2fs 20gb
/ Home F2FS 210GB

Swap will be in the file running.

Copy the data from HDD on SSD

Transfer data from / home

On the SSD in section / Home, create a folder with your username, assign yourself to its owner

sudo Mkdir $ User && Chown "$ User": "$ User" $ User

and copy everything that we need not forgetting to copy the basic configuration files and folders, such as:
.kde.
.local
.config
.mozilla.

To transfer data from the home directory you can use simple copying With the preservation of attributes and rights to files. I did a selective copy from the home folder, as my HDD was exactly twice the new SSD, and everything would not fit, and the "garbage" there was decently accumulated there.

I copied like this:

sudo cp -ar /home/dm/.kde/* / media / f2fs / home / dm

Copy / Root and / Boot

To copy C / ROOT data to LiveUSB Kubuntu, turn on F2FS support by mount the necessary partitions and copy data from sections.

Turn on F2FS support
Sudo Modprobe F2FS

Create a folder in which we will mount
Sudo Mkdir / Media / F2FS_ROOT

Watch which discs are available to us
Sudo Fdisk -L.

Mount the F2FS root section. Instead of SDX, set your section.
Sudo Mount / Dev / SDX / Media / F2FS_ROOT

Copy / Root from HDD on SSD
Sudo CP -AR / Media / Kubuntu / Root / * / Media / F2FS_ROOT

The same makes the same with the section / Boot

Configure FSTAB and GRUB

Reboot to your system.

Set up fstab

We learn the UUID sections on SSD
Sudo Blkid

And FSTAB rules on SSD

sudo Nano / Media / F2FS / ROOT / ETC / FSTAB

He now looks like this:

UUID \u003d xxxxxxxxxxxxxxxxxxxxx/ F2FS RW, Noatime, Discard 0 2
UUID \u003dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
UUID \u003d XXXHHXXHH-XXXHH-XXXHHHHXHXHHHHHHXXXXXXXX / BOOT EXT2 AUTO, NOATIME 1 2

Making Chroot SSD to configure GRUB

sudo Mount / Dev / SDX / Media / F2FS / ROOT / BOOT
sudo Mount / Dev / SDX / Media / F2FS / ROOT / BOOT / EFI
sudo Mount --Bind / Dev / Media / F2FS / ROOT / DEV
sudo Mount --Bind / Proc / Media / F2FS / ROOT / PROC
sudo Mount --Bind / SYS / Media / F2FS / Root / Sys
sudo Chroot / Media / F2FS / ROOT

Then set the bootloader

sudo Grub-Install / Dev / SDX
sudo Update-Grub

Where sDX - SSD device name (for example / dev / sdb)

Without leaving chroot rules grub.cfg on SSD
Open /Boot/Grub/Grub.cfg.

sudo Nano /Boot/Grub/Grub.cfg.

And looking for records like:
Linux /vmlinuz-3.16.0-25-Generic root \u003d / dev / sdb2

in which change / dev / sdb2. on the / dev / sda2

All, turn off the HDD and connect SSD.

Materials used:

In the medium of the modests and Android enthusiasts, as in any sect, there are several shrines that it is customary to read in spite of everything. These are optimized custom kernels, scripts and applications to optimize the system, "sound improvements" and much more. Recently, the F2FS file system has been added to them, which, according to many evidence, significantly raises the performance of working with NADN memory and retains it from wear. But is it really?

Start

For the first time, F2FS (Flash Friendly File System) appeared to human eye in October 2012, when Samsung published patches with its implementation for the Linux kernel. According to the developers, the FS was from scratch designed specifically for flash memory and allowed to improve reading / record performance of such drives and use their features for some optimizations and wear protection.

Already by the end of the year, F2FS has become the official part of Linux 3.8, and after some time its support appeared in CyanogenMod 10.2 and Custom Recovery TWRP. Since then, the modests and optimizers include it into all their kartomic kernels, they write a mass of laudatory reviews, publish screenshots with the proof of the phenomenal performance of the file system.

From the side, all this looks more than encouraging, so newcomers in Android come together in the ranks of those who touched the beautiful and borrowed this beautiful in their smartphone. That's just few people think about why Samsung's miracle miracle itself does not use F2FS even in its latest flagships.

And the reason is simple: F2FS is practically no better than the EXT4 file system used in the default Android. In order not to be unfounded, the disassemble of two main myths relating to F2FS: productivity and careful attitude towards Flash drives.

Performance

In the network you can find many examples of comparison of EXT4 and F2FS performance. They are very similar and very often show a huge winnings of the latter in the speed of data recording. Here, for example, the results of the Androbench comparison for smartphone Sony Experia Z1:

Looks strange, right? The rate of random recording increased 150 times in comparison with EXT4 and six times in comparison with the speed of reading. For the first time, such an anomaly noted Phoronix journalists, when F2FS testing was carried out in early 2013:


Then they reasonably suggested that in fact F2FS writes data to the disk not immediately, but instead it caches them for a subsequent record. If you look at the F2FS architecture, it becomes obvious that this is true. F2FS Works with 4 Kbyte data blocks, combining them into segments of 2 MB, and those, in turn, are combined into sections that can be up to six pieces.

Why, we need such a system, we will talk later, but for now we will only dwell on the fact that before writing in the memory of the section should be filled with blocks. In other words, F2FS collects the recorded 4-kilobyte data blocks into pieces bigger sizeAnd then throws them on the disk at the same time. This is the reason for the abnormally high performance F2FS in the speed of the random 4 kilobyte block and quite comparable to the EXT4 performance of the sequential record of multiple blocks.

The latest PHORONIX tests also confirm the almost equal performance of both file systems. F2Fs came out noticeably forward only in the test on simultaneous work with thousands of files, which is due to its internal optimizations. However, no smartphone works simultaneously with so many files. This situation is rare even on a desktop and specific for servers.

Careful attitude towards the drive

The second misconception relative to F2FS is associated with a more careful attitude towards flash memory. We all know that Flash memory is a fragile thing and withstands only a few thousand data recording / erasing cycles. For this reason, it is recommended to place data on the Flash-drive in a log format when new blocks do not overwritten old, and instead they are written into an unoccupied area, after which old block marked as unused and subsequently cleared, freeing the space.

This is how F2FS works, and that is why many people consider her the best choice For flash memory in comparison with EXT4, working according to the classic scheme, which involves changing data on site. But there is one nuance. The fact is that absolutely any modern flash memory, ranging from USB flash drives and ending with SSD server, contains the FTL controller (Flash Translation Layer), which is responsible for presenting to imagine magnetic discs Flash memory as normal Diskwhich you can record a certain number of data blocks.

In addition to things like combining multiple Flash memory chips to one "disk" and executing the Trim operation, which clears no longer used blocks, FTL is also responsible for choosing the physical placement of the recordable block in memory. And here it uses (surprise!) Log-structured mini-fs. In other words, any modern flash memory itself is engaged in an increase in its service life no matter what file System You create on it: F2FS, EXT4, FAT32 or any other, - the result will be one.

In fact, the reason why F2FS is called "Flash Friendly) (Flash Friendly), not at all in a careful attitude to memory, but that it knows how to take some of its features to make work with memory more efficient. One example of an increase in efficiency is the one mechanism for combining data in the section.

The fact is that many flash memory microcircuits include not one, but several independent drives. And the record in each of them can occur simultaneously. Combining data in the section, F2FS can send them to a record at the same time, which in theory will lead to an increase in the recording performance in the number of times, a multiple of the number of drives.

But here is not so simple. All F2FS optimization require individual setup File system for each Flash memory model. The file system will be so effective as accurately configured it. And this should not be a custom firmware user, but the memory maker itself, because only he can know all the nuances of its device.

TOTAL

F2FS is an excellent file system. This indicates at least the fact that, only appearing on the light, it is already able to successfully compete with the eXT4 people lick and hundreds. However, you should not wait for the wonders from it and run to format your device. Yes, many people declare noticeable even without tests to increase performance, but again, most likely, these effects are thus caused by the mechanism of deferred recording and in fact there is no significant increase in speed.

Alexey Fedorchuk
Ubuntu'wa passion, 06/12/2013

F2FS file system (FLASH-FRIENDLY FILE SYSTEM - "FROM FLACE SYSTEM FLACK SYSTEM") is designed specifically for accommodation on SSD and similar solid-state media. It is supported by the Linux kernel, starting with version 3.8.0 - the one that is part of Ubuntu 13.04.

In F2FS supports, it is easy to make sure the team

$ ls /lib/modules/3.8.0-23-generic/kernel/fs/f2fs.

in the output of which we will see the module

However, by default, it is not involved. Therefore, you can try to upload it in the usual way:

$ sudo modprobe f2fs

The attempt will be successful, as we will tell us the team

$ lsmod | Grep F2FS F2FS 109231 0

Interestingly, while the conclusion of the team

Dmesg | Grep -i F2fs.

it will still be empty. And after rebooting, no hint of this module will be found. So you need to ensure its download at the start system manually. To do this, it is enough to add a string to file / etc / modules

What can be done on the face of the superuser or in text editoror a sequence of type commands

$ sudo -i $ echo f2fs \u003e\u003e / etc / modules $ exit

As it is easy to guess, this achieves the obligation to load the corresponding module at the system initialization stage.

However, there is little joy from the most support of any file system, if there are no appropriate tools for working with it. And to work with F2FS they have them in Ubuntu yet.

However, the receipt of this toolkit is not great. And he is in checking the availability of the Universe repository with the subsequent team

Sudo Apt-Get Install F2FS-Tools

However, the entire toolkit for working with F2FS is currently coming down to a single command - /sbin/mkfs.f2fs and related documentation - MAN (8) MKFS.F2FS.

Creating F2FS on a section or RAW device is performed in the usual way:

MKFS.F2FS / DEV / SDF1

in response to which this conclusion follows:

F2FS-Tools: Ver: 1.1.0 (29-Nov-2012) Info: Sector Size \u003d 512 info: Total sectors \u003d 30308319 (in 512Bytes) Info: Zone Aligned Segment0 Blkaddr: 256 Info: This Device Doesn "T Support Trim Info : Format Successful.

The given example relates to a flash drive, why and we see a message about the absence of TRIM support - on any modern SSD, it will not be clear.

The mkfs.f2fs command has several options. One of them is -L sets the label for the corresponding partition or device, which is very expedient when using F2FS on interchangeable media of the type of flash drives. The rest define block distribution policies (-A), the size of the provision area (-o), the number of segments to the section (-s) and sections on the zone (-Z). However, the effect provided by them is not documented, and I did not have opportunities for experiments. So it remains to rely on defaults, what, except in aunt's mani, you can also look at the MKFS.F2FS command without argument:

A Heap-Based Allocation -o OverProvision Ratio -S # of Segments Per Section -z # of Sections Per Zone

After creating the F2FS file system, a natural desire arises to test it in business. For which it is desirable to mount it somewhere. Automatically system it is not recognized, despite the provision of downloading the desired module. That is, in contrast to other file systems on external media, it is not visible by default file managers Type Nautilus or Thunar.

However, this does not mean that sections or devices with F2FS must be mounted with hands and even more so from root. It is enough to create in the user's home directory mount point (for example, $ home / test) and enter in / etc / fstab string

/ Dev / SDB1 $ Home / Test F2FS User, Noauto 0 0

Of course, without forgetting to substitute the value of the $ HOME variable and specify the name of the detailed device. After that, the device with F2FS appears among the nautilus or Thunar input points when it is connected (in the form of a label - if this was specified). This refers to interchangeable media - for example, flashcams or SD cards. Internal devices ( sSD drives) It is advisable to mount the usual way "on an ongoing basis."

Unfortunately, place a file hierarchy root to F2FS currently It is impossible. In the Ubuntu Installer, this feature is not provided. And "bypass tracks", similar to those used when installing with the root on ZFS, rest in the fact that the GRUB-PROBE does not recognize F2FS, and no "adjustments" like Grub for Native ZFS, while (?) Does not exist.

File system performance - a very important thing, in this article we will find out which file system works faster on this moment, as well as how the performance depends on the Linux kernel version. We will compare the performance of ext4 VS F2FS VS BTRFS on SSD and we will use the kernel 4.4, 4.5, 4.6 and 4.7.

All three file systems were tested on each of the last stable versions of the kernel. All tests were performed on Samsung 950 Pro M.2 NVM Express SSD.

Ubuntu night assembly 16.10 was used as an operating system for testing, as well as the kernels taken from Ubuntu Mainline Kernel PPA. Tests were carried out fully automated and reproducible using software Phoronix Test Suite. To test each of the file systems, the section was full formatted. Also, formatting was performed for each version of the kernel. For mounting each of the file systems, the default mount parameters were used.

The first test was testing the performance of the SQLite database. Copy speed when writing to BTRFS is slightly lower than in ext4 and F2FS. Ext4 in this test showed the best result. The performance of BTRFS really improved in Linux 4.5 and Linux 4.6 kernels, and for the remaining file systems it remained at the same level.

In the random reading test, all three file systems showed regress starting from the Linux 4.4 kernel.

The results of serial readings have a completely different result, compared with the slowdown of the reading speed on newer nuclei.

Test random recording is not as interesting.

The FS-Mark F2FS test came to first place. It was tested with 1000 files of 1 MB. The performance of EXT4 and BTRFS is approximately at the same level.

Flash-Friendly File System continues to give excellent results. This time 4000 files, 32 subdirectory, size 1 megabyte.

In a multi-threaded test, FS-Mark did not reveal a large difference in the performance of EXT4 VS F2FS VS BTRFS file systems.

F2FS again takes the first place in the speed of reading in the BlogBench test. In second place BTRFS.

The best blogging speed on BlogBench in Ext4.

F2FS is returned to the top in the dbench test.

Ext4 and F2FS have shown themselves better for BTRFS in the PostgreSQL performance test.

conclusions

These are all test results EXT4 VS F2FS VS BTRFS, which we will consider today. As you can see, F2FS is a rather promising file system, but EXT4 and BTRFS hold well. As for the nuclei, the performance here is generally increasing, but this increase is not very large.

Good day. To begin with, we will understand what is F2FS and why it is needed.

F2FS (eng. Flash-Friendly File System) is a file system presented in 2013 optimized for use on flash stitches, including SSD, memory cards and built-in in various devices Memory chips. In general, this is a file system that initially takes into account the constant access time and a limited number of cycles of rewriting of memory cells, so its use and preferably.

Preparation of the device to install the file system

Support for this file system is included in linux kernel Starting with version 3.8. CyanogenMod does not allow using this file system to use this file system, so it must be added. But, fortunately, Comrade Dimfish has already done everything for us, and now we have only right to install operating system. Immediately I warn you that absolutely all the data from the phone will be erased, so it is better to think about all kinds of backups in advance (Google account for contacts, Titanium Backup for the application and hands to extract important photos). If all important has already been kept and confident in the directive of their hands, then proceed. But I remind you that the firmware of the phone is to some extent there is always a lottery, and for your phone only you. You can break it!

When writing the instructions, I stood Paranoid Android, and I did not work from the first time to install F2FS, I made a reset to the factory state, and after that the firmware got up to my home. The only data saving option is if you currently have the usual CM11. IN this case You need to make backup / data, via TWRP, which is available below, and after the installation is restored. If you have any other ROM, including the stock, restore / DATA is not recommended.