guest@backslash:~/posts/linux/linux-disk-management$

Linux disk management

~3 minraid linux mdadm config fstab partitions

Linux disk management

Partitioning, formatting and software RAID on Linux, with the output to expect at each step.

Use UUID in fstab file

Find disks UUID

terminal
$ ls /dev/disk/by-uuid -la
0E8F-D420 -> ../../sdd1
0f43a799-68a1-412f-9d63-67c78375262e -> ../../sdd2
2afcf0ee-f07e-4309-8ea9-76898c5a87ff -> ../../sdd4
a7e287a2-9ada-44cf-b6ce-f32c23e0ebf3 -> ../../sdd3
a9f7fcb5-108a-4210-bc14-1a59cd1f7133 -> ../../md0
e04e6c4d-aea5-4465-8a06-c7163196db27 -> ../../sde1

Use them in fstab

sh
UUID=e04e6c4d-aea5-4465-8a06-c7163196db27       /mnt/ssd1       ext4    defaults        0       3

Create new partition table with parted

Start parted on the disk

terminal
$ parted /dev/sdc

Create GPT disk label

terminal
(parted) mklabel gpt

Create one partition of all available space

Create partition on entire disk

terminal
(parted) mkpart primary 0% 100%

Create partition on spesific size in MB

Switch units to MB and print the free space, then create the partition from start to end:

terminal
(parted) unit MB print free
(parted) mkpart primary ext4 1MB 8001463MB

Print to see current partition table. Output for this example looks like:

terminal
(parted) print
Model: ATA WDC WD100EFAX-68 (scsi)
Disk /dev/sdc: 10.0TB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      0.00TB  10.0TB  10.0TB               primary

Save and quit

terminal
(parted) quit

Format partition

terminal
$ mkfs.ext4 /dev/sdc1
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2441608704 4k blocks and 305201152 inodes
Filesystem UUID: c1692a98-9c4a-4127-9bed-f86e5fcab9dc
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544, 1934917632

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

Mount

sh
mount /dev/sdc1 /mnt/disk1

Linux software RAID setup with mdadm

Manpage

Create new array

Raid 1 (mirror) with 2 devices

sh
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdc /dev/sdd

check status

While creating it could look like this:

terminal
$ cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sdd[1] sdc[0]
      9766305792 blocks super 1.2 [2/2] [UU]
      [===>.................]  resync = 18.5% (1811232960/9766305792) finish=686.7min speed=193056K/sec
      bitmap: 60/73 pages [240KB], 65536KB chunk

Healthy output when everything is up and running looks something like this:

terminal
$ cat /proc/mdstat
md0 : active raid1 sda1[1] sdb1[2]
      3906886272 blocks super 1.2 [2/2] [UU]

unused devices: <none>

scan and find existing

Add to the config, config file location might vary depending on distro

sh
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

md127

If your new raid device appears as /dev/md127 you should try and update initramfs then reboot

sh
sudo update-initramfs -u

Create filesystem on RAID device

sh
sudo mkfs.ext4 -F /dev/md0

fstab config for mdadm devices

sh
/dev/md0        /mnt/md0                        ext4    defaults        0       2
#### mount bind dev
/mnt/md0/development/ /home/slash/development        none    bind

Linux disk check and error handling

SMART

Show info

sh
sudo smartctl --info /dev/sdf

Show attributes

sh
sudo smartctl -a /dev/sdf

Run short test

sh
sudo smartctl -t short -a /dev/sdf

Run long test (type sata)

sh
sudo smartctl -d sat -t long -a /dev/sdf

Show capabilities and status for test

sh
sudo smartctl --capabilities /dev/sdf

Show errors if test fails

sh
sudo smartctl --log=selftest /dev/sdf

BACKSLASH(1)                  User Commands

NAME
       backslash - keyboard navigation

KEYS
       j / k      scroll down / up
       n / p      next / previous post
       gg / G     top / bottom of the page
       /          filter posts
       ?          this help
       Esc        close