Ravindra BagaleCourses & study guides मराठी Track your progress

Linux Disks: lsblk, blkid, fdisk, parted, mkfs, mount, /etc/fstab and swap Explained

A new disk was attached to your server. How do you find it, split it, format it, mount it, and make sure it comes back after reboot? This chapter walks through the whole story: lsblk and blkid to see disks and IDs, fdisk and parted to create partitions, mkfs to make a filesystem, mount and umount, /etc/fstab for permanent mounts, growing a partition and filesystem, and swap. Each command and its key options get Why, What and How.

What you'll learn in this chapter

  • Find disks and partitions with lsblk and blkid
  • Create partitions with fdisk and parted
  • Make filesystems with mkfs (ext4, xfs)
  • Mount, unmount and use /etc/fstab safely
  • Grow partitions and filesystems
  • Add and manage swap

1. An everyday example: a new cupboard at home

Why do we need this?

You buy a new cupboard. First you find a place for it. Then you fit shelves (sections). You line each shelf so things can be kept. You put a label on the door so everyone knows what is inside, and you write in the house notebook which room it is in, so nobody forgets.

What is it?

Cupboard = disk (lsblk). Shelves = partitions (fdisk/parted). Lining = filesystem (mkfs). Label = UUID/LABEL (blkid). Room = mount point (mount). House notebook = /etc/fstab.

How to do it (step by step)

From new disk to permanent mountlsblk: find the new disk (no partitions, no mount)parted or fdisk: create a GPT label and a partitionmkfs.xfs or mkfs.ext4: make the filesystemblkid: copy the UUIDmkdir and mount: test itAdd a UUID line to /etc/fstab and run mount -a to check
Never skip the mount -a test: a bad fstab line can stop the next boot.

2. lsblk: see all block devices

Why do we need this?

Before touching a disk you must be sure which one is new and empty. Formatting the wrong disk destroys data.

What is it?

lsblk shows disks (TYPE disk), partitions (part), LVM (lvm) and their mount points as a tree. -f adds filesystem type, label and UUID. -o NAME,SIZE,TYPE,MOUNTPOINTS picks columns. Cloud NVMe disks look like nvme1n1; older ones xvdf or sdb.

How to do it (step by step)

  1. The tree.
lsblk

Output:

NAME        SIZE TYPE MOUNTPOINTS
nvme0n1      20G disk
└─nvme0n1p1  20G part /
nvme1n1     100G disk

What it means: nvme1n1 is new and empty.

  1. With filesystems.
lsblk -f

Output:

NAME       FSTYPE LABEL UUID                                 MOUNTPOINTS
nvme0n1p1  xfs    /     3f1c...a2  /
nvme1n1

What it means: No FSTYPE on nvme1n1.

  1. Choose columns.
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS

Output:

(same tree, chosen columns)

What it means: Good for scripts and tickets.

3. blkid: UUIDs and filesystem types

Why do we need this?

Device names like sdb can change between boots. UUIDs never change, so fstab should use them.

What is it?

blkid prints UUID, TYPE and LABEL for each filesystem. blkid /dev/nvme1n1p1 for one. blkid -s UUID -o value DEV prints only the UUID. findfs UUID=... finds the device for a UUID.

How to do it (step by step)

  1. All.
sudo blkid

Output:

/dev/nvme0n1p1: LABEL="/" UUID="3f1c...a2" TYPE="xfs"
/dev/nvme1n1p1: UUID="7b9e...44" TYPE="xfs"

What it means: Two filesystems.

  1. Only the UUID.
sudo blkid -s UUID -o value /dev/nvme1n1p1

Output:

7b9e1c2d-...-44

What it means: Ready for fstab.

4. fdisk: create MBR or GPT partitions

Why do we need this?

You may want one disk split into parts, or a single partition so tools know the disk is in use.

What is it?

