标签:success reboot conda mkfs 改名 format track logic pre
准备素材:centos7Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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 label type: dos
Disk identifier: 0x000d72bb
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 106956799 52428800 83 Linux
/dev/sda3 106956800 111151103 2097152 82 Linux swap / Solaris
/dev/sda4 111151104 419430399 154139648 5 Extended
/dev/sda5 111153152 132124671 10485760 83 Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (132126720-419430399, default 132126720):
Using default value 132126720
Last sector, +sectors or +size{K,M,G} (132126720-419430399, default 419430399): +1G
Partition 6 of type Linux and of size 1 GiB is set
Command (m for help): P
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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 label type: dos
Disk identifier: 0x000d72bb
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 106956799 52428800 83 Linux
/dev/sda3 106956800 111151103 2097152 82 Linux swap / Solaris
/dev/sda4 111151104 419430399 154139648 5 Extended
/dev/sda5 111153152 132124671 10485760 83 Linux
/dev/sda6 132126720 134223871 1048576 83 Linux
Command (m for help): W
The 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 will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
此处出现警报,是因为没有同步,
3、[root@centos7 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 512B 0 part
├─sda5 8:5 0 10G 0 part /data
└─sda6 8:6 0 1G 0 part
sdb 8:16 0 20G 0 disk
sr0 11:0 1 10G 0 rom /mnt
此时,sda6已被创建。
我们想要将/home独立出去,要在新分区中创建文件系统:
4、[root@centos7 ~]# mkfs.xfs /dev/sda6
meta-data=/dev/sda6 isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, 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
[root@centos7 ~]# blkid
/dev/sda2: UUID="4f823650-e522-46fa-9904-c1e7476f89ad" TYPE="xfs"
/dev/sr0: UUID="2018-11-26-14-22-58-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="bfb9c261-33b4-4602-91ea-a71995a8ef96" TYPE="xfs"
/dev/sda3: UUID="8cc37a26-d321-4331-a020-05f3a08af552" TYPE="swap"
/dev/sda5: UUID="0f16b61c-d601-4783-8e3d-0a6452aad27d" TYPE="xfs"
/dev/sda6: UUID="d52cade8-fb69-447c-b236-f004ab27112f" TYPE="xfs"
5、将分区先挂载,/home下文件拷贝到/mnt下,
[root@centos7 ~]# mount /dev/sda6 /mnt
[root@centos7 ~]# ls /mnt
[root@centos7 ~]# ls /home
wang
[root@centos7 ~]# cp -a /home/* /mnt/
[root@centos7 ~]# ll /mnt
total 0
drwx------. 3 wang wang 78 Apr 11 2018 wang
6、将/dev/sda6挂载到/home中,所以修改/etc/fstab文件:
[root@centos7 ~]# vim /etc/fstab
/dev/sda6: UUID="d52cade8-fb69-447c-b236-f004ab27112f" TYPE="xfs"
#
UUID=4f823650-e522-46fa-9904-c1e7476f89ad / xfs defaults 0 0
UUID=bfb9c261-33b4-4602-91ea-a71995a8ef96 /boot xfs defaults 0 0
UUID=0f16b61c-d601-4783-8e3d-0a6452aad27d /data xfs defaults 0 0
UUID=8cc37a26-d321-4331-a020-05f3a08af552 swap swap defaults 0 0
UUID=d52cade8-fb69-447c-b236-f004ab27112f /home xfs defaualt 0 0
将UUID=d52cade8-fb69-447c-b236-f004ab27112f /home xfs defaualt 0 添加其中。
7、[root@centos7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 52403200 4171040 48232160 8% /
devtmpfs 915824 0 915824 0% /dev
tmpfs 931624 0 931624 0% /dev/shm
tmpfs 931624 10452 921172 2% /run
tmpfs 931624 0 931624 0% /sys/fs/cgroup
/dev/sda5 10475520 33012 10442508 1% /data
/dev/sda1 1038336 177912 860424 18% /boot
tmpfs 186328 12 186316 1% /run/user/42
tmpfs 186328 0 186328 0% /run/user/0
/dev/sr0 10491772 10491772 0 100% /mnt
/dev/sda6 1038336 33100 1005236 4% /home
8、用其他用户登录查看
[root@centos7 ~]# su - wang
[wang@centos7 ~]$ pwd
/home/wang
[wang@centos7 ~]$ ls -a
. .bash_logout .bashrc .config
.. .bash_profile .cache .mozilla
[wang@centos7 ~]$ exit
logout
原数据还在,所以很成功。
9、现在,我们创建逻辑卷,它的突出优势就是可以变大变小。
A、首先,为了方便做实验,我们新增一块2G的新硬盘sdc。
[root@centos7 ~]# echo ‘- - -‘ > /sys/class/scsi_host/host0/scan
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 512B 0 part
├─sda5 8:5 0 10G 0 part /data
└─sda6 8:6 0 1G 0 part /home
sdb 8:16 0 20G 0 disk
sdc 8:32 0 2G 0 disk
sr0 11:0 1 10G 0 rom /mnt
B、我们在新硬盘上做分区,并修改名称为“ 8e ”:
[root@centos7 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x2889f07c.
Command (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):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): P
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 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 label type: dos
Disk identifier: 0x2889f07c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
Command (m for help): T
Selected partition 1
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext‘d (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux‘ to ‘Linux LVM‘
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 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 label type: dos
Disk identifier: 0x2889f07c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 512B 0 part
├─sda5 8:5 0 10G 0 part /data
└─sda6 8:6 0 1G 0 part /home
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 1G 0 part
sdc 8:32 0 2G 0 disk
sr0 11:0 1 10G 0 rom /mnt
因为是干净硬盘,所以不需同步。
C、我们把sdb1和sdc组合在一起做逻辑卷。
[root@centos7 ~]# pvs
[root@centos7 ~]# pvcreate /dev/sd{b1,c}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdc" successfully created.
[root@centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 1.00g 1.00g
/dev/sdc lvm2 --- 2.00g 2.00g
[root@centos7 ~]# pvdisplay
"/dev/sdc" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ht6mmd-jV04-acuk-4Ez7-9VZP-Pdho-dfTz5h
"/dev/sdb1" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 2HmtlV-G0kb-YkqG-zU0A-Zh6U-SIKC-k4zrbL
“ pvdisplay ”可看到更详细信息。
D、我们将sdb1分区和sdc硬盘一起添加在一个vg name中,
[root@centos7 ~]# vgcreate -s 16M vg0 /dev/sd{b1,c}
Volume group "vg0" successfully created
[root@centos7 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0
PV Size 1.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 63
Free PE 63
Allocated PE 0
PV UUID 2HmtlV-G0kb-YkqG-zU0A-Zh6U-SIKC-k4zrbL
--- Physical volume ---
PV Name /dev/sdc
VG Name vg0
PV Size 2.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 127
Free PE 127
Allocated PE 0
PV UUID ht6mmd-jV04-acuk-4Ez7-9VZP-Pdho-dfTz5h
[root@centos7 ~]# blkid
/dev/sda2: UUID="4f823650-e522-46fa-9904-c1e7476f89ad" TYPE="xfs"
/dev/sr0: UUID="2018-11-26-14-22-58-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="bfb9c261-33b4-4602-91ea-a71995a8ef96" TYPE="xfs"
/dev/sda3: UUID="8cc37a26-d321-4331-a020-05f3a08af552" TYPE="swap"
/dev/sda5: UUID="0f16b61c-d601-4783-8e3d-0a6452aad27d" TYPE="xfs"
/dev/sda6: UUID="d52cade8-fb69-447c-b236-f004ab27112f" TYPE="xfs"
/dev/sdb1: UUID="2HmtlV-G0kb-YkqG-zU0A-Zh6U-SIKC-k4zrbL" TYPE="LVM2_member"
/dev/sdc: UUID="ht6mmd-jV04-acuk-4Ez7-9VZP-Pdho-dfTz5h" TYPE="LVM2_member"
[root@centos7 ~]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size <2.97 GiB
PE Size 16.00 MiB
Total PE 190
Alloc PE / Size 0 / 0
Free PE / Size 190 / <2.97 GiB
VG UUID qOMCgY-yImZ-18AI-qJFH-Mueb-3FzP-TEE0Kh
此时,物理卷已经变成了卷组,我们可以在上表中看到非常详细地信息。
E、创建逻辑卷,LV Name为mysql,VG Name为vg0
[root@centos7 ~]# lvs
[root@centos7 ~]# lvcreate -n mysql -l 100%FREE vg0
Logical volume "mysql" created.
注:lvcreate -n mysql -l :-l 后跟PE的个数,-L后跟容量x.G大小。
[root@centos7 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/mysql
LV Name mysql
VG Name vg0
LV UUID meorkL-K7yM-2PlH-4Ovx-JjnW-sb2I-8ubEU5
LV Write Access read/write
LV Creation host, time centos7, 2019-02-11 18:06:31 +0800
LV Status available
LV Size <2.97 GiB
Current LE 190
Segments 2
Allocation inherit
Read ahead sectors auto
currently set to 256
Block device 253:0
以上是详细信息。
F、接着,我们创建文件系统:
[root@centos7 ~]# mkfs.xfs /dev/vg0/mysql
meta-data=/dev/vg0/mysql isize=512 agcount=4, agsize=194560 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=778240, 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
[root@centos7 ~]# blkid
/dev/sda2: UUID="4f823650-e522-46fa-9904-c1e7476f89ad" TYPE="xfs"
/dev/sr0: UUID="2018-11-26-14-22-58-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="bfb9c261-33b4-4602-91ea-a71995a8ef96" TYPE="xfs"
/dev/sda3: UUID="8cc37a26-d321-4331-a020-05f3a08af552" TYPE="swap"
/dev/sda5: UUID="0f16b61c-d601-4783-8e3d-0a6452aad27d" TYPE="xfs"
/dev/sda6: UUID="d52cade8-fb69-447c-b236-f004ab27112f" TYPE="xfs"
/dev/sdb1: UUID="2HmtlV-G0kb-YkqG-zU0A-Zh6U-SIKC-k4zrbL" TYPE="LVM2_member"
/dev/sdc: UUID="ht6mmd-jV04-acuk-4Ez7-9VZP-Pdho-dfTz5h" TYPE="LVM2_member"
/dev/mapper/vg0-mysql: UUID="4f9e419d-8959-4f18-b24e-1ed7847021cf" TYPE="xfs"
我们并没有给sdb1和sdc创建文件系统,而是对逻辑卷创建的文件系统。
[root@centos7 ~]# vim /etc/fstab
/dev/sda6: UUID="d52cade8-fb69-447c-b236-f004ab27112f" TYPE="xfs"
#
#
#
UUID=4f823650-e522-46fa-9904-c1e7476f89ad / xfs defaults 0 0
UUID=bfb9c261-33b4-4602-91ea-a71995a8ef96 /boot xfs defaults 0 0
UUID=0f16b61c-d601-4783-8e3d-0a6452aad27d /data xfs defaults 0 0
UUID=8cc37a26-d321-4331-a020-05f3a08af552 swap swap defaults 0 0
UUID=d52cade8-fb69-447c-b236-f004ab27112f /home xfs defaualt 0 0
UUID=4f9e419d-8959-4f18-b24e-1ed7847021cf /data/mysql xfs defaults0 0
我们将UUID=4f9e419d-8959-4f18-b24e-1ed7847021cf /data/mysql xfs defaults0 0 填入。
[root@centos7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 52403200 4170528 48232672 8% /
devtmpfs 915824 0 915824 0% /dev
tmpfs 931624 0 931624 0% /dev/shm
tmpfs 931624 10464 921160 2% /run
tmpfs 931624 0 931624 0% /sys/fs/cgroup
/dev/sda5 10475520 33012 10442508 1% /data
/dev/sda1 1038336 177912 860424 18% /boot
tmpfs 186328 12 186316 1% /run/user/42
tmpfs 186328 0 186328 0% /run/user/0
/dev/sr0 10491772 10491772 0 100% /mnt
/dev/sda6 1038336 33108 1005228 4% /home
/dev/mapper/vg0-mysql 3102720 32992 3069728 2% /data/mysql 此处已生效。
G、使用逻辑卷读写文件
[root@centos7 ~]# cd /data/mysql/
[root@centos7 /data/mysql]# ls
[root@centos7 /data/mysql]# dd if=/dev/zero of=f1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 2.16338 s, 496 MB/s
H、查看逻辑卷的各功能的工作情况
[root@centos7 /data/mysql]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0
PV Size 1.00 GiB / not usable 16.00 MiB
Allocatable yes (but full)
PE Size 16.00 MiB
Total PE 63
Free PE 0
Allocated PE 63
PV UUID 2HmtlV-G0kb-YkqG-zU0A-Zh6U-SIKC-k4zrbL
--- Physical volume ---
PV Name /dev/sdc
VG Name vg0
PV Size 2.00 GiB / not usable 16.00 MiB
Allocatable yes (but full)
PE Size 16.00 MiB
Total PE 127
Free PE 0
Allocated PE 127
PV UUID ht6mmd-jV04-acuk-4Ez7-9VZP-Pdho-dfTz5h
[root@centos7 /data/mysql]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 52403200 4171056 48232144 8% /
devtmpfs 915824 0 915824 0% /dev
tmpfs 931624 0 931624 0% /dev/shm
tmpfs 931624 10464 921160 2% /run
tmpfs 931624 0 931624 0% /sys/fs/cgroup
/dev/sda5 10475520 33012 10442508 1% /data
/dev/sda1 1038336 177912 860424 18% /boot
tmpfs 186328 12 186316 1% /run/user/42
tmpfs 186328 0 186328 0% /run/user/0
/dev/sr0 10491772 10491772 0 100% /mnt
/dev/sda6 1038336 33108 1005228 4% /home
/dev/mapper/vg0-mysql 3102720 1081568 2021152 35% /data/mysql
至此,我们的逻辑卷创建就圆满结束。
总结:1、pvcreate /dev/sd{b1,c}
2、vgcreate -s 16M vg0 /dev/sd{b1,c}
3、lvcreate -n mysql -l 100%FREE vg0
4、mkfs.xfs /dev/vg0/mysql 格式化文件系统
5、mount /dev/vg0/mysql /data/mysql 挂载文件
标签:success reboot conda mkfs 改名 format track logic pre
原文地址:http://blog.51cto.com/14128387/2349260