March 16

Linux: Centos – Installing VBOX Guest Additions

How to install Virtual Box Guest Additions in CentOS

log in as root and type in terminal

yum install gcc -y

yum install kernel-headers -y (The need for this appears to vary by Redhat/Fedora version)

yum install kernel-devel -y

restart the system

now go to the VBox Addition directory in your /media directory and type:

sh VBoxLinuxAdditions.run

restart the system again

By: yoyo

Category: Linux | Comments Off on Linux: Centos – Installing VBOX Guest Additions
February 15

Linux: Backtrack networking options including autostart

Note: Commands listed should be run as root or with sudo (switch user do) command.

Enter the following command to enable or start your networking in BackTrack
/etc/init.d/networking start

This command will start all the interfaces in the /etc/network/interfaces file.

Below are more information in how to enable or start networking in Backtrack.

Setting your interfaces to get ip addresses via DHCP.
See my sample /etc/network/interfaces file.

root@wiztechie:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp

auto ath0
iface ath0 inet dhcp

auto wlan0
iface wlan0 inet dhcp

Setting your interfaces manually or having static ip addresses.
See my sample /etc/network/interfaces file.

auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1

Setting up your nameserver.
See my sample /etc/resolv.conf file.

root@wiztechie:~# cat /etc/resolv.conf
nameserver 192.168.0.1

If you only want specific interfaces to get ip address via the DHCP (in this example, let’s say eth0 and wlan0 only) then remove every thing else for the file with the exception of the lo interface.
See my sample /etc/network/interfaces file.
Note: Backup first your /etc/network/interfaces file if you’re having some doubt with what you are doing, in this way you can revert back to the original file. To do this enter cp /etc/network/interfaces /etc/network/interfaces.bak (this create a backup of the /etc/network/interfaces file)

root@wiztechie:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet dhcp

If you want to autostart or run this at startup, enter the command.

update-rc.d networking defaults

Category: Linux | Comments Off on Linux: Backtrack networking options including autostart
January 22

Linux: lsof

lsof is a very powerful “list open files” command.

eg:  lsof -i -n -P : grep firefox
lsof -PNL -i4

Overview

LiSt Open Files is a useful and powerful tool that will show you opened files. In Unix everything is a file: pipes are files, IP sockets are files, unix sockets are files, directories are files, devices are files, inodes are files…

Useful Examples

So in this tangle of files lsof listst files opened by processes running on your system.

When lsof is called without parameters, it will show all the files opened by any processes.

lsof | nl

Let us know who is using the apache executable file, /etc/passwd, what files are opened on device /dev/hda6 or who’s accessing /dev/cdrom:

lsof `which apache2`
lsof /etc/passwd
lsof /dev/hda6
lsof /dev/cdrom

Now show us what process IDs are using the apache binary, and only the PID:

lsof -t `which apache2`

Show us what files are opened by processes whose names starts by “k” (klogd, kswapd…) and bash. Show us what files are opened by init:

lsof -c k
lsof -c bash
lsof -c init

Show us what files are opened by processes whose names starts by “courier”, but exclude those whose owner is the user “zahn”:

lsof -c courier -u ^zahn

Show us the processes opened by user apache and user zahn:

lsof -u apache,zahn

Show us what files are using the process whose PID is 30297:

lsof +p 30297

Search for all opened instances of directory /tmp and all the files and directories it contains:

lsof +D /tmp

List all opened internet sockets and sockets related to port 80:

lsof -i
lsof -i :80

List all opened Internet and UNIX domain files:

lsof -i -U

Show us what process(es) has an UDP connection opened to or from the host www.akadia.com at port 123 (ntp):

lsof [email protected]:123

lsof provides many more options and could be an unvaluable foresinc tool if your system get compromised or as daily basis check tool.

Category: Linux | Comments Off on Linux: lsof
January 11

Linux: Resetting a Forgotten Root Password

If you have forgotten the root password it is possible to set a new one as follows:

Interrupt the boot at the GRUB stage and boot to runlevel 1, AKA single user mode. Interrupt GRUB by typing a character such as “space” then append to the kernel line by typing “a”, backspacing through “rhgb quiet” and appending ” 1<enter>”. This will give you a root shell and not a login prompt. From there you can use the “passwd” command to set a new root password.

Other user passwords can be reset, and other administrative tasks can be performed as well. Exiting the single user root shell will boot to the multi-user mode defined in /etc/inittab.

CentOS-6 Note: Due to an upstream SELinux bug the root password cannot be reset on a fresh install of CentOS-6 without an additional step. Booting with “selinux=0” appended to the grub kernel line, or doing “setenforce 0” after logging in and before attempting to reset the password are work-arounds. This is corrected by applying already-released errata updates.

Category: Linux | Comments Off on Linux: Resetting a Forgotten Root Password
January 11

Linux: Extending a virtual raw hard-disk image

Extending a libvirt raw storage volume in Debian Squeeze

