Skip to content

Latest commit

 

History

History
467 lines (345 loc) · 11.7 KB

Storage.md

File metadata and controls

467 lines (345 loc) · 11.7 KB

Storage.md

20% of Exam

  • Configure and manage LVM storage
  • Manage and configure the virtual file system
  • Create, manage, and troubleshoot filesystems
  • Use remote filesystems and network block devices
  • Configure and manage swap space
  • Configure filesystem automounters
  • Monitor storage performance

Section 1

show commands

lsblk
sudo mkswap /dev/sdb
df -TH 
swapon -h
swapon -s
10MB 21MB 15MB
sudo fdisk /dev/vdb
# m for menu
m
# n for new partition 
n
# enter defaults and +10M for size 
+10M
# w for writing the partition
w
mkswap /dev/vdb2
swapon /dev/vdb2
swapon -s
swapoff /dev/vdb2
cfdisk

Summary

  • List block devices: lsblk

    • Display information about all block devices on the system.
  • Create a swap area on /dev/sdb: sudo mkswap /dev/sdb

    • Initialize the partition /dev/sdb as swap space.
  • Check file system disk usage: df -TH

    • Show disk usage information for all mounted filesystems, with sizes in human-readable format and file system type.
  • Display active swap space: swapon -h

    • Show the currently active swap spaces in a human-readable format.
  • View detailed swap space information: swapon -s

    • Display detailed information about all swap spaces.
  • Open fdisk to partition /dev/vdb: sudo fdisk /dev/vdb

    • Open fdisk to manage partitions on /dev/vdb.
  • Use m for the help menu in fdisk: m

    • Display the help menu in fdisk.
  • Create a new partition in fdisk: n

    • Create a new partition.
  • Enter default values for the partition size and set it to +10M: +10M

    • Set the size of the new partition to 10MB.
  • Write partition changes: w

    • Write changes and exit fdisk.
  • Create a swap space on the new partition /dev/vdb2: mkswap /dev/vdb2

    • Initialize /dev/vdb2 as swap space.
  • Enable the new swap space: swapon /dev/vdb2

    • Activate the swap space on /dev/vdb2.
  • View swap space status: swapon -s

    • Display the status of active swap spaces.
  • Disable a swap space: swapoff /dev/vdb2

    • Disable the swap space on /dev/vdb2.
  • Open the cfdisk partition manager: cfdisk

    • Start the cfdisk utility to manage disk partitions with a graphical interface.

Section 2

show commands

mkfs.xfs -L "DataDisk" /dev/vdb
mkfs.ext4 -N 2048 /dev/vdc
mount /dev/vdb/ /mnt
mount /dev/vdb/ /mnt/
lsblk
mount /dev/vdb /mnt/
umount /mnt
mkdir /test
sudo mano /etc/fstab
cat /etc/fstab
sudo nano /etc/fstab


# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/8ee8caa8-cef0-4e5c-a626-03f2a0f13c00 / ext4 defaults 0 1
/swap.img       none    swap    sw      0       0
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
#VAGRANT-END
/dev/vdc /test ext4 defaults 0 2
/dev/vdb none swap defaults 0 0

xfs_admin -L "SwapFS" /dev/vdb

Summary

  • Format a disk with XFS and label it: mkfs.xfs -L "DataDisk" /dev/vdb

    • Format /dev/vdb with the XFS file system and label it "DataDisk."
  • Format a disk with ext4 and specify the number of inodes: mkfs.ext4 -N 2048 /dev/vdc

    • Format /dev/vdc with the ext4 file system and create 2048 inodes.
  • Mount a disk to a directory: mount /dev/vdb /mnt

    • Mount the /dev/vdb device to the /mnt directory.
  • List block devices and their mount points: lsblk

    • Display information about block devices and their mount points.
  • Unmount a device: umount /mnt

    • Unmount the device mounted at /mnt.
  • Create a new directory: mkdir /test

    • Create the directory /test.
  • Edit the /etc/fstab file with nano: sudo nano /etc/fstab

    • Open the /etc/fstab file in the nano text editor to manage filesystem mounts.
  • View the contents of /etc/fstab: cat /etc/fstab

    • Display the contents of the /etc/fstab file.
  • Example entry for /etc/fstab:

    <file system> <mount point>   <type>  <options>       <dump>  <pass>
    /dev/disk/by-uuid/8ee8caa8-cef0-4e5c-a626-03f2a0f13c00 / ext4 defaults 0 1
    /swap.img       none    swap    sw      0       0
    /dev/vdc /test ext4 defaults 0 2
    /dev/vdb none swap defaults 0 0
  • Change the label of an XFS file system: xfs_admin -L "SwapFS" /dev/vdb

    • Change the label of the XFS file system on /dev/vdb to "SwapFS."

Section 3

show commands

cat /proc/mounts
findmnt
findmnt /dev/vda1
umount /mnt
mount /dev/vdb1 /mnt/ -o ro,noexec,nosuid
mount -o remount,rw /dev/vdb1 /mnt
vi /etc/fstab
/dev/vdb1 /mnt ext4 defaults,ro 0 2

Summary

  • View currently mounted file systems: cat /proc/mounts

    • Display information about all mounted file systems from /proc/mounts.
  • Find mounted file systems: findmnt

    • Display a tree of mounted file systems.
  • Find where a specific device is mounted: findmnt /dev/vda1

    • Display the mount point for /dev/vda1.
  • Unmount a device: umount /mnt

    • Unmount the device mounted at /mnt.
  • Mount a device with specific options: mount /dev/vdb1 /mnt/ -o ro,noexec,nosuid

    • Mount /dev/vdb1 to /mnt with read-only, no execution, and no SUID options.
  • Remount a device as read-write: mount -o remount,rw /dev/vdb1 /mnt

    • Remount /dev/vdb1 as read-write on /mnt.
  • Edit the /etc/fstab file: vi /etc/fstab

    • Open /etc/fstab for editing to manage filesystem mounts.
  • Example /etc/fstab entry: /dev/vdb1 /mnt ext4 defaults,ro 0 2

    • Mount /dev/vdb1 to /mnt with the ext4 file system in read-only mode.

Section 4

show commands

vi /etc/exports
/home 10.0.0.0/24(ro)
sudo exportfs -r
systemctl restart nfs-server
grep "/home" /etc/exports
mount 127.0.0.1:/home /mnt
vi /etc/fstab
127.0.0.1:/home /mnt nfs defaults 0 0
vi /etc/exports
/home 192.0.0.0/24(ro) 127.0.0.10(rw,no_root_squash)
exportfs -r

Summary

  • Edit the NFS exports file: vi /etc/exports

    • Open /etc/exports to configure NFS shared directories.
  • Example NFS export entry: /home 10.0.0.0/24(ro)

    • Share /home as read-only for the 10.0.0.0/24 subnet.
  • Apply NFS export changes: sudo exportfs -r

    • Re-export all directories in /etc/exports without restarting the NFS service.
  • Restart the NFS server: systemctl restart nfs-server

    • Restart the NFS server to apply changes.
  • Verify NFS export configuration for /home: grep "/home" /etc/exports

    • Search for /home in the /etc/exports file to verify export configurations.
  • Mount an NFS share locally: mount 127.0.0.1:/home /mnt

    • Mount the NFS share from 127.0.0.1:/home to /mnt.
  • Edit /etc/fstab to mount NFS share automatically: vi /etc/fstab

    • Open /etc/fstab to configure automatic mounting.
  • Example NFS /etc/fstab entry: 127.0.0.1:/home /mnt nfs defaults 0 0

    • Automatically mount the NFS share from 127.0.0.1:/home to /mnt at boot.
  • Add multiple NFS export rules: vi /etc/exports

    • Open /etc/exports to add multiple export rules.
  • Example multi-host NFS export entry: /home 192.0.0.0/24(ro) 127.0.0.10(rw,no_root_squash)

    • Export /home as read-only for the 192.0.0.0/24 subnet and as read-write with no_root_squash for 127.0.0.10.
  • Apply NFS export changes: exportfs -r

    • Re-export all configured directories without restarting the NFS service.

Section 5

show commands

sudo apt install lvm2 -y
sudo lvmdiskscan

pvcreate /dev/vdb /dev/vdc

pvs
vi /root/pvsize

pvremove /dev/vdc
vgcreate volume1 /dev/vdb
vgextend volume1 /dev/vdc
vgreduce volume1 /dev/vdc
vgs
lvcreate --size 0.5G --name smalldata volume1
lvresize --size 752M volume1/smalldata
mkfs.xfs /dev/volume1/smalldata
sudo lvremove volume1/smalldata

Summary

  • Install LVM2: sudo apt install lvm2 -y

    • Install the LVM2 package for managing Logical Volume Management (LVM).
  • Scan disks for LVM physical volumes: sudo lvmdiskscan

    • Scan the system for available physical disks for LVM.
  • Create physical volumes: pvcreate /dev/vdb /dev/vdc

    • Initialize /dev/vdb and /dev/vdc as physical volumes for LVM.
  • Display physical volumes: pvs

    • Show information about all physical volumes on the system.
  • Open a file for editing: vi /root/pvsize

    • Open /root/pvsize for editing (e.g., to save size info).
  • Remove a physical volume: pvremove /dev/vdc

    • Remove the LVM label from /dev/vdc and wipe the physical volume.
  • Create a volume group: vgcreate volume1 /dev/vdb

    • Create a volume group named volume1 using /dev/vdb as the physical volume.
  • Extend a volume group: vgextend volume1 /dev/vdc

    • Add /dev/vdc to the volume1 volume group.
  • Reduce a volume group: vgreduce volume1 /dev/vdc

    • Remove /dev/vdc from the volume1 volume group.
  • Display volume groups: vgs

    • Show information about all volume groups on the system.
  • Create a logical volume: lvcreate --size 0.5G --name smalldata volume1

    • Create a logical volume named smalldata with a size of 0.5 GB in the volume1 group.
  • Resize a logical volume: lvresize --size 752M volume1/smalldata

    • Resize the logical volume smalldata in volume1 to 752 MB.
  • Format a logical volume with XFS: mkfs.xfs /dev/volume1/smalldata

    • Format the logical volume smalldata in volume1 with the XFS file system.
  • Remove a logical volume: sudo lvremove volume1/smalldata

    • Remove the logical volume smalldata from the volume1 volume group.

Section 6

show commands

# https://www.redhat.com/sysadmin/linux-access-control-lists
raid1 mirrored
cat /proc/mdstat
getfacl archive
# https://www.alibabacloud.com/help/en/ecs/use-cases/create-a-raid-array-for-a-linux-instance#:~:text=Run%20the%20mdadm%20command%20to,based%20on%20your%20business%20requirements.&text=If%20you%20are%20prompted%20that,to%20install%20the%20mdadm%20tool.

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/vd[bc]
lsblk

setfacl --modify user:john:rw specialfile
setfacl --remove user:john specialfile
setfacl --modify group:mail:rx specialfile
setfacl --recursive --modify user:john:rwx collection/

Summary

  • Check RAID status: cat /proc/mdstat

    • Display the current status of RAID arrays and devices.
  • View access control lists (ACLs) of a file: getfacl archive

    • Show the ACLs for the file archive.
  • Create a RAID 1 (mirrored) array: sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/vd[bc]

    • Create a RAID 1 array using two devices (/dev/vdb and /dev/vdc) and name it /dev/md0.
  • List block devices: lsblk

    • Display information about block devices in a tree format.
  • Modify ACLs to give user john read and write permissions: setfacl --modify user:john:rw specialfile

    • Grant read and write permissions to the user john on the file specialfile.
  • Remove ACLs for user john: setfacl --remove user:john specialfile

    • Remove ACL entries for the user john on specialfile.
  • Modify ACLs to give the group mail read and execute permissions: setfacl --modify group:mail:rx specialfile

    • Grant read and execute permissions to the group mail on specialfile.
  • Recursively modify ACLs to give user john read, write, and execute permissions: setfacl --recursive --modify user:john:rwx collection/

    • Recursively grant read, write, and execute permissions to the user john on the collection/ directory and its contents.