According to Dr. Brown’s recipes

According to Dr. Brown's recipes

Dr. Chris Brown

Doctor teaches, writes and consults on Linux. PhD in elementary particle physics it this does not help.

Esoteric system administration of bizarre volvulus server

Old Tux?

We all know Tux. This chubby penguin became the face of Linux in the mid-1990s, but those remained. But few of us are lucky like me, met him in life. Now he is retired and lives on the beach in the coastal Penguins zoo in Devon. In spite of the progressive disease of fins, he hobbled up to me and graciously gave me an interview. I asked him how his fame began.

«Well, Linus took a mascot in the form of a penguin, he sent to me by Larry Ewing [Larry Ewing], and I told him to pose. This was back in 1996. The result I did not like — he gave me complete. And some sleek. » He thought. «I was three, I do not know any better.» Now he was twenty, and it’s not a bad age for Penguin.

«And then it began. I’ve been everywhere. Blinded distribution Linux? Need logotipchik? Here’s "good old fat" Tux. And I just started to care for the girl [pingvinkoy], and this, believe, for the benefit of me not going. «

Kombez with rhinestones

«But do not you star? — I asked. — And what about Super Tux Kart? Or Pingus? »« Where I sooner or later tear off a cliff and die absurd death? No, thank you! «

I asked him what he was doing then. «Well, basically I am eating herring. Yes, touted at a photo shoot. Conducts training Linux? Put on a master’s cap (it’s all right). They want to emphasize the safety of Linux? Shingles padlock. Performance Tuning? Pinned on his back rocket starter. I beg you! Then they wanted a rear view of a USB-connector in my … — I really do not know why. But I did not say a single tear. «

As a thank you for the interview, I asked the old days Tux, what would he do such a nice response. He crept closer and whispered, «Herring is?»


We pay tribute to Debian: sing the praises of the most influential distro Linux.

June 15 — less than two-odd years since the previous release, Squeeze, appeared in February 2011 — finally came Debian 7 (for friends — just Wheezy). Debian does not attract as much attention as some other distributions, Debian because no one beats the drums as well as, for example, Mark Shuttleworth [Mark Shuttleworth] for Ubuntu; but Debian, of course, remains one of the most stable, respected and influential distributions.

I caught a tree diagram of the evolution of Debian Linux — and it reminded me of the very trees biological evolution from the book by Richard Dawkins [Richard Dawkins] «The Ancestor’s Tale,» an interesting perspective on the evolution, the origin of humanity can be traced right up to the first organic burp.

The fact that Debian has laid the foundation for an incredible amount of the systems; one died pretty quickly (remember Quantian? No? I do not remember), and others (the main

The Hurd Debian and examples — Ubuntu and Knoppix), in turn, gave rise to a whole phylogeny [in biology — the development of species over time — approx. Lane] distributions — MoonOS, Trisquel, Semplice, CrunchBang, Christian Edition, Satanic edition and many others that are almost impossible to count. Each of them has its ecological niche, and DNA has much in common with Debian.


Wheezy has nine modifications processor architectures, including SPARC, IBM S / 390 and, of course, 32-bit and 64-bit PCs. There is even a version with the core BSD Unix, which goes beyond the boundaries of what we call the «distribution Linux», and stresses that the objective reality is that most people are only important user programs, and to delve into the core, they are not going to.

So if you are tired of blowing dust in the eyes of the Unity or already boring dispute about the graphic server X11 / Wayland / Mir and just want an operating system that works, try Debian. I promise you will not regret.

Cows, oil and TARDIS *

Btrfs If you have not played with the best file system, it’s time to do it. Even the Good Doctor eventually was granted.

Recently, on the stage of Linux will be two exciting new filesystems. First — btrfs (binary tree file system — file system is a binary tree) — a reference to its internal data structures, and seems to have all pronounced her name as the "butter filesystem [oil filesystem]". Second — ZFS (originally meant "zettabyte filesystem [zetabaytnaya filesystem]"), And because of its American origin, we, probably, have to pronounce the name as "Zee F S [Z-ef es]".

And btrfs, and zfs — more than just a file system: features such as volume management, compression, and images built right into them. This month we’ll talk about btrfs.

Examples in this article were carried out in Debian Wheezy, is running on a virtual machine. If you want to follow us, first create a virtual machine with four hard drives (sda, sdb, sdc, and sdd, in Linux-terminology) of 20 GB each. Then install Wheezy, by btrfs as the root file system for sda. Then after installation you will have a file system btrfs and three blank disc. (Of course, Wheezy is not necessary to install — you can use almost any modern distribution, setting it package btrfs-tools)

You need to be the administrator!

So, let’s begin. By the way, for most teams in this article, you must be an administrator. First make sure we can see all the drives:

# Ls -l / dev / sd?

brw-rw — T root disk 1 8 0 May 23 11:44 / dev / sda brw-rw — T 1 root disk 8, May 16, 23 11:44 / dev / sdb brw-rw — T 1 is root disk 8, 32 May 23 11:44 / dev / sdc brw-rw — T 1 root disk 8, 48 May 23 11:44 / dev / sdd

Yes it’s OK!

In this system, I started by creating a new file system spanning two discs, sdb and sdc. Whether it is ext3, would require a lot of work — it would have to either merge the two into a software disk raid-array using mdadm, or create one volume group, and then select the logical volume. But btrfs is impressively simple:

# Mkfs.btrfs / dev / sdb / dev / sdc

That’s all true, true! Now I’ve got an empty file system, ready to be mounted. To have warmed pleasant feeling that all is well, you can see your file system btrfs, commanded

# Btrfs filesystem show

Label: none uuid: 8bb3017d-6932-42d9-8c06-7c31f634fabb

Total devices 2 FS bytes used 28.00KB devid 2 size 20.00GB used 2.01GB path / dev / sdc devid 1 size 20.00GB used 2. 03GB path / dev / sdb

Label: ‘btrfs-root’ uuid: 13090010-18a0-43c9-a6a7-acd8050f82d3

Total devices 1 FS bytes used 3.45GB devid 1 size 16.76GB used 6.04GB path / dev / sda1

As expected, we have two volumes: one — sda1, created during installation, and another covering sdb, and sdc. And we have just created.

# Tardis — time machine and spacecraft from the British television series «Doctor Who» — a comment. per.

Then I created the mount point / data and installed a new volume btrfs:

# Mkdir / data

# Mount / dev / sdb / data

Note that the file system can be identified by any one of its devices, so the team

# Mount / dev / sdc / data would work the same way.

Now that is mounted, and can be seen in the output of df:

# Df -h / data

Filesystem Size Used Avail Use% Mounted on / dev / sdb 40G 3.9M 38G 1% / data

Cool feature number 1 Resize

One of the many cool features btrfs — resizing the file system on the fly. For example, to reduce by 10 GB is sufficient skomandovat

# Btrfs filesystem resize -10G / data

Now, df shows the reduced size:

# Df -h / data

Filesystem Size Used Avail Use% Mounted on

/ dev / sdb 30G 3.9M 18G 1% / data

…or you can return to the maximum size of the system:

# Btrfs filesystem resize max / mnt

Large and small files

Btrfs works well with large files, supporting files up to 16 million terabytes; but it copes with small, as is able to stamp several small files into a single logical disk block. Compare: file systems such as ext3 allocate a block in the 4K bytes, even for file sizes in a matter of a couple of bytes. To test, I experiment a bit. At first, I wrote a small script that creates a lot of small files:

#! / bin / bash x = 1 while [$ x -le $ 1] do dd if = / dev / zero of = / data / x $ x bs = $ 2 count = 1 x = $ (($ x + 1)) done

Then I run the script to create 1,000 files of 100 bytes each, and using df compared the space before and after:

# Df / data

# Makelotsoffiles 1000 100

# Df / data

The results were interesting. The ext3 file system on the number of free blocks 1KB fell flat on 4096, which proves that everyone took my file on a 4 KB block. In btrfs number of available blocks has decreased in all by 1200.

Cool feature number 2 subvolume

Another really useful feature btrfs — subvolume. In traditional file system, each partition (or each logical volume if using LVM) contains its own file system structure. When mounting the device its file system appears as a directory hierarchy mount point. For example, if / dev / sdb1 I have a file system that contains the directories a and b of the upper level, and I mount it under / mnt as follows:

# Mount / dev / sdb1 / mnt these directories appear in the file system tree as the / mnt / a and / mnt / b. In traditional file system can not mount the directory only a — albeit with subvolume possible.

Here’s how it works. The file system btrfs subvolume I created three — web, mysql and home:

# Btrfs subvolume create / data / web Create subvolume ‘/ data / web’

# Btrfs subv cr / data / mysql Create subvolume ‘/ data / mysql’

# Btrfs subv cr / data / home Create subvolume ‘/ data / home’

Note that the command can be abbreviated to btrfs (as I did with the last two teams), if they are treated uniquely.

For comparison, create an ordinary top-level directory of the volume:

# Mkdir / data / test

# Btrfs subvolume list / data

ID 258 top level 5 path web

ID 259 top level path mysql 5

ID 260 top level 5 path home

Subvolume to some extent look like regular folders — such as they appear in the directory list:

# Ls -l / data total 0 drwx —— 1 root root 0 May 23, 13:03 home drwx —— 1 root root 0 May 23 13:02 mysql drwxr-xr-x 1 root root 0 May 23 13:06 test drwx —— 1 root root 0 May 23 13:02 web

But, unlike directories subvolume can be mounted. Here I created the mount points / web and / mysql and installed two of its subvolume:

# Mkdir / web

# Mount -o subvol = web / dev / sdb / web

Subtopic can also be specified by its ID (subvolume from the list):

# Mkdir / mysql

# Mount -o subvolid = 259 / dev / sdb / mysql

Mount subvolume "home" to / home a little more complicated, because the on / home already has the content you want and then add the contents of the volume. Therefore, we need such a reshuffle:

# Mv / home / home-temp

# Mkdir / home

# Mount -o subvol = home / dev / sdb / home

# Cp -a / home-temp / * / home

# Rm -r / home-temp /

We have turned the circuit shown in the figure on the right, with a different subvolume, took their places in the file system tree.

Cool feature number 3 Pictures

In btrfs snapshots can be made subvolume. That’s really cool! At first I found it hard to understand how it works, mainly because it all seemed to me it was more complicated than it really is. Here’s how it works. Command

# Btrfs subvolume snapshot / data / web / data / web-snap1 Create a snapshot of ‘/ data / web’ in ‘/ data / web-snap1’ creates a copy of the web subvolume named web-snapl. Firstly, in the original and the copy, naturally the same contents. But if you change the contents of each of them, it takes up the technology for recording btrfs, which is stored on the disc, only the differences between the two on the subvolume as over time they begin to differ. Now, the web or web-snapl — just two subvolumes, most of the content is the same. You can change any subvolume, and it will not affect the other.

Snapshots allow, in the Tardis, return to the past (the future is impossible, sorry). Explicit command «roll back» to return to an earlier snapshot is not, for that just need to unmount the current volume and install in its place a picture:

# Umount / web

# Mount -o subvol = web-snap1 / dev / sdb / web

You can then delete the volume from which you rolled:

# Btrfs subvol delete / data / web

A copy of a read-only (which is closer to what we usually call image), you can create as follows:

# Btrfs subvolume snapshot -r / data / web / data / web-snap2 Create a readonly snapshot of ‘/ data / web’ in ‘/ data / websnap2’

Trying to change it will fail:

# Touch / data / web-snap2 / junk

Filesystem touch: can not touch 7data / web-snap2 / junk ‘: Read-only file system Snapshot read only useful if you want to make a backup copy of the operating system, and you want the system was not changed until backed up.

Cool feature number 4 Adding disk

If you are still not happy with btrfs, you do nothing to please. Here’s another interesting trick. Assume that my fact filled. I can expand it in a simple manner by adding another disk (the last of my four virtual drives) as follows:

# Btrfs device add / dev / sdd / data

# Btrfs filesystem show / dev / sdb

Label: none uuid: 8bb3017d-6932-42d9-8c06-7c31f634fabb

Total devices 3 FS bytes used 9.93GB devid 2 size 20.00GB used 7.01GB path / dev / sdc devid 1 size 20.00GB used 7.03GB path / dev / sdb devid 3 size 20.00GB used 0.00 path / dev / sdd

Note that although the third disc is now entered in the fact it does not have the data, so you need to repeat the balancing data:

# Btrfs filesystem balance / data

Now the data is distributed (more or less) uniform:

# Btrfs filesystem show / dev / sdb

Label: none uuid: 8bb3017d-6932-42d9-8c06-7c31f634fabb

Total devices 3 FS bytes used 9.93GB devid 2 size 20.00GB used 5.25GB path / dev / sdc devid 1 size 20.00GB used 5.01GB path / dev / sdb devid 3 size 20.00GB used 5.26GB path / dev / sdd

On the rebalancing even in my tiny filesystem it took a full four minutes. I imagine how long can be filled rebalancing of the file system size of 2 TB after adding a new disk of 1 TB.

Cool feature number 5 Striping and Mirroring

As we have seen, that btrfs is easily extended to multiple discs. You can choose how to distribute data between disks. Default information about a data structure known as metadata mirrored (i.e., a double-disk configuration is recorded on both of the disk), but the data is interleaved (i.e., the first piece of data written to the first disk, the second — on the second, third — again First, it.d.). These two technologies, mirroring and striping, commonly known as RAID1 and RAID0, respectively.

RAID level can be controlled by the file system. For example, the command

# Mkfs.btrfs -d raid1 / dev / sdb / dev / sdc lead to the fact that both data and metadata will be mirrored. This mirroring provides redundancy — if any of the disks fails, data can be recovered; but actually it halves the available disk space. Remember that the default raid0 does not provide redundancy. On the contrary, if any disk fails, you lose the entire file system.

You can also implement what is commonly called the "raid10" (RAID0 on top of RAID1), but this requires four drives.

I’m not trying to measure performance (in my toy system that made no sense), but if you click on the link to, you will find a lot of tests. There is also a utility btrfs-convert, which can be used on the spot [in-place] to migrate to ext3, or ext4 (and keep the original picture, in case you want to roll back the changes). Finally, a team of btrfs scrub, run background checks data integrity — something like fsck, but a running file system.

If you are a Linux seriously, you can not ignore the btrfs. This is the future. Next month: ZFS. Alternative future!

Like this post? Please share to your friends: