## Educating the world

Our blog has over 10,000 readers a month

## Creating and resizing logical volumes on a 1and 1 dedicated server

March 1st, 2011

1&1’s documentation is pretty awful but to be fair they only expect real system administrators to be using their dedicated servers. They give you a copy of Plesk 10 but it doesn’t have any capabilities to alter the disk or volume group layouts. 1&1 layout their default image in a way that only gives you 4GB on each of the major partitions and it leaves the other 212GB as unallocated. So in order to use the server properly you have to get interested in the Logical Volume Manager.

It is a daunting prospect because it can so easily go pear shaped if you are not careful. I haven’t done any volume management since my Macro 4 days sorting out HP-UX boxes. So consider this a beginners guide to 1&1 servers as well as Logical Volume Management.

You don’t get any information about the dedicated servers layout when you start the 1&1 contract. All you get is a user name and a password, you have to do a full investigation of the hardware, disks, partitions, volume groups and all the other scary stuff you don’t really want to be touching.

The article will take you through the platform hardware investigation and volume layout. Once we know what we have to deal with I will look at extending a logical volume and creating a new one.

I’ll start with a few terms that you need to understand if you haven’t done much work with logical volumes before. I’ll talk in terms of disks and partitions because that’s what we had to deal with before LVM.

Physical disk is an actual hard-drive with spinning platters and everything.
Partition is a space allocated on a physical disk that can hold a file system. You can’t put a file system straight on to the disk you need to have a container for it to sit in.
Physical volume same as a partition (an area on a physical disk drive).
Volume group is one or more physical volumes glued together to make one virtual drive.
Logical volume is a part of a volume group.

In the olden days you split your disks into partitions and used each partition as a chunk of storage. Nowadays we glue all the disk drives together to make an uber virtual disk that we can split up into lots of different pieces. It works by splitting each volume group into pieces called extends and then allocating groups of extends into logical partitions - a bit like the way a file system works with sectors and blocks.

Ok, we are now sitting in front of our new 1&1 dedicated server with the blank sheet of instructions they gave us!

First we need to know the state of the system. So for this we need to check the display messages. These are the messages that appear on the screen during boot up and can be seem by typing: dmesg. The bit we are interested in begins with SCSI device. Here is an example:

SCSI device sda: 488397168 512-byte hdwr sectors ( 250059 MB )
sda: Write Protect is off
sda: Mode Sense: 00 3a 00 00
SCSI device sda: drive cache: write back
sda: sda1 sda2 sda3

The first line describes the size of the physical hard drive. Don’t worry about the other stuff because it is the final line we are interested in. It shows that the sda drive has 3 partitions: sda1, sda2 and sda3. If we look a bit further down the file we can see there is a similar set up sdb which also has 3 partitions: sdb1, sdb2 and sdb3.

The next section in dmesg output talks about setting up the disk partitions to mirror each other. md3 is made of:

md: created md3
md: bind<sda3>
md: bind<sdb3>
md: running: <sdb3><sda3>

md: created md1
md: bind<sda1>
md: bind<sdb1>
md: running: <sdb1><sda1>

Further down we can see:

2. Priority:-1 extents:1 across:1959920k
Adding 1959920k swap on /dev/sdb2. Priority:-2 extents:1 across:1959920k

which shows that our 2 remaining partitions are used as swap space.

The 1&1 default image set up contains the following pre-configured partitions:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md1 3.7G 332M 3.4G 9% /
/dev/mapper/vg00-usr 4.0G 1.1G 3.0G 26% /usr
/dev/mapper/vg00-var 4.0G 2.1G 2.0G 52% /var
/dev/mapper/vg00-home 4.0G 2.1G 2.0G 51% /home

/dev/md1 is accounted for as the root partition so /dev/md3 must be the drive which is backing our logical volume. As you can see only 12GB is being used so there is still about 215GB which is unallocated.
We can confirm this with the vgs command, which shows that there is 215GB free. Even though they are mirrored 250GB drives we lose about 20GB to the file system indexes.

# vgs
VG #PV #LV #SN Attr VSize VFree
vg00 1 3 0 wz–n- 227.28G 215.28G

