Divided into 2 parts, in the first part I introduced the concept that everything is a file and I introduced special devices/dev/ null, / dev / zero, / dev / random and / dev / full.
In this part 2, I will present interesting didactic features about this, for example, how to transform a file into a partition! Reading this post requires prior knowledge of Part 1!You are a scholar who has the following knowledge:
- If I format a hard drive or pen drive, I’m setting a partition on a media – MBR, GPT, BSD, Amiga, etc… – and, inside it, I’ll save my data, files, the installation of my OS, anyway… Each partition on disk allows me to apply a different file system – NTFS, EXT4, FAT32 and etc – and within that file system I will install the system and put my personal files.
With that in mind, let’s make a little joke, quite simple:
1. Create a 4Gb file filled with zeros using the DD command.
It will be created in / home / $ USER; change this path if you do not have enough disk space.
$ dd if = /dev/zero of=~/test bs=1M count=40962
Now let’s format this file. Yes, and more, it will have the EXT4 format in our example!
A little confused? Trust me, buddy. Come on:
$ mkfs.ext4 -m .005 ~/test
The -m flag in the command causes us to decrease the “root” space that the EXT4 sets to 05 by default. This is even useful for installing a system and preventing EXT4 from consuming a lot of disk space by default.3. Formatted? Okay, now you have a 4GB file of type “unknown” called “test” in your / home, and nothing else opens it. Sit in a chair (if you’re not already in one) and note that now comes the best part:
Mount it as a partition!
$ sudo mkdir /media/test $ sudo mount -rw ~/test/media/test/
Hey buddy congratulations, you not only created a file in .EXT4 format, you created an EXT4 PARTY inside a common file in your / home and you can still store things inside it!
The same procedure can be done for any file format: EXT2, FAT32, NTFS, etc. Everything only depends on your needs! But do not think you can install Windows on it, as it is a partition inside a partition, who manages it under EXT4 (or btrfs, or xfs depending on your system). It’s also tricky to mount it as a partition on a Windows since the system does not operate as UNIX-based devices reading block devices as files, but treating them differently. You can even force your assembly with the -F flag but only UNIX-based systems will recognize it and mount it.
This detail has been made explicit here.
As I explained in Part 1, “everything is a file“:
That is, a folder, a directory, a partition (that is, things that store things) are nothing more than “index files” that define what’s in it sector of your disk or SSD. When they say that UNIX-based systems have a philosophy of simplicity, it’s this simplicity we’re talking about: Everything is just a file, palpable, simple and functional, easily manipulated, bluntly.
The biggest lesson here is that you just learn how basic way Virtualization of an operating system (VirtualBox): You create a partition in a file (in VirtualBox it is in .vdi format) and within you install your system.
- And what do I do with this 4 Gb EXT4 partition here?
Oh, you can store things in it, you can install an entire operating system on it (non-Windows, preferably), you can put it on a USB stick to enhance the security of your files, you can encrypt it and turn it into a safe, it inside an HD with Windows formatted as NTFS, so it will be hidden …. or just disassemble and delete it!
Some file systems such as JFS operate by allowing for better organization of data if they are small (text documents) and in other cases like XFS if they are large files (disk images, HD photos, .flac songs). Having a virtual partition with one of these formats can optimize the disk space consumed.
- And how do I dismantle her?
$ sudo umount / media / test
After that, you can play this file-partition in the trash.
In this second and last part of the session “Did You Know? Everything is File “I have said about the virtual partitioning of files to be used as disk partitions and some advantages of these.
Along with the earlier part, where I board on special devices, there is the knowledge that can be added to any Linux student (or other UNIX-based systems), improving their understanding of how a system works.