linux disk administration - ghdrako/doc_snipets GitHub Wiki
Prepping the disk for use
sudo fdisk -l # display all attached disks and partitions
sudo fdisk /dev/sdb # initialize disk
sudo mkfs.xfs /dev/sdb1 # create the filesystem
sudo lsblk -f # List all block devices and filesystems
sudo blkid /dev/sdb1 # display the UUID
sudo mkdir /opt/software # create dir to mount new partition
sudo mount /dev/sdb1 /opt/software
mount |grep sdb1
# Edit the /etc/fstab file to make this mount permanent, which means that it will survive a system reboot.
UUID=ca2701e0-3e75-4930-b14e-d83e19a5cffb /opt/software xfs defaults 0 0
# alter the permissions of /opt/software to allow users to access it or create subdirectories with appropriate permissions.
Check disk
sudo e2fsck /dev/sdaX
Check file system
sudo tune2fs -l /dev/sdc1 | grep -i 'last checked\|mount count'
If for example, you want to run fsck after every 25 boots (mounts), type:
sudo tune2fs -c 25 /dev/sdc1
You can also set the maximal time between two checks. For example, to set it one month you would run:
sudo tune2fs -i 1m /dev/sdc1
To force fsck to run at boot time on SystemD distributions pass the following kernel boot parameters:
fsck.mode=force
fsck.repair=yes
Resize
resize2fs /dev/(your device) ####
Repair Corrupted File System
- Unmount the device:
sudo umount /dev/sdc1
- Run fsck to repair the file system:
sudo fsck -p /dev/sdc1
The -p option tells fsck to automatically repair any problems that can be safely fixed without user intervention.
- Once the file system is repaired, mount the partition:
sudo mount /dev/sdc1