Now that we have finished all the checks, we now know that there aren’t any more physical drives or logical volumes that are unaccounted for.

On my system there are quite a lot of databases so I need to either increase the /var partition or create a new partition that I can place under /var/lib/mysql.

Having read all the documentation it’s pretty easy to do either. My unix administration background is erring me on the side of a new logical partition. The nice thing about LVM is that you can always change your mind later. If I create a new partition then it will free up space in my /var partition so I won’t have to extend it for a while.

I will start by showing you how to resize an existing logical volume. I’m using CentOS 5 which has symbolic links to the lvm command making it somewhat simpler.

# ls -l /usr/sbin/vgdisplay
lrwxrwxrwx 1 root root 3 Jan 31 22:00 /usr/sbin/vgdisplay -> lvm

This means I can type vgdisplay instead of lvm vgdisplay so in the instructions below I’ll be using the short versions of the commands.

The logical volumes can be extended (or reduced) in units of Extends which are defined when the volume group is set up. We must see how much we can extend the logical volume by, so let’s check the volume group and see how many we have left.

# vgdisplay
— Volume group —
VG Name vg00
System ID
Format lvm2
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 227.28 GB
PE Size 4.00 MB
Total PE 58184
Alloc PE / Size 3072 / 12.00 GB
Free PE / Size 55112 / 215.28 GB
VG UUID t5aC2D-DWv9-Dh5s-Hz2c-dzIH-oSxX-4jMjwo

Here we can see that a Physical Extend is 4MB and we have 55112 of them which are unallocated. Next we need to look at what I have in my current /var logical partition:

# lvdisplay /dev/mapper/vg00-var
— Logical volume —
LV Name /dev/vg00/var
VG Name vg00
LV UUID xRq5Oj-Y41X-M6VK-s2es-nCOT-dDFF-X0Sznp
LV Status available
# open 1
LV Size 4.00 GB
Current LE 1024
Segments 1
Allocation inherit
- currently set to 256
Block device 253:1

The Logical Extend and the Physical Extend are the same size, but I’m sure there is a reason why they have different names (anyone?). From the read out above you can see that we have 1024 extends. So if I wanted to extend the partition by 6GB making it 10GB in size I would have to increase the extends to 10240. To extend the logical partition I issue the command:

# lvm lvresize -l 10240 /dev/mapper/vg00-var
Extending logical volume vg00 to 10.0 GB
Logical volume vg00 successfully resized

The logical volume is now bigger but the file system that lives in it is still the same size, so we need to update it. Under CentOS 5 we can resize the filing system without unmounting it, which is really handy because there are loads of programs running which have open files on the /var partition. The command is simple:

# resize2fs /dev/mapper/vg00-var

Note: I just tried this and it didn’t work. The CentOS documentations says the the code for ext2online (which was the old method of extending ext2/ext3 file systems) had been merged into resize2fs. My system uses xfs and not ext2/ext3 so I had to use:

xfs_growfs /dev/vg00/var

The command gives you the following output, which is very similar to what you get when you are creating the xfs filesystem.

meta-data=/dev/vg00/var isize=256    agcount=4, agsize=262144 blks
=              sectsz=512   attr=2
data     =              bsize=4096   blocks=1048576, imaxpct=25
=              sunit=0      swidth=0 blks, unwritten=1
naming   =version 2     bsize=4096
log      =internal      bsize=4096   blocks=2560, version=2
=              sectsz=512   sunit=0 blks, lazy-count=0
realtime =none          extsz=4096   blocks=0, rtextents=0
data blocks changed from 1048576 to 2097152


I have decided to create a brand new logical volume that I can resize independently. The logical volume group already exists so I don’t need to create that.

Even though I have 2 physical disks they are joined together as 1 mirror and used as 1 entity in the volume group so I can’t specify the -i option to have the volume group manager organise writes to both disks. I don’t think it matters it you do the mirroring up in the volume group level or on the disk partition level.

We issue the logical volume create command and set it to 10GB

# lvcreate -n mysql -L10G vg00
Logical volume “mysql” created

A quick check shows that everything is ok:

