Disks¶
Format a disk¶
-
gpt partitions:
-
mbr/dos
sudo parted /dev/sdb mklabel msdos parted -a opt /dev/sdb mkpart primary 0% 100% sudo mkfs.vfat /dev/sdb1
You might need to change partition type to HPFS//NFFS/exFAT (you can check it in the output of
sudo fdisk -l /dev/sdb
):
Move image to a drive¶
Get the list of physical disks¶
*-namespace:2
description: NVMe disk
physical id: 1
bus info: nvme@0:1
logical name: /dev/nvme0n1
size: 3726GiB (4TB)
*-disk
description: ATA Disk
product: INTEL SSDSC2
physical id: 0.0.0
bus info: scsi@1:0.0.0
logical name: /dev/sda
lsblk --fs
— shows all block devices along with uuids.
Erase disk¶
HDD & SD cards¶
sudo dd if=/dev/zero of=/dev/sdX bs=1M status=progress
sudo shred -v -n 3 /dev/sdX
(might need to installcoreutils
)
NVME¶
sudo nvme format /dev/nvme0n1 --ses=1 # or --ses=2
(might need to installnvme-cli
)
Resize a GPT with a ext4¶
- Run parted:
parted /dev/sdX
- Change display unit to sectors:
unit s
. - Print current partition table and note the start sector for your partition:
p
- Delete your partition (won’t delete the data or filesystem):
rm <number>
- Recreate the partition with the starting sector from above:
mkpart primary <start> <end>
- Exit parted:
quit
- Check the filesystem:
sudo e2fsck -f /dev/sdXX
- Resize filesystem:
sudo resize2fs /dev/sdXX
Add encrypted disk¶
sudo cryptsetup luksFormat /dev/nvme0n1
sudo cryptsetup open /dev/nvme0n1 nvme0_crypt
sudo mkfs.ext4 -L VortexHome /dev/mapper/nvme0_crypt
then add it in /etc/crypttab
:
nvme0_crypt UUID=dd3a78d4-1085-422f-abd4-e42a1bf50073 none luks,discard
# Or
# nvme0_crypt UUID=c652c9c4-54a0-440f-824a-ec1d8e0d2d50 none luks,keyscript=/usr/share/yubikey-luks/ykluks-keyscript,discard
Update initramfs: sudo update-initramfs -u
and finally in fstab:
Disk health checks¶
Non-destructive disk health check (with smartctl
)¶
- Start test:
sudo smartctl -t long /dev/sdf # or sudo smartctl -t short /dev/sdf
- Check results:
sudo smartctl -l selftest /dev/sdf or sudo smartctl -a /dev/sdf
Note. If smartctl
test says that disk is healthy, it does not necessarily mean so. See the section below.
Destructive disk health check (with badblocks
)¶
-
-
-b
– block size. -
-w
— use write-mode test. -
-c
— is the number of blocks which are tested at a time. -
-v
—verbose mode. -
-s
— show the progress. -
-p
— number of passes.
-
Later, you can verify unreadability of particular sector with hdparm
command:
-
Note that if do not set
-b
option properlybadblocks
, you have to adjust sector here.The default block size in badblocks is 1024 bytes (from
badblocks
man:-b block-size Specify the size of blocks in bytes. The default is 1024.
), whereas Logical block size is 512 bytes (sudo hdparm -I /dev/sdf: Logical Sector size: 512 bytes
), hence 3012759284 (= 1506379642 * 2).
mdadm & RAID¶
Replacing a faulty/failing HDD in an mdadm RAID¶
Determine removed by mdadm disk:
- How to determine removed by mdadm disk.
- Light up the led of the failed HDD (assuming you know the failed disk, see the link above):
cat /dev/sdz >/dev/null