centostricks

Just another WordPress.com site

Tag Archives: Parted

Hot add scsci Disk in Centos 6.x/5.x without reboot of OS


Steps to Identify a newly added scsi disk in Centos 6.0 without rebooting OS

[root@localhost ~]# ls /sys/class/scsi_host/host
host0/ host1/ host2/
[root@localhost ~]#

This command will identify and hot add the disk running on host 2 , below we can see then as scsi2..

[root@localhost ~]# echo “- – -” > /sys/class/scsi_host/host2/scan

Now displaying the identified disks /dev/sdc, /dev/sdd, /dev/sdb

[root@localhost ~]# fdisk -l |grep sd
Disk /dev/dm-0 doesn’t contain a valid partition table
Disk /dev/dm-1 doesn’t contain a valid partition table
Disk /dev/sdc doesn’t contain a valid partition table
Disk /dev/sdd doesn’t contain a valid partition table
Disk /dev/sdb doesn’t contain a valid partition table
Disk /dev/sda: 14.0 GB, 13958643712 bytes
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 1698 13118464 8e Linux LVM
Disk /dev/sdc: 1073 MB, 1073741824 bytes
Disk /dev/sdd: 1073 MB, 1073741824 bytes
Disk /dev/sdb: 1073 MB, 1073741824 bytes

[root@localhost ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 01 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 02 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 03 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

current status : there are 2 scsi drives with 1 scsi drive (CDROM) on scsi 1 is the harddrive. Now i have added 1 more scsi drive. We will see what happens

Adding one more disk, but identifying with a different command

Another method used to identify the newly added disk : this command will not alter/overwrite any existing configurations

[root@localhost ~]# echo “scsi add-single-device 2 0 4 0” > /proc/scsi/scsi

When we run with a wrong values, below will be the output. there is no changes or damage. i have not encountered any issues. but not recommended to do so !

[root@localhost ~]# echo “scsi add-single-device 0 0 4 0” > /proc/scsi/scsi
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo “scsi add-single-device 0 4 4 0” > /proc/scsi/scsi
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo “scsi add-single-device 0 3 4 0” > /proc/scsi/scsi
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo “scsi add-single-device 0 2 4 0” > /proc/scsi/scsi
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo “scsi add-single-device 0 1 4 0” > /proc/scsi/scsi
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo “scsi add-single-device 1 0 4 0” > /proc/scsi/scsi
-bash: echo: write error: Invalid argument
[root@localhost ~]# echo “scsi add-single-device 4 0 4 0” > /proc/scsi/scsi
-bash: echo: write error: No such device or address
[root@localhost ~]# echo “scsi add-single-device 3 0 4 0” > /proc/scsi/scsi
-bash: echo: write error: No such device or address

The effect of echo “scsi add-single-device 2 0 4 0” > /proc/scsi/scsi is shown below :

[root@localhost ~]# echo “scsi add-single-device 2 0 4 0” > /proc/scsi/scsi
[root@localhost ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 01 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 02 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 03 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 04 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

We can see that there is a newly identified disk, Please use fdisk or parted to create required partitions ….

Initializing the Newly added disk before creating partitions

Better to use fdisk to create partitions with fdisk(Initializes the Disk) , as this disks are not initialized yet, and will give below errors, if parted is used

[root@localhost ~]# parted -l |grep sd*
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 14.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
Error: /dev/sdb: unrecognised disk label
Error: /dev/sdc: unrecognised disk label
Error: /dev/sdd: unrecognised disk label
Error: /dev/sde: unrecognised disk label

See the below results, parted is not even allowing to create partitions :

[root@localhost ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) p
Error: /dev/sdc: unrecognised disk label
(parted) u s
(parted) mkpart primary 64 -1s
Error: /dev/sdc: unrecognised disk label
(parted) p
Error: /dev/sdc: unrecognised disk label
(parted)

See the below output. “Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)”

If you are flexible with fdisk, you can go ahead and create partitions and save it.

If you are not flexible with fdisk and good with parted, just use the below steps , don’t create any partitions. just access the device and type ‘w’ later use parted to create partitions

[root@localhost ~]# 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 0xfa03eeaf.
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): w
The partition table has been altered!

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

Now use parted and create partitions. see the below output, no more errors or warning. you are good to proceed with next steps of creating partitions. Good Luck !!!