# ls -l /dev/mapper/
total 0
crw——- 1 root root 10, 63 Jan 31 22:30 control
brw-rw—- 1 root disk 253, 2 Jan 31 22:31 vg00-home
brw-rw—- 1 root disk 253, 3 Feb 7 21:11 vg00-mysql
brw-rw—- 1 root disk 253, 0 Jan 31 22:31 vg00-usr
brw-rw—- 1 root disk 253, 1 Jan 31 22:31 vg00-var

# lvdisplay /dev/mapper/vg00-mysql
— Logical volume —
LV Name /dev/vg00/mysql
VG Name vg00
LV UUID LQpgnU-Of2d-y3LP-Mj2n-0FH1-CaGd-1OW0kQ
LV Status available
# open 0
LV Size 10.00 GB
Current LE 2560
Segments 1
Allocation inherit
- currently set to 256
Block device 253:3

Note: I tried to create a logical volume called “scratch-backup", but when I checked the /dev/mapper it listed the group name as vg00-scratch--backup. In my opinion anything unexpected is bad so I want to delete this logical volume and pick a different name.

lvremove /dev/mapper/vg00-scratch–backup

This new logical volume is blank so I need to create a file system in it. Not sure of all the magic options so I’ll let the system use its defaults:

# mkfs -t xfs /dev/vg00/mysql
meta-data=/dev/vg00/mysql        isize=256    agcount=16, agsize=163840 blks
=                       sectsz=512   attr=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
=                       sunit=0      swidth=0 blks, unwritten=1
naming   =version 2              bsize=4096
log      =internal log           bsize=4096   blocks=2560, version=1
=                       sectsz=512   sunit=0 blks, lazy-count=0
realtime =none                   extsz=4096   blocks=0, rtextents=0


The final disk test is to make sure we can mount it into the file system.

# mount /dev/vg00/mysql /mnt
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md1 3.7G 332M 3.4G 9% /
/dev/mapper/vg00-usr 4.0G 1.1G 3.0G 26% /usr
/dev/mapper/vg00-var 4.0G 2.1G 2.0G 52% /var
/dev/mapper/vg00-home 4.0G 2.1G 2.0G 51% /home
/dev/mapper/vg00-mysql 10G 4.6M 10G 1% /mnt

I want this file system to be mounted when the machine boot’s up so I must add it into the /etc/fstab file. Now I can start the process of copying my existing databases into the new partition and we are done.

Primary documentation site for LVM

Resize instructions
http://wiki.centos.org/TipsAndTricks/ExpandLV

Clear(ish) description of concepts but mainly talks about the management via the system GUI.

Some 1&1 documentation has finally materialised!

## Repairing other people's computers

February 24th, 2011

Another thing that happens when you tell people you’re in I.T. is repairing their computer. Most people haven’t realised that computers are disposable consumer electronics. Wasteful though this is, if your computer breaks after 5 years then throw it in a skip and buy a new one!

Half of the trouble is that most people use a computer for a bit of email and a bit of web surfing and so having spent £400 5 years ago makes them reluctant to discard it. If they bought the same computer at today’s prices they would firstly be lucky to find one and if they did the person on eBay would be practically giving it away because it has no value.

The government lets you write-off a computer against tax in just 3 years, so any business should be buying new computers for its workers every couple of years! but they don’t, they just struggle along on outdated hardware. There is an issue with training that you get to avoid if you stick with the same machines, but then who wants staff that only knows how to use out-of-date technology?

One of the problems with Computer Repair is that of acquiring the parts. If your motherboard blows up then you may find that your motherboard specification is no longer available because it has been superseded by a better version. So now you need different memory as well and sometimes if you are really lucky your old power supply plug won’t fit your new motherboard, and so now you need a new case. In almost all cases it is the motherboard that blows up because novice users don’t hoover inside their PC’s and so over time the dust builds up, with constant heating up and cooling down creates a kind of glue which eventually causes a short on the motherboard and if you’re really lucky a fire! Dust builds up over heat sinks causing their efficiency to reduce considerably which also contributes to component failure.

All those components bought separately can work out more expensive then buying a new computer because don’t forget you are not only having to buy the new parts but also paying some guy in his bedroom to look for the suitable replacements and fit them which can actually take the most time and money.

