linux - Shrink EXT3 and Expand NTFS

04
2013-08
  • aus

    I have a partition table that looks like this:

    [root@tower ~]# fdisk /dev/sda
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): p
    
    Disk /dev/sda: 320.1 GB, 320072933376 bytes
    255 heads, 63 sectors/track, 38913 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x44fdfe06
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1          13      104391   83  Linux
    /dev/sda2              14         275     2104515   82  Linux swap / Solaris
    /dev/sda3             276       36828   293611972+  83  Linux
    /dev/sda4   *       36829       38914    16748544    7  HPFS/NTFS
    

    /dev/sda3 is mounted to /. I would like to shrink the ext3 volume /dev/sda3so I can expand the NTFS volume /dev/sda4 and add about 15GB or so. How would I go about this? I would like to shrink the ext3 partition online if possible, so I don't have to bring down the server. I imagine my steps would be something like this:

    1. Delete the sda3 partion with fdisk.
    2. Create a new partition 3 with start cylinder of 276 and end cylinder of 35000 or so.
    3. Delete sda4 partition.
    4. Create new partition 4 with start cylinder of 35001 and end cylinder of 38914.
    5. Write changes.
    6. resize2fs /dev/sda3
    7. ntfsresize -size 35GB /dev/sda4 (35GB would equal whatever my partition is sized to in fdisk)

    Can anybody double check my steps? I'm too scared to try. :)

  • Answers
  • rakslice

    resize2fs can't shrink mounted filesystems.

    Also, I'd suggest you shrink the filesystem before making the partition table change; if you have trouble in the middle, the filesystems still match the partition table enough to be usable normally.


  • Related Question

    linux - How to create device driver for nested partitions?
  • NVRAM

    I'm running MSWindows virtualized with /dev/sda2 as it's primary drive. Consequently, there is a partition table on that partition, shown as:

    # fdisk -l /dev/sda2
    
    Disk /dev/sda2: 137.4 GB, 137436203520 bytes
    255 heads, 63 sectors/track, 16709 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
         Device Boot      Start         End      Blocks   Id  System
    /dev/sda2p1   *           1       16708   134206978+   7  HPFS/NTFS
    

    So my question is simply: What are the major/minor numbers to create /dev/sda2p1? What about sda2p2 and sda3p1?


  • Related Answers
  • larsks

    Assuming this is a straight disk image (e.g., your virtualization solution is not adding some extra metadata to things), this document (also here) offers some suggestions for accessing your partitions on /dev/sda2 (summary: use the -o offset option to losetup to create a new block device referencing the appropriate offset into sda2).

    You can also use the Network Block Device (NBD) to create a partitioned block device from /dev/sda2, see this LWN article which described the process in detail. And hey, I just learned something new.