Friday, February 22, 2013

Add new hard drive in CentOS/RHEL/OEL without reboot

Add new hard drive in CentOS/RHEL/OEL without reboot:

1. First add an new 200 GB hard drive in scsi mode from VMware ESXi console.

Please notice only scsi disk allow operation while power on.

2. Then echo "- - -" > /sys/class/scsi_host/host2/scan

Please notice host2 is the scsi number I added from the ESXi.

# ls /sys/class/scsi_host/
host0/ host1/ host2/


2.1 Before:

# fdisk -l

Disk /dev/sda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00073bb3

Device Boot Start End Blocks Id System
/dev/sda1 * 1 17 131072 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 17 531 4128768 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 531 2089 12516352 83 Linux

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbf77fef7

Device Boot Start End Blocks Id System
/dev/sdb1 1 13054 104856223+ 83 Linux

2.2 Then run:

# echo "- - -" > /sys/class/scsi_host/host2/scan

2.3 After:

# fdisk -l

Disk /dev/sda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00073bb3

Device Boot Start End Blocks Id System
/dev/sda1 * 1 17 131072 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 17 531 4128768 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 531 2089 12516352 83 Linux

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbf77fef7

Device Boot Start End Blocks Id System
/dev/sdb1 1 13054 104856223+ 83 Linux

Disk /dev/sdc: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2.4 Check if the device showed up:
# ls /dev/sd*
sda sda1 sda2 sda3 sdb sdb1 sdc


3. Format the disk:

3.1 # fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x14910557.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdc: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x14910557

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-26108, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-26108, default 26108):
Using default value 26108

Command (m for help): p

Disk /dev/sdc: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x14910557

Device Boot Start End Blocks Id System
/dev/sdc1 1 26108 209712478+ 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3.2 Format into ext4:

# mkfs.ext4 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428119 blocks
2621405 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872


Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

4. Try to mount the new partition:

# mkdir -p /data2
# mount /dev/sdc1 /data2


vi /etc/fstab
#Data FS - EXT4
/dev/sdb1 /data ext4 defaults 1 2
/dev/sdc1 /data2 ext4 defaults 1 2

5. Test if it works:
# touch lamber_test.please_delete

7 comments:

  1. I really like this site. You write about very interesting things. Thanks for all your tips and information.

    ReplyDelete
  2. This honestly answered my predicament, thank you!

    ReplyDelete
  3. Immediately after study a few of the blog posts on your web page now, and I truly like your way of blogging. I bookmarked it to my bookmark web-site list and will likely be checking back soon. Pls check out my internet website at the same time and let me know what you believe.

    ReplyDelete
  4. Amazing Post.thanks for share..additional wait ..

    ReplyDelete
  5. I've sent a website to this stuff to help few of my friends. That's actually the best recommendation for the info you put listed here that I could give you out.

    ReplyDelete
  6. Hiya very nice web site!! Man .. Beautiful .. Superb .. I will bookmark
    your blog and take the feeds additionally? I'm glad to search out a lot of useful information here within
    the publish, we need work out extra techniques in this regard,
    thank you for sharing. . . . . .

    ReplyDelete
  7. Fantastic blog! Do you have any hints for aspiring writers?
    I'm planning to start my own site soon but I'm a little lost on everything.
    Would you recommend starting with a free platform like Wordpress or go
    for a paid option? There are so many choices out there that I'm totally overwhelmed ..
    Any tips? Thanks!

    ReplyDelete