KandZ – Tuts

We like to help…!

Linux CLI 29 🐧 fsck, mkfs and dd commands

a - fsck command
fsck is used to verify the intergrity of a file system
It checks for error( corrupted inodes, bad sectors, or broken file system structures)
It can attempt to fix those errors
before you check a filesystem you have to unmount it with umount
sudo fsck -N /dev/sda → displays what it will do without doing anything
sudo fsck /dev/sda → performs the check
sudo fsck -n /dev/sda → perform a check but do not repair
sudo fsck -f /dev/sda → forces a check
-a → repairs errors automatically -v → verbose mode -t → test for bad sectors

b - mkfs command
mkfs → Make File System
mkfs is used to create and format file systems
write sudo mkfs and use TAB key to show the supported filesystem types
Create a file system on a partition
sudo mkfs -t ext4 /dev/sda or sudo mkfs.ext4 /dev/sda
Note that mkfs creates a new filesystem on existing partition or drive
It does not resize or delete it. For this task you can use fdisk

c - dd command
dd → Data description
dd is used to copy and convert data from one place to another
syntax → dd if=inputfile [bs=blocksize] [count=numcopies] Of=outputfile
if → input file, where to read data from
bs → sets the block size, default is 512 bytes (optional)
count → specifies how many blocks will be transferred. All is default (optional)
of → output file, where the data will be transferred to

d - dd command examples
dd If=input.txt Of=backup.txt → copy a file
dd If=/dev/sda bs=4M count=10240 of=image.img → create an image file from /dev/sda
dd If=/dev/sda Of=/dev/sdc → clone a disk to another
dd if=/dev/sda1 of=~/sda1partition.img → backup a partition
dd if=sda1partition.img of=/dev/sda1 → restore the previous backup
and if you need to create an CD-ROM ISO
dd if=/dev/cdrom of=tgsservice.iso bs=2048

Leave a Reply