Archive for the ‘linux’ Category

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/

Generate SSL Certificate For VSFTPD Server:

openssl req -x509 -nodes -days 365 -newkey rsa:1024  -keyout /etc/vsftpd/vsftpd.pem  -out /etc/vsftpd/vsftpd.pem

Add this lines to vsftpd.conf:
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=NO
force_local_logins_ssl=NO
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES
rsa_cert_file=/etc/vsftpd/vsftpd.pem

Useful debug/rescue commands
history
grep
diff
find /dir -cmin -60
strace command
tail -f logfile
Generate additional information
*.debug in syslog
–debug option in application

Things to Check: Boot Process
Bootloader configuration
Kernel
Starting init
/sbin/init
/etc/rc.d/rc.sysinit
Entering runlevel [0-6]
/etc/rc.d/rc, /etc/rc.d/rc[0-6].d/
/etc/rc.d/rc.local
Virtual Consoles
X Display Manager

LVM

Creating Logical Volumes
1.
Prepare underlying block devices
Can use partitions of type 0x8e or software RAID devices
2.
Create physical volumes
# pvcreate /dev/hda3
3.
Create volume group containing physical volume
# vgcreate vg0 /dev/hda3
4.
Create logical volumes inside volume groups
# lvcreate -L 256M -n data vg0
5.
Format and mount logical volume (/dev/vg0/data)

Resizing Logical Volumes
Growing logical volumes and filesystems
lvextend can grow logical volumes
resize2fs can grow ext3 filesystems online or offline
Shrinking filesystems and logical volumes
Must be done offline (umount)
Requires a filesystem check (e2fsck) first
Filesystem then reduced (resize2fs)
Lastly, lvreduce can then reduce the volume

Resizing Volume Groups
Volume Groups can be enlarged with:
# vgextend vg0 /dev/sdb1
Volume Groups can be reduced with:
# pvmove /dev/hda3
# vgreduce vg0 /dev/hda3

Logical Volume Manager Snapshots
Snapshots are special Logical Volumes that are an exact copy of an existing Logical Volume at the time the snapshot is created
Snapshots are perfect for backups and other operations where a temporary copy of an existing dataset is needed
Snapshots only consume space where they are different from the original Logical Volume
Snapshots are allocated space at creation but do not use it until changes are made to the original Logical Volume or the Snapshot
When data is changed on the original Logical Volume the older data is copied to the Snapshot
Snapshots contain only data that has changed on the original Logical Volume or the Snapshot since the Snapshot was created.

Using LVM Snapshots
1. Create snapshot of existing Logical Volume
# lvcreate -l 64 -s -n datasnap /dev/vg0/data
2. Mount snapshot
# mkdir -p /mnt/datasnap
# mount -o ro /dev/vg0/datasnap /mnt/datasnap
3. Perform backup
4. Remove snapshot
# umount /mnt/datasnap
# lvremove /dev/vg0/datasnap

Software RAID Recovery
To simulate disk failure
# mdadm /dev/md0 -f /dev/sda1
Recovering from a software RAID disk failure
1.
Replace and reboot, or hot-remove if hardware supports it
# mdadm /dev/md0 -r /dev/sda1
2.
Add replacement partition into array
# mdadm /dev/md0 -a /dev/sda1
To disassemble/stop a disk array
# mdadm -S /dev/md0