Tuesday 24 January 2017

Figure out Hidden used space in Linux

First Option:
root@devops-test:/ lsof | grep -i delete | sort –k8 | awk '{for(i=1;i<=6;i++){printf "%s ", $i}; print
$7/1048576 "MB" " "$8" "$9 }

Second Option:
Another situation was garbage file which was in /mnt/var/lib/mysql/garbage.file which again decreased disk usage to 23% upon removing the garbage.file
Tried to mount such files from root to /mnt using mount –bind / /mnt

Create EBS Volume and attach it to client

To Create an extra EBS Volume I ran the below command.
root@devops-test:~# aws ec2 create-volume --size 1 --region eu-central-1 --availability-zone eu-
central-1a --volume-type gp2

Found out availability zone and other details using below command:
root@devops-test:~# curl http://169.254.169.254/latest/meta-data/ adding appropriate keywords at the end of the command. For example, if I need to find instance-id, I will query
using curl http://169.254.169.254/latest/meta-data/instance-id

Attaching volume to AWS Client:
root@devops-test:~# aws ec2-attach-volume --volume-id vol-0b991fe06085ee22a --region eu-
central-1 --instance-id i-047c048c06938669e --device /dev/xvde

Why should you be worried about somebody executing this at the shell prompt? :(){ :|:& };:

It’s a fork bomb, crashes the system.

How do we shrink ibdata?

Below are the steps performed to shrink ibdata1

1. Backup MySQL DB and drop the DB
2. Stop MySQL service and add innodb_file_per_table=1 in my.cnf
3. Remove ibdata1, ib_logfile0 and ib_logfile1
4. Start MySQL service and restore the database

Converting ibdata to .ibd files per table

First enabling innodb_file_per_table and then when we optimize the tables, we can see that it creates .ibd files per table. Optimize table drops and recreates table so new .ibd files are created. Below are the steps:

Mysql> set global innodb_file_per_table=1;
Mysql> optimize table table_name;

How to recover MySQL Password without restart?

There is option to recover root access without restarting MySQL Service. But that needs creating another instance without InnoDB engine. Once we have another instance. We can copy the .frm, .myi & .myd files to new instance and change/recover root user password as we normally do in new instance and copy them back to original instance.

How to Recover MySQL Password ?

We need to skip grant tables and start MySQL service. It helps to login MySQL without
password. Once we login MySQL CMD, we can change the password of root accordingly.

root@devops-test:/var/lib# mysqld_safe --skip-grant-tables &
root@devops-test:/var/lib# mysql -u root -D mysql -Bse "update user set password=PASSWORD("***") where User='root'"
root@devops-test:/var/lib# mysql -u root -D mysql -Bse "flush privileges"