I'd like to give my box some more disk space. I'm trying to do this through the vagrantfile as follows:
Vagrant::Config.run do |config|
# ..
config.vm.customize ["modifyvm", :id, "--memory", 1024]
config.vm.customize ["modifyhd", :id, "--resize", 4096]
end
This gives me the error:
A customization command failed:
["modifyhd", "e87d8786-88be-4805-9c2a-45e88b8e0e56", "--resize", "4096"]
The following error was experienced:
VBoxManage: error: The given path 'e87d8786-88be-4805-9c2a-45e88b8e0e56' is not fully qualified
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Medium, interface IMedium, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 178 of file VBoxManageDisk.cpp
Please fix this customization and try again.
I'm trying to piece the information together from http://docs.vagrantup.com/v1/docs/config/vm/customize.html
http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi
You are sending modifyhd the UUID of the VM (provided by vagrant) while it expects the UUID of the VDI.
You will need to use the absolute path to the actual VDI file or its UUID. You can use the following command to get the UUID of the VDI: VBoxManage showhdinfo <filename> (see virtualbox - how to check what is the uuid of a vdi?)
I created a new disk, added and extended the older.
My Vagrantfile:
Vagrant.configure(2) do |config|
config.vm.box = "bseller/oracle-standard"
config.vm.define :oracle do |oracle|
oracle.vm.hostname = 'oraclebox'
oracle.vm.synced_folder ".", "/vagrant", owner: "oracle", group: "oinstall"
oracle.vm.network :private_network, ip: '192.168.33.13'
oracle.vm.network :forwarded_port, guest: 1521, host: 1521
oracle.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "4096"]
vb.customize ["modifyvm", :id, "--name", "oraclebox"]
if !File.exist?("disk/oracle.vdi")
vb.customize [
'createhd',
'--filename', 'disk/oracle',
'--format', 'VDI',
'--size', 60200
]
vb.customize [
'storageattach', :id,
'--storagectl', "SATA",
'--port', 1, '--device', 0,
'--type', 'hdd', '--medium', 'disk/oracle.vdi'
]
end
end
oracle.vm.provision "shell", path: "shell/add-oracle-disk.sh"
oracle.vm.provision "shell", path: "shell/provision.sh"
end
end
This will create new disk in
disk
|-- oracle.vdi
shell
|-- provision.sh
Vagrantfile
and add in your box. The new disk is of 60GB
My shell provision.sh
set -e
set -x
if [ -f /etc/disk_added_date ] ; then
echo "disk already added so exiting."
exit 0
fi
sudo fdisk -u /dev/sdb <<EOF
n
p
1
t
8e
w
EOF
sudo pvcreate /dev/sdb1
sudo vgextend VolGroup /dev/sdb1
sudo lvextend -L50GB /dev/VolGroup/lv_root
sudo resize2fs /dev/VolGroup/lv_root
date > /etc/disk_added_date
This script was adapted from SHC to box bseller/oracle-standard. For full code, see my project oraclebox in GitHub
I've been looking at this, and I haven't found any way to actually do this directly. However, you can achieve the effect using Ansible as a provisioner. First of all, it is definitely possible with Vagrant to create and add a second disk, which you can then add and mount any way you like using Ansible.
However, Ansible also has the ability to run local commands (on the host). This is with Ansible's local_action feature. I used it here to reboot a Vagrant VM after a kernel upgrade and tell the host to wait until it has restarted, but you could use this with the command or shell actions to find the HD identifier, shutdown the VM, and configure the hard disk, then reboot. At least in theory.
Although the question is old but I saw no answer accepted.
The given path 'e87d8786-88be-4805-9c2a-45e88b8e0e56' is not fully qualified shows up because the UUID e87d8... is VirtualBox vm UUID, not your SATA storage disk device UUID. You an find the storage device UUID by VBoxManage showvminfo e87d8786-88be-4805-9c2a-45e88b8e0e56|grep vdi. The replace :id with the SATA storage UUID in Vagrantfile modifyhd line.
It solved my problem.
OK... Solved...
VBoxManage.exe wan't in my path so what I did was go to (you have to go to that path):
C:\Program Files\Oracle\VirtualBox
then used the command:
VBoxManage.exe modifyhd "C:\Users\MyUser\VirtualBox VMs\MachineName\HDName.vdi " --resize 20480
For 20 GB size a HD
This DON'T work:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "C:\Users\MyUser\VirtualBox VMs\MachineName\HDName.vdi " --resize 20480
You have to be in the path: C:\Program Files\Oracle\VirtualBox
You can add new disk instead.
First use virtual box GUI to add another
virtual disk
then use fdisk to create a primary disk partion
root#linux-dev:/# fdisk -l
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 9.9 GiB, 10632560640 bytes, 20766720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x83312a2b
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 19816447 19814400 9.5G 83 Linux
/dev/sda2 19818494 20764671 946178 462M 5 Extended
/dev/sda5 19818496 20764671 946176 462M 82 Linux swap / Solaris
root#linux-dev:/# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x5eb328b9.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5eb328b9
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5eb328b9
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 41943039 41940992 20G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Make newly created disk partition a ext4 filesystem
root#linux-dev:/# mkfs.ext4 /dev/sdb1
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 0301b56a-1d80-42de-9334-cc49e4eaf7b2
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Mount the disk partition to a directory
root#linux-dev:/# mount -t ext4 /dev/sdb1 /home/chenchun
root#linux-dev:/# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.2G 3.3G 5.5G 38% /
udev 10M 0 10M 0% /dev
tmpfs 74M 4.4M 70M 6% /run
tmpfs 185M 0 185M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 185M 0 185M 0% /sys/fs/cgroup
none 372G 240G 133G 65% /vagrant
/dev/sdb1 20G 44M 19G 1% /home/chenchun
Related
I'm running a CentOS 7 guest on a VirtualBox 6 on Windows. The result of the free command is as follows:
$ free -h
total used free shared buff/cache available
Mem: 15G 2.4G 11G 162M 1.5G 12G
Swap: 1.2G 0B 1.2G
showing that the swap partition has 1.2 GB. I need to extend it to at least 2GB. So, with the guest stopped, I added a new volume of 1.2 GB and, after having rebooted, I did as follows:
$ sudo pvcreate /dev/sdb
$ sudo vgextend centos /dev/sdb
$ sudo lvextend -L+1G /dev/centos/swap
Now, the lvdisplay command shows the new created volume, as follows:
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 1OT4R8-69eL-vczL-zydM-XrwS-jA47-YfikMS
LV Write Access read/write
LV Creation host, time localhost, 2019-12-30 22:01:35 +0100
LV Status available
# open 2
LV Size <2.20 GiB
Current LE 563
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID hGDGPf-iPMB-TUtM-nqRv-aDNd-D3mw-W15H8Z
LV Write Access read/write
LV Creation host, time localhost, 2019-12-30 22:01:35 +0100
LV Status available
# open 1
LV Size <76.43 GiB
Current LE 19565
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
The fstab file looks as follows:
dev/mapper/centos-root / xfs defaults 0 0
UUID=4ef0416f-1617-40da-99d2-83896d808eed /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
showing that the swap is allocated on the /dev/mapper/centos-swap partition. Here is the out put of the fstab command:
Disk /dev/mapper/centos-root: 82.1 GB, 82061557760 bytes, 160276480 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2361 MB, 2361393152 bytes, 4612096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
But after reboot the swapon command doesn't seem to reflect the extension:
$ sudo swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 1257468 0 -2
For some reason, the swap doesn't seem to be on the /dev/mapper/centos-swap partition but on /dev/dm-1, which doesn't even exist. And the free command still shows the same result like in the beggining:
$ free -h
total used free shared buff/cache available
Mem: 15G 2.4G 11G 155M 1.5G 12G
Swap: 1.2G 0B 1.2G
and the /proc/swaps:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-1 partition 1257468 0 -2
What am I missing here ?
Seymour
I'm answering my own question. The issue is simply solved by running the following command:
sudo mkswap /dev/mapper/centos-swap
After that, the free command shows the new increased swap space and the /proc/swaps file also reflect that.
I found the solution by chance, while surfing for another topic. It seems that, as a matter of fact, after having created the physical volume and after having extended the virtual group and the logical volume, it's not enough to declare the new swap with swapon command, but it also requires to effectively "make" the swap using the mkswap command.
Don't ask me why, this is the way it works :-).
I am starting a VM with QEMU this way:
qemu-system-x86_64 \
-m 512M \
-drive file=ovmf.qcow2,if=pflash,format=qcow2,unit=0,readonly=on \
-drive file=ovmf.vars.qcow2,if=pflash,format=qcow2,unit=1 \
-nographic \
-drive file=file.uefiimg,if=ide,format=raw
fdisk -l file.uefiimg output:
Disk file.uefiimg: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DC9B048E-91D0-4DD0-BD7A-4D6130AA726F
Device Start End Sectors Size Type
file.uefiimg1 16384 49151 32768 16M EFI System
file.uefiimg2 49152 1589247 1540096 752M Linux filesystem
file.uefiimg3 1589248 3129343 1540096 752M Linux filesystem
file.uefiimg4 3129344 4177919 1048576 512M Linux filesystem
Now the tricky part is that I would like to start this on Virtualbox. If not possible vmware is also an option. I tried converting the uefiimg to a raw image with VBoxManage then to vdi, without success. I think the main problem was that I need to include the qcow2 files. I read about those 2 files, inserted as pflash but I don't understand how to load them in VirtualBox (or if it's possible)
I converted the image to vdi with
VBoxManage convertfromraw file.uefiimg --format vdi file.vdi
Then, loaded this vdi and it works perfectly.
I have one amazonw ec2 instance and would like to extend root device device form 100G to 500G. After create a new 500G volume and reattached to instance.
I can see volume is there by command $lsblk. However, after I resize the disk. I cannot do it with error "The filesystem is already 26212055 blocks long. Nothing to do!
name#ip-172-1-1-3:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 8.0K 3.9G 1% /dev
tmpfs 799M 840K 798M 1% /run
/dev/xvda1 99G 92G 3.1G 97% /
name#ip-172-1-1-3:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE
MOUNTPOINT
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 100G 0 part /
name#ip-172-1-1-3:~$sudo resize2fs /dev/xvda1
resize2fs 1.42.9 (4-Feb-2014)
The filesystem is already 26212055 blocks long. Nothing to do!
here's exactly what to do:
df -h #print the name of your boot partition
lsblk #show info on all your block devices
You'll see from that output what the name of the disk is of your root partition. For example, you probably see something like this:
xvde 202:64 0 32G 0 disk
└─xvde1 202:65 0 8G 0 part /
Our goal is to make xvde1 use the whole available space from xvde.
Here's how to resize your partition:
fdisk /dev/xvda (the disk name, not your partition)
This enters into the fdisk utility.
u #Change the display to sectors
p #Print info
d #Delete the partition
n #New partition
p #Primary partition
1 #Partition number
2048 #First sector
Press Enter to accept the default
p #Print info
a #Toggle the bootable flag
1 #Select partition 1
w #Write table to disk and exit
Now, reboot your instance:
reboot
After it comes back do:
resize2fs /dev/xvde1 (the name of your partition, not the block device)
And finally verify the new disk size:
df -h
After I follow #error2007s step 12 with "a" a #Toggle the bootable flag stop and reboot. I can not bring up instance.
Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders, total 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/xvda1 2048 1048575999 524286976 83 Linux
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 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
name#ip-172-1-1-3:~$ reboot
reboot: Need to be root
name#ip-172-1-1-3:~$ sudo reboot
Broadcast message from name#ip-172-1-1-3
(/dev/pts/1) at 10:18 ...
The system is going down for reboot NOW!
$ ssh -i "a.pem" name#ec2-172.1.1.3.compute-1.amazonaws.com -p 22
ssh: connect to host ec2-172.1.1.3.compute-1.amazonaws.com port 22: Operation timed out
You need to extend the available space:
$ lsblk
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 100G 0 part /
$ growpart /dev/xvda 1
$ resize2fs /dev/xvda1
I have cPanel & WHm installed on an EC2 instance.
The EC2 EBS volume is 100GB
CentOS 6 x86_64 (2014_09_29) EBS pv-1-adc4348e-1dc3-41df-b833-e86ba57a33d6-ami-809020e8.2 (ami-bc8131d4)
This is what df -h shows:
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 7.8G 6.6G 834M 89% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
/usr/tmpDSK 485M 11M 449M 3% /tmp
The EBS is mounted at /dev/sda
I am trying to increase the size of the xvde1 to almost fill the 100GB
When I run resize2fs /dev/xvde1 i get this:
root#vs1 [~]# resize2fs /dev/xvde1
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 2096896 blocks long. Nothing to do!
I have tried the solution stated here: EC2 Can't resize volume after increasing size
But when i reboot the instance it gets stuck on 1/2 Status Checks
I saw something that stated to start the partition on 16 and also to use the same start as it is in the original configuration. This did not work.
Here is some more information and other things that i have tried:
root#vs1 [~]# resize2fs /dev/xvde1
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 2096896 blocks long. Nothing to do!
root#vs1 [~]# resize2fs /dev/xvde
resize2fs 1.41.12 (17-May-2010)
resize2fs: Device or resource busy while trying to open /dev/xvde
Couldn't find valid filesystem superblock.
root#vs1 [~]# resize2fs /dev/xvde1
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 2096896 blocks long. Nothing to do!
root#vs1 [~]# resize2fs /dev/xvde1 +25G
resize2fs 1.41.12 (17-May-2010)
The containing partition (or device) is only 2096896 (4k) blocks.
You requested a new size of 6553600 blocks.
root#vs1 [~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 7.8G 6.6G 834M 89% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
/usr/tmpDSK 485M 11M 449M 3% /tmp
root#vs1 [~]# resize2fs /dev/xvde1 +15g
resize2fs 1.41.12 (17-May-2010)
The containing partition (or device) is only 2096896 (4k) blocks.
You requested a new size of 3932160 blocks.
root#vs1 [~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 7.8G 6.6G 834M 89% /
tmpfs 3.7G 0 3.7G 0% /dev/shm
/usr/tmpDSK 485M 11M 449M 3% /tmp
root#vs1 [~]# resize2fs /dev/xvde1
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 2096896 blocks long. Nothing to do!
root#vs1 [~]# fdisk -l
Disk /dev/xvde: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x00098461
Device Boot Start End Blocks Id System
/dev/xvde1 * 1 1045 8387584 83 Linux
root#vs1 [~]# Write failed: Broken pipe
This is the last step in a complete build that has taken over 18 hours.
I may just be delirious. Any and all help will be greatly appreciated!
EDIT:
The system log on the server shows this, not sure if it is any help:
Thread "main": pointer: 0x21e0003760, stack: 0x3740000
"main" "root=/dev/sda" "ro" "4"
vbd 2048 is hd0
******************* BLKFRONT for device/vbd/2048 **********
backend at /local/domain/0/backend/vbd/60/2048
209715200 sectors of 512 bytes
**************************
[H[J
GNU GRUB version 0.97 (7864320K lower / 0K upper memory)
[m[4;2H+-------------------------------------------------------------------------+[5;2H|[5;76H|[6;2H|[6;76H|[7;2H|[7;76H|[8;2H|[8;76H|[9;2H|[9;76H|[10;2H|[10;76H|[11;2H|[11;76H|[12;2H|[12;76H|[13;2H|[13;76H|[14;2H|[14;76H|[15;2H|[15;76H|[16;2H|[16;76H|[17;2H+-------------------------------------------------------------------------+[m
Use the ^ and v keys to select which entry is highlighted.
Press enter to boot the selected OS, 'e' to edit the
commands before booting, or 'c' for a command-line.[5;78H [m[7m[5;3H CentOS (2.6.32-504.el6.x86_64) [5;75H[m[m[6;3H CentOS (2.6.32-431.29.2.el6.x86_64) [6;75H[m[m[7;3H [7;75H[m[m[8;3H [8;75H[m[m[9;3H [9;75H[m[m[10;3H [10;75H[m[m[11;3H [11;75H[m[m[12;3H [12;75H[m[m[13;3H [13;75H[m[m[14;3H [14;75H[m[m[15;3H [15;75H[m[m[16;3H [16;75H[m[16;78H [5;75H[23;4H The highlighted entry will be booted automatically in 1 seconds. [5;75H[H[J Booting 'CentOS (2.6.32-504.el6.x86_64)'
root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
kernel /boot/vmlinuz-2.6.32-504.el6.x86_64 ro root=LABEL=_ console=ttyS0,115200
crashkernel=no SYSFONT=latarcyrheb-sun16 LANG=en_US.UTF-8 KEYTABLE=us
initrd /boot/initramfs-2.6.32-504.el6.x86_64.img
============= Init TPM Front ================
Tpmfront:Error Unable to read device/vtpm/0/backend-id during tpmfront initialization! error = ENOENT
Tpmfront:Info Shutting down tpmfront
Before resizing the filesystem by "resize2fs" command you should first resize your partition:
let's list block devices attached to our box:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
└─xvda1 202:1 0 8G 0 part /
As you can see /dev/xvda1 is only 8 GiB partition on a 16 GiB device and there are no other partitions on the volume.
step-1) We will use "growpart" to resize 8G partition up to 16G:
# install "cloud-guest-utils" if it is not installed already
apt install cloud-guest-utils
# resize partition
growpart /dev/xvda 1
Let's check the result (you can see /dev/xvda1 is now 16G):
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
└─xvda1 202:1 0 16G 0 part /
Lots of SO answers suggest to use fdisk with delete / recreate partitions, which is nasty, risky, error-prone process especially when we change boot drive.
step-2) resize file system to grow all the way to fully use new partition space
# Check before resizing ("Avail" shows 1.1G):
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 6.3G 1.1G 86% /
# resize filesystem
resize2fs /dev/xvda1
# Check after resizing ("Avail" now shows 8.7G!-):
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 16G 6.3G 8.7G 42% /
And by the way, there's no need to stop instance and detach EBS volume to resize it anymore! 13-Feb-2017 Amazon announced: "Amazon EBS Update – New Elastic Volumes Change Everything" See my other SO answer for details.
Update: Use sudo xfs_growfs /dev/xvda1 instead of resize2fs when XFS filesystem
This answer is dangerous, hasn't been verified since 2016, and has the potential to delete your partition if you're not aware of what's happening. Use with caution, and please reference #Dmitry's answer below as well.
To expand on JD's answer, here's exactly what to do:
df -h #print the name of your boot partition
lsblk #show info on all your block devices
You'll see from that output what the name of the disk is of your root partition. For example, you probably see something like this:
xvde 202:64 0 32G 0 disk
└─xvde1 202:65 0 8G 0 part /
Our goal is to make xvde1 use the whole available space from xvde.
Here's how to resize your partition:
fdisk /dev/xvda (the disk name, not your partition)
This enters into the fdisk utility.
u #Change the display to sectors
p #Print info
d #Delete the partition
n #New partition
p #Primary partition
1 #Partition number
2048 #First sector
Press Enter to accept the default
p #Print info
a #Toggle the bootable flag
1 #Select partition 1
w #Write table to disk and exit
Now, reboot your instance:
reboot
After it comes back do:
resize2fs /dev/xvde1 (the name of your partition, not the block device)
And finally verify the new disk size:
df -h
After searching and searching with no answer here, i FINALLY came across the answer!
"fdisk, put it into 'units' mode by typing 'u' then 'p' to print the partition table as it is now and write down the starting sector of the existing partition. Then delete that partition and make a new one, with the same partition number and starting on exactly the same sector and ending at the end of the disk, make sure that partition is 'active' then save your changes and reboot. Once you reboot after that, you should be able to resize2fs the existing filesystem to take up all space. Backups are recommended and it's your data to lose!!"
Putting it into sectors via Units mode helped me select the proper start and end of the FS!!
Credit: https://www.centos.org/forums/viewtopic.php?t=4783
I know the question is answered already. But still, if someone is stuck with the problem and need a more detailed step by step explanation. You can check out the official Amazon docs. This has the steps to increase the size and specific commands if you are using the "ec2-user (amazon ami)" instance.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html
also if you are using windows instance. You can visit
"For information about extending a Windows file system, see Extending a Windows file system after resizing a volume in the Amazon EC2 User Guide for Windows Instances."
https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/recognize-expanded-volume-windows.html
None of the above answers helped me. Here is something to consider for centos.
I wanted to extend my root volume from 8GB to 16GB
[root#ip-10-0-0-218 ~]# cat /etc/centos-release
CentOS Linux release 8.2.2004 (Core)
Determine the current state
[root#ip-10-0-0-218 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 60G 0 disk
├─nvme0n1p1 259:1 0 600M 0 part /boot/efi
└─nvme0n1p2 259:2 0 7.8G 0 part /
First attempt to increase space (failed)
[root#ip-10-0-0-218 /]# xfs_growfs -d /dev/nvme0n1p2
meta-data=/dev/nvme0n1p2 isize=512 agcount=4, agsize=508800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=2035200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data size unchanged, skipping
Use Parted
[root#ip-10-0-0-218 ~]# parted
GNU Parted 3.2
Using /dev/nvme0n1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart 2 +20GiB
Warning: Partition /dev/nvme0n1p2 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [8966MB]? 16966MB
quit
Now extend the size (success)
[root#ip-10-0-0-218 ~]# xfs_growfs /dev/nvme0n1p2
meta-data=/dev/nvme0n1p2 isize=512 agcount=4, agsize=508800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=2035200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2035200 to 3988233
Verify
[root#ip-10-0-0-218 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs 1.7G 0 1.7G 0% /dev/shm
tmpfs 1.7G 22M 1.7G 2% /run
tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup
/dev/nvme0n1p2 16G 7.1G 8.2G 47% /
/dev/nvme0n1p1 599M 6.4M 593M 2% /boot/efi
tmpfs 345M 0 345M 0% /run/user/1000
1. Confirm the kernel.
~]# uname -r
2.6.32-431.29.2.el6.x86_64
2. Confirm the initial allocated size
]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.9G 797M 6.7G 11% /
tmpfs 498M 0 498M 0% /dev/shm
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 **15G 0 disk**
└─xvda1 202:1 0 **8G 0 part /**
3. Install EPEL6 Repo
~]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
~]# rpm -ivh epel-release-6-8.noarch.rpm
3. Install the dracut & cloud-utils growpart modules-growroot
~]# yum install -y dracut-modules-growroot cloud-utils-growpart
4. The initrd needs to be rebuilt after installing the dracut-modules-growroot.
Create a backup copy of the current initramfs:
~]# cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
(ii)Create the initramfs for the current kernel:
~]# dracut -f
4. Result after reboot
~]# reboot
~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 **15G 0 disk**
└─xvda1 202:1 0 **15G 0 part /**
~]# resize2fs /dev/xvda1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/xvda1 to 3931652 (4k) blocks.
The filesystem on /dev/xvda1 is now 3931652 blocks long.
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 **15G** 932M 14G 7% /
tmpfs 498M 0 498M 0% /dev/shm
I have a virtual server under VMware, where I got 10 more GB harddisk from the sysadm.
Inside Linux (running Ubuntu 11.04 server), things are set up with LVM. In [c]fdisk, I do find these extra 10 gigs - they are present directly after the primary LVM partition.
I understand that I could make a new LVM partition out of this extra space, and then add this to the volume group, and then to the logical volume, and then resize the filesystem.
However, is it possible to assimilate these extra gigs into the existing LVM partition? So that the LVM's view of the physical volume increased instead of adding another physical volume into the volume group (preferably automatically percolating up to the volume group)?
I just built a test virtual machine with a 15GB disk and LVM on /dev/sda2. Then I grew the disk to 20GB and made LVM see the extra 5GB without adding another physical volume.
Here are the steps I followed:
apt-get install gnu-fdisk (or yum install gnu-fdisk)
I had to use gfdisk to make the whole thing work. No luck with the "standard" fdisk.
gfdisk /dev/sda
Switch to "sectors" as the unit (this is critical!!!) and print the partition table:
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): p
Disk /dev/sda: 21 GB, 21089617920 bytes
255 heads, 63 sectors/track, 2564 cylinders, total 41190660 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 257008 83 Linux
Warning: Partition 1 does not end on cylinder boundary.
/dev/sda2 501758 29798632 14643247 8e Linux LVM
Warning: Partition 2 does not end on cylinder boundary.
Command (m for help):
Write down the "start" sector of the "Linux LVM" partition (/dev/vda2).
Delete the partition and recreate it using the same "start" sector (501758) and the same partition type (8e):
Command (m for help): d
Partition number (1-2): 2
Command (m for help): n
Partition type
e extended
p primary partition (1-4)
p
First sector (default 63s): 501758
Last sector or +size or +sizeMB or +sizeKB (default 41190659s):
Command (m for help): p
Disk /dev/sda: 21 GB, 21089617920 bytes
255 heads, 63 sectors/track, 2564 cylinders, total 41190660 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 257008 83 Linux
Warning: Partition 1 does not end on cylinder boundary.
/dev/sda2 501758 41190659 20338290 83 Linux
Command (m for help): t
Partition number (1-2): 2
Hex code (type L to list codes): 8e
Changed type of partition 2 to 8e (Linux LVM)
Command (m for help):
WARNING: please note that I didn't accept the default start sector for the partition, I entered it manually so that it matches the original value! I did accept the default value for the "last sector" though, because I want this partition to be as large as the disk.
Verify that you did everything correctly with "p" and write the new partition table to disk:
Command (m for help): w
Reboot the virtual machine.
Now log-in the virtual machine and run:
root#git:~# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
Done! Now run vgdisplay and you will see the extra 5GB available as free extents.
CAVEATS:
If LVM is not the last (or only) partition on the virtual machine disk, you might have an hard time extending the size of the partition. It might even be impossible.
If LVM is on a logical partition (which is where Debian puts it by default at install time) or in other words if LVM is on /dev/sda5 instead of /dev/sda2, you must write down the starting sector of both the extended partition (let's call it /dev/sda2) and the logical partition (let's call it /dev/sda5), then delete both partitions, then recreate them with the same starting sector. The last sector of both /dev/sda2 and /dev/sda5 should be the last sector of the disk.
Since this is a risky procedure I recommend doing a backup of the virtual machine before attempting it.
Here are the instructions I always use when I'm doing the same thing...
Do “fdisk –l /dev/sda” I’m assuming /dev/sda2 is your LVM partition
and you don’t have a /dev/sda3. Adjust the instructions to match your config.
1) Make sure you have expanded the VM disk.
2) do “fdisk /dev/sda”
p (to see existing partitions)
n (new partition)
p (primary partition) -- give it the next available partition number, probably 3
accept the defaults. It will use the rest of the disk
w (write changes)
3) REBOOT
4) run ‘pvcreate /dev/sda3’
5) run ‘vgdisplay’ to get the name of the volume group. In this example, it’s “VolGroup”, as in:
6) run vgextend VolGroup /dev/sda3
7) run “df” to see the name of the root volume group.
8) run lvextend /dev/mapper/VolGroup-lv_root -r -l+100%FREE
( the (-r) option causes it to format it, too)
9 run “df –h” to see your new disk space
This is one of the reasons I prefer to have one big physical volume on the VMs that is separate from the /boot and other initial parts. This allows you to create a whole disk as an LVM physical disk (pvcreate /dev/sdb). Then if you need to do a resize, none of the file system changes need to happen because it is directly on disk.
In that scenario, you simply run pvresize /dev/sdb and move on with your vgextend, lvextend and resize2fs. Much simpler to maintain.
Personally I followed the instruction in this blog.
To summarize the steps:
Increase the virtual disk size using the vm-ware tools vmware-vdiskmanager
Boot on another system (GParted live CD or mount an Iso CD-ROM to boot on)
Use the Gparted tools (easy and graphic interface) to increase the recently expended drive
remove the CD-ROM (or the ISO) and boot on the original partition.
For expanding my Linux VM (RedHat EL 6) I did boot on the GParted ISO image (from here) and I was able to extend the partition I wanted. Note I had to move the partition I wanted unchanged at the end.
It was safe with one of my colleague as well, but I would recommand to backup the VM before running Gparted Linux.
extend disk without reboot
echo 1 > /sys/block/sda/device/rescan
echo 1 > /sys/block/sdb/device/rescan
partprobe
gdisk fix warnging
parted change partion size
## parted can executed as command line. but this is very dangerous
parted -s /dev/sdb "resizepart 2 -1" quit
parted -s /dev/sdb "resizepart 3 100%" quit
resizepart 3 100%
pvresize /dev/sda3
lvextend -l +100%FREE cs/root
xfs_growfs /dev/cs/root