Linux Basics Tutorial 33-hard disk partitioning and mounting

Source: Internet
Author: User
Tags gpg


Mount command


 In the Windows system, if you insert a USB flash drive, a mobile hard disk, an optical drive, etc., as long as it can be recognized by the Windows system, the system will automatically mount and add the drive letter, then we can access, and all of this is done by the system, the user does not need to do anything to use. In Linux, though, some Linux systems have already done some automatic mounts, but most of them need to be mounted manually. This function is done by the command Mount and the umount command.


Mount command


 The Mount command is primarily used to load the file system to a specified mount point. Its basic syntax is as follows:


mount [options] [device name] [mount point]

 


The common options are as follows:


Options Description
-A,--all Mount all file systems in the/etc/fstab file
-F,--fork Often used with-A to increase mount speed when the system mounts a large number of NFS systems
-F,--fake Often used for troubleshooting, does not perform a real mount operation, only simulates the mount process and is often used with-V
-N,--no-mtab Do not write the load record to/etc/mtab, usually when the/etc directory is read-only
-R,--read-only Mount the file as read-only mode, with-o ro
-W,--RW,--read-write Mount the file as a readable writable mode, with-o RW, system default mode
-T,--types Vfstype Specifies the type of file system to mount, and if you do not specify this option, the default is auto
-O,--options opts Specify how mounts are mounted
-V,--version Display version Information
-V,--verbose Show more information


When using the mount command to mount, you need to confirm that the mount point must be an existing directory.

 


Where-T,--types commonly used file system formats are as follows:


File System Format Description
Ext2 Common file system formats for Linux systems
Ext3 Common file system formats for Linux systems
Ext4 Common file system formats for Linux systems
iso9660 Cd-row disc standard File system format
Vfat Windows FAT32 File System format
Xfs Common file system formats for Linux systems, supported in CentOS7
Nfs Network File System format
Ntfs Windows NTFS file system format, requires a separate installation package
Auto Automatically detect file system formats


Where-O,--options commonly used options are as follows:


Options Description
Atuo Allow use with-a
Noauto Not allowed with-a
Defaults Use default options: RW, suid, dev, exec, auto, Nouser, and Async
Ro Mount in read-only mode
rw Mount in read-write mode
Nouser Prohibit a user (root) from mounting a file system
Users Allow all users to mount and Unmount file systems
Owner Allow non-root mount, but the user must have all permissions for the device
Loop Mount in loop form


In Linux, there is a special device called loop device, which is a virtual block device formed by mapping normal files on the operating system. So we can create a mechanism for a virtual file system that exists in other files based on this device.

 Umount command 


The Umount function, in contrast to mount, is used primarily to unload a mounted file system, similar to deleting a USB flash drive in Windows, moving a hard disk, and so on. Its basic syntax is as follows


umount [options] [mount point]

 


The common options are as follows:


Options Description
-A Uninstall all file systems recorded in the/etc/mtab
-R If it cannot be uninstalled, it is re-mounted as read-only
-D If the uninstalled device is a loop device, release the loop device while uninstalling
-T Vfstype Uninstalls only file systems of the specified type
-F Forcibly uninstall
Hard Disk Partitioning command


? ? In Windows, if the system has increased the hard disk, can be recognized by the system, usually only need to select the corresponding hard disk in the Computer Management right-click to select the format. And how does Linux work? We introduce two formatted command fdisk and parted commands.


In practical applications, how to choose these two commands is determined by the capacity of the hard disk-if the hard disk capacity is less than 2TB, MBR is preferred, then use the fdisk command-if the hard disk capacity is greater than or equal to 2TB, you must select GPT, then use the parted command

 FDISK command 


The basic syntax is as follows:


fdisk [options] [device]

 


The common options are as follows:


Options Description
-H Display Help information
-L Displays the partition table information for the specified device, which displays the records in/proc/partitions by default, if no device is specified
-V Display version Information
-S partition Displays the specified device partition size


The Fdisk menu is commonly described as follows:


menu item Description
D Delete Partition table
L Show supported partition table types
M displaying menus and help information
N New Partition Table
P Show partition information
Q Exit does not save
V Partition Table Check
W Save partition table information and exit
parted command


The common syntax is as follows:


parted [options] [device] [command]

 


The common options are as follows:


Options Description
-H,--help Display Help information
-L,--list Show partition table information for all devices
-V,--version Display version Information
-S,--script Automatic mode, no manual intervention required
-A Alignment-type Partition alignment


Commonly used alignment methods are as follows:-none: select the minimum alignment based on the type of hard disk-cylinder: alignment based on the cylinder of the hard disk-optimal: select the optimal alignment based on the hard disk topology information

 


The common commands are as follows:


command description
Help [command] displays the helpful information for the specified command
mklabel label-type Specify partition table type
Mkpart Part-type [fs-type] start end create partition, start/end to start and end, default to MB
RM partition Delete partition
Select Device specify the device to edit
set partition flag state set partition type and status
print display partition table information
quit exit


The common label-types are as follows:-bsd, dvh, gpt, loop, mac, msdos, pc98, sun The common part-types are as follows (must specify a type when creating a partition):-primary, logical Common extended fs-types are as follows:-ext2, ext3, ext4, fat32, ntfs, xfs common flags are as follows:-boot, root, swap, hidden, raid (software RAID), lvm (logical volume) Common states are as follows:-on, off

 


The starting and ending positions in the partition are represented by:


Start Position End Position Description
1 -1 Use full capacity
0% 100% Use full capacity
0 30G Use the space capacity of the front 30G
30G 100% Use the remaining space capacity
formatting partitions


The MKFS command is all called Make filesystem, and the main purpose is to create a Linux file system.


MKFS command


Its common syntax format is as follows:



mkfs [-t fstype] [fs-options] [device]


The common options are as follows:


Options Description
-T Fstype You can view the Fs-type in parted and default to ext2 if not specified
-C Check the partition for bad paths before creating the file system
-L filename Read bad message from file
-V Show more information
MKE2FS command


? ? Used to create the Ext2,ext3,ext4 file system. The common syntax is as follows:



mke2fs [options]


The common options are as follows:


Options Description
-B block-size Set the amount of space per data chunk to support 1024B, 2048B, 4096B
-C Check the partition for bad paths before creating the file system
-F Forcing the file system to be created
-j Creating a file system of the ext3 type
-Q Silent mode
-T Fs-type Specifies the type of file system created
-V Show detailed procedures


mke2fs is equivalent to mke2fs.ext2 / mke2fs.ext3 / mke2fs.ext4.

 MKFS.XFS command 


? ? Used to create the XFS file system (CentOS 7 Default file system). The common syntax is as follows:



mkfs.xfs [options] [device]


The common options are as follows:


Options Description
-B block-size Set the amount of space per data chunk, default is 4KiB, minimum is 512, 64KiB Max
-F Forcibly overwrite a file system that already exists
-Q Silent mode
Example


1. Mount the ISO image file


[[email protected] ~] # ll * .iso
-rw-rw-r--. 1 root root 4470079488 June 20 21:04 CentOS-7.5-x86_64-DVD-1804.iso
# Create a mount point
[[email protected] ~] # mkdir -p / tmp / CDROM

[[email protected] ~] # mount -t iso9660 -o loop ~ / CentOS-7.5-x86_64-DVD-1804.iso / tmp / CDROM /
mount: / dev / loop2 is write-protected and will be mounted read-only

[[email protected] ~] # ll / tmp / CDROM /
Total dosage 678
-rw-rw-r-- 1 root root 14 May 2 19:28 CentOS_BuildTag
drwxr-xr-x 3 root root 2048 May 4 04:34 EFI
-rw-rw-r-- 1 root root 227 Aug 30 2017 EULA
-rw-rw-r-- 1 root root 18009 December 10 2015 GPL
drwxr-xr-x 3 root root 2048 May 4 04:44 images
drwxr-xr-x 2 root root 2048 May 4 04:34 isolinux
drwxr-xr-x 2 root root 2048 May 4 04:34 LiveOS
drwxrwxr-x 2 root root 655360 May 4 04:52 Packages
drwxrwxr-x 2 root root 4096 May 4 04:54 repodata
-rw-rw-r-- 1 root root 1690 December 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root 1690 December 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 May 4 04:55 TRANS.TBL

# View mount point
[[email protected] ~] # df -h
File System Capacity Used Available Used% Mount Point
/ dev / sda2 275G 20G 255G 8% /
/ dev / sda1 500M 9.8M 490M 2% / boot / efi
/ dev / sdb1 15T 4.2G 15T 1% / home / data
/ dev / loop2 4.2G 4.2G 0 100% / tmp / CDROM


2. Unloading mount point



[[email protected] ~] # umount / dev / loop2

[[email protected] ~] # ll / tmp / CDROM /
Total dosage 0


3. fdisk create partition, format and Mount


[[email protected] home] # fdisk -l / dev / sdb
Disk / dev / sdb: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sector of 1 * 512 = 512 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / optimal): 512 bytes / 512 bytes

[[email protected] home] # fdisk / dev / sdb
Welcome to fdisk (util-linux 2.23.2).

Changes stay in memory until you decide to write the changes to disk.
Think twice before using the write command.

Device does not contain a recognized partition table
Create a new DOS disk label with the disk identifier 0xa8afbc5f.

Command (enter m for help): m
Command operation
   a toggle a bootable flag
   b edit bsd disklabel
   c toggle the dos compatibility flag
   d delete a partition
   g create a new empty GPT partition table
   G create an IRIX (SGI) partition table
   l list known partition types
   m print this menu
   n add a new partition
   o create a new empty DOS partition table
   p print the partition table
   q quit without saving changes
   s create a new empty Sun disklabel
   t change a partition ‘s system id
   u change display / entry units
   v verify the partition table
   w write table to disk and exit
   x extra functionality (experts only)