Computer repairing does have several advantages. There is a case at one of my clients where their server has blown up after a power spike. We really needed to get the data off the server and because it is a Mac we have the security that we can just swap out the power supply without having to replace everything.

One thing worth mentioning is that when you send your computer in for repair the person doing the repair will probably rifle through all your files. For some reason they don’t see it as a personal private history of you they will be nosy and curious of what you have been up to. Unlike being under anaesthetic at a hospital where you can be pretty sure the doctor and his staff won’t bum you, your computer will be handed over to literally anyone with no checks or balances and if they see anything they don’t like then they could steal it or just call the police. The only way you can prevent this is if you watch them repair it. For some reason they are less inclined to rifle through your personal files while you are watching over them.

If you are worried about sensitive material you could take the hard drive out and explain to them that they can fix a hardware problem without it. The repairer will have to put one of their own hard drives in to boot it, but if they are a proper repairer outlet they will understand and will have everything they need. They may charge you a bit extra because it will be more hassle for them and it will take a bit longer to fix your PC …but it beats egg on your face when government secrets end up with the press, your company is exposed for poor customer security or you have to go to prison!

## Recursive directory check-in using Clearcase

February 10th, 2011

It’s one of those fiddly things to recursively check-in an entire directory structure under Clearcase, and each time I do it I have to remember how. So I’m putting it into my long term memory here!

1. Move to the parent directory of the directory you would like to check-in.

cd c:\my\local\folder
c:\my\local\folder> dir

10/02/2011 14:58 &ltIR> .
10/02/2011 14:58 &ltIR> ..
10/02/2011 14:51 &ltIR> dir_i_want_to_check_in
19/01/2011 15:35 97 file_i_want_to_check_in.txt

2. Pick a location to check-in to.
3. Ensure that the folder you are checking-in to is itself checked-in.
4. The following will check-in all files in the current directory:

clearfsimport -rec -nset * Z:\path\to\dir

5. The following will check-in the single specified directory in the current directory:

clearfsimport -rec -nset dir_i_want_to_check_in Z:\path\to\dir

The -rec stands for recursive, so directories with all their contents will be checked-in.

The -nset stands for no set modification time. If this option is not set then only the Clearcase Administrator can check in the files because after the check in it modifies the time of the checked-in file to that of the original file. Changing the modification time of a Clearcase element requires Clearcase administration rights. To be honest I can’t think of a time when you are that bothered about the modification time of the file, so we nicknamed this flag the “make it work flag”

After you have checked everything in, you may want to update the permissions so that any executables can be run from a clearcase drive.

cleartool protect -rec -chmod 777 Z:\path\to\dir\dir_i_want_to_check_in

## Windows 7 Growing Pains

February 2nd, 2011

I haven’t even got my own copy of Windows 7 yet. The I.T. department is rolling it out across the company and already my colleagues are complaining about its idiosyncrasies. Phrases like “What the hell is that green bar doing again?", “it keeps doing a different thing each time” and “there so much GUI I can’t actually see *my* stuff".

So I have started this article as blogglue to join together all the blogs, articles and links I will discover or write that tell you how to switch off or work around all the new “features” of Windows 7. God help us all - I am more seriously thinking of switching over to MacOS than ever before. Think I might start with a laptop (they are kind of sexy) and after all it is Unix underneath (queue coy smile).

A lot of these “features” exist in Windows Vista as well and may work there too.

Anyway here’s one I know I will need because it has made its way from Vista which is on one of my home computers

Remove Favorites, Libraries, and Homegroup from Navigation Pane
This is a real pane (get it?). Favorites and Libraries occupy quite a large proportion of the navigation panel in File Explorer. This means that when ever you load it in you always have to scroll down to the place you want. You can rarely get the whole thing in one panel without scrollbars. As soon as the scrollbars appear you need to make the panel wider because the ends of the folders are now hidden behind the scrollbars and the thing keeps shifting from left to right whenever you move around.

Where is Quick Launch on Windows 7

