Thursday, December 17, 2015

How to install Linux on Pendrive using F2FS Filesystem

Well, F2FS filesystem is specially designed by Samsung which is good for SSDs and pendrives. It makes the read and write operations on the devices much faster, because it is specially designed for those mediums. Even take a look at these benchmarks to prove that F2FS performance is better.


We all know how a little bit slow the live USB installations can be. So if we can install Linux on an F2FS filesystem, it will make it a bit faster. Also, as a plus point, F2FS increases the life of your pen drive or SSD. Neat!

Unfortunately, the most famous linux distro – Ubuntu – does not support installing on F2FS yet. (Although, it is in the wishlist.) So we would have to look for the F2FS support in another Linux distro – Manjaro.

Manjaro is an Arch Linux based distro. It is similar to Ubuntu… one exception being that the package manager is different. In Ubuntu we type sudo apt-get ..., but in Arch/Manjaro we type sudo pacman …. If you use the built in GUI Software installer (pamac or octopi) you would hardly notice the change.

But I have to admit Manjaro works like Ubuntu but its way faster than Ubuntu.
Also, Manjaro is a rolling release distro. That means you will get the latest version of the software faster than Ubuntu! When you update, you will always have the latest distro ready for your clicks and tweets!

The steps are very easy but 2 requirements are necessary for this:
-1 DVD or USB pendrive (2GB or more to accommodate 1.3 gb+ image) to run LiveDVD
-1 Pendrive from which you want your Manjaro to run from (8GB or more)

A word of CAUTION: Backup any files on the medium and maybe also in your hard drive. Linux installers are powerful and failing to use it skillfully may wipe your hard disk!! I will not be responsible for any damage. Please proceed with caution.

Another WARNING is: F2FS is new technology. It has yet not been made stable by Samsung. (While I am writing this, 3.8 version is the latest one which is Unstable and there is not a single stable release yet.) So do not use this filesystem yet for serious data... Users say it is quite stable, but it is not officially marked as "Stable". So please keep this in mind.

Step 1: Download Manjaro

I have used the development version of Manjaro because it has better filesystem support (and F2FS support is quite new).

Go to https://manjaro.github.io/download/
Download the latest release. The stable release may not have the support when I am writing this so I have used the development version. I have used 12.15 version (XFCE 12.15-rc1 32 bit version).

After downloading you will get a .ISO image file. We'll need that in a moment.

Step 2: Prepare Live DVD or Live USB

(I'll assume you have Windows installed.) Manjaro cannot be installed from Windows. The installation wizard is designed to run in Manjaro only. So first we need to run Manjaro from a temporary LiveDVD or a temporary pendrive. From it, we will install it in our final Pendrive.

You need either a DVD or a USB pendrive.

-For making a LiveDVD you can use any DVD writing software to write the ISO file to DVD. (This is a guide that may help you, it uses freeware software.)
-For making a LiveUSB you can try Universal USB Installer (UUI) or Linux Live USB (LiLi). They are both very easy to use. Just Select the pendrive and select the distro and then select the ISO image that you downloaded on Step 1. (Here is a tutorial on how to use UUI.)

Step 3: Boot the Live medium

You may need to change some BIOS settings in order to boot from the medium you just created (your LiveDVD or LiveUSB). Enter BIOS, go to Boot priority settings, and make sure your DVD drive and USB drives are at the topmost position. (Here is a tutorial to help you with this.)

You need to attach or insert the medium and reboot the computer. Manjaro will automatically boot up.

Step 4: Prep the USB!

Now insert your final installation pendrive. You can use Gparted or you can use the partitioning option in the installer. I prefer to use Gparted to partition before entering the setup.

Run Gparted and select the pendrive. Delete all the existing partitions and create:

-A FAT32 partition of 512 mb or more in size. You can use the rest of the pendrive deducting the size of the F2FS partition below. (most probably be called /dev/sdc1)
-An F2FS partition of 7 gb or more in size. (most probably be called /dev/sdc2)

We keep the first partition FAT32 because it will make that partition accessible from windows. The rest of the pendrive space will be used by Linux and will not be visible (but if you are desperate, it be viewed with a special software).

[ In order to create an F2FS partition with Gparted or any partitioning software, you need to install f2fs-tools package which was installed already in the LiveUSB. So you'll not need to install it yourself. Just saying this as a note. ]

Now we are ready!

Step 5: Run the installer

ATTENTION: I found out that Currently the “Thus” installer can only use F2FS. So I am using that one. There is another installer named “Calamares”. I did not have success with it. I did not find an option for F2FS although f2fs-tools was installed. This should not be the case. Maybe it is a temporary bug and will be fixed in future versions.

So search in the Applications menu and find Thus installer. Run it.

Carry on with the on screen instructions.


When the partition part comes, select your device and choose Manual partitioning. Select the 512 mb partition, click Edit, choose Format, then choose Mount as /boot.

Then select the F2FS partition, click Edit, choose Format, then choose mount as /.

ATTENTION!! Don't forget to change the bootloader device… before going to the next step! It resets itself to hard disk everytime you edit a partition!! Be sure to set it to the pendrive you are installing to, not the hard drive. If you keep it as hard drive, it will make your Windows installation unbootable by entering into GRUB recovery. (Although it is repairable.)

Now continue with the installation. At the end you will be prompted to reboot. Don't just reboot yet. Just select No on that dialog.

Step 6: Modify the GRUB config

You will have to modify the GRUB config because it says /dev/sdc2. Now go to the file /dev/sdc2/boot and edit the GRUB config to say /dev/sdb2 instead of /dev/sdc2

==

To get UUID first run:

fdisk -l

You will find the partition that you want as root (that you showed as / when installing). For example, /dev/sdc2.

Now run

sudo blkid

and find the UUID for the device.

Now open the boot partition in file manager, then go to grub/grub.cfg

in that file you will find a line like this:

linux /vmlinuz-4.1-i686 root=/dev/sdc2 rw quiet splash

Notice that /dev/sdc2 is there. It will make trouble for us. Because when there will be only one pendrive in the computer when booting, our pendrive will be /dev/sdb2 and it will not boot. So we will boot with UUID, which will not change and Grub2 will be able to find it no matter how many devices are there.

Now you can use it like this

root=UUID=XXXXXX

For example:

root=UUID=cadc967d-83c9-4998-bf39-02447a1d6a6f

So change the line:

linux /vmlinuz-4.1-i686 root=/dev/sdc2 rw quiet splash

into…

linux /vmlinuz-4.1-i686 root=UUID=cadc967d-83c9-4998-bf39-02447a1d6a6f rw quiet splash

==

Once you booted successfully, run
sudo update-grub


Step 7: Reboot and enjoy

Reboot the computer. Unplug the temporary USB or eject the DVD.
Make sure the final USB pendrive is the only one inserted in the computer.

Now it should gradually reboot to Manjaro and it will run with F2FS filesystem!

Last lines

I don't know about SSD hard disks, but for pendrives you will find it better than other filesystems, such as, ext2, ext3, ext4, btrfs etc. It will be much more responsive and faster than those other filesystems out there.

I am a big fan of running Linux from pendrives. I tried many distros and many techniques.

But for first time in life I was happy with the performance in Persistent LiveUSB Installation. Thanks to the great team at Samsung who are working with this amazing filesystem!

I can barely feel if I am using it from hard disk or my pendrive!


UPDATE 1 (27 JAN 2016): It seems the pendrive created like this can run on the machine that created it. But it cannot boot on other machines... or other monitors. This is because some X11 configs are saved inside /etc/X11/xorg.conf.d directory. Just summon up PCManFM/Dolphin/whatever file manager with root access (sudo pcmanfm) then keep a copy of the above directory, then delete the contents inside it.

Also, I found that it is more logical to create a seperate boot partition with the size of ~100mb with Ext2. Ext2 is supported by GRUB so grub files can easily stay in it, but windows viruses cannot see it because Ext2 is not seen by Windows. So, viruses won't be able to attack the grub files.

Another interesting find! I found that the Windows FAT32 partition done with gparted is not accessible from windows. When I insert it on Windows it shows a message to format it. (Please, don't format!) I used BootIce (Download from here or here). With the pendrive inserted I launched Bootice, then selected Destination disk as my pendrive, then clicked "Parts manage". With the first (FAT32) partition selected, I clicked "Re-partitioning", then selected "USB HDD mode (Single partition)", then click OK. Done! It is accessible again!

If you want to restore the pendrive to its original state then read this gem! This will of course delete all your linux installations and format it to a 100% FAT32 partition pendrive.

No comments:

Post a Comment