How to create a partition of a running instance of AWS?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm running an EC2 instance in AWS with 12 GB volume attached to it. The OS is Ubuntu. I want to create a partition of 2GB from this 12GB volume.
So, here is the output of sudo fdisk -l
:
$ sudo fdisk -l
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x89cdb65f
Device Boot Start End Sectors Size Id Type
/dev/xvda1 * 2048 25165790 25163743 12G 83 Linux
How to create a partition without deleting the OS? To be exact how to create a partition from xvda1
and how to decide first and last sector values?
linux ubuntu partition disk aws
add a comment |Â
up vote
1
down vote
favorite
I'm running an EC2 instance in AWS with 12 GB volume attached to it. The OS is Ubuntu. I want to create a partition of 2GB from this 12GB volume.
So, here is the output of sudo fdisk -l
:
$ sudo fdisk -l
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x89cdb65f
Device Boot Start End Sectors Size Id Type
/dev/xvda1 * 2048 25165790 25163743 12G 83 Linux
How to create a partition without deleting the OS? To be exact how to create a partition from xvda1
and how to decide first and last sector values?
linux ubuntu partition disk aws
Please don't post images of text, if you can just copy and paste the terminal output.
â Hunter.S.Thompson
Jan 31 at 9:58
Run fdisk /dev/xvda and then select the option to create a new partition.
â Raman Sailopal
Jan 31 at 10:01
Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition."
â Masud Shaik
Jan 31 at 10:28
How to decide first and last sector ?
â Masud Shaik
Jan 31 at 10:36
The first sector of the new partition remains the same (so enter 2048 when prompted).fdisk
allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size.
â mjturner
Feb 2 at 6:46
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm running an EC2 instance in AWS with 12 GB volume attached to it. The OS is Ubuntu. I want to create a partition of 2GB from this 12GB volume.
So, here is the output of sudo fdisk -l
:
$ sudo fdisk -l
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x89cdb65f
Device Boot Start End Sectors Size Id Type
/dev/xvda1 * 2048 25165790 25163743 12G 83 Linux
How to create a partition without deleting the OS? To be exact how to create a partition from xvda1
and how to decide first and last sector values?
linux ubuntu partition disk aws
I'm running an EC2 instance in AWS with 12 GB volume attached to it. The OS is Ubuntu. I want to create a partition of 2GB from this 12GB volume.
So, here is the output of sudo fdisk -l
:
$ sudo fdisk -l
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x89cdb65f
Device Boot Start End Sectors Size Id Type
/dev/xvda1 * 2048 25165790 25163743 12G 83 Linux
How to create a partition without deleting the OS? To be exact how to create a partition from xvda1
and how to decide first and last sector values?
linux ubuntu partition disk aws
edited Feb 1 at 5:19
galoget
36319
36319
asked Jan 31 at 9:49
Masud Shaik
62
62
Please don't post images of text, if you can just copy and paste the terminal output.
â Hunter.S.Thompson
Jan 31 at 9:58
Run fdisk /dev/xvda and then select the option to create a new partition.
â Raman Sailopal
Jan 31 at 10:01
Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition."
â Masud Shaik
Jan 31 at 10:28
How to decide first and last sector ?
â Masud Shaik
Jan 31 at 10:36
The first sector of the new partition remains the same (so enter 2048 when prompted).fdisk
allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size.
â mjturner
Feb 2 at 6:46
add a comment |Â
Please don't post images of text, if you can just copy and paste the terminal output.
â Hunter.S.Thompson
Jan 31 at 9:58
Run fdisk /dev/xvda and then select the option to create a new partition.
â Raman Sailopal
Jan 31 at 10:01
Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition."
â Masud Shaik
Jan 31 at 10:28
How to decide first and last sector ?
â Masud Shaik
Jan 31 at 10:36
The first sector of the new partition remains the same (so enter 2048 when prompted).fdisk
allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size.
â mjturner
Feb 2 at 6:46
Please don't post images of text, if you can just copy and paste the terminal output.
â Hunter.S.Thompson
Jan 31 at 9:58
Please don't post images of text, if you can just copy and paste the terminal output.
â Hunter.S.Thompson
Jan 31 at 9:58
Run fdisk /dev/xvda and then select the option to create a new partition.
â Raman Sailopal
Jan 31 at 10:01
Run fdisk /dev/xvda and then select the option to create a new partition.
â Raman Sailopal
Jan 31 at 10:01
Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition."
â Masud Shaik
Jan 31 at 10:28
Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition."
â Masud Shaik
Jan 31 at 10:28
How to decide first and last sector ?
â Masud Shaik
Jan 31 at 10:36
How to decide first and last sector ?
â Masud Shaik
Jan 31 at 10:36
The first sector of the new partition remains the same (so enter 2048 when prompted).
fdisk
allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size.â mjturner
Feb 2 at 6:46
The first sector of the new partition remains the same (so enter 2048 when prompted).
fdisk
allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size.â mjturner
Feb 2 at 6:46
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
All space available in your volume /dev/xvda
is already used up by partition /dev/xvda1
.
If a filesystem (and data) exists on the volume, but unused space is available at the end of the file system, first shrink the file system using resize2fs <device> <size>
, e.g. resize2fs /dev/xvda 2G
.
Then use fdisk
to reduce end of partition /dev/xvda1
to match the new size of the file system placed on this partition (here: reduce by 2G).
Now you can create a new partition, e.g. /dev/xvda2
, using the free space at the end of the volume.
Start of the second partition will be end of the first partition + 1.
End of the second partition depends on your needs, e.g. the number of available sectors (here: 25165824).
Note: In a virtualized environment, I recommend placing only one disk partition per disk device/volume. This makes later changes much easier, e.g. if file system/disk partition must get increased for any reason.
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
@MasudShaik As the filesytem is on the partition, you need to use/dev/xvda1
and not/dev/xvda
when callingresize2fs
. Can you try that and let us know the results.
â mjturner
Feb 1 at 10:41
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
Ah yes - I had forgotten thatresize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.
â mjturner
Feb 2 at 6:53
add a comment |Â
up vote
0
down vote
As the discussion has shown, there isnâÂÂt an easy way to shrink the root file system of a running system (resize2fs
doesnâÂÂt support it). You have two options:
- If the VM canâÂÂt be restarted, youâÂÂll need to do an online resize (see, for example, this answer).
- If the VM can be restarted and can have a period of downtime for the resize, the better approach is to take a snapshot of the EBS volume, mount it on another VM and use that VM to resize it. There is a good guide in this answer.
Regarding your question about the first and last sectors - the first sector of partition 1 remains 2048 (ie enter 2048 when prompted) and fdisk
will calculate the last sector number based on the partition size you enter (eg, if you specify a partition size of 2GiB it will calculate the last sector automatically for you).
As others have suggested, having a single partition per EBS volume does make management easier, so you may want to take the opportunity to do that while youâÂÂre at it (ie, shrink the root EBS volume to 2GiB and add a second one of 10GiB instead of having a single partitioned volume).
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
All space available in your volume /dev/xvda
is already used up by partition /dev/xvda1
.
If a filesystem (and data) exists on the volume, but unused space is available at the end of the file system, first shrink the file system using resize2fs <device> <size>
, e.g. resize2fs /dev/xvda 2G
.
Then use fdisk
to reduce end of partition /dev/xvda1
to match the new size of the file system placed on this partition (here: reduce by 2G).
Now you can create a new partition, e.g. /dev/xvda2
, using the free space at the end of the volume.
Start of the second partition will be end of the first partition + 1.
End of the second partition depends on your needs, e.g. the number of available sectors (here: 25165824).
Note: In a virtualized environment, I recommend placing only one disk partition per disk device/volume. This makes later changes much easier, e.g. if file system/disk partition must get increased for any reason.
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
@MasudShaik As the filesytem is on the partition, you need to use/dev/xvda1
and not/dev/xvda
when callingresize2fs
. Can you try that and let us know the results.
â mjturner
Feb 1 at 10:41
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
Ah yes - I had forgotten thatresize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.
â mjturner
Feb 2 at 6:53
add a comment |Â
up vote
0
down vote
All space available in your volume /dev/xvda
is already used up by partition /dev/xvda1
.
If a filesystem (and data) exists on the volume, but unused space is available at the end of the file system, first shrink the file system using resize2fs <device> <size>
, e.g. resize2fs /dev/xvda 2G
.
Then use fdisk
to reduce end of partition /dev/xvda1
to match the new size of the file system placed on this partition (here: reduce by 2G).
Now you can create a new partition, e.g. /dev/xvda2
, using the free space at the end of the volume.
Start of the second partition will be end of the first partition + 1.
End of the second partition depends on your needs, e.g. the number of available sectors (here: 25165824).
Note: In a virtualized environment, I recommend placing only one disk partition per disk device/volume. This makes later changes much easier, e.g. if file system/disk partition must get increased for any reason.
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
@MasudShaik As the filesytem is on the partition, you need to use/dev/xvda1
and not/dev/xvda
when callingresize2fs
. Can you try that and let us know the results.
â mjturner
Feb 1 at 10:41
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
Ah yes - I had forgotten thatresize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.
â mjturner
Feb 2 at 6:53
add a comment |Â
up vote
0
down vote
up vote
0
down vote
All space available in your volume /dev/xvda
is already used up by partition /dev/xvda1
.
If a filesystem (and data) exists on the volume, but unused space is available at the end of the file system, first shrink the file system using resize2fs <device> <size>
, e.g. resize2fs /dev/xvda 2G
.
Then use fdisk
to reduce end of partition /dev/xvda1
to match the new size of the file system placed on this partition (here: reduce by 2G).
Now you can create a new partition, e.g. /dev/xvda2
, using the free space at the end of the volume.
Start of the second partition will be end of the first partition + 1.
End of the second partition depends on your needs, e.g. the number of available sectors (here: 25165824).
Note: In a virtualized environment, I recommend placing only one disk partition per disk device/volume. This makes later changes much easier, e.g. if file system/disk partition must get increased for any reason.
All space available in your volume /dev/xvda
is already used up by partition /dev/xvda1
.
If a filesystem (and data) exists on the volume, but unused space is available at the end of the file system, first shrink the file system using resize2fs <device> <size>
, e.g. resize2fs /dev/xvda 2G
.
Then use fdisk
to reduce end of partition /dev/xvda1
to match the new size of the file system placed on this partition (here: reduce by 2G).
Now you can create a new partition, e.g. /dev/xvda2
, using the free space at the end of the volume.
Start of the second partition will be end of the first partition + 1.
End of the second partition depends on your needs, e.g. the number of available sectors (here: 25165824).
Note: In a virtualized environment, I recommend placing only one disk partition per disk device/volume. This makes later changes much easier, e.g. if file system/disk partition must get increased for any reason.
edited Jan 31 at 16:03
answered Jan 31 at 15:57
Gerd Prümm
263
263
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
@MasudShaik As the filesytem is on the partition, you need to use/dev/xvda1
and not/dev/xvda
when callingresize2fs
. Can you try that and let us know the results.
â mjturner
Feb 1 at 10:41
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
Ah yes - I had forgotten thatresize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.
â mjturner
Feb 2 at 6:53
add a comment |Â
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
@MasudShaik As the filesytem is on the partition, you need to use/dev/xvda1
and not/dev/xvda
when callingresize2fs
. Can you try that and let us know the results.
â mjturner
Feb 1 at 10:41
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
Ah yes - I had forgotten thatresize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.
â mjturner
Feb 2 at 6:53
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock."
â Masud Shaik
Jan 31 at 23:42
@MasudShaik As the filesytem is on the partition, you need to use
/dev/xvda1
and not /dev/xvda
when calling resize2fs
. Can you try that and let us know the results.â mjturner
Feb 1 at 10:41
@MasudShaik As the filesytem is on the partition, you need to use
/dev/xvda1
and not /dev/xvda
when calling resize2fs
. Can you try that and let us know the results.â mjturner
Feb 1 at 10:41
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
@mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported "
â Masud Shaik
Feb 2 at 1:55
Ah yes - I had forgotten that
resize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.â mjturner
Feb 2 at 6:53
Ah yes - I had forgotten that
resize2fs
doesnâÂÂt support online shrinking. There are ways to work around it but they are risky - see this answer.â mjturner
Feb 2 at 6:53
add a comment |Â
up vote
0
down vote
As the discussion has shown, there isnâÂÂt an easy way to shrink the root file system of a running system (resize2fs
doesnâÂÂt support it). You have two options:
- If the VM canâÂÂt be restarted, youâÂÂll need to do an online resize (see, for example, this answer).
- If the VM can be restarted and can have a period of downtime for the resize, the better approach is to take a snapshot of the EBS volume, mount it on another VM and use that VM to resize it. There is a good guide in this answer.
Regarding your question about the first and last sectors - the first sector of partition 1 remains 2048 (ie enter 2048 when prompted) and fdisk
will calculate the last sector number based on the partition size you enter (eg, if you specify a partition size of 2GiB it will calculate the last sector automatically for you).
As others have suggested, having a single partition per EBS volume does make management easier, so you may want to take the opportunity to do that while youâÂÂre at it (ie, shrink the root EBS volume to 2GiB and add a second one of 10GiB instead of having a single partitioned volume).
add a comment |Â
up vote
0
down vote
As the discussion has shown, there isnâÂÂt an easy way to shrink the root file system of a running system (resize2fs
doesnâÂÂt support it). You have two options:
- If the VM canâÂÂt be restarted, youâÂÂll need to do an online resize (see, for example, this answer).
- If the VM can be restarted and can have a period of downtime for the resize, the better approach is to take a snapshot of the EBS volume, mount it on another VM and use that VM to resize it. There is a good guide in this answer.
Regarding your question about the first and last sectors - the first sector of partition 1 remains 2048 (ie enter 2048 when prompted) and fdisk
will calculate the last sector number based on the partition size you enter (eg, if you specify a partition size of 2GiB it will calculate the last sector automatically for you).
As others have suggested, having a single partition per EBS volume does make management easier, so you may want to take the opportunity to do that while youâÂÂre at it (ie, shrink the root EBS volume to 2GiB and add a second one of 10GiB instead of having a single partitioned volume).
add a comment |Â
up vote
0
down vote
up vote
0
down vote
As the discussion has shown, there isnâÂÂt an easy way to shrink the root file system of a running system (resize2fs
doesnâÂÂt support it). You have two options:
- If the VM canâÂÂt be restarted, youâÂÂll need to do an online resize (see, for example, this answer).
- If the VM can be restarted and can have a period of downtime for the resize, the better approach is to take a snapshot of the EBS volume, mount it on another VM and use that VM to resize it. There is a good guide in this answer.
Regarding your question about the first and last sectors - the first sector of partition 1 remains 2048 (ie enter 2048 when prompted) and fdisk
will calculate the last sector number based on the partition size you enter (eg, if you specify a partition size of 2GiB it will calculate the last sector automatically for you).
As others have suggested, having a single partition per EBS volume does make management easier, so you may want to take the opportunity to do that while youâÂÂre at it (ie, shrink the root EBS volume to 2GiB and add a second one of 10GiB instead of having a single partitioned volume).
As the discussion has shown, there isnâÂÂt an easy way to shrink the root file system of a running system (resize2fs
doesnâÂÂt support it). You have two options:
- If the VM canâÂÂt be restarted, youâÂÂll need to do an online resize (see, for example, this answer).
- If the VM can be restarted and can have a period of downtime for the resize, the better approach is to take a snapshot of the EBS volume, mount it on another VM and use that VM to resize it. There is a good guide in this answer.
Regarding your question about the first and last sectors - the first sector of partition 1 remains 2048 (ie enter 2048 when prompted) and fdisk
will calculate the last sector number based on the partition size you enter (eg, if you specify a partition size of 2GiB it will calculate the last sector automatically for you).
As others have suggested, having a single partition per EBS volume does make management easier, so you may want to take the opportunity to do that while youâÂÂre at it (ie, shrink the root EBS volume to 2GiB and add a second one of 10GiB instead of having a single partitioned volume).
answered Feb 2 at 7:05
mjturner
3,8681224
3,8681224
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420890%2fhow-to-create-a-partition-of-a-running-instance-of-aws%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Please don't post images of text, if you can just copy and paste the terminal output.
â Hunter.S.Thompson
Jan 31 at 9:58
Run fdisk /dev/xvda and then select the option to create a new partition.
â Raman Sailopal
Jan 31 at 10:01
Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition."
â Masud Shaik
Jan 31 at 10:28
How to decide first and last sector ?
â Masud Shaik
Jan 31 at 10:36
The first sector of the new partition remains the same (so enter 2048 when prompted).
fdisk
allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size.â mjturner
Feb 2 at 6:46