Linux Partition Management

Source: Internet
Author: User
Tags uuid

The previous introduction of disk storage this time to implement how to manage the disk, how to partition, create file system and other administrative partition commands

1. LSBLK list all currently mounted devices

[[email protected] ~]#lsblk NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsr0     11:0    1  3.7G  0 rom  sdb      8:16   0   20G  0 disk sda      8:0    0  200G  0 disk ├─sda1   8:1    0    1G  0 part /boot├─sda2   8:2    0 48.8G  0 part /├─sda3   8:3    0 29.3G  0 part /data├─sda4   8:4    0    1K  0 part └─sda5   8:5    0    3G  0 part [SWAP]sdc      8:32   0   20G  

2, fdisk create MBR partition, also support GPT partition, but still in testing phase, GPT partition has special partition command Gdisk usage and fdisk

Fdisk-l [-u] [device ...] view partition
FDISK/DEV/SDB Administrative partition
subcommand (option used when partitioning with Fdisk/dev/sdb)
1, p------ ----Partition List
3, M----------Get help
2, T----------change partition type
3, n---------Create new partition
4, D----------Delete partition
5, v--------- -Check partition
6, U----------Conversion Unit
7, W----------Save and exit
8, Q----------do not save and exit

[[email protected] ~] #fdisk/dev/sdbdevice contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabe Lbuilding a new DOS disklabel with disk identifier 0x769c63d5 .... Command (M for help): Mcommand action A toggle a bootable flag B edit BSD Disklabel c toggle the DOS Compatibi   Lity flag D Delete a partition 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 NE W Empty Sun Disklabel t change a partition ' s system ID u change display/entry units v Verify the Partition tab   Le W write table to disk and exit X extra functionality (experts only) Command (M-help): Ncommand action E Extended P Primary partition (1-4) ppartition number (1-4): 1First cylinder (1-2610, default 1): Using default Val UE 1Last Cylinder, +cylinders or +size{k,m,g} (1-2610, default 2610): +1gcomMand (M for help): pdisk/dev/sdb:21.5 GB, 21474836480 bytes255 heads, sectors/track, 2610 cylinders .... Device Boot Start End Blocks Id system/dev/sdb1 1 1060258+ Linux

3, the operation of parted is effective in real time, careful use

Usage: parted [options] ..... [Device [command [parameters] ...] ...]

# to do a GPT format partition on the current device/dev/sdb #parted/dev/sdb mklabel gptwarning:the Existing disk label ON/DEV/SDB will be destroyed and Al L Dataon This disk would be lost. Want to continue? Yes/no?  Yes information:you may need to update/etc/fstab. # View current/DEV/SDB information [[email protected] ~] #parted/dev/sdb printmodel:vmware, VMware Virtual S (SCSI) disk/dev/sdb:21.5 Gbsector size (logical/physical): 512b/512bpartition table:gptnumber Start End size File system Name flags# direct to/dev /SDB Primary partition immediately takes effect [[email protected] ~] #parted/dev/sdb Mkpart primary 1 200 # Delete the 2nd partition under/dev/sdb [[Email protecte  D] ~] #parted/dev/sdb RM * list partition information [[email protected] ~] #parted-lmodel:vmware, VMware Virtual S (SCSI) DISK/DEV/SDA:      215GBSector size (logical/physical): 512b/512bpartition table:msdosnumber Start End size Type File system Flags 1 1049kB 1075MB 1074MB primary EXT4 boot 2 1075MB 53.5GB 52.4GB Primary EXT4 3 53.5GB 85.0GB 31.5GB primary EXT4 4 85.0GB 215GB 130GB Extended 5 85.0GB 88.2GB 3228MB Logical Linux-swap (v1) model:vmware, VMware Virtual S (SCSI) disk/dev/sdb:21.5gbsector size (l ogical/physical): 512b/512bpartition table:gpt .....

4, after the partition is created, you need to synchronize the partition table, the command used has PARTX, partprobe

1. Partx for CentOS6 system

[[email protected] ~] #partx-a/dev/sba[[email protected] ~] #kpartx-a-F/DEV/SDA # Delete one of the partitions [[email  Protected] ~] #lsblk NAME maj:min RM SIZE RO TYPE mountpointsda 8:0 0 200G 0 disk├─sda1 8:1 0 1G 0 p Art/boot├─sda2 8:2 0 48.8G 0 part/├─sda3 8:3 0 29.3G 0 part/data├─sda4 8:4 0 1K 0 Part├─sda5 8:  5 0 3G 0 Part [swap]├─sda6 8:6 0 1G 0 part└─sda7 8:7 0 1G 0 part sdb 8:16 0 20G 0 disk SDC 8:32 0 20G 0 disk sr0 11:0 1 3.7G 0 rom [[email protected] ~] #partx-D--nr 7/dev/sda[[emai    L protected] ~] #lsblk NAME maj:min RM SIZE RO TYPE mountpointsda 8:0 0 200G 0 disk├─sda1 8:1 0 1G 0 part/boot├─sda2 8:2 0 48.8G 0 part/├─sda3 8:3 0 29.3G 0 part/data├─sda4 8:4 0 1K 0 PART├─SD  A5 8:5 0 3G 0 Part [swap]└─sda6 8:6 0 1G 0 part sdb 8:16 0 20G 0 disk SDC 8:32 0 20G 0 disk Sr0 11:0 1 3.7G 0 ROM   

2, Partprobe centos5, 7 system use

Command (M for help): pdisk/dev/sda:214.7 GB, 214748364800 bytes, 419430400 sectorsunits = sectors of 1 * MB = byte Ssector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:do Sdisk identifier:0x000bcc63 Device Boot Start End Blocks Id system/dev/sda1 * 2048 20   99199 1048576 linux/dev/sda2 2099200 176179199 87040000 8e Linux lvm/dev/sda3 176179200 178276351 1048576 5 extended/dev/sda5 176181248 177205247 512000 linuxcommand (M for help): WTh E partition table has been altered! Calling IOCTL () to re-read partition table. Warning:re-reading the partition table failed with error 16:device or resource busy. The kernel still uses the old table. The new table is being used atthe next reboot or after you run Partprobe (8) or KPARTX (8) Syncing disks. #直接使用partprobe命令 [[EMA Il protected] ~]# lsblk NAME maj:min RM SIZE RO TYPE MOUNTPOINTSDA 8:0 0 200G 0 disk├─sda1 8:1 0 1G 0 part/boot└─sda2 8:2 0 83G 0 part├─centos-root 253:0 0 50G 0 LVM/├─centos-swap 253:1 0 3G 0 LVM [Swap]└─centos-dat A 253:2 0 30G 0 lvm/datasr0 11:0 1 8.8G 0 rom [[email protected] ~]# partprobe Warning:un  able to open/dev/sr0 Read-write (read-only file system). /dev/sr0 has been opened read-only.  [[email protected] ~]# lsblk NAME maj:min RM SIZE RO TYPE mountpointsda 8:0 0 200G   0 disk├─sda1 8:1 0 1G 0 part/boot├─sda2 8:2 0 83G 0 part│├─centos-root 253:0 0            50G 0 LVM/│├─centos-swap 253:1 0 3G 0 LVM [swap]│└─centos-data 253:2 0 30G 0 Lvm/data├─sda3   8:3 0 512B 0 part└─sda5 8:5 0 500M 0 Part sr0 11:0 1 8.8G 0 rom
File system

A file system is the method and data structure used by the operating system to explicitly store files on a device or partition; The method of organizing files on a storage device. The software structure that manages and stores the file information in the operating system is called the file management system, referred to as file system
From a system perspective, a file system is a system that organizes and distributes the space of a file storage device, which is responsible for storing files and protecting and retrieving the files deposited. Specifically, it is responsible for creating files for users, depositing, reading, modifying, dumping files, controlling file access, security control, logging, compression, encryption, etc.
Supported file systems:/lib/modules/ uname–r /kernel/fs

[[email protected] ~]# ls /lib/modules/`uname -r`/kernel/fsbinfmt_misc.ko.xz  dlm      gfs2           nfs_common  udfbtrfs              exofs    isofs          nfsd        xfscachefiles         ext4     jbd2           nlsceph               fat      lockd          overlayfscifs               fscache  mbcache.ko.xz  pstorecramfs             fuse     nfs            squashfs

Various file systems:
Https://en.wikipedia.org/wiki/Comparison_of_file_systems

File System classification

1. linux File system
1.1, Ext2 (Extended file system): For those situations where the partition capacity is not too large and is not updated frequently, such as the/boot partition.
1.2, Ext3: is an improved version of EXT2, its support log function, can help the system from the abnormal shutdown caused by the exception to recover. It is commonly used as a universal file system
1.3, EXT4: Is the latest version of the Ext file system. Provides a number of new features, including nanosecond timestamps, creation and use of jumbo Files (16TB), maximum 1EB file system, and speed improvements
1.4, XFS:SGI, support the maximum 8EB file system
1.5. Btrfs (Oracle), ReiserFS, JFS (AIX), swap
2. CD: ISO9660
3, Windows:fat32,exfat,ntfs
4, Unix:ffs (FAST), UFS (Unix), JFS2
5. Network File system: NFS, CIFS
6. Cluster file system: GFS2, OCFS2 (Oracle)
7. Distributed File System: Fastdfs,ceph, Moosefs, MogileFS, Glusterfs, Lustre
8. RAW: Unprocessed or unformatted file system

Depending on whether it supports the "journal" feature:
journaled file system: ext3, Ext4, XFS, ...
Non-journaled file system: ext2, VFAT

Part of the file system:
Modules in the kernel: Ext4, XFS, VFAT
User space management tools: MKFS.EXT4, Mkfs.xfs,mkfs.vfat
Virtual file system for Linux: VFS
Pre-check supported file systems: Cat/proc/filesystems

[[email protected] ~]# cat /proc/filesystems nodev   sysfsnodev   rootfsnodev   ramfsnodev   bdevnodev   procnodev   cgroupnodev   cpusetnodev   tmpfsnodev   devtmpfsnodev   debugfsnodev   securityfsnodev   sockfsnodev   daxnodev   pipefsnodev   anon_inodefsnodev   configfsnodev   devptsnodev   hugetlbfsnodev   autofsnodev   pstorenodev   mqueuenodev   selinuxfs        xfsnodev   rpc_pipefs
Vfs

File System Selection

Creating a file system

MKFS command
Mkfs. Fs_type/dev/device
Ext4
Xfs
Btrfs
Vfat
-L ' LABEL ' Add volume label

#格式化成ext4文件系统[[email protected] ~]#mkfs.ext4 /dev/sda6#格式化成vfat文件系统[[email protected] ~]#mkfs.vfat /dev/sda6#指定文件系统后加卷标[[email protected] ~]#mkfs -t ext4 -L ‘/mnt/sda6‘ /dev/sda6mke2fs 1.41.12 (17-May-2010)Filesystem label=/mnt/sda6OS type: Linux# 查看卷标及文件系统类型[[email protected] ~]#blkid /dev/sda2: UUID="9d14df54-a9ce-4c41-bdbe-dc9d851d11d1" TYPE="ext4" /dev/sda1: UUID="eb942a01-ecc7-40f4-ac87-8a1dbb07841e" TYPE="ext4" /dev/sda3: UUID="e49f600c-7f88-4e84-aba2-bb85296647ad" TYPE="ext4" /dev/sda5: UUID="b92b7eda-51dc-4e22-a0fc-09f72a542158" TYPE="swap" /dev/sda6: LABEL="/mnt/sda6" UUID="201198ba-54ec-47ae-8b1f-bd0a2afa550f" TYPE="ext4" ...........

Mke2fs:ext Series file system dedicated management tools

Option:-t {EXT2|EXT3|EXT4}-b {1024|2048|4096}-l ' LABEL '-j: equivalent to-t ext3 mkfs.ext3 = mkfs-        T ext3 = Mke2fs-j = mke2fs-t ext3-i#: Create an inode for each number of bytes in the data space; This size should not be less than the size of the block-N #: Specify how many inode to create in a partition -I an Inode record takes up a disk space size of---4096-m #: Default 5%, the percentage of total space reserved for administrative staff-O feature[,...] : Enable the specified attribute-o ^feature: Turn off the specified attribute mke2fs/dev/sda6 default using ext2 file system [[email protected] ~] #mke2fs/dev/sda6mke2fs 1.41.12 (17-may-2010) Filesystem label=os type:linuxblock size=4096 (log=2) Fragment size=4096 (log=2) stride=0 blocks, Stripe width=0 blocks659 Inodes, 263292 blocks13164 blocks (5.00%) reserved for the Super Userfirst data block=0maximum filesystem blocks=272629 7609 block groups32768 blocks per group, 32768 fragments per group7328 inodes per groupsuperblock backups stored on blocks : 32768, 98304, 163840, 229376[[email protected] ~] #blkid/dev/sda2:uuid= "9d14df54-a9ce-4c41-bdbe-dc9d851d11 D1 "type=" Ext4 "/dev/sda1:uuid=" eb942a01-ecc7-40f4-ac87-8a1dbb07841e "type=" Ext4 "/dev/sda3:uuid=" E49f600c-7f88-4e84-aba2-bb85296647ad "TYPE=" Ext4 "/dev/ Sda5:uuid= "b92b7eda-51dc-4e22-a0fc-09f72a542158" type= "swap"/dev/sda6:uuid= "  8ca19e66-2024-4e30-ab12-6e07e2782793 "type=" ext2 "
File System Tags

Another way to point to a device
Device-Independent

Blkid: Block Device properties Information view
Blkid[option] ... [DEVICE]
-U UUID: Find the corresponding device based on the specified UUID

[[email protected] ~]#blkid -U 8ca19e66-2024-4e30-ab12-6e07e2782793/dev/sda6

-L Label: finds the corresponding device according to the specified label

[[email protected] ~]#blkid -L /mnt/sda6/dev/sda6

Findfs: Finding partitions
Findfs[options] Label=<label>

#根据卷标来查找[[email protected] ~]#findfs LABEL=/mnt/sda6/dev/sda6

Findfs[options] Uuid=<uuid>

#根据UUID查找[[email protected] ~]#findfs UUID=b92b7eda-51dc-4e22-a0fc-09f72a542158/dev/sda5

Tune2fs
TUNE2FS: Reset the values of the EXT series file system adjustable parameters
-L: View the specified file system super block information; Super Block
-L ' LABEL ': Modify volume label
-M #: Fixed percentage of space reserved for administrators
-j: Upgrade ext2 to Ext3
-O: File System Properties enabled or disabled, –O ^has_journal
-O: Adjust default mount options for the file system, –o ^acl
-U uuid: Modifying the UUID number

Linux Partition Management

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.