Introduction:
Disk partitioning allows a hard drive to be divided into multiple logical storage units referred to as portions. By separating a disk into partitions, system administrators can use different partitions to perform different functions.
MBR partitioning scheme:
MBR is a scheme which supports a maximum of four primary partition. On Linux systems, with the use of extended and logical partitions, administrator can create a maximum of 15 partitions. Since partition size data are stored as 32-bit values, disk partitioned with the MBR scheme have a maximum disk and partition size limit of 2 TiB.
GPT partitioning scheme:
For systems running UEFI (Unified Extensible Firmware Interface) firmware, GPT is the standard for laying out partition table on physical hard disk. GPT is part of the UEFI standard and addresses many of the limitation imposed by the old MBR-based scheme. Per UEFI specification, GPT default to supporting up to size 128 partitions. Unlike MBR which use 32 bits address. This allows GPT to accommodate partitions and disks of up to 8 zebibyte(ZiB) or 8 billions tebibytes.
Creating disk partition
Step 1 – Create Disk Partitions fdisk /dev/sdc |
Command (m for help): n Command action e extended p primary partition (1-4) Partition number (1-4): 1 First sector (63-104857599, default 63): 2048 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +10G Save new partitioning table using w command. Command (m for help): w |
Step 2 – Format Disk Partitions mkfs -t ext4 /dev/sdc1 |
We can use any other file system type like: ext2, ext3, ext4, fat, vfat, ntfs etc. mkfs.ext4 /dev/sdc1 |
3. Mount/Unmount Partitions
Before mounting a disk, you are required to create a mount point. Then use the mount command to mound disk partition on a mount point. mkdir /newDisk1 mount /dev/sdc1 /newDisk1 |
Now use one of following command to verify disk is mounted successfully. mount | grep “/dev/sdc1” df -h | grep “/dev/sdc1” |
4. Mount Disk on Startup
Use /etc/fstab file which is used for mounting disk partitions during system boot up. Add the following entry in /etc/fstab file at the end of file. /dev/sdc1 /newDisk1 ext3 defaults 0 2 |
1.To verify that the Linux kernel can see the partition, you can cat out /proc/partitions like this:
cat /proc/partitions |
2.Decide what kind of filesystem you want to create, such as ext4, XFS, or anything else. Here are a few options:
mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs |
3.For the purposes of this exercise, choose ext4. (I like ext4 because it allows you to shrink the filesystem if you need to, a thing that isn’t as straightforward with XFS.) Here’s how it can be done (the output may differ based on device name/sizes):
[root@asim ~]# mkfs.ext4 /dev/sda1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=8191 blocks 194688 inodes, 778241 blocks 38912 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=799014912 24 block groups 32768 blocks per group, 32768 fragments per group 8112 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done |
Mouting a file system
1.First, identify the UUID of your new filesystem. Issue the blkid command to list all known block storage devices and look for sda1 in the output:
[root@ asim ~]# blkid /dev/vda1: UUID=”716e713d-4e91-4186-81fd-c6cfa1b0974d” TYPE=”xfs” /dev/sr1: UUID=”2019-03-08-16-17-02-00″ LABEL=”config-2″ TYPE=”iso9660″ /dev/sda1: UUID=”wow9N8-dX2d-ETN4-zK09-Gr1k-qCVF-eCerbF” TYPE=”LVM2_member” /dev/mapper/test-test1: PTTYPE=”dos” /dev/sda1: UUID=”ac96b366-0cdd-4e4c-9493-bb93531be644″ TYPE=”ext4″ |
2.Run the following command to mount the /dev/sd1 device :
[root@ asim ~]# mkdir /mnt/mount_point_for_dev_sda1 [root@ asim ~]# ls /mnt/ mount_point_for_dev_sda1 |
[root@ asim ~]# mount -t ext4 /dev/sda1 /mnt/mount_point_for_dev_sda1/
[root@ asim ~]# df -h |
Filesystem Size Used Avail Use% Mounted on /dev/vda1 7.9G 920M 7.0G 12% / devtmpfs 443M 0 443M 0% /dev tmpfs 463M 0 463M 0% /dev/shm tmpfs 463M 30M 434M 7% /run tmpfs 463M 0 463M 0% /sys/fs/cgroup tmpfs 93M 0 93M 0% /run/user/0 /dev/sda1 2.9G 9.0M 2.7G 1% /mnt/mount_point_for_dev_sda1 |
Note:The df -h command shows which filesystem is mounted on which mount point. Look for /dev/sd1. The mount command above used the device name /dev/sda1. Substitute it with the UUID identified in the blkid command. Also, note that a new directory was created to mount /dev/sda1 under /mnt.
3.A problem with using the mount command directly on the command line (as in the previous step) is that the mount won’t persist across reboots. To mount the filesystem persistently, edit the /etc/fstab file to include your mount information:
UUID=ac96b366-0cdd-4e4c-9493-bb93531be644 /mnt/mount_point_for_dev_sda1/ ext4 defaults 0 0 |
4.After you edit /etc/fstab, you can umount /mnt/mount_point_for_dev_sda1 and run the command mount -a to mount everything listed in /etc/fstab. If everything went right, you can still list df -h and see your filesystem mounted:
root@ asim ~]# umount /mnt/mount_point_for_dev_sda1/ [root@ asim ~]# mount -a [root@ asim ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 7.9G 920M 7.0G 12% / devtmpfs 443M 0 443M 0% /dev tmpfs 463M 0 463M 0% /dev/shm tmpfs 463M 30M 434M 7% /run tmpfs 463M 0 463M 0% /sys/fs/cgroup tmpfs 93M 0 93M 0% /run/user/0 /dev/sda1 2.9G 9.0M 2.7G 1% /mnt/mount_point_for_dev_sda1 |
5.You can also check whether the filesystem was mounted:
[root@asim ~]# mount | grep ^/dev/sd /dev/sda1 on /mnt/mount_point_for_dev_sda1 type ext4 (rw,relatime,seclabel,stripe=8191,data=ordered) |