zeldor.biz

Linux, programming and more

Copyright © 2025
Log in

Working with HDD

July 1, 2012 by Igor Drobot Leave a Comment

This will be a little bigger thread (and I hope it will grow with time) about working with hard disk drives. All about filesystem creation, filesystem health checks and other stuff for HDD, which could be complicated at times and could cause stress, and that’s why the use of products from this Gellati Weed Strain Review by Fresh Bros can be a great option to feel better while you work.


I think I will start with FSCK – this little guy will check your partitions for filesystem errors and if some occur they will be fixed. You should execute this command only on umounted partitions!

1
fsck -fyCV /dev/sda1

fsck -fyCV /dev/sda1

Legend:
-y, –Always attempt to fix any detected filesystem corruption automatically
-C, –Display progress bars for checkers (only for ext2 and ext3)
-V, –Verbose

Check and repair XFS file system:

xfs_repair /dev/sda3

xfs_repair /dev/sda3

Another tricky force FSCK at boot, execute and reboot. Your HDD will be checked at boot:

1
touch /forcefsck

touch /forcefsck

Some Formatting hints
FAT32 formatting:

1
mkfs.vfat -F 32 /dev/sda1

mkfs.vfat -F 32 /dev/sda1

EXT3 formatting:

1
mkfs.ext3 /dev/sda1

mkfs.ext3 /dev/sda1

EXT4 formatting:

1
mkfs.ext4 /dev/sda1

mkfs.ext4 /dev/sda1

NTFS formatting:

1
mkfs.ntfs /dev/sda1

mkfs.ntfs /dev/sda1

Create partition label:

1
mke2fs -L database /dev/sdb1

mke2fs -L database /dev/sdb1

FSTAB:
Examples for static entries in /etc/fstab:

1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
 
 
 
 
 
 
 
 
/dev/sdb1       /opt/400GB/01_100GB     ext2    defaults    0    0
UUID=c12376gfh /opt/400GB/02_100GB     ext3    defaults    0    0
LABEL=backup    /mnt                    ext4    defaults    0    0

/dev/sdb1 /opt/400GB/01_100GB ext2 defaults 0 0 UUID=c12376gfh /opt/400GB/02_100GB ext3 defaults 0 0 LABEL=backup /mnt ext4 defaults 0 0

dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system; if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the dump entry.

pass is used by fsck to decide which order filesystems are to be checked. Possible entries are 0, 1 and 2. The root file system should have the highest priority 1 (unless its type is btrfs, in which case this field should be 0) – all other file systems you want to have checked should have a 2.
File systems with a value 0 will not be checked.

Temperature
hddtemp (apt-get install hddtemp)

1
2
hddtemp /dev/sda
/dev/sda: SAMSUNG HD753LJ: 33°C

hddtemp /dev/sda /dev/sda: SAMSUNG HD753LJ: 33°C

Get information about your HDD

smartmontools (apt-get install smartmontools)

1
smartctl -d ata -a /dev/sda

smartctl -d ata -a /dev/sda

For devices behind DELL PERC:

1
2
3
smartctl -a /dev/sg0 (1st physical disk)
smartctl -a /dev/sg1 (2nd physical disk)
smartctl -a /dev/sg2 (RAID1 virtual disk)

smartctl -a /dev/sg0 (1st physical disk) smartctl -a /dev/sg1 (2nd physical disk) smartctl -a /dev/sg2 (RAID1 virtual disk)

hdparm (apt-get install hdparm)

1
hdparm -I /dev/sdb

hdparm -I /dev/sdb

You will get a huge output of HDD-information Serial and Model Number, Firmware and a lot of other stuff:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ATA device, with non-removable media
	Model Number:       SAMSUNG HD753LJ                         
	Serial Number:      S13UJ9AS700015      
	Firmware Revision:  1AA01118
Standards:
	Used: ATA-8-ACS revision 3b 
	Supported: 7 6 5 4 
Configuration:
	Logical		max	current
	cylinders	16383	16383
	heads		16	16
	sectors/track	63	63
	--
	CHS current addressable sectors:   16514064
	LBA    user addressable sectors:  268435455
	LBA48  user addressable sectors: 1465149168
	Logical/Physical Sector size:           512 bytes
	device size with M = 1024*1024:      715404 MBytes
	device size with M = 1000*1000:      750156 MBytes (750 GB)