sudo fdisk /dev/DISK opens a menu: p print, g new GPT table, o new MBR (DOS) table, n new partition, t type, d delete, w write, q quit without saving. Nothing changes until w. fdisk -l lists partition tables. Use GPT for disks over 2 TB.

KeyAction
pPrint table
g / oNew GPT / MBR
nNew partition
dDelete
wWrite and exit
qQuit, no changes

How to do it (step by step)

  1. List.
sudo fdisk -l /dev/nvme1n1

Output:

Disk /dev/nvme1n1: 100 GiB
Disklabel type: (none)

What it means: Empty.

  1. Interactive steps.
sudo fdisk /dev/nvme1n1
  g
  n  (Enter, Enter, Enter)
  w

Output:

Created a new GPT disklabel.
Created a new partition 1 of type 'Linux filesystem' and of size 100 GiB.
The partition table has been altered.

What it means: One partition: nvme1n1p1.

  1. Kernel did not see it.
sudo partprobe /dev/nvme1n1 && lsblk /dev/nvme1n1

Output:

nvme1n1    100G disk
└─nvme1n1p1 100G part

What it means: Now visible.

5. parted: scriptable partitioning

Why do we need this?

In automation (cloud-init, Ansible) you cannot answer menus. parted runs in one command line.

What is it?

sudo parted -s DISK mklabel gpt creates a GPT table. mkpart NAME FS START END makes a partition (use 0% 100% for alignment). print shows it. resizepart N 100% grows a partition. -s means script mode (no questions).

How to do it (step by step)

  1. One line.
sudo parted -s /dev/nvme2n1 mklabel gpt mkpart data xfs 0% 100%

Output:

(no output)

What it means: Done.

  1. Print.
sudo parted /dev/nvme2n1 print

Output:

Partition Table: gpt
Number Start  End    Size   File system Name
 1     1049kB 53.7GB 53.7GB             data

What it means: Aligned at 1 MiB.

  1. Two partitions.
sudo parted -s /dev/sdc mklabel gpt mkpart logs ext4 0% 30% mkpart data xfs 30% 100%

Output:

(no output)

What it means: 30/70 split.

6. mkfs: make a filesystem

Why do we need this?

A partition is raw space. A filesystem is what lets you store files and folders on it.

What is it?

mkfs.xfs DEV (RHEL default, great for big files, can grow but not shrink). mkfs.ext4 DEV (Ubuntu default, can grow and shrink offline). -L LABEL sets a label. -f forces over an old filesystem (careful). mkfs erases everything on the device.

xfsext4
GrowOnlineOnline
ShrinkNoOffline
Default onRHEL, Amazon LinuxUbuntu, Debian
Grow toolxfs_growfsresize2fs

How to do it (step by step)

  1. XFS.
sudo mkfs.xfs -L data /dev/nvme1n1p1

Output:

meta-data=/dev/nvme1n1p1 isize=512 agcount=4, agsize=6553536 blks

What it means: Filesystem ready.

  1. ext4.
sudo mkfs.ext4 -L logs /dev/sdc1

Output:

Creating filesystem with 7864320 4k blocks
Writing superblocks and filesystem accounting information: done

What it means: Ready.

  1. Safety stop.
sudo mkfs.xfs /dev/nvme1n1p1

Output:

mkfs.xfs: /dev/nvme1n1p1 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.

What it means: Stop and double check.

7. mount and umount

Why do we need this?

A filesystem is only usable after it is attached to a folder in the tree.

What is it?

sudo mkdir -p /data && sudo mount DEV /data. mount -o ro, noexec, nosuid set options. findmnt /data or findmnt -T PATH shows what is mounted where. umount /data detaches; 'target is busy' means a process uses it (find with lsof +f -- /data or fuser -vm /data).

How to do it (step by step)

  1. Mount.
sudo mkdir -p /data && sudo mount /dev/nvme1n1p1 /data && df -h /data

Output:

