Link to home
Start Free TrialLog in
Avatar of Daniel Hamilton
Daniel Hamilton

asked on

shell script to create partitions on linux

I want to partition Amazon Linux 2 (similar to RHEL 7 or CentOS 7) server using shell script. I also wanted to create a root volume group with it

When I startup the server, 

I get following


nvme0n1   80G disk

--ncme01n1p1   80G  part /

I have tried modifying fstab directly with following, but that didnt work


UUID-xxxxxxxxxxxxxxxxxb  / xfs defaults,noatime 1 1

UUID-xxxxxxxxxxxxxxxxxb  / xfs defaults,noatime 1 2

UUID-xxxxxxxxxxxxxxxxxb  / xfs defaults,noatime 1 3

How can we create different partitions for /home , var , /var/log , etc

thank you


Avatar of noci

1)  partitions are Disk splitting methods.    /dev/sda1 /dev/sda2 /dev/sda3....  or nvme0n1p1 nvme0np2 ...
2)  /home, /var/log etc. are directories..
3)  volume groups are in another ball-park, namely Logical Volumes... 

What you want is carve the disk into partitions and then   (you need one to boot from) 500MB should be enough
the remaing part should become a physical volme, where you can create a Volume group and then carve logical volumes from the VG,
Finaly you can create filesystems on them and them have them mounted using /etc/fstab....

AFIACT, your complete disk (80GB) is in one partition. Shrinking partitions cannot be done.
The partitioning using fdisk / gdisk etc. needs to be done BEFORE the first install of the OS. Most installers have the option to setup disks to any shape & form you want.

For this please restart the initial startup.
If you want to continue on this disk you need to boot using some tool like partition magick, and use that to move data around to be able to shrink the volume. After that you can then createa a 2nd partition and format it using LVM.. (pvcreate, vgcreate, lvcreate )

Or Add a new storage device for all other stuff. 
A shell script is run after the OS is installed which is preceded by partitioning.

You should look at your option on whether you can create a template on whose basis Amazon will create the VM partitioned in a manner you prefer.
Avatar of Yujin Boby
Yujin Boby
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial