Archive
Understanding RAID management in Linux
The first thing you must learn about RAID technologies in Linux is that they have nothing in common with HP-UX, and I mean nothing! Yes there is LVM but that’s all, the mirror of a volume group for example is not done through LVM commands, in fact you are not going to mirror a volume group but the block device/s where the volume group resides.
There are two tools to manage RAID in Linux.
- dmraid
- mdadm
Dmraid is used to discover and activate software (ATA)RAID arrays, commonly known as fakeRAID, and mdadm is used to manage Linux Software RAID devices.
dmraid
Dmraid, uses libdevmapper and the device-mapper kernel driver to perform all the tasks.
The device-mapper is a component of the Linux Kernel. This the way the Linux Kernel do all the block device managment. It maps a block device onto another and forms the base of volume management (LVM2 and EVMS) and software raid. Multipathing support is also provided through the device-mapper. Device-mapper support is present in 2.6 kernels although there are patches for the most recent versions of 2.4 kernel version.
dmraid supports several array types.
[root@caladan ~]# dmraid -l asr : Adaptec HostRAID ASR (0,1,10) ddf1 : SNIA DDF1 (0,1,4,5,linear) hpt37x : Highpoint HPT37X (S,0,1,10,01) hpt45x : Highpoint HPT45X (S,0,1,10) isw : Intel Software RAID (0,1) jmicron : JMicron ATARAID (S,0,1) lsi : LSI Logic MegaRAID (0,1,10) nvidia : NVidia RAID (S,0,1,10,5) pdc : Promise FastTrack (S,0,1,10) sil : Silicon Image(tm) Medley(tm) (0,1,10) via : VIA Software RAID (S,0,1,10) dos : DOS partitions on SW RAIDs [root@caladan ~]#
Following are a couple of examples to show dmraid operation.
- Array discovering
[root@caladan ~]# dmraid -r /dev/dm-46: hpt45x, "hpt45x_chidjhaiaa-0", striped, ok, 320172928 sectors, data@ 0 /dev/dm-50: hpt45x, "hpt45x_chidjhaiaa-0", striped, ok, 320172928 sectors, data@ 0 /dev/dm-54: hpt45x, "hpt45x_chidjhaiaa-1", striped, ok, 320172928 sectors, data@ 0 /dev/dm-58: hpt45x, "hpt45x_chidjhaiaa-1", striped, ok, 320172928 sectors, data@ 0 [root@caladan ~]#
- Activate all discovered arrays
[root@caladan ~]# dmraid -ay
- Deactivate all discovered arrays
[root@caladan ~]# dmraid -an
mdadm
mdadm, is a tool to manage the Linux software RAID arrays. This tool has nothing to do with the device-mapper, in fact the device-mapper is not aware of the RAID arrays created with mdadm.
To illustrate this take a look at the screenshot below. I created a RAID1 device, /dev/md0, I then show its configuration with mdadm –detail. Later with dmsetup ls I list all the block devices seen by the device-mapper, as you can see there is no reference to /dev/md0.
Instead mdadm uses the MD (Multiple Devices) device driver, this driver provides virtual devices created from another independent devices. Currently the MD driver supports the following RAID levels and configurations
- RAID1
- RAID4
- RAID5
- RAID6
- RAID0
- LINEAR (a concatenated array)
- MULTIPATH
- FAULTY (an special failed array type for testing purposes)
The configuration of the MD devices is contained in the /etc/mdadm.conf file.
[root@caladan ~]# cat mdadm.conf ARRAY /dev/md1 level=raid5 num-devices=3 spares=1 UUID=5c9d6a69:4a0f120b:f6b02789:3bbc8698 ARRAY /dev/md0 level=raid1 num-devices=2 UUID=b36f1b1c:87cf9497:73b81e8c:79ee3c44 [root@caladan ~]#
The mdadm tool has seven operation modes.
- Assemble
- Build
- Create
- Manage
- Misc
- Follow or Monitor
- Grow
A more detailed description of every major operation mode is provided in the mdadm man page.
Finally below are examples of some of the more common operations with mdadm.
- Create a RAID1 array
[root@caladan ~]# mdadm --create /dev/md1 --verbose --level raid1 --raid-devices 2 /dev/sd[de]1 mdadm: size set to 1044096K mdadm: array /dev/md1 started. [root@caladan ~]#
- Get detailed configuration of the array
[root@caladan ~]# mdadm --query --detail /dev/md1
/dev/md1:
Version : 00.90.01
Creation Time : Tue Nov 23 22:37:05 2010
Raid Level : raid1
Array Size : 1044096 (1019.80 MiB 1069.15 MB)
Device Size : 1044096 (1019.80 MiB 1069.15 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 1
Persistence : Superblock is persistent
Update Time : Tue Nov 23 22:37:11 2010
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : c1893118:c1327582:7dc3a667:aa87dfeb
Events : 0.2
Number Major Minor RaidDevice State
0 8 49 0 active sync /dev/sdd1
1 8 65 1 active sync /dev/sde1
[root@caladan ~]#
- Destroy the array
[root@caladan ~]# mdadm --remove /dev/md1 [root@caladan ~]# mdadm --stop /dev/md1 [root@caladan ~]# mdadm --detail /dev/md1 mdadm: md device /dev/md1 does not appear to be active. [root@caladan ~]#
- Create a RAID5 array with an spare device
[root@caladan ~]# mdadm --create /dev/md1 --verbose --level raid5 --raid-devices 3 --spare-devices 1 /dev/sd[def]1 /dev/sdg1 mdadm: array /dev/md1 started [root@caladan ~]#
- Check for the status of a task into the /proc/mdstat file.
[root@caladan ~]# cat /proc/mdstat Personalities : [raid6] [raid5] [raid4] md0 : active raid6 sdi1[7] sdh1[6] sdg1[5] sdf1[4] sde1[3] sdd1[2] sdc1[1] sdb1[0] 226467456 blocks level 6, 64k chunk, algorithm 2 [8/8] [UUUUUUUU] [=========>...........] resync = 49.1% (18552320/37744576) finish=11.4min speed=27963K/sec unused devices: <none> [root@caladan ~]#
- Generate the mdadm.conf file from the current active devices.
[root@caladan ~]# mdadm --detail --scan ARRAY /dev/md1 level=raid5 num-devices=3 spares=1 UUID=5c9d6a69:4a0f120b:f6b02789:3bbc8698 ARRAY /dev/md0 level=raid1 num-devices=2 UUID=b36f1b1c:87cf9497:73b81e8c:79ee3c44 [root@caladan ~]# mdadm --detail --scan >> mdadm.conf
As a final thought, my recommendation is that if there is hardware RAID controller available, like the HP Smart Array P400 for example, go hard-RAID five by five and if not always use mdadm even if there is an onboard RAID controller.
Juanma.
LVM and file system basics in HP-UX & Linux
Now that my daily work is more focused on Linux I found myself performing the same basic administration tasks in Linux that I’m used to do in HP-UX. Because of that I thought that a post explaining how the same basic file system and volume management operations are done in both operative systems was necessary, hope you like it :-)
This is going to be a very basic post intended only as a reference for myself and any other Sysadmin coming from either Linux or HP-UX that wants to know how things are done in the other side. Of course this post is no substitute of the official documentation and the corresponding man pages.
I used Red Hat Enterprise Linux 5.5 as the Linux version and 11iv3 as the HP-UX version.
The follwing topics will covered:
- Volume group creation.
- Logical volume operations.
- File system operations.
Volume group creation
Physical volume and volume group creation are the most basic tasks in LVM, both in Linux and HP-UX, but although command syntax is quite similar in both operative systems the whole process differs in many ways.
- HP-UX:
The example used is valid to 11iv2 and 11iv3 HP-UX versions, with the exception of the persistent DSFs you will have to substitute them for the corresponding legacy devices used in 11iv2.
First create the physical volumes.
root@hp-ux:/# pvcreate -f /dev/rdisk/disk10 Physical volume "/dev/rdisk/disk10" has been successfully created. root@hp-ux:/# root@hp-ux:/# pvcreate -f /dev/rdisk/disk11 Physical volume "/dev/rdisk/disk11" has been successfully created. root@hp-ux:/#
In /dev create a directory named as the new volume group, change the ownership to root:root and the permissions ot 755.
root@hp-ux:/# mkdir -p /dev/vg_new root@hp-ux:/# chown root:root /dev/vg_new root@hp-ux:/# chmod 755 /dev/vg_new
Go into the VG subdirectory and create the group device special file. For the Linux guys, in HP-UX each volume group must have a group device special file under its subdirectory in /dev. This group DSF is created with the mknod command, like any other DSFs the group file must have a major and a minor number.
For LVM 1.0 volume groups the major number must be 64 and for the LVM 2.0 one must be 128. Regarding the minor number, the first two digits will uniquely identify the volume group and the remaining digits must be 0000. In the below example we’re creating a 1.0 volume group.
root@hp-ux:/dev/vg_new# mknod group c 64 0x010000
Change the ownership to root:sys and the permissions to 640.
root@hp-ux:/dev/vg_new# chown root:sys group root@hp-ux:/dev/vg_new# chmod 640 group
And create the volume group with the vgcreate command, the arguments passed are the two physical volumes previously created and the size in megabytes of the physical extent. The last one is optional and if is not provided the default of 4MB will be automatically set.
root@hp-ux:/# vgcreate -s 16 vg_new /dev/disk/disk10 /dev/disk/disk11 Volume group "/dev/vg_new" has been successfully created. Volume Group configuration for /dev/vg_new has been saved in /etc/lvmconf/vg_new.conf root@hp-ux:/# root@hp-ux:/# vgdisplay -v vg_new --- Volume groups --- VG Name /dev/vg_new VG Write Access read/write VG Status available Max LV 255 Cur LV 0 Open LV 0 Max PV 16 Cur PV 2 Act PV 2 Max PE per PV 6000 VGDA 2 PE Size (Mbytes) 16 Total PE 26 Alloc PE 0 Free PE 26 Total PVG 0 Total Spare PVs 0 Total Spare PVs in use 0 --- Physical volumes --- PV Name /dev/disk/disk10 PV Status available Total PE 13 Free PE 13 Autoswitch On PV Name /dev/disk/disk11 PV Status available Total PE 13 Free PE 13 Autoswitch On root@hp-ux:/#
- Linux:
Create the physical volumes. Here it is where the first difference appears. In HP-UX a physical volume is composed by a whole disk, with the exception of boot disks in Itanium systems, but in Linux a physical volume can be a whole disk or a partition.
For the whole disk the process is pretty much the same as in HP-UX.
[root@rhel /]# pvcreate -f /dev/sdb Physical volume "/dev/sdb" successfully created [root@rhel /]# pvdisplay /dev/sdb "/dev/sdb" is a new physical volume of "204.00 MB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 204.00 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID Ngyz7I-Z2hL-8R3b-hzA3-qIVc-tZuY-DbCBYn [root@rhel /]#
If you decide to use partitions for the PVs the first, and obvious, thing to do is partition the disk. To setup the disk we’ll use the fdisk tool, following is an example session:
[root@rhel /]# fdisk /dev/sdc Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-204, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-204, default 204): Using default value 204 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: 213 MB, 213909504 bytes 64 heads, 32 sectors/track, 204 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 204 208880 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@rhel /]#
To explain the session first a new partition is created with the command n and the size of the partition is set (in this particular case we are using the whole disk); then we must change the partition type, which by default is set to Linux, to Linux LVM and to do that we use the command t and issue 8e as the corresponding hexadecimal code, the available values for the partition types can be shown by typing L.
Command (m for help): t Selected partition 1 Hex code (type L to list codes): L 0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris 1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx 5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data 6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT Hex code (type L to list codes):
The changes are written with w.
Once the partitions are correctly created, setup the physical volumes.
[root@rhel /]# pvcreate -f /dev/sdc1 Physical volume "/dev/sdc1" successfully created [root@rhel /]# pvcreate -f /dev/sdd1 Physical volume "/dev/sdd1" successfully created [root@rhel /]# [root@rhel /]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 sysvg lvm2 a- 19.88G 0 /dev/sdb lvm2 -- 204.00M 204.00M /dev/sdc1 lvm2 -- 203.98M 203.98M /dev/sdd1 lvm2 -- 203.98M 203.98M [root@rhel /]#
Now that the PVs are created we can proceed with the volume group creation.
[root@rhel /]# vgcreate vg_new /dev/sdc1 /dev/sdd1 Volume group "vg_new" successfully created [root@rhel /]# vgdisplay -v vg_new Using volume group(s) on command line Finding volume group "vg_new" /dev/hdc: open failed: No medium found --- Volume group --- VG Name vg_new System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 400.00 MB PE Size 4.00 MB Total PE 100 Alloc PE / Size 0 / 0 Free PE / Size 100 / 400.00 MB VG UUID lvrrnt-sHbo-eC8j-kC53-Mm5Z-IDDR-RJJtDr --- Physical volumes --- PV Name /dev/sdc1 PV UUID kD0jhk-ws8A-ke3L-a7nd-QucS-SAbH-BrmH28 PV Status allocatable Total PE / Free PE 50 / 50 PV Name /dev/sdd1 PV UUID ZP2bLy-FxR3-gYn9-3Dy1-Llgk-6mFI-1iJvTm PV Status allocatable Total PE / Free PE 50 / 50 [root@rhel /]#
As you could see the process in Linux is slightly simple than in HP-UX.
Logical volume operations
In this part we will see how to create a logical volume, extend this LV and then remove it from the system.
- HP-UX:
The logical volume creation can be done with the lvcreate command. With the -L option we can specify the size in MB of the new lvol, if -l is used instead the size must be provided in logical extents.
root@hp-ux:/# lvcreate -n lvol_test -L 256 vg_new Logical volume "/dev/vg_new/lvol_test_S2" has been successfully created with character device "/dev/vg_new/rlvol_test_S2". Logical volume "/dev/vg_new/lvol_test_S2" has been successfully extended. Volume Group configuration for /dev/vg_new has been saved in /etc/lvmconf/vg_new.conf root@hp-ux:~# lvdisplay /dev/vg_new/lvol_test --- Logical volumes --- LV Name /dev/vg_new/lvol_test VG Name /dev/vg_new LV Permission read/write LV Status available/syncd Mirror copies 0 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 256 Current LE 16 Allocated PE 16 Stripes 0 Stripe Size (Kbytes) 0 Bad block on Allocation strict IO Timeout (Seconds) default root@hp-ux:/#
Extend a volume. Of course the first prerequisite to extend a volume is to have enough free physical extends in the volume group.
root@hp-ux:~# lvextend -L 384 /dev/vg_new/lvol_test Logical volume "/dev/vg_new/lvol_test" has been successfully extended. Volume Group configuration for /dev/vg_new has been saved in /etc/lvmconf/vg_new.conf root@hp-ux:~# root@hp-ux:~# lvdisplay /dev/vg_new/lvol_test --- Logical volumes --- LV Name /dev/vg_new/lvol_test VG Name /dev/vg_new LV Permission read/write LV Status available/syncd Mirror copies 0 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 384 Current LE 24 Allocated PE 24 Stripes 0 Stripe Size (Kbytes) 0 Bad block on Allocation strict IO Timeout (Seconds) default root@hp-ux:/#
The final step of this part is to remove the logical volume.
root@hp-ux:/# lvremove /dev/vg_new/lvol_test The logical volume "/dev/vg_new/lvol_test" is not empty; do you really want to delete the logical volume (y/n) : y Logical volume "/dev/vg_new/lvol_test" has been successfully removed. Volume Group configuration for /dev/vg_new has been saved in /etc/lvmconf/vg_new.conf root@hp-ux:/#
- Linux:
Create the logical volume with the lvcreate command, the most basic options (-L, -l, -n) are the same as in HP-UX.
[root@rhel /]# lvcreate -n lv_test -L 256 vg_new Logical volume "lv_test" created [root@rhel /]# lvdisplay /dev/vg_new/lv_test --- Logical volume --- LV Name /dev/vg_new/lv_test VG Name vg_new LV UUID m5G2vT-dsE1-CycS-BMYR-3MYZ-4y8O-Mx04B8 LV Write Access read/write LV Status available # open 0 LV Size 256.00 MB Current LE 16 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:6 [root@rhel /]#
Now extend the logical volume to 384 megabytes as we did in HP-UX.
[root@rhel /]# lvextend -L 384 /dev/vg_new/lv_test Extending logical volume lv_test to 384.00 MB Logical volume lv_test successfully resized [root@rhel /]# [root@rhel /]# lvdisplay /dev/vg_new/lv_test --- Logical volume --- LV Name /dev/vg_new/lv_test VG Name vg_new LV UUID m5G2vT-dsE1-CycS-BMYR-3MYZ-4y8O-Mx04B8 LV Write Access read/write LV Status available # open 0 LV Size 384.00 MB Current LE 24 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:6 [root@rhel /]#
Remove a volume from the system, like creation and extension is a very straight forward process that can be done with one command.
[root@rhel /]# lvremove /dev/vg_new/lv_test Do you really want to remove active logical volume lv_test? [y/n]: y Logical volume "lv_test" successfully removed [root@rhel /]#
Unlike the volume group section, the basic logical operations are performed in almost the same way in both operative systems. Of course if you want to perform mirroring the differences are bigger, but I will leave that for a future post.
File system operations
The final section of the post is about the basic file system operation, we are going to create a file system on the logical volume of the previous section and later to extend it, including this time the volume group extension.
- HP-UX:
Creating the file system with the newfs command.
root@hp-ux:/# newfs -F vxfs -o largefiles /dev/vg_new/rlvol_test version 7 layout 393216 sectors, 393216 blocks of size 1024, log size 1024 blocks largefiles supported root@hp-ux:/#
Create the mount point and mount the filesystem
root@hp-ux:/# mkdir /data root@hp-ux:/# mount /dev/vg_new/lvol_test /data
Filesystem extension, in the current section we are going to suppose that the volume group has not enough physical extension to accommodate the new size of the /data file system.
After we create a new physical volume in the disk12 we are going to extend the vg_new VG.
root@hp-ux:/# vgextend vg_new /dev/disk/disk12 Volume group "vg_new" has been successfully extended. Volume Group configuration for /dev/vg_new has been saved in /etc/lvmconf/vg_new.conf root@hp-ux:/# root@hp-ux:/# vgdisplay -v vg_new --- Volume groups --- VG Name /dev/vg_new VG Write Access read/write VG Status available Max LV 255 Cur LV 0 Open LV 0 Max PV 16 Cur PV 2 Act PV 2 Max PE per PV 6000 VGDA 2 PE Size (Mbytes) 16 Total PE 39 Alloc PE 24 Free PE 15 Total PVG 0 Total Spare PVs 0 Total Spare PVs in use 0 --- Logical volumes --- LV Name /dev/vg_mir/lv_sql LV Status available/syncd LV Size (Mbytes) 384 Current LE 24 Allocated PE 24 Used PV 2 --- Physical volumes --- PV Name /dev/disk/disk10 PV Status available Total PE 13 Free PE 13 Autoswitch On PV Name /dev/disk/disk11 PV Status available Total PE 13 Free PE 13 Autoswitch On PV Name /dev/disk/disk12 PV Status available Total PE 13 Free PE 13 Autoswitch On root@hp-ux:/#
The next part is to extend the logical volume just as we did in the logical volume operations section.
root@hp-ux:/# lvextend -L 512 /dev/vg_new/lvol_test Logical volume "/dev/vg_new/lvol_test" has been successfully extended. Volume Group configuration for /dev/vg_new has been saved in /etc/lvmconf/vg_new.conf root@hp-ux:~#
And finally the most creepy part of the part of the process, extending the file system. To be capable of extending a mounted filesystem in HP-UX the OnlineJFS bundle must be installed.
Use the command fsadm and with the -b option issue the new size in KB as the argument, in the example we want to extend to 512MB, in KB is 524288.
root@hp-ux:/# fsadm -F vxfs -b 524288 /data
vxfs fsadm: V-3-23585: /dev/vg00/rlvol5 is currently 7731200 sectors - size will be increased
root#hp-ux:/#
root@hp-ux:/# bdf /data
Filesystem kbytes used avail %used Mounted on
/dev/vg_new/lvol_test
524288 5243 524288 1% /data
root@hp-ux:/#
- Linux:
Here in the filesystem part is where the commands are completely different to HP-UX. In Linux the most common file system types are ext2 and ext3, although others like ext4 or reiserfs are supported.
To create an ext3 file system issue the command mkfs.ext3 using the logical volume to create the file system on as the argument.
[root@rhel ~]# mkfs.ext3 /dev/vg_new/lv_test
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
98304 inodes, 393216 blocks
19660 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
48 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@rhel ~]#
As in HP-UX create the mount point and mount the file system.
[root@rhel ~]# mkdir /data
[root@rhel ~]# mount /dev/vg_new/lv_test /data
[root@rhel ~]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_new-lv_test
372M 11M 343M 3% /data
[root@rhel ~]#
The final part of the section is the file system extension, as we did in the HP-UX part the first task is to extend the volume group.
[root@rhel ~]# vgextend vg_new /dev/sde1
Volume group "vg_new" successfully extended
[root@rhel ~]# vgdisplay -v vg_new
Using volume group(s) on command line
Finding volume group "vg_new"
--- Volume group ---
VG Name vg_new
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 576.00 MB
PE Size 16.00 MB
Total PE 36
Alloc PE / Size 24 / 384.00 MB
Free PE / Size 12 / 192.00 MB
VG UUID u32c0h-BPGN-HixT-IzsX-cNnC-EspO-xfweaI
--- Logical volume ---
LV Name /dev/vg_new/lv_test
VG Name vg_new
LV UUID ZtArMo-Pyyl-BDHX-9CZQ-uEAK-VDqG-t60xy4
LV Write Access read/write
LV Status available
# open 1
LV Size 384.00 MB
Current LE 24
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:6
--- Physical volumes ---
PV Name /dev/sdc1
PV UUID kD0jhk-ws8A-ke3L-a7nd-QucS-SAbH-BrmH28
PV Status allocatable
Total PE / Free PE 12 / 0
PV Name /dev/sdd1
PV UUID ZP2bLy-FxR3-gYn9-3Dy1-Llgk-6mFI-1iJvTm
PV Status allocatable
Total PE / Free PE 12 / 0
PV Name /dev/sde1
PV UUID wbiNu5-csig-uwY7-y14y-3C8Q-oeN0-hAT49g
PV Status allocatable
Total PE / Free PE 12 / 12
[root@rhel ~]#
Extend the logical volume with lvextend.
[root@rhel ~]# lvextend -L 512 /dev/vg_new/lv_test Extending logical volume lv_test to 512.00 MB Logical volume lv_test successfully resized [root@rhel ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_home sysvg -wi-ao 256.00M lv_root sysvg -wi-ao 5.84G lv_swap sysvg -wi-ao 1.00G lv_tmp sysvg -wi-ao 1.00G lv_usr sysvg -wi-ao 9.75G lv_var sysvg -wi-ao 2.03G lv_test vg_new -wi-ao 512.00M [root@rhel ~]#
Finally resize the file system, to do that use the resize2fs tool. Unlike in HP-UX with fsadm, that needs the new size as an argument in order to extend the file system, if you simply issue the logical volume as the argument the resize2fs utility will extend the file system to the maximum size available in the LV.
[root@rhel ~]# resize2fs /dev/vg_new/lv_test resize2fs 1.39 (29-May-2006) Filesystem at /dev/vg_new/lv_test is mounted on /data; on-line resizing required Performing an on-line resize of /dev/vg_new/lv_test to 524288 (1k) blocks. The filesystem on /dev/vg_new/lv_test is now 524288 blocks long. [root@rhel ~]#
And at this point we are done. Any comments are welcome as always :-)
Juanma.
Linux LVM commands in HP-UX
Some of the features I always liked about the Linux LVM2 implementation are the lvs, vgs and pvs command. with this simple commands a short list of the LVs, VGs and PVs active on the system can be obtained.
www04:~ # vgs VG #PV #LV #SN Attr VSize VFree vgwww01 1 6 0 wz--n- 39.75G 6.25G vgbbdd 3 3 0 wz--n- 94.25G 0 vgsys 1 6 0 wz--n- 34.74G 1.25G www04:~ #
In HP-UX there is nothing similar available, well since HP-UX 11.31 and LVM2 a “-F” option has been added to produce a formated, more script friendly list but is not very “human readable”.
[root@nfscl02] ~ # vgdisplay -vF vg00 vg_name=/dev/vg00:vg_write_access=read,write:vg_status=available:max_lv=255:cur_lv=9:open_lv=9:max_pv=16:cur_pv=1:act_pv=1:max_pe_per_pv=4353:vgda=2:pe_size=32:total_pe=4322:alloc_pe=1539:free_pe=2783:total_pvg=0:total_spare_pvs=0:total_spare_pvs_in_use=0:vg_version=1.0:vg_max_size=2228736m:vg_max_extents=69648 lv_name=/dev/vg00/lvol1:lv_status=available,syncd:lv_size=1856:current_le=58:allocated_pe=58:used_pv=1 lv_name=/dev/vg00/lvol2:lv_status=available,syncd:lv_size=8192:current_le=256:allocated_pe=256:used_pv=1 lv_name=/dev/vg00/lvol3:lv_status=available,syncd:lv_size=1504:current_le=47:allocated_pe=47:used_pv=1 lv_name=/dev/vg00/lvol4:lv_status=available,syncd:lv_size=512:current_le=16:allocated_pe=16:used_pv=1 lv_name=/dev/vg00/lvol5:lv_status=available,syncd:lv_size=8192:current_le=256:allocated_pe=256:used_pv=1 lv_name=/dev/vg00/lvol6:lv_status=available,syncd:lv_size=5024:current_le=157:allocated_pe=157:used_pv=1 lv_name=/dev/vg00/lvol7:lv_status=available,syncd:lv_size=5024:current_le=157:allocated_pe=157:used_pv=1 lv_name=/dev/vg00/lvol8:lv_status=available,syncd:lv_size=8704:current_le=272:allocated_pe=272:used_pv=1 lv_name=/dev/vg00/lv_crash:lv_status=available,syncd:lv_size=10240:current_le=320:allocated_pe=320:used_pv=1 pv_name=/dev/disk/disk1_p2:pv_status=available:total_pe=4322:free_pe=2783:autoswitch=On:proactive_polling=On [root@nfscl02] ~ #
Because of this I decided to write three scripts to emulate the behavior of vgs, lvs and pvs on my HP-UX servers. This scripts take advantage of the mentioned LVM2 “-F” switch so they will not work on HP-UX 11.23 or any other previous versions. If anyones recognize the “scripting” style is because I grab some parts of the code from Olivier’s ioscan_fc2.sh and adapted them to my needs so credit goes to him also :-)
- VGS: List the volume group on the /etc/lvmtab file, if the server is part of a cluster the volume groups active on other nodes will be showed as deactivated. With the “-v” switch single VGs can be queried.
root@cldpp01:~# ./vgs.sh VG PVs LVs Status Version VGSize Free vg00 1 9 available 1.0 135G 77G vgdpp 1 1 available,exclusive 1.0 49G 0G vgidbbck deactivated root@cldpp01:~# ./vgs.sh -v vgdpp VG PVs LVs Status Version VGSize Free vgdpp 1 1 available,exclusive 1.0 49G 0G root@cldpp01:~#
The code:
#!/sbin/sh
#
# vgs.sh - script to emulate the Linux LVM command vgs in HP-UX 11iv3
#
# (C) 2010 - Juan Manuel Rey (juanmanuel.reyportal@gmail.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
version="v0.1 2010/02/15"
function usage
{
echo
echo "VGS for HP-UX ${version}"
echo
echo "Usage: vgs [-v vg_name]"
echo
exit 1
}
if [ ! "$(uname -r)" = "B.11.31" ]
then
echo "VGS for HP-UX only works on HP-UX 11iv3"
exit 1
fi
if [ "$1" ]
then
case "$1" in
-v) shift; [ "$1" = "" ] && usage || vg_name=${1};;
*) usage;;
esac
fi
vg_display="vgdisplay -F"
[ ! "${vg_name}" = "" ] && vg_display="vgdisplay -F ${vg_name}"
printf "%-10s %-5s %-5s %-20s %-8s %-6s %-5s\n" VG PVs LVs Status Version VGSize Free
eval ${vg_display} | while IFS=":" read vgdisplay
do
echo ${vgdisplay} | cut -d ":" -f 2 | cut -d "=" -f 2 | read status
if [ "${status}" = "deactivated" ]
then
status=deactivated
vg_size=""
vg_free=""
else
echo ${vgdisplay} | cut -d ":" -f 3 | cut -d "=" -f 2 | read status
echo ${vgdisplay} | cut -d ":" -f 13 | cut -d "=" -f 2 | read total_pe
echo ${vgdisplay} | cut -d ":" -f 12 | cut -d "=" -f 2 | read pe_size
echo ${vgdisplay} | cut -d ":" -f 15 | cut -d "=" -f 2 | read free_pe
vg_size="`/usr/bin/expr $total_pe \* $pe_size / 1024`G"
vg_free="`/usr/bin/expr $free_pe \* $pe_size / 1024`G"
fi
echo ${vgdisplay} | cut -d ":" -f 1 | cut -d "=" -f 2 | cut -d "/" -f 3 | read vg_name
echo ${vgdisplay} | cut -d ":" -f 8 | cut -d "=" -f 2 | read pvs
echo ${vgdisplay} | cut -d ":" -f 5 | cut -d "=" -f 2 | read lvs
echo ${vgdisplay} | cut -d ":" -f 19 | cut -d "=" -f 2 | read version
printf "%-10s %-5s %-5s %-20s %-8s %-6s %-5s\n" "${vg_name}" "${pvs}" "${lvs}" "${status}" "${version}" "${vg_size}" "${vg_free}"
done
- LVS: Like its Linux counterpart shows a list with every active logical volume. As in vgs with the -v switch you can ask the list of a specific volume group.
root@asoka:/# ./lvs.sh -v vg00 LV VG Status LVSize Permissions Mirrors Stripes Allocation lvol1 vg00 available,syncd 1G read,write 0 0 strict,contiguous lvol2 vg00 available,syncd 8G read,write 0 0 strict,contiguous lvol3 vg00 available,syncd 1G read,write 0 0 strict,contiguous lvol4 vg00 available,syncd 0G read,write 0 0 strict lvol5 vg00 available,syncd 20G read,write 0 0 strict lvol6 vg00 available,syncd 1G read,write 0 0 strict lvol7 vg00 available,syncd 5G read,write 0 0 strict lvol8 vg00 available,syncd 20G read,write 0 0 strict lv_crash vg00 available,syncd 9G read,write 0 0 strict root@asoka:/#
The code:
#!/sbin/sh
#
# lvs.sh - script to emulate the Linux LVM command lvs in HP-UX 11iv3
#
# (C) 2010 - Juan Manuel Rey (juanmanuel.reyportal@gmail.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
version="v0.1 2010/02/15"
function usage
{
echo
echo "LVS for HP-UX ${version}"
echo
echo "Usage: lvs [-v vg_name]"
echo
exit 1
}
if [ ! "$(uname -r)" = "B.11.31" ]
then
echo "LVS for HP-UX only works on HP-UX 11iv3"
exit 1
fi
if [ "$1" ]
then
case "$1" in
-v) shift; [ "$1" = "" ] && usage || vg_name=${1};;
*) usage;;
esac
fi
lv_list="vgdisplay -vF | grep lv_name"
[ ! "${vg_name}" = "" ] && lv_list="vgdisplay -vF ${vg_name} | grep lv_name"
printf "%-30s %-12s %-17s %-6s %-10s %-7s %-8s %-8s %-7s\n" LV VG Status LVSize Permissions Mirrors Stripes Allocation
eval ${lv_list} | while IFS=":" read lvlist
do
echo ${lvlist} | cut -d ":" -f 1 | cut -d "/" -f 4 | read lv_name
echo ${lvlist} | cut -d ":" -f 1 | cut -d "=" -f 2 | read lv_long_name
lvdisplay -F ${lv_long_name} | cut -d ":" -f 2 | cut -d "/" -f 3 | read vg_name
lvdisplay -F ${lv_long_name} | cut -d ":" -f 4 | cut -d "=" -f 2 | read lv_status
lvdisplay -F ${lv_long_name} | cut -d ":" -f 3 | cut -d "=" -f 2 | read lv_perm
lvdisplay -F ${lv_long_name} | cut -d ":" -f 5 | cut -d "=" -f 2 | read lv_mirrors
lvdisplay -F ${lv_long_name} | cut -d ":" -f 11 | cut -d "=" -f 2 | read lv_stripes
lvdisplay -F ${lv_long_name} | cut -d ":" -f 14 | cut -d "=" -f 2 | read lv_allocation
lvdisplay -F ${lv_long_name} | cut -d ":" -f 8 | cut -d "=" -f 2 | read size_megs
lv_size="`/usr/bin/expr $size_megs / 1024`G"
printf "%-30s %-12s %-17s %-6s %-17s %-7s %-2s %-5s\n" "${lv_name}" "${vg_name}" "${lv_status}" "${lv_size}" "${lv_perm}" "${lv_mirrors}" "${lv_stripes}" "${lv_allocation}"
done
- PVS: And now the last one. List the activated physical volumes, if a VGs is not active on the current node its PVs wouldn’t be shown. Like in pvs and vgs there is a “-v” switch.
root@oracle:~# ./pvs.sh PV VG Status PVSize Free /dev/disk/disk1_p2 vg00 available 135G 48G /dev/disk/disk28 vgora available 1G 0G /dev/disk/disk29 vgora available 5G 0G /dev/disk/disk30 vgora available 3G 0G /dev/disk/disk31 vgora available 51G 1G /dev/disk/disk32 vgora available 1G 0G /dev/disk/disk37 vgora available 3G 0G /dev/disk/disk38 vgora available 6G 0G /dev/disk/disk43 vgoracli available 3G 0G /dev/disk/disk119 vgoracli available 2G 0G root@oracle:~#
And the code:
#!/sbin/sh
#
# pvs.sh - script to emulate the Linux LVM command pvs in HP-UX 11iv3
#
# (C) 2010 - Juan Manuel Rey (juanmanuel.reyportal@gmail.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
version="v0.1 2010/02/15"
function usage
{
echo
echo "PVS for HP-UX ${version}"
echo
echo "Usage: pvs [-v vg_name]"
echo
exit 1
}
if [ ! "$(uname -r)" = "B.11.31" ]
then
echo "PVS for HP-UX only works on HP-UX 11iv3"
exit 1
fi
if [ "$1" ]
then
case "$1" in
-v) shift; [ "$1" = "" ] && usage || vg_name=${1};;
*) usage;;
esac
fi
pv_list="vgdisplay -vF | grep disk"
[ ! "${vg_name}" = "" ] && pv_list="vgdisplay -vF ${vg_name} | grep disk"
printf "%-20s %-10s %-20s %-6s %-5s\n" PV VG Status PVSize Free
eval ${pv_list} | while IFS=":" read pvlist
do
echo ${pvlist} | cut -d ":" -f 1 | cut -d "=" -f 2 | read pv_name
pvdisplay -F ${pv_name} | cut -d ":" -f 2 | cut -d "=" -f 2 | cut -d "/" -f 3 | read vg_name
pvdisplay -F ${pv_name} | cut -d ":" -f 3 | cut -d "=" -f 2 | read status
pvdisplay -F ${pv_name} | cut -d ":" -f 8 | cut -d "=" -f 2 | read total_pe
pvdisplay -F ${pv_name} | cut -d ":" -f 7 | cut -d "=" -f 2 | read pe_size
pvdisplay -F ${pv_name} | cut -d ":" -f 9 | cut -d "=" -f 2 | read free_pe
pv_size="`/usr/bin/expr $total_pe \* $pe_size / 1024`G"
pv_free="`/usr/bin/expr $free_pe \* $pe_size / 1024`G"
printf "%-20s %-10s %-20s %-6s %-5s\n" "${pv_name}" "${vg_name}" "${status}" "${pv_size}" "${pv_free}"
done
As always any comments, corrections and/or suggestions are welcome.
Juanma.


