linux poison RSS
linux poison Email
2

HowTo take backup of Partition Table

Many of us are doing backups of all kinds of data: from regular files, databases, to full partitions or hard drives. What I have noticed that very few peoples even think about the partition table. Given the importance of the partition table I would suggest to have a backup of it, in case you will have a corrupted partition table, if you made a change by mistake or even if that gets deleted somehow (by mistake or intentionally). You still have the data on the disk but without recreating the correct partition table it will not be very easy to get the data back. Anyway this is very easy to do, so it is better to have it on hand, than regret that you have not done this when needed.

We can get a quick look on all the existing partitions on all the available hard drives with fdisk using the -l switch without any other parameter:

fdisk -l
Disk /dev/sda: 74.3 GB, 74355769344 bytes
255 heads, 63 sectors/track, 9039 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 16 128488+ 83 Linux
/dev/sda2 17 259 1951897+ 82 Linux swap / Solaris
/dev/sda3 260 2083 14651280 83 Linux
/dev/sda4 2084 9039 55874070 83 Linux

Disk /dev/sdb: 73.4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 8924 71681998+ 83 Linux

If we add to the command line the particular device that corresponds to a hard disk, like /dev/sdb we get the same result only for that device:

fdisk -l /dev/sdb

Disk /dev/sdb: 73.4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 8924 71681998+ 83 Linux

Of course someone might use only this information to recreate the partition table by manually creating the same partitions with the same start/end blocks (in case you want to do that you just have to save the above output in a file so you have that information on hand when needed), but there is a simpler way using sfdisk:

sfdisk -d /dev/sda
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 63, size= 256977, Id=83
/dev/sda2 : start= 257040, size= 3903795, Id=82
/dev/sda3 : start= 4160835, size= 29302560, Id=83
/dev/sda4 : start= 33463395, size=111748140, Id=83

Using sfdisk with the -d option we can get a dump of the current partition table in a regular file, and if needed we can restore it from that file:

sfdisk -d /dev/sda > sda_table

and to restore the partition table:

sfdisk /dev/sda <>

Regardless on the method used, having a backup of the partition table might be handy. ;)

One more tip: another usage of sfdisk with -d is to create an identical partition table from another hard disk. In this example we are partitioning sdb with the exact same partitions as sda:

sfdisk -d /dev/sda | sfdisk /dev/sdb

of course this can be handy when the hard drives are identical, in raid1 setups, etc.

Read more
0

Encrypt-Decrypt file using GPG

With GPG you can encrypt and decrypt files with a password. GPG is an encryption and signing tool for Linux/UNIX like operating system such as OpenBSD/Solaris/Fedora.

In this first example I will show you the basics on how to encrypt a file. But before we do that lets create a file called encrypt_example.

# touch encrypt_example

To encrypt single file, use the GPG command as follows: gpg -c encrypt_example. This will create a encrypt_example.gpg file. The -c option will Encrypt with symmetric cipher

Now to decrypt it, use command - gpg encrypt_example.gpg
Read more
24

Script to convert .wav to .mp3

Put all your .wav files (that you want to convert) into a folder and execute the following script from within this folder, make sure to make this script executable (chmod 777 wav2mp3.sh)

#!/bin/sh
# name of this script: wav2mp3.sh
# wav to mp3

for i in *.wav; do
 if [ -e "$i" ]; then
   file=`basename "$i" .wav`
   lame -h -b 192 "$i" "$file.mp3"
 fi
done
Dependencies
faad2 and lame


Read more
12

Script to convert .m4a to .mp3

Put all your .m4a files (that you want to convert) into a folder and execute the following script from within this folder, make sure to make this script executable (chmod 777 m4a2mp3.sh)

#!/bin/sh
# name of this script: m4a2mp3.sh
# m4a to mp3

for i in *.m4a; do
  faad "$i"
  x=`echo "$i"|sed -e 's/.m4a/.wav/'`
  y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
  lame -h -b 192 "$x" "$y"
  rm "$x"
done

Dependencies
faad2 and lame


Read more
0

Security Guide for Linux by NSA

Guide for Linux is presented as Hardening Tips for the Red Hat Enterprise Linux 5 and Guide to the Secure Configuration of Red Hat Enterprise Linux 5. Of course most of recommendation suit other distributions. Here is the introduction quote from latter guide:
"The purpose of this guide is to provide security configuration recommendations for the Red Hat Enterprise Linux (RHEL) 5 operating system. The guidance provided here should be applicable to all variants (Desktop, Server, Advanced Platform) of the product. Recommended settings for the basic operating system are provided, as well as for many commonly-used services that the system can host in a network environment.
The guide is intended for system administrators. Readers are assumed to possess basic system administration skills for Unix-like systems, as well as some familiarity with Red Hat’s documentation and administration conventions. Some instructions within this guide are complex. All directions should be followed completely and with understanding of their effects in order to avoid serious adverse effects on the system and its security."
Above mentioned guide covers the following directions: system-wide configuration (for example, iptables and ip6tables setup, logging, selinux and etc.) and services configuring (SSH, Avahi server, MTA, LDAP and many others).


Read more
Related Posts with Thumbnails