Common Commands

Server Administration

Smartctl

LVM - Add new disk and extend FS

Rescan for newly added disks without rebooting:

The command will iterate over all found host adapters and trigger a rescan.

>> for host in /sys/class/scsi_host/*; do echo "- - -" | sudo tee $host/scan; ls /dev/sd* ; done
- - -
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdc  /dev/sdc1
- - -
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdc  /dev/sdc1
- - -
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdc  /dev/sdc1  /dev/sdd
- - -
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdc  /dev/sdc1  /dev/sdd  /dev/sdd1

The output shows when a new drive has been discovered.

LVM add "physical" disk and extend FS

fdisk /dev/<disk>
>> create new gpt table: g
>> create new partition: n
>> set type of partition to lvm: t 
>> show partition codes: L
>> insert type: <type from L (Linux LVM)>
>> write changes: w
pvcreate /dev/<disk-partition>
vgextend <existing-vg> /dev/<disk-partition>
# find the correct logical volume
lvdisplay | grep Path 

# expand found lv
lvresize -l +100%free <lv path>
resize2fs <lv path>

Sources:

SSD Secure Erase

Secure erase commands:

Check current status of the disk:

>> sudo hdparm -I /dev/sdX

-----
Security:
	Master password revision code = 65534
		supported
	not	enabled   	
	not	locked
	not	frozen
	not	expired: security count
		supported: enhanced erase

The disk needs to be not locked, not frozen but enabled. To enable secure erase set a password for the master user on the disk.

>> sudo hdparm --user-master u --security-set-pass password /dev/sdX

-----
security_password: "password"

/dev/sdd:
 Issuing SECURITY_SET_PASS command, password="password", user=user, mode=high

If something else appears, like I/O errors or so, check if you are connected to a motherboard port that supports these ATA commands. e.g. my USB Sata adapter did not, thus the commands could not be sent to the drive.

Afterwards we can erase the drive

sudo hdparm --user-master u --security-erase password /dev/sdX

-----
security_password: "password"

/dev/sdd:
 Issuing SECURITY_ERASE command, password="password", user=user

After this, the drive should appear unformated and without a partition table.

User Management

SSH2 Public Key to OpenSSL format for SSH Server

To convert a given Public Key to a useful format for SSH servers use the following command. It will print out the expected format to use.

ssh-keygen -i -f /path/to/file