linux添加硬盘并且格式化
时间:2016-12-24 21:07 来源:linux.it.net.cn 作者:IT
前段时间玩了一阵子LFS。这一段时间一直做Linux系统防护,需要加一块硬盘,有些知识点忘记了。因此写一点东西记录一下。用虚拟机演示吧
1.首先添加一块硬盘
2.选择scsi
3.创建磁盘
4指定磁盘容量(选择默认)
5完成确定
6.开启虚拟机
7.查看当前磁盘信息
[root@centos6 ~]# 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: 0x000aefbd
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 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: 0x00000000
Disk /dev/mapper/vg_centos6-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 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
Disk /dev/mapper/vg_centos6-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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
可知新添加的磁盘在/dev/sdb 8.格式化
[root@centos6 ~]# 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 0x70d443e5.
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):
我们可以输入m查看帮助
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility 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 new empty Sun disklabel
t change a partition's system 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):
9.创建分区
Command (m for help): n#创建分区
Command action
e extended
p primary partition (1-4)
p#选择主分区
Partition number (1-4):
Value out of range.
Partition number (1-4): 1#选择分区名称
First cylinder (1-2610, default 1):#选择分区起始位置
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):#选择分区结束位置(我全部默认了)
Using default value 2610
Command (m for help): w#写入分区表
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
10.格式化
[root@centos6 ~]# mkfs -t ext4 /dev/sdb1 #格式化分区
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
11.挂载,查看
[root@centos6 ~]# mkdir /lfs
[root@centos6 ~]# mount /dev/sdb1 /lfs/
[root@centos6 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos6-lv_root
18G 1.2G 16G 7% /
tmpfs 498M 0 498M 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/sdb1 20G 44M 19G 1% /lfs
12.开机自动挂载
编辑
[root@centos6 ~]# vi /etc/fstab
#加入以下内容
/dev/sdb1 /lfs ext4 defaults, 0 1
附格式化swap 分区
1.构造系统文件
dd if=/dev/zero of=/swapfile bs=1024 count=102400
这里构建一个100M的系统文件
mkswap /swapfile
增加交换条目:
/swapfile swap swap defaults 0 0
swapon -a
3.swapon -s
此时可以看到刚刚添加的两个交换分区,其类型分别是partition和file.
或者
mkswap /dev/hdb1
格式化分区并创建文件系统
在/etc/fstab中增加挂载条目:
/dev/sdb2 swap swap defaults 0 0
激活交换分区
swapon -a
将所有/etc/fstab中的交换条目都开启
查看交换分区状态
swapon -s
(责任编辑:IT)
前段时间玩了一阵子LFS。这一段时间一直做Linux系统防护,需要加一块硬盘,有些知识点忘记了。因此写一点东西记录一下。用虚拟机演示吧
[root@centos6 ~]# 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: 0x000aefbd Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 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: 0x00000000 Disk /dev/mapper/vg_centos6-lv_root: 18.8 GB, 18832424960 bytes 255 heads, 63 sectors/track, 2289 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 Disk /dev/mapper/vg_centos6-lv_swap: 2113 MB, 2113929216 bytes 255 heads, 63 sectors/track, 257 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 可知新添加的磁盘在/dev/sdb 8.格式化 [root@centos6 ~]# 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 0x70d443e5. 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): 我们可以输入m查看帮助 Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility 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 new empty Sun disklabel t change a partition's system 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): 9.创建分区 Command (m for help): n#创建分区 Command action e extended p primary partition (1-4) p#选择主分区 Partition number (1-4): Value out of range. Partition number (1-4): 1#选择分区名称 First cylinder (1-2610, default 1):#选择分区起始位置 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):#选择分区结束位置(我全部默认了) Using default value 2610 Command (m for help): w#写入分区表 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. 10.格式化 [root@centos6 ~]# mkfs -t ext4 /dev/sdb1 #格式化分区 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 11.挂载,查看 [root@centos6 ~]# mkdir /lfs [root@centos6 ~]# mount /dev/sdb1 /lfs/ [root@centos6 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos6-lv_root 18G 1.2G 16G 7% / tmpfs 498M 0 498M 0% /dev/shm /dev/sda1 477M 30M 422M 7% /boot /dev/sdb1 20G 44M 19G 1% /lfs 12.开机自动挂载 编辑 [root@centos6 ~]# vi /etc/fstab #加入以下内容 /dev/sdb1 /lfs ext4 defaults, 0 1 附格式化swap 分区 1.构造系统文件 dd if=/dev/zero of=/swapfile bs=1024 count=102400 这里构建一个100M的系统文件 mkswap /swapfile 增加交换条目: /swapfile swap swap defaults 0 0 swapon -a 3.swapon -s 此时可以看到刚刚添加的两个交换分区,其类型分别是partition和file. 或者 mkswap /dev/hdb1 格式化分区并创建文件系统 在/etc/fstab中增加挂载条目: /dev/sdb2 swap swap defaults 0 0 激活交换分区 swapon -a 将所有/etc/fstab中的交换条目都开启 查看交换分区状态 swapon -s (责任编辑:IT) |