Add hard drive to extend existing LVM volume 

3 Comments

Previously I posted how to add a hard drive and create a new volume in LVM. This time we’ll add a new hard drive and then increase or extend the size of an existing volume or partition. This is an example using an RHEL 5 derivative, OEL 5. The server is really a VM inside VMware vSphere 4, but that is of no consequence to what we are doing.

In this example, we have an existing /data partition of 350 GB. Well, it’s just not big enough, so we’ll add another 100 GB hard drive and give it to the /data partition.

After adding the 100 GB hard drive to the VM through vCenter, connect to the server through SSH or the console. Here’s the existing setup:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.7G 2.2G 5.2G 30% /
/dev/sda1 99M 24M 71M 26% /boot
tmpfs 1.5G 0 1.5G 0% /dev/shm
/dev/mapper/VolGroup01-LogVol00
345G 15G 313G 5% /data

# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

First we tell Linux to find the new drive in the correct location:

# echo "scsi add-single-device 0 0 2 0" > /proc/scsi/scsi

Now we see the new drive has been detected:

# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

If we check fdisk, we see the new drive is blank like we expect:

# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1566 12474472+ 8e Linux LVM

Disk /dev/sdb: 375.8 GB, 375809638400 bytes
255 heads, 63 sectors/track, 45689 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 45689 366996861 83 Linux

Disk /dev/sdc: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn’t contain a valid partition table

So let’s give it a partition:

# 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 13054.
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
(e.g., DOS FDISK, OS/2 FDISK)
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)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054):
Using default value 13054

Command (m for help): p

Disk /dev/sdc: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

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

Fdisk now confirms that everything looks good:

# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1566 12474472+ 8e Linux LVM

Disk /dev/sdb: 375.8 GB, 375809638400 bytes
255 heads, 63 sectors/track, 45689 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 45689 366996861 83 Linux

Disk /dev/sdc: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Verify that LVM can see the drive:

# lvmdiskscan
…skip…
/dev/sdc1 [ 100.00 GB]
…skip…

Create a physical volume within LVM:

# pvcreate /dev/sdc1
Physical volume “/dev/sdc1” successfully created

Add/Extend this physical volume to the volume group:

# vgextend VolGroup01 /dev/sdc1
Volume group “VolGroup01” successfully extended

Extend the logical volume to use the full size of the volume group:

# lvm lvextend -l +100%FREE /dev/VolGroup01/LogVol00
Extending logical volume LogVol00 to 449.99 GB
Logical volume LogVol00 successfully resized

Actually resize the partition for the OS to recognize the new size:

# resize2fs -p /dev/mapper/VolGroup01-LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup01-LogVol00 is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup01-LogVol00 to 117961728 (4k) blocks.
The filesystem on /dev/mapper/VolGroup01-LogVol00 is now 117961728 blocks long.

And the new drive space is now available to the user, who is already busy filling it:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.7G 2.2G 5.2G 30% /
/dev/sda1 99M 24M 71M 26% /boot
tmpfs 1.5G 0 1.5G 0% /dev/shm
/dev/mapper/VolGroup01-LogVol00
443G 48G 373G 12% /data

Fixing Windows Telnet 

No Comments

Breaking with tradition and posting something about Windows again….

One thing that I have always hated about using a Windows PC is when I pull up a command prompt to telnet to a mail server or something to test.  If you’ve ever tried this you know what I’m talking about – you can’t see what you are typing!  It’s not that bad, if you type perfectly all the time, but I do not.  Well, I was looking something up on MSDN today and happened to stumble upon this gem:  “set localecho”.  You have to specify it within the telnet prompt – you can’t specify it in one line on the command prompt, but at least it’s something.

From the command prompt, type just telnet, instead of the full line:

> telnet

Type in set localecho and then open the server port that you want:

telnet> set localecho
telnet> open mailserver.domainname.com 25

Delete multiple files that contain spaces based on age 

1 Comment

I had a problem on a FTP server running Solaris 9 that had tons of old files and many of them had spaces in the names. How do you automate removing the old files (the real concern being the spaces in the filenames)? Most solutions recommend using -print0 in find or xargs -0, neither of which are options in Solaris 9.

This command removes any files older then 2 years old in the current directory:

find . -type f -mtime +730 | while read filename; do rm -f “$filename”; done

Adding a Drive to a Veritas Disk Group 

2 Comments

Last time I showed you how to add a new drive to make a new disk group. Well, what if you already have a disk group, with just one drive on it and you want to mirror that data across another drive? The process is easy and here’s how:

Let’s start off with a simple disk group:

# vxprint
Disk group: tempdg-tmp

TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0
dg tempdg-tmp tempdg-tmp – – – – – –

dm tempdg-tmp02 emcpower1s2 – 733975296 – – – –

v templv-tmp fsgen ENABLED 733975296 – ACTIVE – –
pl templv-tmp-02 templv-tmp ENABLED 733975296 – ACTIVE – –
sd tempdg-tmp02-01 templv-tmp-02 ENABLED 733975296 0 – – –

This shows the disk group’s name is tempdg-tmp, the original disk in the group is called tempdg-tmp02, the logical volume is called templv-tmp, which is made up of one plex called templv-tmp-02, which has one subdisk called tempdg-tmp02-01.

