Ubuntu服务器挂载新硬盘的步骤

发布时间:2025-09-17 点击:8
最近公司新购了一台戴尔r720的服务器,昨天u盘安装ubuntu系统后,首先要做的就是把另外两个raid设备挂载到服务器。现在在虚拟机中用root用户操作,挂载的具体步骤如下。
1、测试硬盘是否已连接
首先先查看硬盘信息。sda是虚拟的第一块硬盘,sdb是第二块硬盘,以此类推。
root@zhang:~# ls -l /dev/sd*brw-rw---- 1 root disk 8, 0 2013-08-13 08:33 /dev/sdabrw-rw---- 1 root disk 8, 1 2013-08-13 08:33 /dev/sda1brw-rw---- 1 root disk 8, 2 2013-08-13 08:33 /dev/sda2brw-rw---- 1 root disk 8, 5 2013-08-13 08:33 /dev/sda5brw-rw---- 1 root disk 8, 16 2013-08-13 08:33 /dev/sdb#此命令测试linux系统是否能找到挂载的未分区硬盘root@zhang:~# hdparm -i /dev/sdb#这个是未挂载之前的硬盘信息root@zhang:~# fdisk -ldisk /dev/sda: 8589 mb, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk identifier: 0x000cf88cdevice boot start end blocks id system/dev/sda1 * 1 994 7977984 83 linuxpartition 1 does not end on cylinder boundary./dev/sda2 994 1045 407553 5 extended/dev/sda5 994 1045 407552 82 linux swap / solarisdisk /dev/sdb: 8589 mb, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk identifier: 0x00000000disk /dev/sdb doesn\'t contain a valid partition table2、创建硬盘分区
root@zhang:~# fdisk /dev/sdbdevice contains neither a valid dos partition table, nor sun, sgi or osf disklabelbuilding a new dos disklabel with disk identifier 0xcbd0c60e.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\').# 输入m,查看帮助信息 command (m for help): mcommand actiona toggle a bootable flag 将分区设置为启动区b edit bsd disklabel 编辑bsd的disklabelc 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 tablep print the partition table查看分区信息q quit without saving changes 退出不保存s create a new empty sun disklabelt change a partition\'s system id改变分区类型u change display/entry unitsv verify the partition tablew write table to disk and exit 保存退出x extra functionality (experts only)#查看sdb这块硬盘的分区command (m for help): pdisk /dev/sdb: 8589 mb, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk identifier: 0xcbd0c60edevice boot start end blocks id system#创建sdb这块硬盘的分区command (m for help): ncommand action e extended p primary partition (1-4)ppartition number (1-4): 1first cylinder (1-1044, default 1):using default value 1last cylinder, cylinders or size{k,m,g} (1-1044, default 1044):using default value 1044#查看创建sdb硬盘的分区command (m for help): pdisk /dev/sdb: 8589 mb, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk identifier: 0xcbd0c60edevice boot start end blocks id system/dev/sdb1 1 1044 8385898 83 linux#保存退出,分区创建结束。command (m for help): wthe partition table has been altered!calling ioctl() to re-read partition table.syncing disks.#再用fdisk -l查看硬盘信息就可以看到sdb1新分区了root@zhang:~# fdisk -ldisk /dev/sda: 8589 mb, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk identifier: 0x000cf88cdevice boot start end blocks id system/dev/sda1 * 1 994 7977984 83 linuxpartition 1 does not end on cylinder boundary./dev/sda2 994 1045 407553 5 extended/dev/sda5 994 1045 407552 82 linux swap / solarisdisk /dev/sdb: 8589 mb, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylindersunits = cylinders of 16065 * 512 = 8225280 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/optimal): 512 bytes / 512 bytesdisk identifier: 0xcbd0c60edevice boot start end blocks id system/dev/sdb1 1 1044 8385898 83 linux3、格式化硬盘
root@zhang:~# mkfs -t ext4 /dev/sdb1mke2fs 1.41.11 (14-mar-2010)文件系统标签=操作系统:linux块大小=4096 (log=2)分块大小=4096 (log=2)stride=0 blocks, stripe width=0 blocks524288 inodes, 2096474 blocks104823 blocks (5.00%) reserved for the super user第一个数据块=0maximum filesystem blocks=214748364864 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupsuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632正在写入inode表: 完成creating journal (32768 blocks): 完成writing superblocks and filesystem accounting information: 完成this filesystem will be automatically checked every 29 mounts or180 days, whichever comes first. use tune2fs -c or -i to override.4、给新建的sdb1设置卷标命名,创建挂载点。
root@zhang:~# e2label /dev/sdb1 /dataroot@zhang:~# mkdir /data5、设置开机自动挂载
在上面一个步骤中,我已经把sdb1这个分区重新命名,当然也可以在设置自动挂载的时候用uuid。
root@zhang:~# ls -l /dev/disk/total 0drwxr-xr-x 2 root root 280 2013-08-13 08:47 by-iddrwxr-xr-x 2 root root 60 2013-08-13 08:52 by-labeldrwxr-xr-x 2 root root 180 2013-08-13 08:47 by-pathdrwxr-xr-x 2 root root 100 2013-08-13 08:51 by-uuid#查看设置的卷标名称,这里有上一步中命名的分区/dataroot@zhang:~# ls -l /dev/disk/by-label/total 0lrwxrwxrwx 1 root root 10 2013-08-13 08:52 \\x2fdata -> ../../sdb1#查看各个分区的uuid号root@zhang:~# ls -l /dev/disk/by-uuid/total 0lrwxrwxrwx 1 root root 10 2013-08-13 08:33 b6dbd10c-7995-4b3d-abf0-2da1622298da -> ../../sda1lrwxrwxrwx 1 root root 10 2013-08-13 08:33 d0d8b0bf-dc99-4d38-937d-f34d88072ce9 -> ../../sda5lrwxrwxrwx 1 root root 10 2013-08-13 08:52 f90991b0-1082-45d8-b00d-87dceb81115e -> ../../sdb1#设置开机自动挂载分区sdb1root@zhang:~# vi /etc/fstab# /etc/fstab: static file system information.## use \'blkid -o value -s uuid\' to print the universally unique identifier# for a device; this may be used with uuid= as a more robust way to name# devices that works even if disks are added and removed. see fstab(5).## <file system> <mount point> <type> <options> <dump> <pass>proc /proc proc nodev,noexec,nosuid 0 0# / was on /dev/sda1 during installationuuid=b6dbd10c-7995-4b3d-abf0-2da1622298da / ext4 errors=remount-ro 0 1# swap was on /dev/sda5 during installationuuid=d0d8b0bf-dc99-4d38-937d-f34d88072ce9 none swap sw 0 0label=/data /data ext4 defaults 0 2#或者用uuid,效果都是一样的。#uuid=f90991b0-1082-45d8-b00d-87dceb81115e /data ext4 defaults 0 26、重新启动查看挂载结果
root@zhang:~# df -lhfilesystem size used avail use% mounted on/dev/sda1 7.5g 1.5g 5.7g 20% /none 243m 216k 243m 1% /devnone 247m 0 247m 0% /dev/shmnone 247m 56k 247m 1% /var/runnone 247m 0 247m 0% /var/locknone 247m 0 247m 0% /lib/init/rw/dev/sdb1 7.9g 146m 7.4g 2% /data#挂载成功

亲爱的西部数码技术大大-其他问题
网站建设服务过程中需要具备哪些实力优势
重装镜像失败-市场咨询
我的域名要绑定阿里巴巴店铺
国内不用备案的主机
实名要多久-其他问题
阿里云服务器里怎么修改网站时间
图片文字怎么转换成文字 图片文字转换成文本的方法