What is a Disk partition?
Disk Partition means dividing a single hard disk into multiple logical drives using partition editors such as fdisk, parted tools. Once a hard disk is divided into several partitions, directories and files of different categories may be stored in different partitions or locations.
Many new system admin creates only two partitions one is on /root and the second one is swap for the entire hard disk. So all directories like /bin, /usr, /var are created under the /root partition. Later on, there may be a need to create a new partition for these directories or for other mount points, so the admin should know how to create a new disk partition.
Partition Types:
►Primary Partition: The number of partitions was limited from the very beginning and we can have only four partitions now these partitions are called Primary partitions.
►Extended Partition: The extended partition is a way to overcome the limitation of the four primary partitions on a drive. Here you can create more than four partitions, You can create lots of partitions.
►Logical Partition: A logical partition is a partition that has been created inside of an extended partition
FileSystem:
Linux users make a distinction of the Filesystem stating that a filesystem is a programmatic scheme used to organize and find files on a partition. Whilst the file system refers to all the files on your computer.
What this essentially means is that the Filesystem is the structure used to see, find and use your files using Ubuntu, whilst the File System is both all the separate files in that structure and those files’ format.
File System | Operating System | Description |
---|---|---|
FAT | Legacy | Legacy File System that was universally adopted. Came in 12 FAT12, 16 FAT16, and 32 FAT32. |
NTFS | Windows | New Tech File System – replaced FAT on Windows systems. It is still needed to read Windows partitions. |
Ext2 | Linux | Second Extended filesystem – used by many Linux distros. |
Ext3 | Linux | Third Extended filesystem – default choice for Ubuntu distros. Journaling added. |
Ext4 | Linux | Fourth Extended filesystem – used by many Linux distros. Extends storage limits. |
JFS | Linux | Journaled File System – was introduced by IBM and is still supported but has been replaced by Ext4. |
XFS | Linux/Irix | 64bit option is mostly supported now as an option in Red Hat. |
ReiserFS | Linux/SUSE | This was a file format that was in use across several distros but has largely been replaced by Ext3. |
Similar: Linux User & Group Management
Linux Directories Partition
Directory Name | Content |
---|---|
/bin | Contains the common programs, shared by the system, the system administrator, and the users. |
/boot | This has the start-up files and the kernel, vmlinuz. In some recent distributions, it also has grub data. GRUB is the GRand Unified Boot Loader. |
/dev | Contains references to all the CPU peripheral hardware. They are represented as files with special properties. |
/etc | This has the most important system configuration files, this directory is similar to the control panel in Windows. |
/home | This is the home directory for the common users. |
/initrd | This contains information for booting in some distributions. Do Not Remove. |
/lib | This holds the library files, it includes files for all kinds of programs needed by the user. |
/lost+found | Every partition has a lost+found in its upper directory. Files that were saved during failures reside here. |
/misc | For miscellaneous uses. |
/mnt | Standard mount point for external files systems, such as media players, digital cameras, and CD ROMs. |
/net | Standard mount point for entire remote file systems. |
/opt | Typically this will have third-party software and any extra files required. |
/proc | This is a virtual files system containing information about system resources. You can get more information about the meaning of the files in proc by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail. |
/root | This is the system administrator user’s home directory. Remember there is a difference between / the root directory and /root the home directory of the root user. |
/sbin | This contains programs for use by the system administrator. |
/tmp | This is a temporary space for use by the system. It is regularly wiped so remember not to keep anything you want to retain here. |
/usr | This has programs, libraries, and documentation for all the user-related programs. |
/var | This is the storage for all the variable files and the temporary files created by users. Things like the log files, the mail queue, the print spooler area, space for the internet cache or to keep an image of a CD/DVD before burning it. |
Disk Partition:
Normally there are three types of partition:
►Normal(Physical) Partition: This is the primary partition. There are two ways to create a normal partition.
- MBR: This scheme supports a max of four partitions and eleven of the extended partition. It means we can create a max of 15 partitions. MBR allocated 32bit for logical partition and the max disk partition size limit is 2TB.
- GPT: GPT is standard for laying out a partition table on the physical hard disk. GPT is defaulted to support up to 128 partitions. GTP allocated 64bit and the max partition size is 8ZB.
►Swap Partition: A swap partition is an area of a disk that can be used with the Linux kernel memory management subsystem. Swap space is used to supplement the system RAM by holding inactive pages and services of memory. “In simple terms, we can use a part of the hard disk as RAM”
►LVM Partition: LVM is “dynamic partitions”, meaning that you can create/resize/delete LVM partitions(they’re called “Logical Volumes” in LVM-speak) from the command line while your Linux system is running: no need to reboot the system to make the kernel aware of the newly-created or resized partitions. Basically, it is created for future use.
Create a normal partition:
The first command to see the created partition is:
root@localhost:~#lsblk ##lsblk stands for list of blocks ##
Check the partition table using fdisk command.
Using fdisk command one can identify his device that whether it is your internal Hard disk or external hard disk.
/dev/sd(a,b,c)———–>SCSI
/dev/hd(a,b,c)———–>IDE
root@localhost:~# fdisk -l Disk /dev/sda: 26.8 GB, 26843545600 bytes 255 heads, 63 sectors/track, 3263 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 6 48163+ 83 Linux
/dev/sda2 7 515 4088542+ 83 Linux
/dev/sda3 516 3133 21029085 83 Linux
/dev/sda4 3134 3263 1044225 5 Extended
/dev/sda5 3134 3263 1044193+ 82 Linux swap / Solaris
we have seen that already partition up to /dev/sda5 has been created.
So now we have to create a new partion that will start from /dev/sda6
Before Partition we need to know about our hard disk in use. We use here some commands to know the detail information of hard disk we are using and we are going to partitioning.
root@localhost:~#cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: ATA Model: ST3160215AS Rev: 4.AA ------>> My hard Disk Type: Direct-Access ANSI SCSI revision: 05 Host: scsi4 Channel: 00 Id: 00 Lun: 00 Vendor: Kingston Model: DataTraveler G2 Rev: 1.00 ---->> My usb Device Type: Direct-Access ANSI SCSI revision: 02
We do partition or you can say disks are partitioned to make a separate File System according to our need.
root@localhost:~# fdisk /dev/sda The number of cylinders for this disk is set to 3263. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help):
note: here we have taken sda because fdisk -l shows us our hard disk is sda type, not hda or hdb.
:n this will create a new partition
:l this will create a logical partition
: just press enter to take the default
cylinder value.
:+2000M this means we want to create a partition of size 2GB approx ie 2000Mb.
:w write the changes and save them and exit
If You don’t want to reboot your Linux system for making updates for the changes you have made in the partition table above just use partprobe command.
root@localhost:~# partprobe
make a file system in Linux
Mkfs or mke2fs command is used to create a file system in Linux.
So Create an ext3 file system. (Make File System so that it get recognized by OS)
#mke2fs -j /dev/sda6
or
#mkfs -t ext3 /dev/sda6
or
#mkfs.ext3 /dev/sda6
This will format the /dev/sda6 partition and create a journal file system ext3 which can be recognized by our Linux operation System
Mount point
Now make a new directory and mount /dev/sda6 newly created partition on it. mount points is directories where file systems are mapped.
#mkdir /new #mount /dev/sda6 /new
Now above command will mount /dev/sda6 on /new directory.
So now whatever you write in the new directory will be saved in the newly created partition /dev/sda6
To verify whether the filesystem has been mounted or not.
#df -h
This will show you clearly that your /dev/sda6 is mounted on /new directory
Creating a Swap Partition:
root@localhost:~# lsblk root@localhost:~# fdisk /dev/vdb2 :n ## new partition ## :e ## extended ## :n ## new ## :l ## for logical partition ## :+1G ## size of partition in GB ## :t ## type of partition ## :5 ## partition number ## :82 ## Hex code for Swap partition ## :w ## for save ##
root@localhost:~# partprobe root@localhost:~# mkswap /dev/vdb2 ## To create file system ## root@localhost:~# swapon /dev/vdb2 ## for temporary mount ## root@localhost:~# free -m ## to check the swap partition ##
For permanent mount :
root@localhost:~# blkid /dev/vdb2 ## copy the block id of swap and past it in /etc/fstab file ## root@localhost:~# echo "UUID------- swap swap deafault 0 0" >> /etc/fstab
Deleting a Partition
First, unmount the partition and remove the entry from /etc/fstab u have made above
#umount /dev/sda6
Then use fdisk command to delete the partition
#fdisk /dev/sda:d here d is used to delete the partion:6 it means delete the partion /dev/sda6:w save the abve changes and exit
update change without a reboot.
#partprobe
Now check the partition table whether it is updated or not.
#fdisk -l
You will find /dev/sda6 has been deleted.
How do see the filesystem type creation command exists for your system?
root@localhost:~#
Pingback: What is Swap Partition and how to create it on Linux - Youngster Company
Pingback: What is LVM Partition and how to create it on Linux - Youngster Company