Command (enter m for help): n
Partition type:
   p primary (0 primary, 0 extended, 4 free)
   e extended
Select (default p): p
Partition number (1-4, default 1): 2
Starting sector (2048-8388607, default is 2048):
Will use the default value of 2048
Last sector, + sector or + size {K, M, G} (2048-8388607, default is 8388607):
Will use the default value of 8388607
Partition 2 is set to Linux type and size is set to 4 GiB

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

Calling ioctl () to re-read partition table.
Disk syncing.

[[email protected] home] # fdisk -l / dev / sdb

Disk / dev / sdb: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sector of 1 * 512 = 512 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe0dcbc1d

   Device Boot Start End Blocks Id System
/ dev / sdb2 2048 8388607 4193280 83 Linux

# Format the created partition
[[email protected] home] # mkfs -v -t ext4 / dev / sdb2
mke2fs 1.42.9 (28-Dec-2013)
fs_types for mke2fs.conf resolution: ‘ext4’
File system label =
OS type: Linux
Block size = 4096 (log = 2)
Block size = 4096 (log = 2)
Stride = 0 blocks, Stripe width = 0 blocks
262144 inodes, 1048320 blocks
52416 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks = 1073741824
32 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: complete
Writing to inode table: complete
Creating journal (16384 blocks): completed
Writing superblocks and filesystem accounting information: complete

# Create a mount point
[[email protected] home] # mkdir -p / home / MountDisk

# Add mount information to / etc / fstab
[[email protected] ~] # echo "/ dev / sdb2 / home / MountDisk ext4 defaults 0 0" >> / etc / fstab

# Mount the hard disk and view the mount point
[[email protected] ~] # mount -a && df -h
File System Capacity Used Available Used% Mount Point
/ dev / sda6 19G 4.8G 15G 25% /
/ dev / sda1 1014M 281M 734M 28% / boot
/ dev / sda2 8.0G 76M 8.0G 1% / home
/ dev / sda3 8.0G 1.2G 6.9G 15% / var
/ dev / sdb2 3.9G 16M 3.7G 1% / home / MountDisk


4, parted creating partitions, formatting, and mounting


[[email protected] ~] # parted / dev / sdb
GNU Parted 3.1
Use / dev / sdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) print Model: VMware, VMware Virtual S (scsi)
Disk / dev / sdb: 4295MB
Sector size (logical / physical): 512B / 512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system logo
# Set partition type
(parted) mklabel gpt

Warning: The existing disk label on / dev / sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes / Yes / No / No? Yes
# Set partition size
(parted) mkpart primary 1 -1
# Save and exit
(parted) quit
Information: You may need to update / etc / fstab.

[[email protected] ~] # parted -l
Model: VMware, VMware Virtual S (scsi)
Disk / dev / sda: 42.9GB
Sector size (logical / physical): 512B / 512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system logo
 1 1049kB 1075MB 1074MB primary xfs boot
 2 1075MB 9665MB 8590MB primary xfs
 3 9665MB 18.3GB 8590MB primary xfs
 4 18.3GB 42.9GB 24.7GB extended
 5 18.3GB 22.6GB 4295MB logical linux-swap (v1)
 6 22.6GB 42.9GB 20.4GB logical xfs


Model: VMware, VMware Virtual S (scsi)
Disk / dev / sdb: 4295MB
Sector size (logical / physical): 512B / 512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name logo
 1 1049kB 4294MB 4293MB ext4 primary

# Format the created partition
[[email protected] ~] # mkfs.xfs -f / dev / sdb1
meta-data = / dev / sdb1 isize = 512 agcount = 4, agsize = 262016 blks
         = sectsz = 512 attr = 2, projid32bit = 1
         = crc = 1 finobt = 0, sparse = 0
data = bsize = 4096 blocks = 1048064, imaxpct = 25
         = sunit = 0 swidth = 0 blks
naming = version 2 bsize = 4096 ascii-ci = 0 ftype = 1
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

# Create a mount point
[[email protected] home] # mkdir -p / home / MountDisk

# Add mount information to / etc / fstab
[[email protected] ~] # echo "/ dev / sdb1 / home / MountDisk xfs defaults 0 0" >> / etc / fstab

# Mount the hard disk and view the mount point
[[email protected] ~] # mount -a; df -h -T
File System Type Capacity Used Available Used% Mount Point
/ dev / sda6 xfs 19G 4.8G 15G 25% /
/ dev / sda1 xfs 1014M 281M 734M 28% / boot
/ dev / sda2 xfs 8.0G 76M 8.0G 1% / home
/ dev / sda3 xfs 8.0G 1.2G 6.9G 15% / var
/ dev / sdb1 xfs 4.0G 33M 4.0G 1% / home / MountDisk 


This article is posted on the subscription number, such as your friends like my article, you can also follow my subscription number: Woaitest, or scan the following QR code to add attention:



Linux Basics Tutorial 33-hard disk partitioning and mounting


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.