[root@localhost ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags

(parted)

***** END****

Disk increase with parted in CentOS 5.5 (Physical Disk)


Steps to Increase Disk Size with Parted with Sectors as an unit

 

Here we are starting to increase the partition size with parted Tools ( BE CAUTIOUS, CHANGES TAKES PLACE IMMEDIATELY)

 

In this case, we have a physical disk capacity of 177GB. But we have used only 80GB of space, which are further managed via LVM. Now, below steps shows how to allocate (Increase) the remaining 96 GB to /var partition.

 

[root@system~]# parted /dev/sda

GNU Parted 1.8.1

Using /dev/sda

Welcome to GNU Parted! Type ‘help’ to view a list of commands.

(parted) print

 

Disk /dev/sda: 177GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start   End     Size    Type     File system  Flags

1      32.8kB  107MB   107MB   primary  ext3

2      107MB   80.5GB  80.4GB  primary               lvm

 

(parted) u s                                                        ( Changing the Default Unit to Sectors)

(parted) print

 

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start    End         Size        Type     File system  Flags

1      64s      208895s     208832s     primary  ext3

2      208896s  157276349s  157067454s  primary               lvm

 

(parted) rm 2                                     ( Here we are deleting the partition and recreating with new size, In this we are requested to increase the second partition to the new size. So we are deleting it)

(parted) print

 

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start  End         Size          Type       File system  Flags

1                64s    208895s 208832s  primary  ext3

 

(parted) mkpart primary 208896s 346030079s      ( Here we are recreating the second partition which was deleted in the previous step, We are passing the Partition type, Starting sector(Starting sector will be next sector of the last partition i.e., if the sector of last partition ends at  208895s and the starting sector of the new partition should be 208896s) and ending sector. Here the Ending sector is the max sectors available on this respective disk which can found from line Disk in the print command, changed to color )

 

(parted) print

 

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start    End         Size        Type     File system  Flags

1      64s      208895s     208832s     primary  ext3

2      208896s  346030079s  345821184s  primary

 

(parted) toggle 2 lvm                                     ( This commands set this partition to be of LVM Type)

(parted) print

 

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start    End         Size        Type     File system  Flags

1      64s      208895s     208832s     primary  ext3

2      208896s  346030079s  345821184s  primary               lvm

 

(parted) quit                                      ( Exit from Parted)

Information: Don’t forget to update /etc/fstab, if necessary.

 

[root@system~]# fdisk -l

 

Disk /dev/sda: 177.1 GB, 177167400960 bytes

255 heads, 63 sectors/track, 21539 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

  Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1          14      104416   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              14       21540   172910592   8e  Linux LVM

 

[root@system~]# echo 1 > /sys/block/sda/device/rescan   ( To rescan the changes done on block device)

[root@system~]# reboot             (Please reboot the box to make changes take effect)

 

[root@system~]# fdisk -l

 

Disk /dev/sda: 177.1 GB, 177167400960 bytes

255 heads, 63 sectors/track, 21539 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1          14      104416   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              14       21540   172910592   8e  Linux LVM

 

[root@system~]# pvscan

  PV /dev/sda2   VG VG_00   lvm2 [74.88 GB / 0    free]

  Total: 1 [74.88 GB] / in use: 1 [74.88 GB] / in no VG: 0 [0   ]

 

[root@system~]# pvresize /dev/sda2   ( Increase the Physical Volume. Prior to this step we need to reboot the OS)

  Physical volume “/dev/sda2” changed

  1 physical volume(s) resized / 0 physical volume(s) not resized

 

[root@system~]# pvscan

  PV /dev/sda2   VG VG_00   lvm2 [164.88 GB / 90.00 GB free]

  Total: 1 [164.88 GB] / in use: 1 [164.88 GB] / in no VG: 0 [0   ]

 

[root@system~]# lvscan

  ACTIVE            ‘/dev/VG_00/LV_root’ [10.00 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_opt’ [28.03 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_tmp’ [2.00 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_var’ [29.03 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_swap’ [5.81 GB] inherit

 

[root@system~]# lvextend -l +100%FREE /dev/VG_00/LV_var    (Extend the requested partition with the new size. In this case it is /var)

  Extending logical volume LV_var to 119.03 GB

  Logical volume LV_var successfully resized

 

[root@system~]# lvscan

  ACTIVE            ‘/dev/VG_00/LV_root’ [10.00 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_opt’ [28.03 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_tmp’ [2.00 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_var’ [119.03 GB] inherit

  ACTIVE            ‘/dev/VG_00/LV_swap’ [5.81 GB] inherit

 

[root@system~]# resize2fs /dev/VG_00/LV_var                   (Resize the filesystem)

resize2fs 1.39 (29-May-2006)

Filesystem at /dev/VG_00/LV_var is mounted on /var; on-line resizing required

Performing an on-line resize of /dev/VG_00/LV_var to 31203328 (4k) blocks.

The filesystem on /dev/VG_00/LV_var is now 31203328 blocks long.

 

 [root@system~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VG_00-LV_root

                      9.7G  3.6G  5.7G  39% /

/dev/mapper/VG_00-LV_opt

                       28G 1008M   25G   4% /opt

/dev/mapper/VG_00-LV_tmp

                      2.0G  418M  1.5G  23% /tmp

/dev/mapper/VG_00-LV_var

                      116G   23G   88G  21% /var

/dev/sda1              99M   26M   69M  28% /boot

tmpfs                 2.0G     0  2.0G   0% /dev/shm

 

 You should be ALL SET 🙂

 

Disk resize with parted in Centos 5.5 (Virtual Machines)


Steps to Increase Disk Size with Parted with Sectors as an unit (Recommended on Virtual Machines)

See the Next Article to find steps to increase space on physical Disk

Below are the steps which should be followed to perform disk increase.

First increase the VMDK size on Virtual Machine then follow the below steps, In My case here , I am extending +90GB more and increasing the same @ OS level adding to /var partition.

Here we are starting to increase the partition size with parted Tools ( BE CAUTIOUS, CHANGES TAKES PLACE IMMEDIATELY)

Please take a look at this page too https://centostricks.wordpress.com/2012/05/01/disk-resize-steps-when-we-see-partitions-as-a-separate-disk-in-fdisk/

[root@personal ~]# parted /dev/sda

GNU Parted 1.8.1

Using /dev/sda

Welcome to GNU Parted! Type ‘help’ to view a list of commands.

(parted) print

Model: VMware Virtual disk (scsi)

Disk /dev/sda: 177GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags

1      32.8kB  107MB   107MB   primary  ext3

2      107MB   80.5GB  80.4GB  primary               lvm

(parted) u s                                                        ( Changing the Default Unit to Sectors)

(parted) print

Model: VMware Virtual disk (scsi)

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number  Start    End         Size        Type     File system  Flags

1      64s      208895s     208832s     primary  ext3

2      208896s  157276349s  157067454s  primary               lvm

(parted) rm 2                                     ( Here we are deleting the partition and recreating with new size, In this we are requested to increase the second partition to the new size. So we are deleting it first)

(parted) print

Model: VMware Virtual disk (scsi)

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number  Start  End         Size          Type       File system  Flags

1                64s    208895s 208832s  primary  ext3

(parted) mkpart primary 208896s 346030079s      ( Here we are recreating the second partition which was deleted in the previous step, We are passing the Partition type, Starting sector(Starting sector will be next sector of the last partition i.e., if the sector of last partition ends at  208895s and the starting sector of the new partition should be 208896s) and ending sector. Here the Ending sector is the max sectors available on this respective disk which can found from line Disk in the print command, changed to color )

(parted) print

Model: VMware Virtual disk (scsi)

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number  Start    End         Size        Type     File system  Flags

1      64s      208895s     208832s     primary  ext3

2      208896s  346030079s  345821184s  primary

(parted) toggle 2 lvm                                     ( This commands set this partition to be of LVM Type)

(parted) print

Model: VMware Virtual disk (scsi)

Disk /dev/sda: 346030079s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number  Start    End         Size        Type     File system  Flags

1      64s      208895s     208832s     primary  ext3

2      208896s  346030079s  345821184s  primary               lvm

(parted) quit                                              ( Exit from Parted)

Information: Don’t forget to update /etc/fstab, if necessary.

[root@personal ~]# fdisk -l

Disk /dev/sda: 177.1 GB, 177167400960 bytes

255 heads, 63 sectors/track, 21539 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1          14      104416   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              14       21540   172910592   8e  Linux LVM

[root@personal ~]# echo 1 > /sys/block/sda/device/rescan   ( To rescan the changes done on block device)

[root@personal ~]#

[root@personal ~]# reboot    ( To make changes take effect)

[root@personal ~]# fdisk -l

Disk /dev/sda: 177.1 GB, 177167400960 bytes

255 heads, 63 sectors/track, 21539 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1          14      104416   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              14       21540   172910592   8e  Linux LVM

[root@personal ~]# pvscan

PV /dev/sda2   VG VG_00   lvm2 [74.88 GB / 0    free]

Total: 1 [74.88 GB] / in use: 1 [74.88 GB] / in no VG: 0 [0   ]

[root@personal ~]# pvresize /dev/sda2   ( Increase the Physical Volume. Prior to this step we need to reboot the OS)

Physical volume “/dev/sda2” changed

1 physical volume(s) resized / 0 physical volume(s) not resized

[root@personal ~]# pvscan

PV /dev/sda2   VG VG_00   lvm2 [164.88 GB / 90.00 GB free]

Total: 1 [164.88 GB] / in use: 1 [164.88 GB] / in no VG: 0 [0   ]

[root@personal ~]# vgscan

Reading all physical volumes.  This may take a while…

Found volume group “VG_00” using metadata type lvm2

[root@personal ~]# vgdisplay “VG_00”

— Volume group —

VG Name               VG_00

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  20

VG Access             read/write

VG Status             resizable

MAXLV                0

CurLV                5

OpenLV               5

Max PV                0

Cur PV                1

Act PV                1

VG Size               164.88 GB

PE Size               32.00 MB

Total PE              5276

AllocPE/ Size       2396 / 74.88 GB

  Free  PE / Size       2880 / 90.00 GB

VG UUID               KWCu75-D0E1-lmAm-AAiq-t6vA-ISuh-93ISaF

[root@personal ~]# lvscan

ACTIVE            ‘/dev/VG_00/LV_root’ [10.00 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_opt’ [28.03 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_tmp’ [2.00 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_var’ [29.03 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_swap’ [5.81 GB] inherit

[root@personal ~]# lvextend -l +100%FREE /dev/VG_00/LV_var    (Extend the requested partition with the new size. In this case it is /var)

Extending logical volume LV_var to 119.03 GB

Logical volume LV_var successfully resized

[root@personal ~]#

[root@personal ~]#

[root@personal ~]# lvscan

ACTIVE            ‘/dev/VG_00/LV_root’ [10.00 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_opt’ [28.03 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_tmp’ [2.00 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_var’ [119.03 GB] inherit

ACTIVE            ‘/dev/VG_00/LV_swap’ [5.81 GB] inherit

[root@personal ~]# resize2fs /dev/VG_00/LV_var          (Resize the filesystem)

resize2fs 1.39 (29-May-2006)

Filesystem at /dev/VG_00/LV_var is mounted on /var; on-line resizing required

Performing an on-line resize of /dev/VG_00/LV_var to 31203328 (4k) blocks.

The filesystem on /dev/VG_00/LV_var is now 31203328 blocks long.

[root@personal ~]#

[root@personal ~]#

[root@personal ~]#

[root@personal ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VG_00-LV_root

9.7G  3.6G  5.7G  39% /

/dev/mapper/VG_00-LV_opt

28G 1008M   25G   4% /opt

/dev/mapper/VG_00-LV_tmp

2.0G  418M  1.5G  23% /tmp

/dev/mapper/VG_00-LV_var

116G   23G   88G  21% /var

/dev/sda1              99M   26M   69M  28% /boot

tmpfs                 2.0G     0  2.0G   0% /dev/shm

You should be ALL SET 🙂

Somecases, you need to extend the Extended partition to allocate space to Logical Partition, In that case, you need to resize the extended partition and then resize the logical partition

Please follow the below steps to resize the extended partition whose partition number is 4

# resize 4 <start sector> <end sector>  (End sector will the last sector of the Harddisk which is seen in Disk line of parted tool)

Now all other steps you followed the recreate the primary partition has to be applied on the last available logical partition in parted. thanks