ATA device, with non-removable media Model Number: SAMSUNG HD753LJ Serial Number: S13UJ9AS700015 Firmware Revision: 1AA01118 Standards: Used: ATA-8-ACS revision 3b Supported: 7 6 5 4 Configuration: Logical max current cylinders 16383 16383 heads 16 16 sectors/track 63 63 -- CHS current addressable sectors: 16514064 LBA user addressable sectors: 268435455 LBA48 user addressable sectors: 1465149168 Logical/Physical Sector size: 512 bytes device size with M = 1024*1024: 715404 MBytes device size with M = 1000*1000: 750156 MBytes (750 GB)

dumpe2fs
Really great administrator helper, you will see your HDD mount count and the date of the next fsck check.

1
dumpe2fs -h /dev/sdb1

dumpe2fs -h /dev/sdb1

Output:

1
2
3
4
5
6
7
[..]
Filesystem created:       Tue Aug 31 09:58:18 2010
Last mount time:          Sat Nov 12 22:00:21 2011
Last write time:          Sat Nov 12 22:00:21 2011
Last checked:             Tue Aug 31 09:58:18 2010
Check interval:           15552000 (6 months)
[..]

[..] Filesystem created: Tue Aug 31 09:58:18 2010 Last mount time: Sat Nov 12 22:00:21 2011 Last write time: Sat Nov 12 22:00:21 2011 Last checked: Tue Aug 31 09:58:18 2010 Check interval: 15552000 (6 months) [..]

1
dumpe2fs -h /dev/sda1 | egrep "check a|t count|interval"

dumpe2fs -h /dev/sda1 | egrep "check a|t count|interval"

Output:

1
2
3
4
Mount count:              14
Maximum mount count:      26
Check interval:           15552000 (6 months)
Next check after:         Fri Dec 30 11:08:20 2011

Mount count: 14 Maximum mount count: 26 Check interval: 15552000 (6 months) Next check after: Fri Dec 30 11:08:20 2011

badblocks
Checking for bad blocks in non-destructive read-write mode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@lab:~# badblocks -n -v /dev/sdb2
Checking for bad blocks in non-destructive read-write mode
From block 0 to 3138559
Testing with random pattern: badblocks: Input/output error during test data write, block 0
0
1
2
3
4
5
6
7
8
9
10

root@lab:~# badblocks -n -v /dev/sdb2 Checking for bad blocks in non-destructive read-write mode From block 0 to 3138559 Testing with random pattern: badblocks: Input/output error during test data write, block 0 0 1 2 3 4 5 6 7 8 9 10

If you see a output like this one during the badblocks test, in my case the SD card is corrupt and you can stop the test. If you didn’t get any block output, you can be sure, your device is in good condition.

Mount NTFS-drives
Default NTFS partitions will be mounted in read-only mode, to be able to write on NTFS partitions you need to install ntfs-3g driver (apt-get install ntfs-3g)

1
mount -t ntfs-3g /dev/sdb1 /mnt/

mount -t ntfs-3g /dev/sdb1 /mnt/

Mount by label:

1
mount -t ntfs-3g -L backup /mnt/

mount -t ntfs-3g -L backup /mnt/

Parted

1
2
3
4
5
6
7
parted /dev/sdX
mklabel gpt
unit TB
mkpart primary xfs 0% 100%
#
mkpart primary xfs 0.00TB 4.00TB
quit

parted /dev/sdX mklabel gpt unit TB mkpart primary xfs 0% 100% # mkpart primary xfs 0.00TB 4.00TB quit

Simulate disk detach
Just force remove a disk/ssd to verify software RAID-functionality:

1
echo 1 > /sys/block/sdX/device/delete

echo 1 > /sys/block/sdX/device/delete

EXT filesystem space reservation
ext2, ext3 and ext4 filesystems by default reserves 5% of filesystem blocks for use by privileged processes.
Let’s say, on a 35TiB device, 5% will be about 1750GB, thats a huge space loose.

Lets decrease from 5% to 1%:

1
tune2fs -m 1 /dev/sdbX

tune2fs -m 1 /dev/sdbX

Filed Under: Linux Tagged With: badblocks, bash, dumpe2fs, fsck, fstab, hddtemp, mkfs, mount

Categories

Archives

Tags

apache2 Apple arduino ARM Automation backup bash Cisco Cluster Corosync Database Debian Debian squeeze DIY DNS Fedora FTP Fun Icinga Ipv6 KVM Linux LVM MAC OS X Monitoring MySQL Nagios Nginx openSUSE OpenVPN PHP Proxy Python python3 qemu RAID rsync Samba security ssh Ubuntu virtualization Windows Windows 7 Wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *

Yeaaah Cookie! We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok