Pages

Wednesday, January 31, 2018

Create and configure Linux Partition on VM

Lets discuss how can we add a new partition on Linux VM.
1. First edit the settings on the VM and add harddisk,

2. Run fdisk -l. you can see a new /dev/sdb with what space you provided. it is still the Raw harddisk partition. We need to partition it and make it usable.

3. Assume that /dev/sdb is the new hdd we had, run the following commands,
[root@LINUX] # fdisk /dev/sdb
it'll ask a prompt, we should give n as option to create a new partition and mention the first and last cylinder for its size. then give w to write the partition table.

4. To verify the partition, run the fdisk -l, now it'll show the partition. assume /dev/sdb1 is the partition which we created now. now we should make the partition readable to linux. run the following command,
[root@LINUX] # mkfs -t ext4 /dev/sdb1


5. Now mount the partition manually to some partition. in my case i am going to create a separate var partition for my jenkins, so i ran the following commands,
[root@LINUX] #  mv /var /var-OLD
[root@LINUX] # mkdir /var
[root@LINUX] # mount /dev/sdb1 /var

6. To add this mount permantenly please add the entry to /etc/fstab file
[root@LINUX] # vi /etc/fstab

/dev/sdb1 /var ext4 defaults 0 0

7. Reboot your machine, you are all set.

FYI,
incase for jenkins, if you move /var to /var-OLD and create new partition. please do this step, else you'll not able to connect to the VM through SSH/Putty client. and start the sshd service.

[root@LINUX] # cp -fr /var-OLD/empty /var
[root@LINUX] # service sshd status

No comments:

Post a Comment