Automatically Expand Navigation Pane Tree to Current Folder in Windows 7
I’ve been trying to use the new Windows Explorer style of navigating around the directory structure but it makes it really difficult to compare directories. The biggest pain is that if you cut and paste a directory into the navigation bar at the top then the directory tree structure doesn’t expand out to display where you are in the file system. If you are comparing folders or have folders that are similar then you never know which one you are looking at. You also can’t hop between different folders in a random-access way, you either have to go forwards/backwards or think about where those folders live to expand them. I spent most of my explorer time synchronising the tree view with the file view.

How To Toggle the Navigation Pane with a Button in Windows Explorer

Start -> Run, enter shell:sendto to open the SendTo folder; then just drag the applications you want into it.

Windows removes context menu entries when more than 15 files are selected
Strange one this! To stop us doing stupid things when large numbers of files are selected, Windows removes most of the “add-on” entries from the context menu. Nice idea in principle, but if you’re trying to add a load of source files to a source controller then you can’t.

Folder view is different even, though you have set them to be the same
Under Windows XP you would configure a folder just the way you like it and then go to Tools->Folder Options…, select the View tab then click the Apply to Folders button. From that point on your lovely settings would be used across all folders. This is not the same under Windows 7. If you read the Folder views title it says viewS and the blurb says “You can apply the view (such as Details or Icon) that you are using for this folder to all folders of this type“.
Windows 7 decides what class of folder it is and lets you create a viewing profile for how to view the contents of that folder. We are not sure how it decides, probably Microsoft Voodoo, or how you can find out what classes of folder you have. The up shot of this, is that if you have a all folders of pictures will show thumbnails and all folders of Word documents to show full details.
To make this work you must go to a folder and set it up the way you want and click through to the Apply to Folders button. You’ll have to do this for each of the folder classes individually.

Windows Explorer expands folders inappropriately, jumping the folder you expand to the bottom of the navigation pane
This is by far and away the most annoying bug I’ve found in Windows 7 so far. If you use the left hand directory tree to navigate your way around the filing system then you will definitely have noticed this bug. As you expand each of the tree branches the branch you have just expanded jumps to the bottom of the screen. So to navigate down a directory you have to expand, scroll the newly expanded directory back to the mouse pointer, expand the next folder down, scroll the newly expanded directory back to the mouse pointer. If you keep the folder at the bottom where it has moved itself you still have to scroll upwards because you can’t see the next folder to expand.
Just to show how much Microsoft listens to its customers there are 23 pages of requests to fix this on the Microsoft answers site spanning 2 years, with no official answer.
There is also an issue on Microsoft’s Connect site with a hundred people asking for this issue to be addressed.
There is however a list of work-a-rounds, one of which is to install ClassicShell which is a SourceForge project that, amongst other things fixes explorer and replaces the crappy new start menu with the old style one. Give it a go!

Resources
If you can’t find what you are looking for here, then try these pages:
http://blogs.msdn.com/b/tims/archive/2009/01/12/the-bumper-list-of-windows-7-secrets.aspx

## Building Python 2.7.1 from sources with OpenSSL support under Windows win32 and x64

February 1st, 2011

With all projects we must create an area to place our sources so that we both have a frame of reference.

mkdir c:\python-modules

Next we must download the sources we need. First up is Python itself. Navigate to: http://www.python.org/download/ Download the bzipped source tarball and uncompress it into c:\python-modules\Python-2.7.1 using 7-zip.

Next up we are going to download the pre-compiled OpenSSL development libraries (containing the headers, DLLs and libs) for the win32 and x64 platforms. So navigate to: http://code.google.com/p/openssl-for-windows/ Click Downloads at the top of the page and download the latest _WIN32 and _X64 which in my case is openssl-0.9.8k_WIN32.zip and openssl-0.9.8k_X64.zip. Unzip them to C:\python-modules\openssl-0.9.8k_WIN32 and C:\python-modules\openssl-0.9.8k_X64 respectively.

The Python project has a funny directory structure so we need to merge the OpenSSL folders to keep it happy. Create a new folder just containing the openssl-ver i.e. without the platform name. Which in my case would be:

mkdir C:\python-modules\openssl-0.9.8k

Now we must copy the lib and include folders from the platform specific folders into the combined folder as a different name which incorporates the platform number. Windows batch copying commands are a joke (you seem to have to know in advance what the directory structure looks like before you can copy files into it) but here you go:

