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

lsblk

nvme0n1   80G disk

--ncme01n1p1   80G  part /


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

/etc/fstab

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

Dan

Linux* Disk partitioningRedhatShell Scripting

Avatar of undefined
Last Comment
Yujin Boby

8/22/2022 - Mon
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. 
arnold

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.
ASKER CERTIFIED SOLUTION
Yujin Boby

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23