Posts Tagged linux

Linux software raid

Failed hard drive on my software raid (Ubuntu Gutsy 7.1)  – SDA.

Commands to use:

fdisk -l (list information for the physical disks)
mdadm –detail /dev/md? (md stands for Multiple Disk. Replace ? with # as in 0, 1, 2)
fsck (file system check)
runlevel (show what runlevel the system is currently in)
init or telinit # (# = runlevel number you want to change to. Under ubuntu instead of init “upstart” is used while maintaining existing scripts.)
hdparm -i /dev/sda Use to get S/N and identify disk (Good way to verify which physical drive to replace.  Can run the command on the drive that has not failed so you know which one not to replace and in a RAID1 setup, just remove the other one.

I got this from obstinate.org (I’m not posting the link because McAfee has shown it to be linked to a spam distributing site, but this is good information)

Software RAID 1 Recovery in Linux

I wrote these steps up for a customer and figured it would be useful to people who find this on google. Enjoy.
1. Check the status of the RAID
This command will output the status of all RAID disks on your system.

> # cat /proc/mdstat

> Personalities : [raid1]
> md2 : active raid1 sda2[0]
> 1052160 blocks [2/1] [_U]
> md1 : active raid1 sda3[0]
> 37921344 blocks [2/1] [_U]
> md0 : active raid1 sda1[0]
> 104320 blocks [2/1] [_U]
> unused devices: <none>

We can clearly see that one of the disks is lost from the array by
seeing the [U_] for each slice of the disk. A fully functional RAID
system would show [UU] for each slice.

Since you had the second hard drive plugged in, we could proceed
immedietly to step 2.

2. Copy partition table from running drive to the replacment drive
In order to do this we need first to make a copy of the partition table
on the running disk. This is accomplished with the following command:

> # sfdisk -d /dev/sda > partitions.sda

Then we need to copy this partition to the new disk. This is
accomplished with the following command:

> # sfdisk --force /dev/sdb < partitions.sda
3. Add the newly partitioned disks to the array volume
We now need to add each partition back to the original volume.

> # mdadm --add /dev/md0 /dev/sdb1
> # mdadm --add /dev/md1 /dev/sdb3
> # mdadm --add /dev/md2 /dev/sdb2

4. Wait for the volumes to rebuild.
Now that we have added the new disk back to the volume we should see the
system rebuilding the drives. The two very small partitions /swap and
the boot partition sync very fast(in seconds) the larger partition will
take around 20 minutes to complete. You can check the status with
/proc/mdstat

> # cat /proc/mdstat

> Personalities : [raid1]
> md2 : active raid1 sdb2[2] sda2[1]
> 1052160 blocks [2/1] [_U]
> resync=DELAYED
> md1 : active raid1 sdb3[2] sda3[1]
> 37905280 blocks [2/1] [_U]
> [>....................] recovery = 2.0% (770944/37905280) finish=12.8min speed=48184K/sec

> md0 : active raid1 sdb1[0] sda1[1]
> 104320 blocks [2/2] [UU]

Once this process is complete you should see a fully functional RAID
array (complete with [UU] on every slice).

> # cat /proc/mdstat

> Personalities : [raid1]
> md2 : active raid1 sdb2[0] sda2[1]
> 1052160 blocks [2/2] [UU]
> md1 : active raid1 sdb3[0] sda3[1]
> 37905280 blocks [2/2] [UU]
> md0 : active raid1 sdb1[0] sda1[1]
> 104320 blocks [2/2] [UU]

5. Add newly built drive to GRUB
Now that the disk is ready to use, we want to make sure that it is
bootable by the system the next time you need to reboot. This is
accomplished by running the following sequence of GRUB commands:

> # grub
> grub> device (hd0) /dev/sdb
> grub> root (hd0,0)
> grub> setup (hd0)
> grub> device (hd0) /dev/sda
> grub> root (hd0,0)
> grub> setup (hd0)
> grub> quit

It should be noted that there is grub output from those command that I
have omitted.

I hope that this has cleared up your questions on how we use software
RAID on the Linux.

This is another good link -> http://www.texsoft.it/index.php?c=hardware&m=hw.storage.grubraid1&l=it

Tags: ,

Unix File Modes

In order to understand these numeric modes, you must first understand that these modes are actually represented by the system as three octal digits, one each for the user, the group, and others. Within each category, the Read/Write/eXecute bits are represented by the bits of an octal digit. The Read bit is in the 4s place, the Write bit is in the 2s place, and the eXecute bit is in the 1s place.

USER GROUP OTHER

r w x r w x r w x

4 2 1 4 2 1 4 2 1

In order to determine the numeric code for a given set of permissions, you just add up the octal digits for the modes that are on. For example, if a file is readable and writable by the user and read-only for the group and others, the numeric mode would be 644, as illustrated below:

USER GROUP OTHER

r w – r – - r – -

4+2 4 4

Similarly, a directory that has permissions ‘rwxr-xr-x’ would have an octal mode of 755. You can use this numeric mode to set permissions. For example,

chmod 644 somefile

sets the permission of the file to ‘rw-r–r–’.

via IUCS CSG FAQ – How do I use Unix file permissions?.

Tags: , ,

Linux overwrite a directory with same structured directory

If you prefer you can overwrite the contents of /var/www/testsite by doing

cp-arv testsite/* /var/www/testsite/

Tags: ,

Bad Behavior has blocked 473 access attempts in the last 7 days.

Better Tag Cloud