cd C:\python-modules
set OPENSSL_DIR=openssl-0.9.8k
mkdir %OPENSSL_DIR%\inc32\openssl
mkdir %OPENSSL_DIR%\inc64\openssl
mkdir %OPENSSL_DIR%\out32
mkdir %OPENSSL_DIR%\out64

xcopy /e %OPENSSL_DIR%_WIN32\include %OPENSSL_DIR%\inc32
xcopy /e %OPENSSL_DIR%_X64\include %OPENSSL_DIR%\inc64
xcopy /e %OPENSSL_DIR%_WIN32\lib %OPENSSL_DIR%\out32
xcopy /e %OPENSSL_DIR%_X64\lib %OPENSSL_DIR%\out64

Copying under Windows is so good, it’s easier to use explorer! Unless there isn’t anyone there because you’re running in a batch file. I digress.

Now that we have the directory structure that the Python builder desires we must change the Visual Studio project properties file to update the opensslDir property. The creator of the project files was using openssl-0.9.8l which wasn’t available in a pre-built binary for both our platforms. Load C:\python-modules\Python-2.7.1-win32\PCbuild\pyproject.vsprops into your favourite text editor and change the macro opensslDir to be the same name as your OpenSSL directory.

The Python Visual Studio solution tries to build OpenSSL from sources which is a bit bizarre so it has to use a combination of ms-dos batch files, python scripts and perl scripts in order to determine how to build OpenSSL. This creates a dependency on you having pre-installed python and pre-installed Perl. Why give yourself more work? OpenSSL comes in pre-built releases for win32/x64.

Now that we have got the ssl folders in the right places we can get rid of the build_ssl.py pre-build option that requires Perl to be installed. I really do wonder what the project architects where thinking when they set it up this way.

“Let’s double the amount of work we must make everyone do by forcing them to build all the dependencies from source". “Ace and while we’re at it let’s add loads of dependencies so they have to install all kinds of extra stuff they are never going to use for anything else” ….what really?????? NO, No, No let’s use the other project’s pre-built development libraries so we can just compile against their stable versions. Sorry feeling a bit ranty today.

Now that we have re-organised the OpenSSL to use pre-compiled libraries we can remove all the dependencies in the Visual Studio solution that try and use Perl and build OpenSSL from source. Change to the C:\python-modules\Python-2.7.1\PCbuild directory and load _hashlib.vcproj and _ssl.vcproj into your favourite text editor. Remove all the VCPreBuildEventTool configuration Tool commands which refer to build_ssl.py for all configurations (Win32|Debug etc).

In true windows fashion, you must shutdown Visual Studio and restart it by running the pcbuild.sln. This will pick up the new settings from the updated property files.

Set the Solution Configuration to Debug or Release and set the Solution Platform to Win32 or x64 for the desired build. From the menu select Build->Build Solution.

I selected win32 debug and ran the build. The build process creates all the intermediate files in Python-2.7.1\PCbuild\Win32-temp-Debug and placed all end product files into Python-2.7.1\PCbuild. I needed to build all the combinations of releases for our in house development and production releases on each of our supported platforms. So I need to run the build 4 times with Win32/Debug, Win32/Release, x64/Debug and x64/Release. After each build I need to copy the output files out of the PCBuild folder into somewhere else.

The win32 platform build, places intermediary build files into PCbuild/Win32-temp-[Debug|Release]/<proj> whereas x64 places everything on one level at PCBuild/amd64, presumably because their definitions where created by different people. Each build type however saves the deliverables into the same location, presumerably because this is where the installer creator picks them up from.

In order to build our product we need the python27.dll, python27.lib and python27.pdb for the Release versions and python27_d.dll, python27_d.lib and python27_d.pdb for the Debug versions for both win32 and x64. The easiest way to find them is by right-clicking on PCBuild selecting Search and entering

python*.dll;python*.lib;python*.pdb

then you don’t need to hunt around for them

Between each build make sure you do a Build->Clean Solution to clean up any artefacts that may interfere with the build.

Well that’s 2 days I’ll never get back. Windows programmers should *really* take a leaf out of the Unix programmers book.