Pages

Friday, April 26, 2024

fsck--Mount partition using alternate superblock

To mount a partition using an alternate superblock, first, use dumpe2fs to find the superblock locations. Then, check and repair the filesystem with fsck using the -b option to specify the alternate superblock location if needed. Once repaired, mount the partition using the mount command. Access the filesystem, navigate to the mounted partition, and verify its contents. Lastly, ensure to regularly backup important data to prevent any potential data loss.

Find out the superblock location for /dev/sda2:
# dumpe2fs /dev/sda2 | grep superblock

Sample output:

Primary superblock at 0, Group descriptors at 1-6
Backup superblock at 32768, Group descriptors at 32769-32774
Backup superblock at 98304, Group descriptors at 98305-98310
Backup superblock at 163840, Group descriptors at 163841-163846
Backup superblock at 229376, Group descriptors at 229377-229382
Backup superblock at 294912, Group descriptors at 294913-294918
Backup superblock at 819200, Group descriptors at 819201-819206
Backup superblock at 884736, Group descriptors at 884737-884742
Backup superblock at 1605632, Group descriptors at 1605633-1605638
Backup superblock at 2654208, Group descriptors at 2654209-2654214
Backup superblock at 4096000, Group descriptors at 4096001-4096006
Backup superblock at 7962624, Group descriptors at 7962625-7962630
Backup superblock at 11239424, Group descriptors at 11239425-11239430
Backup superblock at 20480000, Group descriptors at 20480001-20480006
Backup superblock at 23887872, Group descriptors at 23887873-23887878

Now check and repair a Linux file system using alternate superblock # 32768:
# fsck -b 32768 /dev/sda2

Sample output:

fsck 1.40.2 (12-Jul-2007)
e2fsck 1.40.2 (12-Jul-2007)
/dev/sda2 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #241 (32254, counted=32253).
Fix? yes
Free blocks count wrong for group #362 (32254, counted=32248).
Fix? yes
Free blocks count wrong for group #368 (32254, counted=27774).
Fix? yes
..........
/dev/sda2: ***** FILE SYSTEM WAS MODIFIED *****

/dev/sda2: 59586/30539776 files (0.6% non-contiguous), 3604682/61059048 blocks

Now try to mount file system using mount command:
# mount /dev/sda2 /mnt


You can also use superblock stored at 32768 to mount partition, enter:
# mount sb={alternative-superblock} /dev/device /mnt
# mount sb=32768 /dev/sda2 /mnt


Try to browse and access file system:
# cd /mnt
# mkdir test
# ls -l
# cp file /path/to/safe/location

You should always keep backup of all important data including configuration files

Analyse slow-query-log using mysqldump

Analyzing the slow-query-log using tools like mysqldumpslow, pt-query-digest, and mysqlsla can provide valuable insights into the performance of your MySQL database. Here's a step-by-step guide on how to use these tools:

1. Enable slow-query-log:

  • Uncomment the following lines in /etc/mysql/my.cnf:
slow-query-log = 1
slow-query-log-file = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes

  • Adjust long_query_time based on your server's performance and the expected execution time of queries.

2. Collect slow query logs:

  • Let the server run with the slow query log enabled for some time to collect data.

3. Analyze slow query logs:

Using mysqldumpslow:

  • Command to show top 5 queries returning maximum rows:
    mysqldumpslow -a -s r -t 5 /var/log/mysql/mysql-slow.log
  • Command to sort output by count (frequency of occurrence) of queries:
    mysqldumpslow -a -s c -t 5 /var/log/mysql/mysql-slow.log

Using pt-query-digest:

  • Basic command to analyze slow query logs:
    pt-query-digest /var/log/mysql/mysql-slow.log
  • Filter queries for a specific database:
    pt-query-digest /var/log/mysql/mysql-slow.log --filter '$event->{db} eq "db_wordpress"'

Using mysqlsla:

  • Basic command to analyze slow query logs
./mysqlsla /var/log/mysql/mysql-slow.log


  • Filter queries for a specific database:

    ./mysqlsla /var/log/mysql/mysql-slow.log -mf "db=db_name"

4. Interpretation and Action:

  • Review the output of the analysis tools to identify slow queries, their frequency, and potential performance bottlenecks.
  • Investigate queries that are returning a large number of rows or have a high frequency of occurrence.
  • Optimize slow queries by adding indexes, rewriting queries, or optimizing database schema.
  • Monitor the performance after optimizations and fine-tune as necessary.

By following these steps and using the provided tools, you can effectively analyze and optimize the performance of your MySQL database, especially in scenarios like debugging WordPress plugins or identifying performance issues in large-scale applications.

Inode space issue , finding largest inode entry direcotry

To find the directory with the largest inode entry, you can use the following command:
For example:

sudo find / -xdev -printf '%h\n' | sort | uniq -c | sort -nr | head

 Let's break down this command:
  • sudo: Run the command with root privileges to access all directories.
  • find / -xdev -printf '%h\n': Find all files and directories starting from the root directory (/) while excluding other mounted filesystems (-xdev). Print only the directory portion of each file found (%h) followed by a newline (\n).
  • sort: Sort the output alphabetically (directories will be grouped together).
  • uniq -c: Count the occurrences of each unique directory.
  • sort -nr: Sort the counts numerically in reverse order (largest counts first).
  • head: Display the first few lines of output, which will show the directories with the largest number of files.

This command will help you identify the directory with the most files, which could be contributing to the inode space issue. Once you find the problematic directory, you can further investigate and take appropriate actions to manage the inode usage.