Archive for September, 2010

Swap space is hard disk space that extends system RAM
Create a swap file (or partition)

dd if=/dev/zero of=/var/local/swapfile bs=1k count=1M

Write special signature

mkswap /var/local/swapfile

Add entry to /etc/fstab
/var/local/swapfile swap swap defaults 0 0
Activate swap space

swapon -a

Backup the partition table

sfdisk -d /dev/sda > /tmp/partitions.sda

Partition the disk

fdisk /dev/sda

Restore partition table after major mistake

sfdisk /dev/sda < /tmp/partitions.sda

Update /proc/partitions

partprobe /dev/sda

Tar:
tar -cvzf name.tgz dir_to_be_archived
tar -cvzf –remove-files name.tgz dir_to_be_archived
Actions (one is required):
-c create an archive
-t list an archive
-x extract files from an archive
Typically required:
-f archivename name of file archive
Optional:
-z use gzip compression
-j use bzip2 compression
-v be verbose
–xattrs store SELinux and ACL properties

Zip:
Supports pkzip-compatible archives
Example:
zip -r etc.zip /etc
unzip etc.zip

sed -i 's/match/replacement/g' file -> writes on file
sed -i.bak -> writes and backups original file

sort [options] file(s)
Common options
-r performs a reverse (descending) sort
-n performs a numeric sort
-f ignores (folds) case of characters in strings
-u (unique) removes duplicate lines in output
-t c uses c as a field separator
-k X sorts by c-delimited field X
Can be used multiple times

Display specific columns of file or STDIN data
cut -d: -f1 /etc/passwd
grep root /etc/passwd | cut -d: -f7
Use -d to specify the column delimiter (default is TAB)
Use -f to specify the column to print
Use -c to cut by characters
cut -c2-5 /usr/share/dict/words

You should know already that you can do this on your own risk/responsibility. No guarantee that this will work in your case.
For removing the password lock you need a live linux cd/stick [I’ve done this using fedora 13 live cd]. Boot the linux and with hdparm -I /dev/sda you can see the security parameters:
Security:
Master password revision code = 65534
supported
enabled
locked
not frozen
not expired

Tested on western digital WDC WD2500YS:
you should read here about hdparm parameters.

hdparm --security-unlock WDCWDCWDCWDCWDCWDCWDCWDCWDCWDCW /dev/sda
hdparm --security-disable WDCWDCWDCWDCWDCWDCWDCWDCWDCWDCW /dev/sda

You should see smth like:
/dev/sda:
Issuing SECURITY_UNLOCK command, password="WDCWDCWDCWDCWDCWDCWDCWDCWDCWDCW", user=master
/dev/sda:
Issuing SECURITY_DISABLE command, password="WDCWDCWDCWDCWDCWDCWDCWDCWDCWDCW", user=master

after checking with hdparm -I /dev/sda: you should see:
Security:
Master password revision code = 65534
supported
not enabled
not locked
not frozen
not expired: security count

That means your hard drive is unlocked.

If you see smth like: expired: security count it means that you have tried more than 3 times invalid password and you should reset(power cicle) the drive.

For this exercise, we will use the mysqldump utility the same as if we were backing up the entire database.

Syntax:

mysqldump -d -h localhost -u root -pmypassword databasename > dumpfile.sql

The only option that is different than creating an entire backup is the -d switch, which tells mysqldump not to output the data.

Example:

mysqldump -d -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql

source http://www.howtogeek.com/howto/programming/mysql/dump-just-the-table-structure-to-a-file-in-mysql/