Adding a New Hard Drive to a Linux VM

I did this with vmware image of RedHat EL4. Basically you should have the new drive created and added to the machine before you start anything.

First you need to fdisk the drive like any other drive in linux. One key step is that you need to change the type; option “t” to “8e” for lvm.

root@iwdponderosa ~# fdisk /dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won’t be recoverable.

The number of cylinders for this disk is set to 7832. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs


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

Command (m for help): n

Command action

e extended

p primary partition (1-4)


Partition number (1-4): 1

First cylinder (1-7832, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-7832, default 7832):

Using default value 7832

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): 8e

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdc: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdc1 1 7832 62910508+ 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

Next you use lvm in command line mode to create the Physical Volume (pv), create the Volume Group (vg), and last create the Logical Volume (lv). Everything in this example is done to the frist partition (sdc1) on the drive sdc.

root@iwdponderosa ~# lvm

lvm> pvcreate /dev/sdc1

Physical volume “/dev/sdc1” successfully created

lvm> pvdisplay

— Physical volume —

PV Name /dev/sda2

VG Name VolGroup00

PV Size 3.88 GB / not usable 0

Allocatable yes

PE Size (KByte) 32768

Total PE 124

Free PE 1

Allocated PE 123

PV UUID pwoJeq-ZRpl-H6CI-jY7A-YlgU-5XFA-JwnHI2

— NEW Physical volume —

PV Name /dev/sdc1

VG Name

PV Size 60.00 GB

Allocatable NO

PE Size (KByte) 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID SJSpZ9-TgmE-6ELg-ANdU-nWzq-811n-UEwCzu

lvm> vgcreate VolGroup02 /dev/sdc1

Volume group “VolGroup02” successfully created

lvm> vgdisplay

— Volume group —

VG Name VolGroup02

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 1

VG Access read/write

VG Status resizable


Cur LV 0

Open LV 0

Max PV 0

Cur PV 1

Act PV 1

VG Size 59.99 GB

PE Size 4.00 MB

Total PE 15358

Alloc PE / Size 0 / 0

Free PE / Size 15358 / 59.99 GB

VG UUID 05Ic5F-IwZB-Ctt6-v02j-LRZM-Oc9i-w0wy6d

— Volume group —

VG Name VolGroup00

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 3

VG Access read/write

VG Status resizable


Cur LV 2

Open LV 2

Max PV 0

Cur PV 1

Act PV 1

VG Size 3.88 GB

PE Size 32.00 MB

Total PE 124

Alloc PE / Size 123 / 3.84 GB

Free PE / Size 1 / 32.00 MB

VG UUID bZKFVO-Lk1T-zuuC-3u1B-7EKq-T8Hx-Cw8lIm

lvm> lvcreate -L 61380M -n LogVol00 VolGroup02

Logical volume “LogVol00” created

lvm> exit


Next edit fstab to mount the drive.

root@iwdponderosa ~# vi /etc/fstab

  1. This file is edited by fstab-sync – see ‘man fstab-sync’ for details

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1

LABEL=/boot /boot ext3 defaults 1 2

none /dev/pts devpts gid=5,mode=620 0 0

none /dev/shm tmpfs defaults 0 0

/dev/VolGroup02/LogVol00 /storage ext3 defaults 0 0

none /proc proc defaults 0 0

none /sys sysfs defaults 0 0

/dev/VolGroup00/LogVol01 swap swap defaults 0 0

/dev/sdb1 /data ext3 defaults 1 1

/dev/hda /media/cdrom auto

pamconsole,fscontext=system_u:object_r:removable_t,exec,noauto,managed 0 0

/dev/fd0 /media/floppy auto

pamconsole,fscontext=system_u:object_r:removable_t,exec,noauto,managed 0 0

“/etc/fstab” 12L, 960C written

Next created the new root directory to mount the drive to.

root@iwdponderosa ~# cd /

root@iwdponderosa # mkdir storage

Next make the file system format.

root@iwdponderosa # mkfs -t ext3 /dev/VolGroup02/LogVol00

mke2fs 1.35 (28-Feb-2004)

max_blocks 4294967295, rsv_groups = 0, rsv_gdb = 1024

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

7864320 inodes, 15713280 blocks

785664 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=16777216

480 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424

Writing inode tables: done

inode.i_blocks = 106504, i_size = 4243456

Creating journal (8192 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.

Last you mount everything and verify it.

root@iwdponderosa # mount /storage/

root@iwdponderosa # df -h

Filesystem Size Used Avail Use% Mounted on


3.3G 2.4G 782M 76% /

/dev/sda1 99M 9.0M 85M 10% /boot

none 506M 0 506M 0% /dev/shm

/dev/sdb1 12G 12G 57M 100% /data


59G 85M 56G 1% /storage

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply