Results 1 to 5 of 5
I want to create a script that will:
Create a Virtual Group and name it 00 Create the following logical volumes: /usr /opt /bin /tmp
Format the Logical Volumes (ext)
...
- 12-22-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
BASH script to automate a process
I want to create a script that will:
- Create a Virtual Group and name it 00
- Create the following logical volumes:
- /usr
- /opt
- /bin
- /tmp
Format the Logical Volumes (ext)
and finally, mount the Logical Volumes
But, I'm not really sure if that would be too effective.Code:I was thinking something like: white true; do cd / mkdir /usr mount usr_lv /usr done
- 12-23-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
Hey,
Before you script this, you need to figure out how to perform the individual commands that perform each step. You need the lvm/lvm2 package installed, thought the exact package depends on your distro. Once you get it installed (e.g. on fedora, "yum install lvm2", start off with reading the man pages of the lv*/pv*/vg* commands (e.g., man vgdisplay).
It's not too complicated, and you can probably find a good tutorial by googling. Just be sure to practice on a system you don't care about hosing!
Once you know the commands, just stick them in your bash script. You won't need a while loop, just do the commands. Your basic order (leaving some details out) might be:
It's a good idea to do error checking when scripting, too.Code:#!/bin/sh pvcreate ... vgcreate ... lvcreate ... mkfs.ext3 ... mkdir ... mount -t ext3 ....
Why must it be scripted? Is this some sort of automated procedure? Just be careful throwing around disk-wiping commands in your scripts! Lots of error checking is in order...Last edited by atreyu; 12-23-2011 at 03:55 AM. Reason: typo
- 12-27-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
Sorry for the late reply. I was busy with some holidays.
Thanks for the suggestions, I'm sure it will prove to be useful, as your posts usually are. The reason why I want to script this is so that I can put it in our VMWare template and if there is some sort of catastrophic incident we will be able to get things going quicker without having to try to remember certain commands.
- 12-27-2011 #4Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
How does this look?
Code:#!/bin/sh # create the primary partition # Device Boot Start End Blocks ID System # /dev/sdb1 1 1 63+ 83 Linux # /dev/sdb2 1 1 5248799+ 8e Linux # fdisk /dev/sdb # n # Partition number: 1 # First Cylinder: 1 # Last Cylinder...: 63+ # # fdisk /dev/sdb # n # Partition number: 2 # First Cylinder: 1 # Last Cylinder...: 5248799+ # # fdisk /dev/sdb # n # Partition number: 3 # First Cylinder: <enter> # Last Cylinder...: 2096504+ # Create physical volume # pvcreate (partition) pvcreate /dev/sdb1 # pvdisplay (displays all physical volumes on system) # create the volume group # vgcreate (vg name) (partition) vgcreate rootvg /dev/sdb1 vgcreate vg00 /dev/sdb2 # create logical volumes # lvcreate -L (size) -n (name) (vggroupname) # (4megabytes) lvcreate -L 400 -n LogVol00 rootvg # (4gigabytes) lvcreate -L 4G -n LogVol00 rootvg # create the file system mkfs.ext3 /dev/rootvg/LogVol00 # Add an entry for new LV in /etc/fstab # Create a mount point for logical volume # mkdir /bin/foobar mkdir /home mkdir /opt mkdir /tmp mkdir /usr mkdir /var # mount logical volume # -a mounts all filesystems in /etc/fstab # -t indicates filesystem type (ext, smbfs...) mount –a cd /home df -h
Last edited by pauhn; 12-27-2011 at 06:26 PM. Reason: updated script
- 12-28-2011 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
It looks to me like you pretty much nailed the lvm commands. It seems like portions of your code are missing, though - at least the portion that does the actual partitioning of the device. You can use sfdisk in this way, e.g.:
man sfdisk for more details.Code:# write the current partition table to file sfdisk -d /dev/sda > sda.out # write the contents of the file back to the partition table sfdisk /dev/sda < sda.out
Last edited by atreyu; 12-28-2011 at 01:57 AM. Reason: typo


Reply With Quote