iSCSI – Initiator and Target.

The target is the name of the iSCSI server. The iSCSI server offers its devices (disks, tape, dvd/cd, etc.) to the clients. One device can by accessed by a few clients.

At first we have to set up a target server:

debian# apt-get install iscsitarget iscsitarget-dkms

then edit the configuration file:

debian# vi /etc/default/iscsitarget

and then, set ISCSITARGET_ENABLE to true: “ISCSITARGET_ENABLE=true“.

Now, we can create a volume group:

debian# vgcreate vg1 /dev/sdc1

but before that, you have to use fdiks to create Linux LVM partition. The next step is to initializes PhysicalVolume for later use by the Logical Volume Manager (LVM):

debian# pvcreate /dev/sdc1

and then, create a logical volume in an existing volume group:

debian# lvcreate -L2000M -n disk_sdc vg1

Now, we can add the “sdc1” disk to /etc/iet/ietd.conf and comment out everything in that file.


Target iqn.2012-10.com.home:disk.sdc
Lun 0 Path=/dev/vg1/disk_sdc,Type=fileio
Alias LUN1
MaxConnections 0

and then, and start the target:

debian# /etc/init.d/./iscsitarget start

The initiator is the name of the iSCSI client. The iSCSI client has a block level access to the iSCSI devices, which can be a disk, tape drive, DVD/CD writer. One client can use multiple iSCSI devices.

To install the initiator:

debian# apt-get install open-iscsi

and then, edit the /etc/iscsi/iscsid.conf file, and set node.srartup to automatic

node.startup = automatic

and then, restart the initiator:

debian# /etc/init.d/./open-iscsi restart

Discover targets using the discovery record with the recid matching the the discovery type and portal passed in. If there is no matching record, it will be created using the iscsid.conf discovery settings. This must be passed in discoverydb mode to instruct iscsiadm to perform discovery. This option is only valid for SendTargets discovery mode.

To do this:

debian# iscsiadm -m discovery -t st -p 192.168.1.100

output:

debian# iscsiadm -m discovery -t st -p 192.168.1.100
192.168.0.100:3260,1 iqn.2012-10.com.home:disk.sdc

Specify the mode. op must be one of discoverydb, node, fw, host iface or session.
If no other options are specified: for discoverydb and node, all of their respective records are displayed; for session, all active sessions and connections are displayed; for fw, all boot firmware values are displayed; for host, all iSCSI hosts are displayed; and for iface, all ifaces setup in /var/lib/iscsi/ifaces are displayed.

and then:

debian# iscsiadm -m node

and finally we can log in, either by running:

iscsiadm -m node --targetname "iqn.2012-10.com.home:disk.sdc" --portal "192.168.1.100:3260" --login

Ohh… that’s useful:

debian# cat /proc/net/iet/volume
debian# cat /proc/net/iet/vsession

Broken Grub menu – Debian.

Broken Grub menu: boot to the menu, drop to a consloe and boot Debian direct.
Sometimes the only thing that works when you boot is the Grub menu appears on your screen.
When you see Grub’s boot menu on your screen, instead fo selecting a boot item, press the “c” key.
That brings up a messages like this:

GNU GRUB version 1.99-14
Minimal BASH-like line editing is supported. For the firs word,
TAB lists possible command completions. Anywhere else TAB lists
posssible device or file completions. ESC at any time exits.

grub>

Now carry out the following commands at the grub prompt:

grub> search.file /sbin/init
hd0,msdos1
grub> search.file /boot/grub/device.map
hd0,msdos1
grub> search.file /vmlinuz
hd0,msdos1

Whatever you use, will ok. What we looking for is:
– Grub pointer to my Debian installation on drive number 1, partition number 1, your pointer
will be different from my example (hd0,msdos1)
– UUID assigned to this partition 625b756b-737e-4502-a914-9d351d50603a


grub> ls (hd0,msdos1)
Partition hd0,msdos1: Filesystem type ext2 - Last modification time
2012-01-11 10:57:44 Wednesday, UUID 625b756b-737e-4502-a914-9d351d50603a -
Partition start at 2048 - Total size 40134656 sectros
grub> set root='(hd0,msdos1)'
grub> linux /boot/vmlinuz-{press TAB key}
Possible files are:
vmlinuz-2.6.32-5-686 vmlinuz-3.2.0-1-686-pae
grub> linux /boot/vmlinuz-3.2.0-1-686-pae ro root=UUID=625b756b-737e-4502-a914-9d351d50603a
grub> initrd /boot/initrd.img-{press TAB key}
Possible files are:

initrd.img-2.6.32-5-686 initrd.img-3.2.0-1-686-pae
grub> initrd /boot/initrd.img-3.2.0-1-686-pae
grub> boot

and the machine boots 🙂

RAID in Linux, using mdadm in Linux.

Linux software RAID has nothing to do with hardware RAID controllers. You don’t need an add-on controller, and you don’t need the onboard controllers that come on most motherboards.

The RAID  devices  are virtual devices created from two or more real block devices. This allows multiple devices (typically disk drives or partitions thereof) to be combined into a single device to hold (for example) a single filesystem.
Some RAID levels include redundancy and  so  can  survive some degree of device failure.

Currently, Linux supports LINEAR md devices, RAID0 (striping), RAID1 (mirroring), RAID4, RAID5, RAID6, RAID10, MULTIPATH, FAULTY, and CONTAINER.
Continue reading “RAID in Linux, using mdadm in Linux.”

Find out the subdomains of a given name with "dig"

You might find yourself in a situation that you would like to know all the listed sub-domains in a domain. If you are the administrator of the DNS server you will not have much trouble of finding the information, if you are not the administrator of the server you can have a hard time finding out the sub-domains for a domain.
First, find out the name server or servers for a domain using the dig command:
Continue reading “Find out the subdomains of a given name with "dig"”

Increase an ext2/3 partition without lossing data.

Resize ext3 partition using resize2fs which support ext3.

root@deb:/disk# ls -la
total 664228
drwxr-xr-x 3 root root 4096 Dec 19 18:29 .
drwxr-xr-x 22 root root 4096 Dec 19 17:19 ..
-rwxrwxrwx 1 nobody nogroup 679477248 Nov 26 11:31 debian-6.0.3-i386-CD-1.iso
drwx------ 2 root root 16384 Dec 19 17:18 lost+found
root@deb:/disk#

There is an ISO of Debian system. I don’t want loose it 🙂
Continue reading “Increase an ext2/3 partition without lossing data.”

Find file by access, change or modify time.

How to find files that were last modified 10 days ago, use:
root# find / -iname "*" -mtime -10 -print

How to find files that were last modified 10 days ago and for each of them do stat:
root# find / -iname "*" -mtime -10 -exec stat {} ;

How to find files that were last modified 24 hours ago and move them to some directory:
root# find / -name "*.png" -mmin -1440 -exec mv {} some_directory ;

How to find all files in your home directory modified or created today. By default, find counts days from midnight, so an age of zero means today.
user~> find ~ -type f -mtime 0

Find all file belongs to group “ftpusers” in /home directory, enter:
root# find /home -group ftpusers

Find all file belongs to user root in / directory
root# find / -user root

Find files and directories that are not owned by user, use:
find ~ ! -user ${USER}

Find anything in the current user’s directory that is not owned by that user and fix the permissions:
find ~ ! -user $USER -exec sudo chown ${USER}:"{}" ;

Find file and redirect errors to /dev/null
find / -name "apache2" -print 2>/dev/null


Other options:
access (read the file’s contents) – atime
change the status (modify the file or its attributes) – ctime
modify (change the file’s contents) – mtime

LVM – create, resize, remove, scan, reduce, etc.

LVM enables flexible distribution of hard disk space over several file systems. It was developed because the need to change the segmentation of hard disk space might arise only after the initial partitioning has already been done during installation. Because it is difficult to modify partitions on a running system, LVM provides a virtual pool (volume group or VG) of memory space from which logical volumes (LVs) can be created as needed. The operating system accesses these LVs instead of the physical partitions.
Continue reading “LVM – create, resize, remove, scan, reduce, etc.”