Filesystem      Size Used Avail Use% Mounted on
/dev/nvme1n1p1  100G 746M 100G   1% /data

What it means: Ready to use.

  1. Show mounts.
findmnt /data

Output:

TARGET SOURCE         FSTYPE OPTIONS
/data  /dev/nvme1n1p1 xfs    rw,relatime

What it means: Options shown.

  1. Busy.
sudo umount /data

Output:

umount: /data: target is busy.

What it means: Someone is inside.

  1. Who?
sudo fuser -vm /data

Output:

USER PID ACCESS COMMAND
/data: ravi 3301 ..c.. bash

What it means: Your own shell: cd out.

8. /etc/fstab: permanent mounts

Why do we need this?

mount is temporary. Without fstab the disk is not mounted after reboot and the app fails.

What is it?

Six fields: device (UUID=...), mount point, type, options, dump (0), fsck order (0 for xfs, 2 for ext4 data). Add nofail for non-root disks in the cloud so boot does not hang if the disk is missing. Test with sudo mount -a and findmnt --verify.

FieldExample
1 deviceUUID=7b9e...
2 mount point/data
3 typexfs
4 optionsdefaults,nofail
5 dump0
6 fsck0 (xfs) / 2 (ext4)

How to do it (step by step)

  1. Add a line.
echo "UUID=$(sudo blkid -s UUID -o value /dev/nvme1n1p1) /data xfs defaults,nofail 0 0" | sudo tee -a /etc/fstab

Output:

UUID=7b9e...44 /data xfs defaults,nofail 0 0

What it means: Permanent.

  1. Test it.
sudo umount /data && sudo mount -a && findmnt /data

Output:

/data /dev/nvme1n1p1 xfs rw,relatime

What it means: fstab works.

  1. Verify syntax.
sudo findmnt --verify

Output:

Success, no errors or warnings detected

What it means: Safe to reboot.

  1. Reload systemd.
sudo systemctl daemon-reload

Output:

(no output)

What it means: systemd builds mount units from fstab.

9. Growing a partition and filesystem

Why do we need this?

In the cloud you can make a volume bigger, but Linux does not use the new space until you grow the partition and the filesystem.

What is it?

1 resize the volume in the cloud. 2 lsblk shows the disk bigger. 3 sudo growpart DISK N grows partition N (from cloud-utils-growpart). 4 grow the filesystem: xfs_growfs MOUNTPOINT for xfs, resize2fs DEV for ext4. All online.

How to do it (step by step)

  1. Disk is bigger.
lsblk /dev/nvme0n1

Output:

nvme0n1     40G disk
└─nvme0n1p1 20G part /

What it means: Partition still 20G.

  1. Grow partition.
sudo growpart /dev/nvme0n1 1

Output:

CHANGED: partition=1 start=4096 old: size=41938911 end=41943007 new: size=83881951

What it means: Partition 40G.

  1. Grow xfs.
sudo xfs_growfs / && df -h /

Output:

data blocks changed from 5242363 to 10485243
/dev/nvme0n1p1 40G 11G 29G 28% /

What it means: Done online.

  1. Grow ext4.
sudo resize2fs /dev/sdc1

Output:

The filesystem on /dev/sdc1 is now 13107200 (4k) blocks long.

What it means: ext4 way.

10. Swap: mkswap, swapon, swap file

Why do we need this?

Small servers can crash with out-of-memory. Swap gives a little slow extra memory so the kernel does not kill the app immediately.

What is it?

Swap file: fallocate -l 2G /swapfile (or dd), chmod 600, mkswap, swapon. swapon --show and free -h show it. fstab line: /swapfile none swap sw 0 0. vm.swappiness (0-100) controls how eager the kernel is to swap.

How to do it (step by step)

  1. Create 2G swap.
sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile

Output:

Setting up swapspace version 1, size = 2 GiB

What it means: Active.

  1. Check.
swapon --show; free -h | grep -i swap

Output:

