Hard disk partitioning, file system in Linux

Source: Internet
Author: User
Tags uuid egrep

LSBLK Viewing block devices

FDISK supports MSDOS, and GPT (not recommended) is recommended for use in CENTOS7. Interactive
FDISK-L View partition information for all hard drives
Fdisk-l/DEV/SDA View partition information for a specified hard disk
Fdisk/dev/sdb
o Set MSDOS partition table
G Set GPT partition table (not recommended)
M help
n Create a partition
P Primary Partition
E Extended partition (please divide all the space into extensions)
The number of sectors starting from the general direct return, take the smallest available sector
The number of sectors to end is typically used +xx k/m/g to specify how many partitions to divide
Q Exit does not save
W Exit and save
T set the type of partition
L View the code representation of the type of the partition
d Delete the specified partition
A sets the partition as the boot partition, or set to non-boot
P Show partition Table
U updates the units that show the start and end of the partition, switching between sectors and cylinders

Non-interactive mode
Echo-e "n\np\n\n\n+1g\nw\n" |fdisk/dev/sdb &>/dev/null

Gdisk can only partition GPT partitions (well remembered, Gdisk--gpt are all g) is also recommended to use interactive partitioning
Gdisk-l list all hard disk partition tables
Gdisk-l/DEV/SDB lists the partition table for the specified hard disk
Gdisk/dev/sdb Partitioning of partitions
o Create a GPT partition table
M help
n Create a partition
The number of sectors starting from the general direct return, take the smallest available sector
The number of sectors to end is typically used +xx k/m/g to specify how many partitions to divide
Q Exit does not save
W Exit and save
T set the type of partition
L View the code representation of the type of the partition
d Delete the specified partition
P Show partition Table

Non-interactive
echo-e "n\n\n\n+2g\n\nw\ny\n" |gdisk/dev/sdb

cat/proc/partitions partition table loaded by the current kernel (kernel load not equal)
For the hard disk that is not on the system, the kernel automatically updates the partition table, and for the hard disk of the system, cannot directly column new, to use the following command
notify the kernel read partition table
Cenots5\centos7:partprobe (centos6 not available)
CENTOS6: Partx-a/dev/sda Add
partx-d--nr/dev/sda7 Delete
mkfs
mkfs.xfs/dev/sdb1
mkfs-t xfs-f/dev/sdb2
Mkfs.ext4 /DEV/SDB2
mkfs-t ext4/dev/sdb2
mke2fs/dev/sdb2 formatted as ext2
MKE2FS
mke2fs-j/dev/sdb2 Add log area, which is formatted as EXT3
- B Block Size
-t EXT2|EXT3|EXT4
-L "LABEL"
E2LABEL/DEV/SDB2 only ext file system
E2label/dev/sdb2 Hello
/etc/ Fstab
Label=mage1/mnt/mage1 ext4 defaults 0 0
Uuid=996b2280-1eaa-4560-b8e3-0c742912afa8/mnt/mage2 ext4 Defaults 0 0

[Email protected]_v7 (Nanyibo) ~]# blkid-u 996b2280-1eaa-4560-b8e3-0c742912afa8
/dev/sdb2
[Email protected]_v7 (Nanyibo) ~]# blkid-l mage1
/dev/sdb1
[Email protected]_v7 (Nanyibo) ~]# FINDFS/DEV/SDB2
/dev/sdb2
[Email protected]_v7 (Nanyibo) ~]# Findfs uuid=996b2280-1eaa-4560-b8e3-0c742912afa8
/dev/sdb2
[Email protected]_v7 (Nanyibo) ~]# Findfs label=mage1
/dev/sdb1

Extended Partition Swap
Partition-based Swap
Fdisk/dev/sda
Mkswap/dev/sda9
Swapon/dev/sda9
Boot auto-activation, write/etc/fstab
File-based Swap
DD If=/dev/zero of=swap.img bs=1m count=1024
Mkswap swap.img
Swapon/app/swap.img
Boot auto-activation, write/etc/fstab

Mke2fs:ext Series file system dedicated management tools
-T {EXT2|EXT3|EXT4}
-B {1024|2048|4096} specifies block size
-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, which should not be smaller than the size of the block
-N #: Specify how many inode to create in a partition
-I an INODE record consumes disk space,---4096
-M #: Default 5%, Percentage of total space reserved for administrative staff
-O feature[,...] : Enable the specified attribute
-O ^feature: Turn off specified attributes

Hard disk
/dev/sdb
Partition
/dev/sdb1
Creating a file system
/dev/sdb1

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 file system, –o ^acl * * *
-U uuid: Modifying the UUID number

Homework:
1, create a 2G file system, block size of 2048byte, reserved 1% free space, file system ext4, Volume label test, require this section automatically mount to the/test directory after boot, and the default ACL mount option
FDISK/DEV/SDA Creating partitions
Mke2fs–t ext4–b 2048–l test–m 1/dev/sda6
Vim/etc/fstab #增加一行sda6信息能自动开机挂载
Uuid:x--x
Tune2fs–o ^acl/dev/sda6
2, write a script to complete the following functions:
(1) List all disk devices identified by the current system
(2) If the number of disks is 1, the space usage information is displayed
Otherwise, the space usage information on the last disk is displayed
A=fdisk -l|egrep -o "Disk /dev/sd[a-z]"|cut -d" " -f2
b=fdisk -l|egrep -o "Disk /dev/sd[a-z]"|cut -d" " -f2|wc -l
[$B = = 1] && echodf -h /dev/sda|| Df-hfdisk -l|egrep -o "Disk /dev/sd[a-z]"|tail -1|cut -d" " -f2
3, the CentOS6 Centos-6.8-x86_64-bin-dvd1.iso and Centos-6.8-x86_64-bin-dvd2.iso two files, merged into a centos-6.8-x86_64- Everything.iso file, and configure it as a Yum source
Create an empty directory. Copying files
mkdir C6c7
CP Iso1 c6/
CP ISO2 c6/
#创建iso文件mkisofs-R-O centos6/c6/
#挂载mount/c6/centos6/mnt/
Edit Warehouse
Vim/etc/yum.repo.d/cento68every.repo
[CENTOS6]
Name=centos6
Baseurl=file:///mnt
Gpgchekc=0
Enabled=1

Hard disk partitioning, file system in Linux

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.