Latest / CyberCode Academy / Course 44 - RH Security Specialist | Episode 4: Performance, Security & Mount Options
Transcript
- 0:00Speaker 1: Imagine, just for a second, that you are building a
- 0:02Speaker 1: server from scratch. I mean, completely from the ground up.
- 0:05Speaker 2: Oh, that's always a fun thought experiment. Right.
- 0:07Speaker 1: And every photo, every massive database, every single line of
- 0:10Speaker 1: code that you actually care about has to be stored
- 0:13Speaker 1: physically on a disk, yet perfectly organized digitally.
- 0:16Speaker 2: Yeah, the physical to digital bridge.
- 0:19Speaker 1: Exactly. How does the computer actually manage this without just
- 0:22Speaker 1: completely losing its mind? Like, when a high-frequency trading server
- 0:26Speaker 1: loses power, Why doesn't it wake up with millions of
- 0:29Speaker 1: dollars of corrupted, half-written data?
- 0:31Speaker 2: It's a phenomenal hidden mechanism. I mean, most of us
- 0:34Speaker 2: just hit save and assume the data is safe. But
- 0:37Speaker 2: underneath that simple action is this layered architectural marvel that's
- 0:42Speaker 2: designed to fight chaos.
- 0:44Speaker 1: And that invisible architecture is exactly what we're looking at today.
- 0:47Speaker 1: We are doing a deep dive into Linux file systems.
- 0:50Speaker 2: The invisible architects of our digital lives.
- 0:53Speaker 1: Beautifully put. And our mission today is pretty straightforward. We
- 0:56Speaker 1: are going to virtually provision a server drive step by step.
- 1:01Speaker 1: We'll pick a file system, format it, mount it, and
- 1:05Speaker 1: tweak its security parameters to make it bulletproof.
- 1:07Speaker 2: And we're doing all of this mentally. No screens, just
- 1:10Speaker 2: visualizing the terminal commands and the logic.
- 1:13Speaker 1: Okay, let's unpack this. Because before we can store a
- 1:16Speaker 1: single byte of data, we have to lay down the tracks, right?
- 1:19Speaker 2: Mm-hmm.
- 1:20Speaker 1: Different tasks require entirely different file system architectures.
- 1:23Speaker 2: Yeah, you really can't just pick one at random. The
- 1:25Speaker 2: foundation dictates your physical limitations. In the Linux world, we
- 1:29Speaker 2: have a few heavyweights. Let's start with BTRFs.
- 1:32Speaker 1: Often pronounced ButterFS, right?
- 1:33Speaker 2: Yeah, exactly. ButterFS. It was actually designed by Oracle. And structurally,
- 1:38Speaker 2: it relies really heavily on a B-tree structure.
- 1:40Speaker 1: Which is super optimized for external memory.
- 1:43Speaker 2: Right. It's optimized for systems reading and writing massive blocks
- 1:47Speaker 2: of data, like heavy databases. Because bee trees remain incredibly shallow,
- 1:51Speaker 2: you minimize those expensive physical disk seeks.
- 1:54Speaker 1: It also has this amazing copy-on-write feature, or COW. The
- 2:01Speaker 1: best way I can think to explain it is, imagine
- 2:03Speaker 1: you have this highly detailed master blueprint for a skyscraper.
- 2:08Speaker 2: Okay, I'm picturing it.
- 2:09Speaker 1: Instead of making a full physical photocopy of that massive
- 2:13Speaker 1: blueprint every time an engineer wants a copy, Everyone just
- 2:16Speaker 1: gets a little index card pointing to the original in
- 2:19Speaker 1: the vault.
- 2:19Speaker 2: Oh, that's a great analogy. Right.
- 2:21Speaker 1: A new copy is only actually drawn up if someone
- 2:24Speaker 1: takes a pen and wants to make a change to
- 2:25Speaker 1: their specific version. It saves an immense amount of disk space.
- 2:29Speaker 2: Yeah, that pointer-based architecture is the whole engine behind its efficiency.
- 2:34Speaker 2: And because it's just tracking pointers, taking a snapshot of
- 2:37Speaker 2: a terabyte of data takes, like, Fractions of a second.
- 2:40Speaker 1: Because you aren't copying data, you're just freezing the pointers.
- 2:42Speaker 2: Exactly. It's instantaneous. It also gives you native quota groups
- 2:46Speaker 2: and sub-volumes.
- 2:47Speaker 1: Sub-volumes being folders you can mount as entirely separate file systems, right?
- 2:50Speaker 2: Yeah, they behave like standard directories, but the OS treats
- 2:54Speaker 2: them as distinct block devices. It gives you incredible flexibility.
- 2:57Speaker 1: But if we step away from BTFS with a classic workhorse, XD4.
- 3:02Speaker 2: The battle-tested standard.
- 3:03Speaker 1: Yeah, it's a huge upgrade from XD. It's backward compatible,
- 3:06Speaker 1: boasts unlimited folders. and has a storage limit of one exabit.
- 3:10Speaker 2: Which is massive. But then, you know, we also have
- 3:11Speaker 2: to talk about XFS.
- 3:13Speaker 1: Ah, right. The default on Red Hat Enterprise Linux 7
- 3:16Speaker 1: and CentOS 7.
- 3:17Speaker 2: Yeah, and XFS pushes that limit up to a mind-bending
- 3:20Speaker 2: eight exabytes. But it's really known for high performance and
- 3:23Speaker 2: handling parallel throughput. It uses 64-bit storage and allocation groups,
- 3:27Speaker 2: so multiple processes can write concurrently without locking each other out.
- 3:31Speaker 1: Perfect for a busy server. So let's visualize this. We
- 3:33Speaker 1: have our blank drive attached. Let's call it devxvdf. If
- 3:37Speaker 1: you're following along in your head, creating these is so satisfying.
- 3:40Speaker 1: You just open your terminal and type mkfs.btrfs or mkfs.ext4
- 3:45Speaker 1: or mkfs.xfs, followed by that device name.
- 3:48Speaker 2: What's fascinating here is how XFS handles that provisioning command.
- 3:53Speaker 1: Oh.
- 3:53Speaker 2: Yeah, it has these really strict safety rails. If that
- 3:56Speaker 2: partition already exists on the drive and you type mkfs.xfs,
- 4:00Speaker 2: it will flat out refuse to format it.
- 4:02Speaker 1: Really? It just stops?
- 4:04Speaker 2: It halts immediately. Unless you explicitly use a force overwrite
- 4:07Speaker 2: flag like MITO-F, it won't let you destroy existing data structures.
- 4:11Speaker 1: A nice little safety net against late-night typos. Also, fun
- 4:15Speaker 1: fact about the XTM4 command under the hood, it actually
- 4:19Speaker 1: uses a program called MKT2 and pulls all its default
- 4:22Speaker 1: settings dynamically from a configuration file at etcmkt2fs. com.
- 4:28Speaker 2: I love that transparency. You can just open that file
- 4:31Speaker 2: and read exactly what ratios it's applying.
- 4:32Speaker 1: Totally. Our drive is formatted, but now we have to
- 4:36Speaker 1: actually attach it to the server hierarchy.
- 4:38Speaker 2: The mounting phase.
- 4:39Speaker 1: Right. And how we mount it dictates the rules of
- 4:42Speaker 1: engagement for the whole system. We can do it manually
- 4:44Speaker 1: with the mount command or automatically on boot through the
- 4:47Speaker 1: fstab file system table.
- 4:49Speaker 2: And this is where you start making big decisions about
- 4:51Speaker 2: performance versus security, like handling rights, sync versus async.
- 4:57Speaker 1: Let's break that down. With async, the system writes data
- 5:00Speaker 1: to the drive, but it keeps the metadata like owner
- 5:02Speaker 1: info and permissions in the WAM to flush to the
- 5:04Speaker 1: disk later.
- 5:05Speaker 2: Right. While sync writes everything, data and metadata, straight to
- 5:09Speaker 2: the physical drive immediately.
- 5:10Speaker 1: Which brings up a huge question. Why wouldn't we just
- 5:13Speaker 1: write everything instantly to be safe? I mean, keeping metadata
- 5:17Speaker 1: in volatile memory seems like a massive risk if the
- 5:20Speaker 1: power drops.
- 5:21Speaker 2: In a vacuum, sure, sync is safer. But in reality...
- 5:25Speaker 2: it causes terrible disk thrashing.
- 5:28Speaker 1: Thrashing. Yeah.
- 5:29Speaker 2: Imagine thousands of tiny writes per second on a busy
- 5:32Speaker 2: web server. If you force the drive to write the payload,
- 5:35Speaker 2: then immediately seek to a different sector for permissions, then
- 5:39Speaker 2: another for timestamps, you completely cripple the server's performance.
- 5:43Speaker 1: Ah, so async batches them up efficiently in memory first.
- 5:46Speaker 2: Exactly. It frees up the hardware. You do risk losing
- 5:49Speaker 2: metadata if the power dies before the flush. But the
- 5:52Speaker 2: performance game is usually worth it.
- 5:54Speaker 1: That makes total sense. And it's a similar balancing act
- 5:56Speaker 1: with tracking access, right? The a-time versus no-time debate.
- 5:59Speaker 2: Yes, the timestamps. Linux tracks, modified time, metadata, change time,
- 6:04Speaker 2: and access time, which is a time.
- 6:06Speaker 1: I always compare a time to this ridiculously strict librarian. Like,
- 6:10Speaker 1: imagine a librarian who insists on making a written entry
- 6:12Speaker 1: in a heavy ledger every single time someone just glances
- 6:16Speaker 1: at the cover of a book.
- 6:17Speaker 2: That sounds exhausting.
- 6:18Speaker 1: Exactly. On a busy server, serving a tiny file causes
- 6:21Speaker 1: thousands of unnecessary writes just to say, hey, this was
- 6:24Speaker 1: looked at. Turning it off by mounting with no time
- 6:27Speaker 1: vastly improves performance.
- 6:29Speaker 2: It does. But I have to push back a little
- 6:31Speaker 2: from a security angle.
- 6:32Speaker 1: Forensics.
- 6:33Speaker 2: Yeah. If a server is hacked, an intruder might just
- 6:36Speaker 2: be running reconnaissance. They might not alter any files. They
- 6:39Speaker 2: might just read your config files to steal keys.
- 6:41Speaker 1: And if no time is on, you have no record
- 6:43Speaker 1: that they looked at it. Exactly.
- 6:45Speaker 2: Atoin lets you trace exactly which files the intruder copied.
- 6:48Speaker 2: It's a really delicate balance between raw speed and forensic visibility.
- 6:53Speaker 1: Wow. Okay, so speaking of security, we can lock these
- 6:57Speaker 1: drives down even further, right? Using flags in that FITSTAB file.
- 7:00Speaker 2: Oh, absolutely. We can mount with Nodev, which tells the
- 7:03Speaker 2: kernel to ignore any device files on that drive.
- 7:06Speaker 1: Super important. And Nosuid prevents users from running programs as
- 7:10Speaker 1: the root user.
- 7:11Speaker 2: Right. And then you have no exec, which just flat
- 7:14Speaker 2: out stops any executable file from running from that mount point.
- 7:17Speaker 1: Which is so perfect for, like, USB drives or CD-ROMs.
- 7:21Speaker 1: You ensure a rogue user can't plug in a flash
- 7:23Speaker 1: drive and just fire off a malicious root script. We
- 7:26Speaker 1: also have nowzer, meaning only Roop can mount the drive,
- 7:30Speaker 1: and auto to make it automount on boot.
- 7:32Speaker 2: Don't forget, roo versus row, read-write versus read-only.
- 7:36Speaker 1: RU being the standard, obviously, and ROW for protecting data,
- 7:39Speaker 1: like when you're copying from a compromised server.
- 7:41Speaker 2: Yeah, though usually, if you see a read-only file system
- 7:45Speaker 2: in the wild on a production server, it's actually a
- 7:48Speaker 2: really bad sign.
- 7:49Speaker 1: Really? Like a failure?
- 7:50Speaker 2: Yeah. It often means the kernel detected a hardware failure
- 7:53Speaker 2: on the physical drive. To prevent further corruption, it automatically
- 7:57Speaker 2: pulls the emergency brake. and locks the whole drive down
- 8:00Speaker 2: as read-only until an admin can fix it.
- 8:02Speaker 1: It sacrifices the server to save the data. That is wild.
- 8:06Speaker 1: Which actually brings us to section three, bulletproofing the system.
- 8:09Speaker 1: We've talked about these disaster scenarios, power loss, failing drives.
- 8:12Speaker 2: How fun stuff.
- 8:13Speaker 1: Let's zoom in on X4 and see exactly how it
- 8:15Speaker 1: survives these catastrophes. And the secret sauce is journaling, right?
- 8:19Speaker 2: That's the core of it. A journal is essentially a
- 8:22Speaker 2: circular log on the disk. Before the file system commits
- 8:25Speaker 2: any real changes, it writes its intentions to this log.
- 8:29Speaker 1: So if the power cuts out mid-write, when the server reboots,
- 8:33Speaker 1: it just checks the journal, sees the unfinished job, and
- 8:37Speaker 1: finishes it without corruption.
- 8:38Speaker 2: Needlessly.
- 8:39Speaker 1: But here's where it gets really interesting. What if the
- 8:41Speaker 1: power cuts out while it's writing to the journal itself?
- 8:46Speaker 2: Ah, the classic edge case.
- 8:47Speaker 1: X4 handles this with something called journal checksum. It basically
- 8:51Speaker 1: ensures the recovery code, like the E2S program, can mathematically
- 8:55Speaker 1: verify that that the journal entry itself isn't corrupted before
- 8:59Speaker 1: acting on it.
- 9:00Speaker 2: Which is brilliant because calculating a checksum has basically zero
- 9:03Speaker 2: performance costs.
- 9:04Speaker 1: So it should literally always be left on.
- 9:05Speaker 2: Always. But you also have to worry about the physical
- 9:07Speaker 2: hardware reordering your writes. That's where write barriers come in.
- 9:11Speaker 1: The guardian of order.
- 9:12Speaker 2: Exactly. Write barriers ensure that metadata is strictly ordered on
- 9:16Speaker 2: the storage device, even if the drive has its own
- 9:19Speaker 2: volatile write cache. The order has to be perfect, write transaction,
- 9:23Speaker 2: flush cache, write commit block, flush cache.
- 9:26Speaker 1: So it physically forces the hardware to write in the
- 9:29Speaker 1: correct sequence.
- 9:30Speaker 2: Right. But if we connect this to the bigger picture,
- 9:33Speaker 2: applications that do heavy file syncing, like databases running sync,
- 9:37Speaker 2: they run noticeably slower with barriers on, which is barrier one.
- 9:41Speaker 1: So if it slows us down so much, when is
- 9:44Speaker 1: it actually safe to turn it off? Like, when can
- 9:47Speaker 1: I use barrier zero?
- 9:48Speaker 2: Basically, only if you are using enterprise hardware with a
- 9:52Speaker 2: non-volatile battery-backed write cache.
- 9:55Speaker 1: Wait, literally a battery on the raid card?
- 9:58Speaker 2: Literally a physical battery. If the power dies, that battery
- 10:01Speaker 2: keeps the cache alive until the system comes back up
- 10:04Speaker 2: and can write to the disk. If you don't have
- 10:06Speaker 2: that battery, never turn barriers off. Ever.
- 10:09Speaker 1: Good to know. Before we wrap up X2. 4, we have
- 10:11Speaker 1: to mention DLAC or delayed allocation.
- 10:13Speaker 2: Oh, this is such a smart feature. It basically tells
- 10:15Speaker 2: the system to procrastinate.
- 10:17Speaker 1: Procrastinate.
- 10:17Speaker 2: Yeah. It tells it not to allocate physical disk blocks
- 10:20Speaker 2: until the exact moment it's time to actually write the
- 10:23Speaker 2: data to the disk.
- 10:24Speaker 1: Oh, I see. Because if it assigns blocks immediately, like
- 10:26Speaker 1: with nodal alloc, it might just scatter the file into
- 10:28Speaker 1: whatever tiny gaps it finds first.
- 10:30Speaker 2: Exactly. Which causes severe fragmentation. By delaying, it waits to
- 10:36Speaker 2: see how big the file is, then finds one clean,
- 10:39Speaker 2: contiguous block of space.
- 10:41Speaker 1: That is so elegant. All right. We have covered an
- 10:44Speaker 1: immense amount of ground today. As promised to you, the listener...
- 10:48Speaker 1: I want to issue a quick mental quiz to reinforce
- 10:50Speaker 1: what we just learned.
- 10:51Speaker 2: Let's hear it.
- 10:52Speaker 1: Okay. You're configuring a massive, highly active database server. You
- 10:57Speaker 1: need to squeeze out every single drop of performance and
- 11:00Speaker 1: reduce unnecessary disk writes. However, you aren't worried about tracking
- 11:04Speaker 1: when employees merely read a file. Which mount option do
- 11:07Speaker 1: you change in the Emlestab file?
- 11:09Speaker 2: Well, this is a good one. Based on everything we discussed,
- 11:12Speaker 2: you would turn off access time by mounting the drive
- 11:14Speaker 2: with no time.
- 11:15Speaker 1: Spot on. Turn off no time and instantly reclaim those IOPS.
- 11:18Speaker 2: You know, thinking about all this, it leaves me with
- 11:20Speaker 2: this crazy thought. Every single time you hit save on
- 11:23Speaker 2: a document, there is this massive invisible symphony happening under
- 11:27Speaker 2: the hood.
- 11:27Speaker 1: Oh, for sure.
- 11:28Speaker 2: You have copy-on-write commands, metadata flushing to RAM, circular journals
- 11:32Speaker 2: calculating cryptographic checksums, and write barriers fighting a literal war
- 11:37Speaker 2: against hardware caches and power failures. all just to keep
- 11:40Speaker 2: your data alive.
- 11:41Speaker 1: Just for a simple text file, next time you save,
- 11:44Speaker 1: definitely take a moment to appreciate the architecture protecting it.
- 11:47Speaker 1: So what does this all mean? It means the digital
- 11:49Speaker 1: infrastructure you rely on every day is a miraculous balancing
- 11:53Speaker 1: act of speed, security, and survival. Thank you for joining
- 11:56Speaker 1: us on this deep dive. Keep exploring, keep questioning the defaults,
- 11:59Speaker 1: and we will catch you next time.