SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

redhatsimplepartitioning

Red Hat Simple Partitioning

This page is about the simple partitions you can configure on red hat. If you're looking for the fancy stuff look here (click for LVM info).

The only really cool thing about this is encryption, scroll down for that.

Creating a Simple Partition

First some basic information, partitions are made on disks and are used to make filesystems on so you can store data on it. On Red Hat, if you would use a physical system the first disk would be known as /dev/sda, the second one as /dev/sdb and so on. Virtual disks (if recognized as virtual disks) would be known as /dev/vda. Created partitions get a number right after the disk, so the first partition on the first virtual disk would be known as /dev/vda1.

In this article I'm not explaining the principles of primary and extended partitions, there are plenty resources about that on the internet.

Partitions are created using fdisk. Since fdisk is by default cylinder bound and red hat is not, you should ALWAYS start fdisk using the -cu option.

This is how I created a new simple partition on a new disk:

[root@localhost ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe2173873.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +1G

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe2173873

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Note that if you would do this on the system disk you would get a warning that the kernel can't reread the partition table. Red hats supported way to solve this is rebooting the system. You could also issue this command which works fine but is not supported:
partx -a /dev/sda

Now the partition is ready for creating a filesystem on it.

Create a FileSystem

You can create a filesystem very easy by issuing this command:

mkfs -t ext4 /dev/sdb1

This can also be done like this:

mkfs.ext4 /dev/sdb1

Now you need to mount the filesystem.

Mount a FileSystem

To mount a filesystem you first need a mountpoint, for example /data

mkdir /data

Now add the filesystem to /etc/fstab so it will mount automatically every time the system boots. For that you need the blockid/UUID of the device:

[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="692571db-cd24-4b41-80bd-73f595f70a17" TYPE="ext4"

Now add it to /etc/fstab:

[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Mar 17 02:25:20 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=57d2527c-66f3-46d8-a7b5-dd45be6169ab /                       ext4    defaults        1 1
UUID=be15d7c6-f4bf-4b0c-8ebb-a86aeb453ce8 /boot                   ext4    defaults        1 2
UUID=8f724c22-a198-4cf5-a58a-4aca739faeee swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID=692571db-cd24-4b41-80bd-73f595f70a17 /data ext4    defaults        1 2
Note that the 1 at the end of the line means it should be added to dump created backups, and the second one means it should be verified during startup.

Now you can mount and verify the mount like this:

[root@localhost ~]# mount /data
[root@localhost ~]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /data type ext4 (rw)

Or you could simply mount all filesystems with mount -a

Adding Storage on a Virtual VMware Guest

Issue these commands to scan scsi hostx bus for new devices:

[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[root@localhost ~]# fdisk -cul

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00056e47

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448    37748735    18566144   83  Linux
/dev/sda3        37748736    41943039     2097152   82  Linux swap / Solaris

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Note that I don't know on which host# the disk was assigned so I scanned a few…
You could leave a comment if you were logged in.
redhatsimplepartitioning.txt · Last modified: 2021/09/24 00:25 (external edit)