This article takes you through the necessary steps to extend a raw libvirt storage volume that is part of a libvirt storage pool on a Debian Squeeze GNU/Linux system. A libvirt storage volume is essentially a virtual raw hard-disk image that is used by a virtual machine.
In this example, I’ll extend “rawdisk.img” raw disk image from 8GB to 12GB. We use the truncate command to extend the image file size, kpartx utility to create device maps from partitions (an association between partitions on the image file and loop devices) then gparted to do the actual file system extension. You can begin by installing kpartx and gparted utilities if you do not have them already installed on your Debian system.
user@host:~$ sudo aptitude install kpartx gparted

The steps for extending the raw image file are as follows.
1) Shutdown the virtual machine
2) Take a back-up of the disk image to be extended by simply copying it in the same folder using a different name
user@host:~$ cd /var/lib/libvirt/images user@host:~$ sudo cp rawdisk.img rawdisk-backup.img
3) Extend the file size of the rawdisk.img volume from 8GB to 12GB using the truncate command.
user@host:~$ sudo truncate –size $((8+4))G rawdisk.img
In the command above, we extend the rawdisk.img file size by 4GB over and above the original 8GB to get 12GB.
4) Create device maps for partition tables found in the raw image file using kpartx.
user@host:~$ sudo kpartx -av rawdisk.img add map loop0p1 (254:4): 0 16755732 linear /dev/loop0 63]
The above command will add partition mappings for the disk image file i.e. setup a loop device (/dev/loop0 in this case) as your hard-disk and create links in /dev/mapper/ director for different partitions found on the disk image (/dev/mapper/loop0p1 in our case)
5) Create similar links in /dev/ directory since utilities like gparted expect to find partition
1 of 3    12/20/2011 03:25 PM
Debian Administration :: Extending a libvirt raw storage vo…    http://www.debian-administration.org/article/Extending_a_li…
maps there. We do so by first checking which device is linked to /dev/mapper/loop0p1 and creating a symbolic link to the same device in /dev directory.
user@host:~$ ls -l /dev/mapper/loop0p1 lrwxrwxrwx 1 root root 7 Apr 23 18:16 /dev/mapper/loop0p1 -> ../dm-4
user@host:~$ ln -s /dev/dm-4 /dev/loop0p1
6) Open and edit the partitions of the mapped disk image using gparted, a gnome editor for manipulating disk partitions. You’ll need to run gparted as root to extend the partition /dev/loop01p on disk /dev/loop0
user@host:~$ sudo gparted /dev/loop0
Note that only /dev/loop0 is provided as an argument to gparted and not /dev/mapper /loop01p or /dev/loop01p.
In gparted, you’ll see the active partition with used and free space (8GB in our example) and a second partition of unallocated free space. The second unallocated free space (4GB in this example) is the space we want to add to the to the active partition.
Select then right click the active /dev/loop01p partition and choose Resize/Move. In the resize/move dialog box, set New Size with values of the Maximum size (i.e combined size of used + unallocated partition)
Next Apply all Operations to commit the change and exit gparted.
7) Well, we are not over yet. If you save the output of gparted, you’ll clearly see that the new changes were not committed to file probably due to a bug with either kpartx or gparted when working on virtual image files. We have to repeat step 4 and 6 after deleting and adding partition mappings for the new change to take effect.
8) Delete the partition mappings using kpartx
user@host:~$ sudo kpartx -d rawdisk.img loop deleted : /dev/loop0
9) Add partition mappings once again as was done in step 4 above.
user@host:~$ sudo kpartx -av rawdisk.img add map loop0p1 (254:4): 0 16755732 linear /dev/loop0 63]
10) Edit the partitions using gparted once again. user@host:~$ sudo gparted /dev/loop0
However, to get gparted to commit the changes to the image file, reduce the partition size by a small factor e.g. 10MiB then increase the partition size again by the same factor (10MiB).
2 of 3    12/20/2011 03:25 PM
Debian Administration :: Extending a libvirt raw storage vo…    http://www.debian-administration.org/article/Extending_a_li…
Apply All Operations for the changes to take effect before exiting gparted. 11) Delete the partition mappings using kpartx
user@host:~$ sudo kpartx -d rawdisk.img loop deleted : /dev/loop0
12) Don’t forget to delete the symlinks in /dev/ directory created in step 5 above. user@host:~$ sudo rm /dev/loop0p1
13) Refresh your libvirt storage pool using the virsh utilities. Replace “default” with your pool name at the end of the command below.
user@host:~$ virsh pool-refresh default Pool default refreshed
14) Examine information about your relatively new extended raw image disk
user@host:~$ sudo virsh vol-info /var/lib/libvirt/images/rawdisk.img Name: rawdisk.img Type: file Capacity: 12.00 GB
Allocation: 8.00 GB
You can see that the capacity has been extended to 12GB. What had been allocated remains at 8GB but the allocation will grow in tandem with the disk.
15) Fire up you virtual machine and let any native disk utilities check and repair the newly extended file system.
DONE.

By Aogulla

Category: Linux | Comments Off on Linux: Extending a virtual raw hard-disk image