Theodoros Emmanouilidis

Notes & Thoughts

Clone Entire Hard Drive With dd

February10

Suppose you want to back-up your entire system hard drive to a remote location as an image that you can roll back your system in case of emergency or copy everything to a new hard drive that will substitute the original system drive that is failing.

The following command clones entire hard drive with dd. First of all you need to boot your machine using a live Linux distro like knopix. Then, supposing that the hard drive you want to clone is sda, give the command

1
dd if=/dev/sda | gzip -1 - | ssh username@remotehost dd of=backup_image.gz

If you want to recover the image give the following command

1
dd if=backup_image.gz | gunzip -1 - | dd of=/dev/sda

dd copies everything bit by bit which means that the whole process takes a very long time. The good thing is that the cloned image is exact, containing original disk’ s partition info, boot sector info, everything.

It helps out though, in terms of speeding up the process a bit, to zero out all unused space, before using dd, issuing the command

1
dd if=/dev/zero of=0bits bs=20M; rm 0bits

Better be safe than sorry!

posted under Tip Of The Day | Comments Off on Clone Entire Hard Drive With dd

awk Script That Adds Specified Prefix To Each Line

February10

This is a useful awk script that adds specified prefix to each line of a given text file.

1
awk -v PRE='THE_PREFIX_THAT_YOU_WANT' '{$0=PRE$0; print}' my_input_file.txt > my_output_file.txt

It’ s so simple with awk!

posted under Tip Of The Day | Comments Off on awk Script That Adds Specified Prefix To Each Line

awk Script To Merge Columns From Different Files

February7

This is a very helpful awk script to merge columns from different files into one single file.

Suppose we have two files with two columns each and the same number of lines.
Our goal is to merge column two from the first file with column one from the second.

First we merge the two files and then we use awk to select the desired columns and print them to a new file.

1
pr -m -t -s\  file1 file2 | awk '{print $2,$3}' >out_file.txt

Give Read – Write Permissions To A Specific Group Of Users

January30

Suppose we have the need to give read – write permissions to a specific group of users. As an example we need a share folder to be readable and writable by all students in a specific class. The following guide addresses such an issue.

First we have to create the group.

1
sudo groupadd class01

Now we add some users and make them members of the class01 group,

1
2
3
4
5
6
sudo adduser student01:class01
sudo usermod -g class01 student01
sudo adduser student02:class01
sudo usermod -g class01 student02
sudo adduser student03:class01
sudo usermod -g class01 student03

we create the directory that will be shared to the group members,

1
sudo mkdir /media/shared/class01

and give the appropriate permissions.

1
sudo chmod -R g+rwxs /media/shared/class01

The above command will give full group read – write access to directory “class01” and also, will set the set-groupID flag so that directories created inside it inherit the group.

That’ s all!

« Older EntriesNewer Entries »