NAME      TYPE SIZE USED PRIO
/swapfile file   2G   0B   -2
Swap: 2.0Gi 0B 2.0Gi

What it means: In use.

  1. Permanent.
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Output:

/swapfile none swap sw 0 0

What it means: After reboot too.

  1. Less eager.
sudo sysctl vm.swappiness=10

Output:

vm.swappiness = 10

What it means: Prefers RAM.

11. Checking and repairing filesystems: fsck, xfs_repair

Why do we need this?

After a crash or power loss, a filesystem may be marked dirty or refuse to mount.

What is it?

Never repair a mounted filesystem. ext4: umount, then fsck -f DEV (or e2fsck). xfs: umount, then xfs_repair DEV (xfs_repair -n only checks). For the root filesystem use rescue mode or attach the disk to another server.

How to do it (step by step)

  1. Check ext4.
sudo umount /logs && sudo fsck -f /dev/sdc1

Output:

Pass 1: Checking inodes, blocks, and sizes
/dev/sdc1: 11/1966080 files, 167971/7864320 blocks

What it means: Clean.

  1. Check xfs without changes.
sudo umount /data && sudo xfs_repair -n /dev/nvme1n1p1

Output:

Phase 1 - find and verify superblock...
No modify flag set, skipping filesystem flush and exiting.

What it means: Read-only check.

12. Real examples from many industries

Why do we need this?

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

What is it?

Each row is a made-up team. It shows who uses this and how.

How to do it (step by step)

Team and cityHow they use itCommand
Pooja, analytics, PuneAdds data disks with UUID fstab linesblkid -s UUID -o value DEV
Liam, media, SydneyGrows root volumes onlinegrowpart /dev/nvme0n1 1 && xfs_growfs /
Hana, robotics, SeoulScripts partitions with partedparted -s DISK mklabel gpt mkpart data xfs 0% 100%
Diego, retail, LimaAdds swap on small instancesfallocate -l 2G /swapfile
Grace, hospital, AccraUses nofail for extra disksdefaults,nofail 0 0
Sagar, school ERP, SolapurTests fstab before rebootmount -a && findmnt --verify

13. Common errors and how to fix them

Why do we need this?

Everyone hits these errors. Knowing the cause saves hours.

What is it?

Read the exact message first. Then match it to a row below.

How to do it (step by step)

Error you seeWhy it happensHow to fix
mount: wrong fs type, bad option, bad superblockNo filesystem yet, or wrong typeCheck with lsblk -f; mkfs if new.
lsblk -f
umount: target is busyA process uses the mountFind and stop it.
sudo fuser -vm /data
Boot stops in emergency modeBad /etc/fstab lineFix fstab from the emergency shell; use nofail.
findmnt --verify
mkfs: appears to contain an existing filesystemDisk already has dataConfirm it is the right disk before -f.
lsblk -f
Re-reading the partition table failed: Device or resource busyKernel did not reload tableRun partprobe.
sudo partprobe /dev/nvme1n1
NOCHANGE: partition 1 is size ... it cannot be grownVolume not resized yetResize in the cloud first.
lsblk
df still shows old sizeFilesystem not grownRun xfs_growfs or resize2fs.
sudo xfs_growfs /
swapon: /swapfile: insecure permissions 0644Swap file readable by otherschmod 600.
sudo chmod 600 /swapfile
mount point /data does not existDirectory missingCreate it.
sudo mkdir -p /data
xfs_growfs: is not a mounted XFS filesystemPassed device or wrong pathPass the mount point.
sudo xfs_growfs /data

14. Troubleshooting step by step

Why do we need this?

When a disk is missing or full of surprises, check from bottom to top.

What is it?

Go top to bottom. Stop at the first step that shows the problem.

How to do it (step by step)

  1. Is the disk seen?
lsblk
  1. Partition and filesystem?
lsblk -f
  1. UUID?
sudo blkid
  1. Mounted where?
findmnt -T /data
  1. fstab valid?
sudo findmnt --verify
  1. Kernel messages?
dmesg -T | tail -20

15. Lab 1: Add a disk end to end with a loop device

Why do we need this?

Practise the full flow safely using a file as a disk.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Make a 1G file disk.
truncate -s 1G /tmp/disk.img && sudo losetup -fP --show /tmp/disk.img

Output:

/dev/loop0
  1. Partition.
sudo parted -s /dev/loop0 mklabel gpt mkpart lab ext4 0% 100%

Output:

(no output)
  1. Filesystem.
sudo mkfs.ext4 -L lab /dev/loop0p1

Output:

done
  1. Mount.
sudo mkdir -p /mnt/lab && sudo mount /dev/loop0p1 /mnt/lab && df -h /mnt/lab

Output:

/dev/loop0p1 974M ... /mnt/lab
  1. Clean up.
sudo umount /mnt/lab && sudo losetup -d /dev/loop0

Output:

(no output)

16. Lab 2: Swap file and fstab test

Why do we need this?

Add a 512M swap file and prove fstab entries with mount -a.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Create.
sudo fallocate -l 512M /swaplab && sudo chmod 600 /swaplab && sudo mkswap /swaplab

Output:

Setting up swapspace
  1. Enable.
sudo swapon /swaplab && swapon --show

Output:

/swaplab file 512M
  1. Verify fstab.
sudo findmnt --verify

Output:

Success
  1. Disable.
sudo swapoff /swaplab

Output:

(no output)
  1. Remove.
sudo rm /swaplab

Output:

(no output)

Ravindra Bagale's Tip

In /etc/fstab always use UUID= and, for any disk except root, add nofail. Then run sudo mount -a and sudo findmnt --verify before you reboot. These three habits prevent the classic 'server will not boot after adding a disk' outage.

17. Frequently asked questions

Q. fdisk or parted?

fdisk for interactive work; parted -s for scripts and large disks.

Q. xfs or ext4?

Use the distro default; xfs cannot shrink, ext4 can offline.

Q. Do I need a partition at all?

Not strictly, but a partition makes it clear the disk is used.

Q. Why UUID in fstab?

Device names can change; UUIDs do not.

Q. What is nofail?

Boot continues even if that disk is missing.

Q. How much swap?

Small servers: 1-2G; large memory servers often little or none.

Q. Can I grow root without reboot?

Yes: growpart then xfs_growfs or resize2fs.

Q. What is a loop device?

A file used as a disk, good for practice.

18. Interview questions and answers

Beginner level

Q. List disks?

lsblk.

Q. Show UUIDs?

blkid.

Q. Make xfs filesystem?

mkfs.xfs DEV.

Q. Make mounts permanent?

Add to /etc/fstab.

Mid level level

Q. Test fstab without reboot?

mount -a and findmnt --verify.

Q. umount says busy?

fuser -vm or lsof to find the process.

Q. Grow root after EBS resize?

growpart DISK 1 then xfs_growfs /.

Q. Add swap file?

fallocate, chmod 600, mkswap, swapon, fstab.

Senior level

Q. Server stuck in emergency mode after disk change?

Boot rescue, fix fstab (UUID, nofail), findmnt --verify, reboot.

Q. Need to shrink an xfs volume?

Not possible; create smaller, copy data, switch.

Q. Automate data disk setup?

cloud-init or Ansible with parted -s, mkfs, fstab with UUID and nofail.

Q. NVMe names change order on Nitro, how to handle?

Use UUIDs or /dev/disk/by-id symlinks.

Try at home

  1. Do Lab 1 again with xfs instead of ext4 and add the fstab line with nofail, then test with mount -a.
  2. Draw your server's disk tree from lsblk -f on paper and label every part.

Practice Tasks

About this scenario

Milan Furniture is a furniture business in Milan. Giulia Rossi looks after its IT and cloud work. They count money in EUR and run their AWS resources in the eu-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 18

