使用fdisk命令在/dev/sdb上建立lvm类型的分区
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用fdisk命令在/dev/sdb上建立lvm类型的分区相关的知识,希望对你有一定的参考价值。
使用fdisk命令在/dev/sdb上建立lvm类型的分区
参考技术A 方法:1、使用ssh远程连接工具登录到系统,使用fdisk-l命令查看磁盘状态
2、输入fdisk/dev/sdb然后回车,给硬盘进行分区
3、输入n回车新建分区,接着再输入p回车新建主分区
4、此处要求选择分区号在1-4间,输入1回车
5、Firstcylinder(1-20805,default1):这里是设置分区起始的柱面,直接回车选择默认即可
6、Lastcylinderor+sizeor+sizeMor+sizeK(1-20805,default20805):此处是设置分区结束柱面,+3G表示从起始柱面开始向后3G结束,也是是设置分区大小为3G,输入+3G后回车、也可以用M全部直接回车
7、此处可输入p查看分区是否成功,输入p回车
8、看看是否划分好,最后输入w回车,进行保存退出
9、再次使用fdisk-l命令就可以查看到磁盘hdb已经分区成功
10、磁盘划分成功,下面就要对分区进行格式化了使用命令mkfs-text3/dev/sdb1
11、用mkdir/mnt/sdb1创建文件夹
12、mount/dev/sdb1/mnt/sdb1
13、cd/mnt/sdb1进入文件夹ls-a查看文件有没有lost+found或者直接使用mount查看挂载情况
fdisk 分区
1.1 fdisk 磁盘分区工具受mbr分区表限制,只能给小于2T的磁盘划分分区,
语法:
[fdisk] [option] [device]
参数:
-l 显示所有磁盘分区的信息
1.1 交互式分区实践
[[email protected] ~]# ls /dev/sd*
[[email protected] ~]# fdisk /dev/sdb
Command (m for help): m
Command action
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
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‘).
-c 提示使用-c关闭dos兼容模式
-u 提示-u 参数使用扇区为单位分区
Command (m for help): m m 是帮助
Command action
a toggle a bootable flag #设置引导分区
b edit bsd disklabel #编辑bsd分区
c toggle the dos compatibility flag #设置dos兼容扇区
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 #创建一个新的dos分区表
p print the partition table #打印分区表
q quit without saving changes #退出不保存更改
s create a new empty Sun disklabel #创建新的sun卷标
t change a partition‘s system id #更改分区系统id
u change display/entry units #改变显示/条目的单位
v verify the partition table #验证分区表
w write table to disk and exit #将操作写入分区表并退出程序
x extra functionality (experts only) #额外的功能
Command (m for help): n #新建立一个分区
Command action
e extended 扩展分区
p primary partition (1-4) 创建主分区
p 创建一个主分区,需要人工输入p后回车
Partition number (1-4): 1 设置主分区编号1
First cylinder (1-261083, default 1): 1G 设置柱起面,默认为1
Last cylinder, +cylinders or +size{K,M,G} (1-261083, default 261083): 100G #设置结束柱面
Command (m for help): p 打印分过的分区表
Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
Command (m for help): n 再建立一个分区表
Command action
e extended
p primary partition (1-4)
e 创建一个扩展分区
Partition number (1-4): 2 设置分区编号为2
First cylinder (101-261083, default 101):
Using default value 101
Last cylinder, +cylinders or +size{K,M,G} (101-261083, default 261083):
Using default value 261083
Command (m for help): p
Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 261083 2096345947+ 5 Extended
Command (m for help): n 再建立一个分区
Command action
l logical (5 or over) 分了扩展分区,这里自动变为逻辑分区
p primary partition (1-4)
p
Partition number (1-4): 3
No free sectors available 不能再创建主分区,没有磁盘空间了
Command (m for help): n 再新建一个分区
Command action
l logical (5 or over)
p primary partition (1-4)
l 新建立一个逻辑分区
First cylinder (101-261083, default 101):
Using default value 101
Last cylinder, +cylinders or +size{K,M,G} (101-261083, default 261083): 400G
Command (m for help): p 打印分区表
Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 261083 2096345947+ 5 Extended
/dev/sdb5 101 400 2409718+ 83 Linux
Command (m for help): n 新建立一个分区
Command action
l logical (5 or over)
p primary partition (1-4)
l 新建立一个逻辑分区
First cylinder (401-261083, default 401): 401
Last cylinder, +cylinders or +size{K,M,G} (401-261083, default 261083):
Using default value 261083
Command (m for help): p
Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 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: 0xc4682775
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 261083 2096345947+ 5 Extended
/dev/sdb5 101 400 2409718+ 83 Linux
/dev/sdb6 401 261083 2093936166 83 Linux
Command (m for help): w 将操作写入分区表生效并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# ls /dev/sd* 查看分区后的状态
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6 /dev/sdc
[[email protected] ~]# partprobe /dev/sdb 执行该命令通知内核分区表已经更改,此部是不重启让分区表生效的命令
[[email protected] ~]#
1.2格式化磁盘
[[email protected] ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
50288 inodes, 200804 blocks
10040 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7184 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override. 执行这个命令可以避免磁盘挂自动检查磁盘。
1.3挂载磁盘分区
[[email protected] ~]# df -h 显示磁盘使用的情况
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 79G 3.4G 71G 5% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
[[email protected] ~]# mount /dev/sdb1 /mnt磁盘只能挂了才能使用,将磁盘挂载到/mnt下
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 79G 3.4G 71G 5% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
/dev/sdb1 773M 17M 717M 3% /mnt
[[email protected] ~]# vim /etc/fstab
/dev/sdb1 /mnt ext4 defaults 0 0
在用交互指令d删除分区时要小心,看好分区的序号,如果删除了扩展分区,那么扩展分区之下的逻辑分区都会被删除,所在在操作时要小心,如果不小心删除错误,按q退出,这样之前的操作就会失效,如果输入(w保存指令)则会保存所有修改
以上是关于使用fdisk命令在/dev/sdb上建立lvm类型的分区的主要内容,如果未能解决你的问题,请参考以下文章
linux:/home没有在fstab里,想mount该怎么办