Vous êtes sur la page 1sur 5

SOP for Managing Partitions, File Systems and Persistent Mounts on a Linux

Title:
System
Prepared By: Mohd Nazri Bin Mazlan

A) Creating GPT disk partitions

There are 8 steps required to create a GPT-style partition.

1. Specify the disk device that used to create a new partition. Execute gdisk command and specify the
disk device name as an argument.

[root@iridium ~]# gdisk /dev/sdb


GPT fdisk (gdisk) version 0.8.6

Partition table scan:


MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.

2. Request a new partition. Enter n to create a new partition.

Command (? for help): n

3. Specify the partition number. It serves as the identification number of the partition on the disk for
use in future partition operations. Default value is the lowest unused partition number.

Partition number (1-128, default 1): 1

4. Specify the disk location that the new partition will start from. Gdisk allow two different input types,
first input type is an absolute disk sector number representing the first sector of the new partition. The
second input type indicates the partition’s starting sector by its position relative to the first or last
sector of the first contiguous block of free sectors on the disk. Using this relative sector position
format, input specified in units of KiB, MiB, GiB, TiB or PiB.

First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: 2048

5. Specify the last sector on the disk which shows the end of the new partition. The default value is the
last of the available unallocated sectors contiguous to the new partition’s first sector. As an example, a
value of +5G signifies an ending partition position that is 5GiB after the first sector.

Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +5G

6. Define partition type. As per default, a new partition created by gdisk is with type Linux file system.
We can choose different partition type by enter the corresponding hex code. A table of hex codes for
all partition types can be displayed with L command.

Current type is 'Linux filesystem'


Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap
a902 NetBSD FFS a903 NetBSD LFS a904 NetBSD concatenated
a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot
af00 Apple HFS/HFS+ af01 Apple RAID af02 Apple RAID offline

1|P a g e
SOP for Managing Partitions, File Systems and Persistent Mounts on a Linux
Title:
System
Prepared By: Mohd Nazri Bin Mazlan

af03 Apple label af04 AppleTV recovery af05 Apple Core Storage
be00 Solaris boot bf00 Solaris root bf01 Solaris /usr & Mac Z
bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var
bf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1
bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4
bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service
ed00 Sony system partitio ef00 EFI System ef01 MBR partition scheme
ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved
fc00 VMWare kcore crash p fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'

7. Save partition table changes. Issue the w command to finalize the partition creation request by
writing the changes to the disk’s partition table. Enter y for a final confirmation.

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y


OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

8. Initiate a kernel re-read of the new partition table. Run partprobe command with the disk device
name as an argument to force a re-read of its partition table.

[root@iridium ~]# partprobe /dev/sdb

B) Removing GPT disk partitions

There are 5 steps required to remove a partition from a disk with GPT partitioning scheme.

1. Specify the disk which contains the partition to be removed.

[root@iridium ~]# gdisk /dev/sdb


GPT fdisk (gdisk) version 0.8.6

Partition table scan:


MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

2. Identify the partition number of the partition to be deleted. Press p to print the partition table. Do
note the number in number field for the partition to be deleted.

Command (? for help): p


Disk /dev/sdb: 54525952 sectors, 26.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 02783418-1BF2-4BC4-B3BF-2F5D6583E7E5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 54525918
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number Start (sector) End (sector) Size Code Name

2|P a g e
SOP for Managing Partitions, File Systems and Persistent Mounts on a Linux
Title:
System
Prepared By: Mohd Nazri Bin Mazlan

1 2048 54525918 26.0 GiB 8E00 Linux LVM

3. Request for partition deletion.

Command (? for help): d


Using 1

4. Save the partition changes.

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y


OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

5. Initiate a kernel re-read of the new partition table. Run partprobe command with the disk device
name as an argument to force a re-read of its partition table.

[root@iridium ~]# partprobe /dev/sdb

C) Creating File Systems

After a block device has been created, next step is applying a file system format to it. A file system
applies a structure to the block device so that data can be stored and retrieved from it.

1. Verify the new partition as per step 8 (Creating GPT disk partitions).

[root@iridium ~]# gdisk /dev/sdb


GPT fdisk (gdisk) version 0.8.6

Partition table scan:


MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p


Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 384D43B0-D8BF-42D2-8055-B3FEC7EB2BBA
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 31457213 sectors (15.0 GiB)

Number Start (sector) End (sector) Size Code Name


1 2048 10487807 5.0 GiB 8300 Linux filesystem

Command (? for help): i


Using 1
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 5BD70F7E-B98C-4380-8A37-079803607D43
First sector: 2048 (at 1024.0 KiB)
Last sector: 10487807 (at 5.0 GiB)

3|P a g e
SOP for Managing Partitions, File Systems and Persistent Mounts on a Linux
Title:
System
Prepared By: Mohd Nazri Bin Mazlan

Partition size: 10485760 sectors (5.0 GiB)


Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'

2. The mkfs command is used to apply a file system to a block device. If no type is specified, an
extended type two (ext2) file system will be used. Specify the file system type with option -t.

[root@iridium ~]# mkfs -t xfs /dev/sdb1 or mkfs.xfs /dev/sdb1


meta-data=/dev/sdb1 isize=256 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

D) Mounting File Systems

Once the file system format has been applied, next is to attach the new file system into the directory
structure. When the file system is attached into the directory hierarchy, user space utilities can access
or write files on the device.

1. Mount /dev/sdb1 to /mnt directory.

[root@iridium ~]# mount /dev/sdb1 /mnt

2. Verify the currently mounted file systems, the mount points and options.

[root@iridium ~]# mount | grep sdb1


/dev/sdb1 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

3. Create a test file and added it inside the newly mounted file systems.

[root@iridium ~]# echo "testing" > /mnt/testing.txt


[root@iridium ~]# ls -l /mnt
total 4
-rw-r--r--. 1 root root 8 Jul 20 14:38 testing.txt
[root@iridium ~]# cat /mnt/testing.txt
testing

4. If the file systems required to persistently mounted, a listing for the file systems need to be added to
/etc/fstab. By adding a listing for a device into /etc/fstab file, we can configure a device to be mounted
to a mount point at system boot. Note that /etc/fstab is a white space-delimited file with six fields per
line. The first field specifies the device to be used (eg: the device UUID or the block device path). The
second field is the mount point where the device should be attached into the directory hierarchy. The
third field contains the file system type that has been applied to the block device. The fourth field is the
list of options that should be applied to the device when mounted to customize the behaviour (eg: a
commonly used option is defaults). The last two fields are dump flag and fsck order, dump flag is used
with the dump command to make a backup of the contents of the device, while fsck order determines if
fsck should be run at boot time, in the event that the file system was not mounted cleanly. The value of
the fsck order indicates the order in which file systems should have fsck run on them if multiple file
systems are required to be checked.

[root@iridium ~]# cat /etc/fstab

4|P a g e
SOP for Managing Partitions, File Systems and Persistent Mounts on a Linux
Title:
System
Prepared By: Mohd Nazri Bin Mazlan

#
# /etc/fstab
# Created by anaconda on Fri May 12 09:53:09 2017
#
# 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
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=dcdf59f9-bd90-4175-9e65-6eb56a2cf523 /boot xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0

4.1 Scan the block devices connected to a machine using blkid command.

[root@iridium ~]# blkid /dev/sdb1


/dev/sdb1: UUID="2de62966-8b03-4b15-b38d-63f4776c5c7b" TYPE="xfs" PARTLABEL="Linux
filesystem" PARTUUID="5bd70f7e-b98c-4380-8a37-079803607d43"

4.2 Adding a listing of /dev/sdb1 to /etc/fstab. Refer to step 4 (Mounting File Systems) for the
descriptions.

[root@iridium ~]# vi /etc/fstab


#
# /etc/fstab
# Created by anaconda on Fri May 12 09:53:09 2017
#
# 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
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=dcdf59f9-bd90-4175-9e65-6eb56a2cf523 /boot xfs defaults
0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
UUID=2de62966-8b03-4b15-b38d-63f4776c5c7b /mnt xfs defaults 0 0

4.3 Verify the entry in /etc/fstab by unmounting the new file system and following below commands.
If the mount –a command returns an error, it should be corrected before rebooting the machine.

[root@iridium ~]# mount -a

[root@iridium ~]# df -h /mnt


Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 5.0G 33M 5.0G 1% /mnt

5|P a g e

Vous aimerez peut-être aussi