Easy Filesystems in tree

Why: Disks hold everything BIZ stores.

What to do: Show /dev/xvdg with filesystem type and UUID.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy One disk

Why: Disks hold everything BIZ stores.

What to do: Show only /dev/xvdg in the tree.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy UUID of one

Why: Disks hold everything BIZ stores.

What to do: Show blkid info for /dev/xvdg1.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List partitions

Why: Disks hold everything BIZ stores.

What to do: List the partition table of /dev/xvdg with fdisk.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Make xfs

Why: Disks hold everything BIZ stores.

What to do: Make an xfs filesystem on /dev/xvdh1 with label media.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Make ext4

Why: Disks hold everything BIZ stores.

What to do: Make an ext4 filesystem on /dev/xvdg1.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Mount it

Why: Disks hold everything BIZ stores.

What to do: Mount /dev/xvdh1 on /media.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy What is mounted

Why: Disks hold everything BIZ stores.

What to do: Show what is mounted on /media.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Test fstab

Why: Disks hold everything BIZ stores.

What to do: Mount everything in fstab and print each result.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Script a GPT label

Why: Disks hold everything BIZ stores.

What to do: Create a GPT label on /dev/xvdh with parted in script mode.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Reload table

Why: Disks hold everything BIZ stores.

What to do: Tell the kernel to re-read partitions of /dev/xvdh.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Read-only mount

Why: Disks hold everything BIZ stores.

What to do: Mount /dev/xvdg1 read-only on /mnt/old.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Who is busy

Why: Disks hold everything BIZ stores.

What to do: Show which processes use the /media mount.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Verify fstab

Why: Disks hold everything BIZ stores.

What to do: Check /etc/fstab for errors without mounting, with full details.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Show swap

Why: Disks hold everything BIZ stores.

What to do: Show active swap areas with sizes in bytes.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Disable a swap file

Why: Disks hold everything BIZ stores.

What to do: Turn off swap file /swap2.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Grow partition 2

Why: Disks hold everything BIZ stores.

What to do: Grow partition 2 of /dev/xvda to fill the disk.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Grow ext4

Why: Disks hold everything BIZ stores.

What to do: Grow the ext4 filesystem on /dev/xvdg1.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. lsblk and blkid find disks and UUIDs.
  2. fdisk (menu) and parted -s (script) make partitions.
  3. mkfs.xfs and mkfs.ext4 create filesystems.
  4. mount, findmnt, umount, fuser.
  5. fstab with UUID, nofail; test with mount -a.
  6. growpart + xfs_growfs/resize2fs; swap with mkswap/swapon.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

New disk in 4 steps. Find it: lsblk. Partition, then mkfs. Mount and add to fstab by UUID. Test fstab.
Revision card: New disk in 4 steps · Download PNG · Open card page
Swap file in 4 steps. Extra memory on disk. fallocate, chmod 600. mkswap, swapon. Check.
Revision card: Swap file in 4 steps · Download PNG · Open card page
ext4 vs xfs. Can grow and shrink. / Can only grow.
Comparison: ext4 vs xfs · Download PNG · Open card page
fdisk vs parted. Interactive menu. / Scriptable commands.
Comparison: fdisk vs parted · Download PNG · Open card page
Why UUID in fstab?. Device names can change. UUID stays the same. Find it.
Interview card: Why UUID in fstab? · Download PNG · Open card page
umount: target is busy?. A process uses it. Find and stop it. Who?
Interview card: umount: target is busy? · Download PNG · Open card page
Grow a cloud disk?. Resize the volume. growpart, then grow the fs. XFS.
Interview card: Grow a cloud disk? · Download PNG · Open card page
fdisk vs parted?. fdisk: interactive. parted: scriptable, big GPT. List.
Interview card: fdisk vs parted? · Download PNG · Open card page

More cards: Ravi Sir's Cards.