Git Product home page Git Product logo

parted-auto-resize's Introduction

WAT

in short resize a partition non-interactive to its maximum size

The long story..

Since using fdisk in this case is pretty complicated due to the case that non-interactive ways are probably not possible or very complicated using printf, i want to use parted resizepart for resizing a partition to its maximum size.

This can be used in scenarios like disk-resizes ( hypervisor / virtualization ). Now you need to adjust your logical volume / pv to the new size (LVM case) or you want to adjust the partition size of a normal partition.

So lets assume i want to resize partition /dev/sda1 on disk /dev/sda to its maximum possible size - how would i do this without getting asked any questions at all.

Eventhough parted /dev/sda resizepart 1 exists, it needs me to calculate and enter the maximum disk size - so how to automate this would be the next question - and the answer was the reason parted auto resize has been written.

Installation

  curl -o /usr/local/bin/resize.sh https://raw.githubusercontent.com/EugenMayer/parted-auto-resize/master/resize.sh

Dependencies

  • parted 3.0 or higher (otherwise probably rename parted resizepart to parted resize)

Usage

Save the script above as resize.sh and make it executable

# resize the fourth partition to the maximum size, so /dev/sda4
# this is the sandbox mode, so no changes are actually done - just previewed
./resize.sh /dev/sda 4

# apply those changes
./resize.sh /dev/sda 4 apply

Scenarios / motivation

Since debian does not allow you to preseed a LVM configuration, which uses a disk as a pv / vg, but always force you to use a partition, you need a convinient way to resize the pv partition, so you can resize any logical volumes. It can be done using fdisk, but this needs ot be done by hand, interactive with a lot more steps ( usual delete / create / set type to Linux LVM / write / reload partition table

Assuming your pv / vg is created on /dev/sdb1 named vgdata and the LV to resize is named data and you resized your disk using your hypervisor.

Now using this script, all you do is

./resize.sh /dev/sdb 1 apply
pvresize /dev/sdb1
lvextend -r /dev/mapper/vgdata-data -l '+100%FREE'

thats it! Note, if you happen to notice -r in lvextend, yes thats pretty cool, it calls resize2fs /dev/mapper/vgdata-data for us automatically after the partition resize ( to adjust the filesystem size )

parted-auto-resize's People

Contributors

eugenmayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

parted-auto-resize's Issues

Not working on Debian parted 3.2

Tried it but had no luck unfortunately:

root@ClearLinuxWLG ~ # ./resize.sh /dev/sda 3
will resize to 64425MB
WARNING!: Sandbox mode, i did not size!. Use 'apply' as third parameter to apply
root@ClearLinuxWLG ~ # ./resize.sh /dev/sda 3 apply
will resize to 64425MB
applying resize operation..
Warning: Partition /dev/sda3 is being used. Are you sure you want to continue?
parted: invalid token: 64425
Yes/No? ^C
root@ClearLinuxWLG ~ # yes | ./resize.sh /dev/sda 3 apply
will resize to 64425MB
applying resize operation..
Warning: Partition /dev/sda3 is being used. Are you sure you want to continue?
root@ClearLinuxWLG ~ # parted -l
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  569MB   568MB   fat16        primary  boot, esp
 3      570MB   42.9GB  42.4GB  ext4         primary


root@ClearLinuxWLG ~ # parted -v
parted (GNU parted) 3.2
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.

CentOS 6 parted.sh just spins endlessly

it appears that stdin to part causes it to hang.

when I execute the command ./resize.sh /dev/sdb 1 the command hangs.

When I do

printf %sn 'unit MB print list' | parted

The cursor runs back and forth as if caught in a loop

Killing from another console kills it.

hang when running scritp

Hello,

I try running the script with command:
./resize.sh /dev/sda 2 apply
and the server will be hanged after that

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.