So, let’s add an additional disk tempdg-tmp01 and use it to mirror the data on tempdg-tmp02. If we look first at how the device is setup for the original drive we see that it is using cdsdisk format:

# vxdisk -o alldgs list
DEVICE TYPE DISK GROUP STATUS
emcpower1s2 auto:cdsdisk tempdg-tmp02 tempdg-tmp online

So let’s make our new device cdsdisk formatted as well:

# vxdisk -o alldgs list
DEVICE TYPE DISK GROUP STATUS
emcpower6s2 auto:none – – online invalid

# /etc/vx/bin/vxdisksetup -i emcpower6 format=cdsdisk

# vxdisk -o alldgs list
DEVICE TYPE DISK GROUP STATUS
emcpower6s2 auto:cdsdisk – – online

Now to add the new disk to the disk group. Note that since the original drive was called 02, the one we are adding is 01:

# vxdg -g tempdg-tmp adddisk tempdg-tmp01=emcpower6

Now we can see the new drive in the disk group (and that it isn’t currently doing anything):

# vxprint
Disk group: tempdg-tmp

TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0
dg tempdg-tmp tempdg-tmp – – – – – –

dm tempdg-tmp01 emcpower6s2 – 733975296 – – – –
dm tempdg-tmp02 emcpower1s2 – 733975296 – – – –

v templv-tmp fsgen ENABLED 733975296 – ACTIVE – –
pl templv-tmp-02 templv-tmp ENABLED 733975296 – ACTIVE – –
sd tempdg-tmp02-01 templv-tmp-02 ENABLED 733975296 0 – – –

So let’s tell the disk group to set tempdg-tmp01 up as a mirror of tempdg-tmp02:

# vxassist -g tempdg-tmp mirror templv-tmp tempdg-tmp01 &

I ran it in the background because it can take a long time depending on how big it is (about 2 hours for 350 GB). To watch the mirroring process, use vxtask. (You can also use vxprint to see what it is doing.)

# vxtask list
TASKID PTID TYPE/STATE PCT PROGRESS
177 ATCOPY/R 04.89% 0/733975296/35921920 PLXATT templv-tmp templv-tmp-01 tempdg-tmp

Once it completes, you will see your new drive setup as a mirror:

# vxprint
Disk group: tempdg-tmp

TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0
dg tempdg-tmp tempdg-tmp – – – – – –

dm tempdg-tmp01 emcpower6s2 – 733975296 – – – –
dm tempdg-tmp02 emcpower1s2 – 733975296 – – – –

v templv-tmp fsgen ENABLED 733975296 – ACTIVE – –
pl templv-tmp-02 templv-tmp ENABLED 733975296 – ACTIVE – –
sd tempdg-tmp02-01 templv-tmp-02 ENABLED 733975296 0 – – –
pl templv-tmp-01 templv-tmp ENABLED 733975296 – ACTIVE – –
sd tempdg-tmp01-01 templv-tmp-01 ENABLED 733975296 0 – – –

Create new Veritas Disk Group 

2 Comments

Earlier I posted about how to add a new LUN to a Solaris 9 server. Today I’ll go through the process of adding that disk (emcpower6) to a new disk group and making it usable with a file system. This server has EMC Powerpath installed as well as the Veritas Storage Foundation running on it.

First, setup the disk inside Veritas, in this example I’ll use the sliced format (emcpower6 is the Veritas Device name – not the PowerPath pseudo name – use vxdisk list to see the name):

# /etc/vx/bin/vxdisksetup -i emcpower6 format=sliced

Initiate the disk group by adding the disk to a new group (tempdg-tmp). The device name is emcpower6 and the name of the disk inside the disk group will be called tempdg-tmp01:

# vxdg init tempdg-tmp cds=off tempdg-tmp01=emcpower6

See how big we can make the disk group:

# vxassist -g tempdg-tmp maxsize
Maximum volume size: 733952000 (358375Mb)

Setup the disk group to the maximum size (templv-tmp is the logical volume name):

# vxassist -g tempdg-tmp -b make templv-tmp 733952000 tempdg-tmp01 layout=nostripe

At this point you can take a look at what you created with vxprint:

# vxprint
Disk group: tempdg-tmp

TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0
dg tempdg-tmp tempdg-tmp – – – – – –

dm tempdg-tmp01 emcpower6s2 – 733952000 – – – –

v templv-tmp fsgen ENABLED 733952000 – ACTIVE – –
pl templv-tmp-01 templv-tmp ENABLED 733952000 – ACTIVE – –
sd tempdg-tmp01-01 templv-tmp-01 ENABLED 733952000 0 – – –

Create a file system on the logical volume, using VXFS:

# /opt/VRTS/bin/mkfs -F vxfs /dev/vx/rdsk/tempdg-tmp/templv-tmp
version 6 layout
733952000 sectors, 366976000 blocks of size 1024, log size 65536 blocks
largefiles supported

Create a mount point, mount it, see it mounted:

# mkdir /u2

# mount -F vxfs /dev/vx/dsk/tempdg-tmp/templv-tmp /u2

# df -h /u2
Filesystem size used avail capacity Mounted on
/dev/vx/dsk/tempdg-tmp/templv-tmp 350G 153M 328G 1% /u2