Unit 5: SELinux and Advanced Storage Management
I. Security and Storage Foundations
Linux administration combines mandatory access control with layered storage management. SELinux supplements traditional permissions by enforcing policy-based access decisions, while partitions, file systems, LVM, Stratis, and VDO organize physical storage into usable, resilient, and efficient layers.
- Defense in depth: Access may require both standard UNIX permissions and an SELinux policy rule; permission from one mechanism does not override denial by the other.
- Persistent configuration: Runtime changes often disappear after reboot, so permanent settings belong in configuration files, policy databases,
/etc/fstab, or storage metadata. - Layered storage: A typical path is physical disk → partition → LVM physical volume → volume group → logical volume → file system → mount point.
- Stable identification: Persistent mounts should use UUIDs, labels, or managed device paths instead of changeable names such as
/dev/sdb1. - Online management: LVM and modern file systems support many capacity changes while mounted, but shrinking is more restrictive and risk-prone.
- Verification: Commands such as
getenforce,lsblk,findmnt,pvs,vgs, andlvsconfirm actual state after configuration.
II. SELinux Security
A. Managing SELinux Security
SELinux limits what processes can do by comparing security contexts against loaded policy rules.
- Security context: Every SELinux-aware process and object has a label commonly displayed as
user:role:type:level, such assystem_u:object_r:httpd_sys_content_t:s0.- Type: The main policy attribute used in targeted policy, for example
httpd_tfor an Apache process. - Level: Represents an MLS/MCS sensitivity and category set, commonly
s0.
- Type: The main policy attribute used in targeted policy, for example
- Type enforcement: Policy might permit a process in
httpd_tto readhttpd_sys_content_tfiles while denying access touser_home_t. - Policy modes: The common
targetedpolicy confines selected network-facing services while leaving many ordinary processes unconfined. - Inspection: Display labels with:
ps -eZ
ls -Z /var/www/html
id -Z- Interaction with DAC: SELinux is checked after discretionary access control; a file normally needs suitable ownership/mode bits and an allowed SELinux rule.
B. Changing the SELinux Enforcement Mode
SELinux modes determine whether policy violations are blocked, merely logged, or not evaluated.
- Runtime mode:
setenforceswitches between enforcing and permissive without rebooting.
getenforce
sudo setenforce 0 # permissive
sudo setenforce 1 # enforcing
sestatus- Persistent mode:
/etc/selinux/configcontrols startup behavior.
SELINUX=enforcing
SELINUXTYPE=targeted- Enforcing: Denied operations are blocked and usually recorded as AVC messages.
- Permissive: Violations are logged but allowed, making this mode useful for diagnosis.
- Disabled: SELinux policy is not active; changing to or from fully disabled generally requires rebooting and may require file-system relabeling.
- Preferred diagnosis: Use permissive mode temporarily instead of disabling SELinux, because permissive mode continues producing evidence.
C. Controlling SELinux File Contexts
Temporary context changes can test a diagnosis, but they do not alter SELinux’s persistent labeling rules.
- View labels:
ls -Zd pathshows the context of a file or directory. - Temporary change:
chconchanges the current extended attribute.
sudo chcon -t httpd_sys_content_t /srv/site/index.html- Limitation: A later
restorecon, relabel, or file recreation may replace achconlabel with the policy-defined default. - Inheritance: Newly created files usually receive labels based on policy transition rules and the parent directory, not simply by copying an arbitrary source label.
- Copy behavior: Ordinary copies normally create destination objects with destination-appropriate labels; moves can preserve the source inode and its unsuitable label.
D. Controlling SELinux File Contexts
Persistent file-context control maps path patterns to required SELinux types and then applies those mappings.
- Persistent mapping:
semanage fcontextstores local rules without directly relabeling existing files.
sudo semanage fcontext -a -t httpd_sys_content_t \
'/srv/site(/.*)?'
sudo restorecon -Rv /srv/site- Pattern meaning:
'/srv/site(/.*)?'covers the directory and every descendant. - Application:
restoreconcompares files with policy expectations and restores matching labels;-Rrecurses and-vreports changes. - Equivalent mapping: Reuse another directory’s definitions with:
sudo semanage fcontext -a -e /var/www /srv/www
sudo restorecon -Rv /srv/www- Verification:
semanage fcontext -llists definitions, whilematchpathcon /srv/site/index.htmlpredicts the expected label.
E. Adjusting SELinux Policy with Booleans
SELinux booleans expose predefined policy choices without requiring administrators to rewrite policy modules.
- Discovery:
getsebool -alists booleans;semanage boolean -ladds descriptions and persistent settings. - Temporary setting: The following change lasts until reboot or policy reload:
sudo setsebool httpd_can_network_connect on- Persistent setting:
-Pwrites the policy customization:
sudo setsebool -P httpd_can_network_connect on- Least privilege: Enable only the boolean matching the required behavior; broad access can increase a compromised service’s capabilities.
- Example:
httpd_can_network_connectpermits confined web-server processes to initiate network connections, which may be needed for a reverse proxy or database client.
F. Investigating and Resolving SELinux Issues
SELinux troubleshooting should identify the denied action before changing labels, booleans, or policy.
- Initial separation: Check ordinary permissions, ownership, ACLs, service configuration, and SELinux labels independently.
- Audit evidence: AVC denials usually appear in
/var/log/audit/audit.log.
sudo ausearch -m AVC,USER_AVC -ts recent
sudo sealert -a /var/log/audit/audit.log- Diagnostic sequence:
- Reproduce the failure and locate the matching denial.
- Compare the source process type, target object type, requested class, and permission.
- Correct an invalid label with
semanage fcontextandrestorecon. - Enable an appropriate documented boolean when the requested behavior is optional policy functionality.
- Custom policy:
audit2allowcan suggest rules, but generated output must be reviewed; it may authorize symptoms of a configuration error. - Permissive domains: Domain-specific permissive settings can isolate troubleshooting more narrowly than making the entire system permissive.
III. Basic Linux Storage
A. Managing Basic Storage and Logical Volumes
Storage management begins by identifying devices and deciding whether direct partitions or LVM flexibility best suit the workload.
- Inventory:
lsblk -fshows devices, file-system types, UUIDs, and mount points;blkidreports persistent identifiers. - Capacity view:
df -hTreports mounted file-system usage, whereasdu -sh directorytotals visible files beneath a path. - Direct storage: A file system placed directly on a partition is simple but less adaptable to later capacity changes.
- LVM storage: Physical volumes are combined into volume groups from which administrators allocate independently sized logical volumes.
- Safety: Confirm device names and backups before partitioning or formatting because
mkfs,wipefs, and partition deletion can destroy metadata.
B. Adding Partitions, File Systems, and Persistent Mounts
A usable persistent disk requires a partition or logical device, a file system, a mount point, and a valid /etc/fstab entry.
- Partitioning:
fdiskcommonly manages MBR or GPT interactively;partedis suitable for scripted or large-disk GPT work.
sudo parted /dev/sdb --script mklabel gpt
sudo parted /dev/sdb --script mkpart primary xfs 1MiB 100%
sudo partprobe /dev/sdb- File-system creation: XFS is widely used for large scalable file systems, while ext4 supports both growing and offline shrinking.
sudo mkfs.xfs /dev/sdb1
sudo mkdir -p /data
sudo mount /dev/sdb1 /data- Persistent mount: Obtain the UUID with
blkidand add an/etc/fstabrecord:
UUID=2f00-example /data xfs defaults 0 0- Validation: Run
mount -aand thenfindmnt /data; this exposes syntax or device errors before reboot. - Mount options: Options such as
noexec,nosuid, andnodevcan reduce risk but may break applications that require those capabilities.
C. Managing Swap Space
Swap provides disk-backed virtual memory and may also support hibernation, but it is much slower than RAM.
- Inspection:
swapon --showlists active swap;free -hsummarizes RAM and swap consumption. - Swap partition: Initialize and activate a dedicated device:
sudo mkswap /dev/sdb2
sudo swapon /dev/sdb2- Swap file: A file is easier to resize or remove.
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile- Persistence: Add
/swapfile none swap defaults 0 0to/etc/fstab. - Removal: Run
swapoffbefore deleting swap storage, and ensure enough RAM exists to absorb its active pages. - Tuning:
vm.swappinessinfluences preference for reclaiming memory through swap; it is not a percentage threshold for starting swap.
IV. Logical Volume Management
A. Creating Logical Volumes
LVM allocates logical devices from pooled physical storage, separating application volumes from physical disk boundaries.
- Physical volume:
pvcreate /dev/sdb1writes LVM metadata to the partition. - Volume group:
vgcreate vgdata /dev/sdb1creates a storage pool namedvgdata. - Logical volume: Allocate a fixed amount or percentage:
sudo lvcreate -L 10G -n lvapp vgdata
sudo mkfs.xfs /dev/vgdata/lvapp
sudo mount /dev/vgdata/lvapp /app- Extent allocation: LVM divides a volume group into physical extents, commonly 4 MiB each, and maps logical extents onto them.
- Monitoring:
pvs,vgs, andlvs -a -o +devicesshow capacity, free extents, and device placement. - Persistence: Use the logical volume’s UUID or
/dev/mapper/vgdata-lvappin/etc/fstab.
B. Extending Logical Volumes
Extending storage requires increasing the logical block device and then growing its file system.
- Available space: Confirm free volume-group capacity with
vgs; add another physical volume withvgextendwhen necessary. - LV extension: Add 5 GiB to a logical volume:
sudo lvextend -L +5G /dev/vgdata/lvapp- File-system growth:
- XFS:
sudo xfs_growfs /app - ext4:
sudo resize2fs /dev/vgdata/lvapp
- XFS:
- Combined operation:
lvextend -r -L +5G deviceinvokes the appropriate file-system resize helper. - All remaining capacity:
-l +100%FREEconsumes every currently free extent, leaving no reserve for other volumes. - Shrinking warning: XFS cannot be shrunk, and ext4 must normally be unmounted and reduced before the logical volume; reversing that order risks data loss.
V. Advanced Storage Features
A. Implementing Advanced Storage Features
Advanced storage layers add pooling, snapshots, thin provisioning, integrity, compression, or deduplication to basic block devices.
- Layer selection: Each layer solves a specific problem and adds metadata, memory, monitoring, and recovery requirements.
- Thin provisioning: Logical capacity may exceed physical allocation because blocks are reserved only when written; pool exhaustion must be monitored.
- Snapshots: Point-in-time block mappings support short-lived testing and backup coordination but are not independent backups.
- Discard support:
fstrimor suitable discard configuration can inform lower layers that deleted blocks are no longer needed. - Operational rule: Administrators should monitor both advertised logical capacity and real backing-store consumption.
B. Managing Layered Storage with Stratis
Stratis provides daemon-managed storage pools and file systems over block devices, using technologies such as device mapper and XFS.
- Components:
stratisdperforms management, while thestratiscommand-line tool controls pools and file systems. - Pool creation:
sudo stratis pool create datapool /dev/sdb
sudo stratis filesystem create datapool records- Persistent mounting: Obtain the Stratis file-system UUID and use
_netdevin/etc/fstabso mounting waits for the storage service.
UUID=example /records xfs defaults,x-systemd.requires=stratisd.service 0 0- Expansion:
stratis pool add-data datapool /dev/sdcadds capacity to the pool. - Inspection:
stratis pool list,stratis blockdev list, andstratis filesystem listexpose each managed layer. - Snapshots: Stratis can create file-system snapshots within a pool, but snapshots still depend on the same underlying pool.
C. Compressing and Deduplicating Storage with VDO
VDO reduces physical storage consumption through zero-block elimination, deduplication, and compression.
- Deduplication: Identical logical blocks are stored once and referenced through metadata; effectiveness depends on repeated block content.
- Compression: Unique blocks are compressed before physical storage, benefiting compressible data but adding CPU work.
- Provisioning: VDO may expose a logical size larger than its physical backing device, so physical utilization must be monitored continuously.
- LVM integration: On systems supporting LVM VDO, a VDO pool and virtual logical volume can be created with
lvcreate --type vdo. - Workload suitability: Virtual-machine images and repeated container data often deduplicate well; already compressed or encrypted data usually saves little space.
- Risk control: Reaching physical capacity can disrupt writes despite apparent logical free space; alerts and realistic capacity thresholds are essential.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →