Fork me on GitHub
KeKe Blog

Linux挂载新磁盘并进行分区

  由于业务需要,某台DB的磁盘使用满了。刚好使用的那台机子是虚拟机,就直接在ESXi上划了一块磁盘来用。之前没做过,跟着相关教程做一下。顺带将新挂载的盘作为禅道迁移的服务器。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 查看现有的磁盘分区
[root@KE_03 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f3a29
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1332 10485760 83 Linux
/dev/sda3 1332 2479 9216000 83 Linux
/dev/sda4 2479 2611 1063936 5 Extended
/dev/sda5 2479 2610 1048576 82 Linux swap / Solaris
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@KE_03 ~]# cd /opt
[root@KE_03 opt]# ls
[root@KE_03 opt]# ll
总用量 0
# 查看分区文件
[root@KE_03 opt]# ll /dev/disk/by-
by-label/ by-path/ by-uuid/
[root@KE_03 opt]# ll /dev/disk/by-path/
总用量 0
lrwxrwxrwx 1 root root 9 1月 18 22:19 pci-0000:00:07.1-scsi-1:0:0:0 -> ../../sr0
lrwxrwxrwx 1 root root 9 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:0:0-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:0:0-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:0:0-part5 -> ../../sda5
lrwxrwxrwx 1 root root 9 1月 18 22:19 pci-0000:00:10.0-scsi-0:0:1:0 -> ../../sdb
# 查看已有的磁盘分区
[root@KE_03 opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.7G 1.2G 7.1G 15% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 194M 27M 158M 15% /boot
/dev/sda2 9.9G 151M 9.2G 2% /export
#
[root@KE_03 opt]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7f800bb1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221):
Using default value 5221
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7f800bb1
Device Boot Start End Blocks Id System
/dev/sdb1 1 5221 41937651 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#
[root@KE_03 opt]# mkfs.
mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.ext4dev
#
[root@KE_03 opt]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10484412 blocks
524220 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
320 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, 1605632, 2654208,
4096000, 7962624
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@KE_03 opt]# mount /dev/sdb
sdb sdb1
[root@KE_03 opt]# mount /dev/sdb1 /opt
# 将sdb1设置
[root@KE_03 opt]# echo "/dev/sdb1 /opt ext4 default 0 0" >> /etc/fstab
-------------本文结束 感谢您的阅读-------------