20BCA1177 (Roshan Kumar) Linux EXP-2
20BCA1177 (Roshan Kumar) Linux EXP-2
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.
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.
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.
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
Output answer 4
Learning outcomes (What I have learnt):
a) Formatting disk
b) Swapping command
c) Partitioning of disk
Evaluation Grid: