[FrontPage] [TitleIndex] [WordIndex

This is a read-only archived version of wiki.centos.org

Xen DomU LV NTFS Resize using Command Line

1. Draft

This document is actively being developed and is incomplete. Please post any suggestions to CentOS/docs with subject:Xen_DomU_LV_NTFS_resize suggestions.

2. Introduction

GNU/Linux/CentOS5/Xen is a great virtualization platform. Virtual machines can be used to reduce equipment, run alternate OS's and/or for other purposes. Virtualization can reduce server resources like electricity and make resource allocation (processor, memory, disk) more flexible. Specifically, it can be used to virtualize MS Windows desktops so workstations don't have to be upgraded/replaced every few years. Instead, allocating additional resources expands the virtual machine for additional needs. Users access the virtual machine desktop using a thin client or application on a GNU/Linux desktop or other access method. Also, virtual machines can be centralized for distributed access to centralized resources.

2.1. About

This document intends to describe the process of extending a MS Windows (NTFS) DomU virtual disk that is on a Logical Volume from the Command Line on the virtual machine server. We assume you know how to log into your server, either at the console or using SSH.

2.2. Disclaimer

There is absolutely no guarantee of anything. We've made a reasonable effort to test these instructions, but as your situation could be different from the test environment(s), your results could vary. This includes destroying all data on your server. Please, read this document completely and verify all steps on a test server that doesn't have any critical data before attempting to use on a live server.

2.3. Requirements

Verifying packages can be done using rpm -qa | grep ntfs

ntfsprogs-1.13.1-1.el5.rf
kernel-module-ntfs-2.6.18-128.el5xen-2.1.27-0.rr.10.11

3. Stop Virtual Machine

The first step of resizing the Windows partition is making sure the virtual machine is stopped. If the partition were resized while the machine was running, we would expect unpredictable behavior.

Please refer to Virtualization Guide for information on how to control a virtual machine; Specifically, Chapter 15: Managing Virtual Machines with virsh, section 8 and section 10 or Chapter 17: Managing Virtual Machines Using xm, section 2.

At a command prompt,

lvs

should return something like:

  LV          VG    Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  root        vg    -wi-ao   9.75G
  swap        vg    -wi-ao   5.16G
  test        vg    -wi-a-  10.00G

notice that LV test does not have attribute o (open).

4. Verify Partition information

Mostly as a control, verify partition information before any changes are made:

fdisk -lu /dev/vg/test

should return something like:

Disk /dev/vg/test: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/vg/test        *          63    20948759    10474348+   7  HPFS/NTFS

Record the block Start (63), block End (20948759) and Id (filesystem type: 7). Note the partition is marked bootable (active).

5. Extend Logical Volume

lvextend is relatively straightforward:

lvextend --size +10G vg/test

should return:

  Extending logical volume test to 20.00 GB
  Logical volume test successfully resized

We can verify using lvs

  LV          VG    Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  root        vg    -wi-ao   9.75G
  swap        vg    -wi-ao   5.16G
  test        vg    -wi-a-  20.00G

6. Resize NTFS Partition

This is the first dangerous step.

6.1. Delete old partition

Using fdisk, start program, delete existing partition, write changes:

[root@vtst ~]# fdisk /dev/vg/test

The number of cylinders for this disk is set to 2610.
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)

Command (m for help): d
Selected partition 1

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

<!> Note the warning. This is expected due to the device not being real.

6.2. Create Larger Partition

Using fdisk, start program, create new/larger partition, change type, set active, write changes:

[root@vtst ~]# fdisk /dev/vg/test

The number of cylinders for this disk is set to 2610.
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)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
Using default value 2610

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7 (HPFS/NTFS)

Command (m for help): a
Partition number (1-4): 1

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

6.3. Verify Partition Table

fdisk -lu /dev/vg/test

should return something like:

Disk /dev/vg/test: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/vg/test        *          63    41929649    10474348+   7  HPFS/NTFS

The important things to note are Start is the same, the End is higher, Id is the same and Boot is set.

7. Extend NTFS Filesystem

This is the second and potentially most dangerous step.

7.1. Create Device

First create a new device from the logical volume so that it is easier to work on. This will flag the LV as 'open'.

kpartx -av /dev/vg/test

Should return something like

add map test1 : 0 41929587 linear /dev/vg/test 63

Please notice the name of the new device, test1. If the LV name ended in a number, the new device should have a p1 at the end. This new device is in /dev/mapper/, so the complete device name is /dev/mapper/test1.

7.2. Extend Filesystem

This is the key piece.

ntfsresize /dev/mapper/test1

It should do some sanity checks then prompt for y to continue.

ntfsresize v1.13.1 (libntfs 9:0:0)
Device name        : /dev/mapper/test1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 10725732864 bytes (10726 MB)
Current device size: 21474804224 bytes (21475 MB)
New volume size    : 21474800128 bytes (21475 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 5746 MB (53.6%)
Collecting resizing constraints ...
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/mapper/test1'.

7.3. Remove Device

We are done resizing. Remove the temporary device. This will remove the open flag from the LV.

kpartx -dv /dev/vg/test

Should return something like

del devmap : test1

8. Test

Start virtual machine.


2023-09-11 07:19