0% found this document useful (0 votes)
22 views

20BCA1177 (Roshan Kumar) Linux EXP-2

semester-4

Uploaded by

RK HealingPower
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

20BCA1177 (Roshan Kumar) Linux EXP-2

semester-4

Uploaded by

RK HealingPower
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Experiment 2

Student Name: Roshan Kumar UID: 20BCA1177


Branch: BCA Section/Group:3/A
Semester: 4 Date of Performance:22/02/2022
Subject Name: Linux Administration Lab
Subject Code: 22E-20CAP-256

1. Aim/Overview of the practical:


Adding Disks, Partitions, and File Systems to a Linux System.

a. Create, remove, and resize various types of partitions through command line using
fdisk, gdisk, mkfs, mount.
b. Swapping: Managing swap spaces as well as swap file.

2. Task to be done:
1. Write a command used to display existing partitions and sizes using 2 different
commands. After than compare the outputs of both. After this create a new 400MB
primary partition and 2 extended partition under that primary partition and check whether
both partitions are created or not.

2. Write a command that can (possibly) be used to format a partition. Write a command to
add a swap partition of size 200MB and show the purpose of using Partprobe.

3. Create a file system partition of 60GB and mount the partition on the data directory.
4. Create a swap partition of 4.5GB and turn on the newly created swap partition
temporarily.

3. Concept used:
Answer 1: Concept used while displaying existing partition and sizes are fdisk command or
lsblk command

Further we can create primary and extended partition using fdisk command and /dev/sda
directory and creating partition appropriate values.

Answer 2: we can format a partition using mkfs command in Linux for adding a swap
partition of any size we use the swapoff command in the terminal and protprobe is a
program that inform the operating system kernel of partition table changes, by requesting
that the re-read the partition table.

Answer 3: we will create file system partition using fdisk and then using mount command
we will mount they partition on the data directory.

Answer 4: creating swap partition we will use the command swap and by using swapon
command we would the swap file we can also view the created swap partition using
swapon /swapfile.

4. Steps/Commands involved to perform practical:

Steps of Answer 1
1. Open Linux terminal
2. Write fdisk –l to view the partitions
3. Select the partition using fdisk /dev/sda1
4. Disk Partitions displayed with details

We can also view Disk partitions using lsblk. it displays block devices, when used with
the -f option, it prints file system type on partitions as well
now Creating primary partition and 2 extended partitions
1. Verify the partitions available on the server: fdisk -l
2. Choose which device you wish to use (such as /dev/sda or /dev/sdb)
3. Run fdisk /dev/sdX (where X is the device you would like to add the partition to)
4. Type ‘n’ to create a new partition.
5. Specify where you would like the partition to end and start. You can set the
number of MB of the partition instead of the end cylinder. For example: 400M.
6. Type ‘p’ to view the partition, and type ‘w’ to save the partition

Steps of Answer 2
The lsblk command without additional options does not display information about the
devices’ file systems.
Formatting Disk Partition in Linux
There are three ways to format disk partitions using the mkfs command, depending on the
file system type:
●ext4
●FAT32
●NTFS
1. Format a disk partition with the ext4 file system using the following command:
sudo mkfs -t ext4 /dev/sdb1
2. Next, verify the file system change using the command:
3. lsblk -f the terminal prints out a list of block devices.
4. Locate the preferred partition and confirm that it uses the ext4 file system.

Partprobe is a program that informs the operating system kernel of partition table changes,
by requesting
that the operating system re-read the partition table.

Steps for adding a swap space


●Create a file that will be used for swap:
●sudo fallocate -l 200M /swapfile
●sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
●Only the root user should be able to write and read the swap file.
●sudo chmod 600 /swapfile
●Use the mkswap utility to set up the file as Linux swap area:
●sudo mkswap /swapfile
●Enable the swap with the following command:
●sudo swapon /swapfile
●To verify that the swap is active, use either the swapon

Steps for Answer 3


1. Create a Partition

You can check disk space using fdisk –l

2. Set Disk Label on the partition

You can use e2label command to set or change disk labels. The e2label command must
be run as root user.

3. Create a filesystem

In Linux, you can create filesystem using mkfs, mkfs. ext2, mkfs. ext3, mkfs. ext4, mke4fs
or mkfs.xfs commands. On RHEL and CentOS system you may install an additional
package called e4fsprogs which can manage ext4 filesystem.

4. Mounting a Filesystem

The most commonly used method for mounting the filesystem is either manually using
mount command or by adding entries in /etc/fstab file, so that filesystem gets mounted
during boot time.

5. Display Mount Information


You can run df -h or lsblk command to get mounted device information such as mount
point.

Steps for Answer 4

1. We will create a swap file of size 2GB using the dd command as follows. Note that
bs=1024 means read and write up to 1024 bytes at a time and count = (1024 x 2048) MB
size of the file.

2. Now setup the file for swap space with the mkwap command.

3. Next, enable the swap file and add it to the system as a swap file.

4. Afterwards, enable the swap file to be mounted at boot time. Edit the /etc/fstab file
and add the following line in it.

5. To set how often the swap file can be used by the kernel, open the /etc/sysctl.conf
file and add the line below.
6. Now verify the swap file was created using the swapon command.

5. Result/Output/Writing Summary:
Output of Answer 1
Viewing Disk Partition using fdisk command

Output of Answer 1
Viewing Disk partition using fdisk
comm
Viewing Disk partition using fsblk Command

Creating a primary partition and 2 extended partition under that primary


Confirming that Whether the partition Created or Not
Output of Answer 2

Formatting a disk using lsblk command

Output answer 4
Learning outcomes (What I have learnt):

a) Formatting disk
b) Swapping command
c) Partitioning of disk

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Worksheet 10
2. Demonstration/Performance /Pre 5
Lab Quiz
3. Post Lab Quiz 5

You might also like