也许是杞人忧天,也就是说没有必要!但如果你看懂了,那你就基本可以熟练掌握fdisk技巧了。
系统环境:Debian 9,10 在 DELL和联想 笔记本上
用Debian已经很长时间了,最近刚刚发现硬盘有分区出错,虽然在使用上没有发现什么问题,据说 Debian (可能其他发行版也一样)可以容忍这个错误,但心里还是有点不爽,在网上查了方法,但觉得写得不够清楚,心中有不少疑问,毕竟是否会把盘重写而丢失数据,但网上的分享都没有交代得很清楚,所以在此特意记录下来并分享。
整篇分享主要用到的是fdisk功能,主要的篇幅都是fdisk的问答,如果有不明白的地方,试一下fdisk就一目了然了,只要最后不用w写入硬盘就什么也没有发生,但写入之前一定要知道自己在做什么,fdisk用错了是有严重后果的,所以保险起见请在之前务必做磁盘备份

Debian 9 + DELL/联想 笔记本 + 偶然的发现

user1@dell_notebook:~$ sudo fdisk -l
[sudo] password for user1:
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x6593c9a1Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048 960239613 960237566 457.9G 83 Linux
/dev/sda2       960239614 976771071  16531458   7.9G  5 Extended
/dev/sda5       960239616 976771071  16531456   7.9G 82 Linux swap / SolarisPartition 2 does not start on physical sector boundary.

Partition 2 does not start on physical sector boundary. 是一条报错信息

出错是因为 “/dev/sda2 960239614” 中的960239614无法被512整除,调整以后的 960237568 可以被512整除;

解决方案很简单

  1. 删除分区 d
  2. 马上添加这个分区 n
  3. 重写分区 w
  4. reboot

在使用命令前请确认分区是primary还是extended !!
在这个例子里下面的命令
user1@dell_notebook:~$ sudo fdisk /dev/sda (保险起见请在之前务必做磁盘备份),关于备份将在下次介绍,一种特别牛叉的方法。
用 d 删除分区,先删除 1 ,然后马上用 n 添加这个分区,是 primary,编号为 1,出现Do you want to remove the signature? [Y]es/[N]o:时答复 n;然后再用 d 删除分区 2,马上用 n 添加这个分区 2,其他的数字问题按回车就可以了;最后再出现 Command (m for help): 时用 w 写入磁盘,重新启动就大功告成。

调整好后的信息:

user1@dell_notebook:~$ sudo fdisk -l
[sudo] password for user1:
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: TOSHIBA MKO1ACF0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xb95bacf7Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048 960237567 960235520 457.9G 83 Linux
/dev/sda2       960237568 976773167  16535600   7.9G  5 Extended

还没有完全完,在纠正了上面的错误以后要看一下在启动过程中是否会出现
a start job is running for dev-disk-by UUID 1min 30s 启动错误,原因:swap或其他分区的UUID错误。这个虽然不是严重的错误,但在启动会让你都等30秒到1分30秒,不同的系统等待时间不一样。在这个例子中的原因是实际的swap id 跟/etc/fstab表中的swap id对不上;具体在这个案例中,就是把fstab表中的swap id 注释掉:
先查看swap的状况

user1@dell_notebook:~$ free -htotal        used        free      shared  buff/cache   available
Mem:           7.7G        750M        6.3G         95M        640M        6.6G
Swap:            0B          0B          0B

swap为0,说明没有swap,所以只要在fstab表中把swap 这行注释掉:

user1@dell_notebook:~$ cat /etc/fstab
[sudo] password for user1: # /etc/fstab: static file system information.
#
# Use 'blkid' 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>
# / was on /dev/sda1 during installation
UUID=616c317d-6256-43b1-b669-4a7304f72576 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
# UUID=67d5b7a6-d098-47d7-a3da-0d19fecc30f0 none            swap    sw              0       0

然后重新启动系统就不会再出现1分30秒的等待时间。

另外网上有不少分享 把 /etc/fstab 中的 errors=remount-ro 0当作出错来处理,但实际这是系统的出错处理方案,具体意思是:出现errors时remount 重新挂载系统 ro 意思是只读/不能写,一般情况下只要系统正常运行根本就到不了这里。

如果需要设置swap可以参考这篇分享;方法一:这是一种用文件设置swap方法,比较安全没有什么风险,分享也写得非常清楚。

方法二:在之前的/dev/sda2 7.9G 5 Extended 建swap区
user1@dell_notebook:~$ sudo fdisk /dev/sda # 保险起见请在之前务必做磁盘备份

Welcome to fdisk (util-linux 2.33.1).
Changes 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: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: TOSHIBA MQ01ACF0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xb95fedf7Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048 960237567 960235520 457.9G 83 Linux
/dev/sda2       960237568 976773167  16535600   7.9G  5 Extended     #这分区可以分配给swap,但不能直接用Command (m for help): n      #新建逻辑分区
All space for primary partitions is in use.
Adding logical partition 5
First sector (960239616-976773167, default 960239616):    #直接回车
Last sector, +/-sectors or +/-size{K,M,G,T,P} (960239616-976773167, default 976773167):     #直接回车Created a new partition 5 of type 'Linux' and of size 7.9 GiB.
Partition #5 contains a swap signature.Do you want to remove the signature? [Y]es/[N]o: n       #保持原来的编号Command (m for help): p      #显示目前的状况Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: TOSHIBA MQ01ACF0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xb95fedf7Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048 960237567 960235520 457.9G 83 Linux
/dev/sda2       960237568 976773167  16535600   7.9G  5 Extended
/dev/sda5       960239616 976773167  16533552   7.9G 83 Linux      #还是Linux格式,要改成swap格式Command (m for help): t
Partition number (1,2,5, default 5):
Hex code (type L to list all codes): l0  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 or  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 ea  Rufus alignmente  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT
Hex code (type L to list all codes): 82     #选82 swap 格式Changed type of partition 'Linux' to 'Linux swap / Solaris'.Command (m for help): p
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: TOSHIBA MQ01ACF0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xb95fedf7Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048 960237567 960235520 457.9G 83 Linux
/dev/sda2       960237568 976773167  16535600   7.9G  5 Extended
/dev/sda5       960239616 976773167  16533552   7.9G 82 Linux swap / SolarisCommand (m for help): w      #写入磁盘
The partition table has been altered.
Syncing disks.user1@dell_notebook:~$ sudo vim /etc/fstab     # 在reboot前修改fstab说明,把之前注释掉的# UUID=67d5b7a6-d098-47d7-a3da-0d19fecc30f0 none            swap    sw              0       0  再去掉注释号“#”
user1@dell_notebook:~$ free -m    #查看swap状况total        used        free      shared  buff/cache   available
Mem:           7857         509         164          46        7183        7004
Swap:             0           0           0            #swap为零
user1@dell_notebook:~$ sudo swapon /dev/sda5  #激活swap
user1@dell_notebook:~$ free -m    #查看swap状况total        used        free      shared  buff/cache   available
Mem:           7857         511         174          46        7172        7003
Swap:          8071           0        8071
user1@dell_notebook:~$ sudo reboot
user1@dell_notebook:~$ lsblk     #列出块设备信息补充说明
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk
├─sda1   8:1    0 457.9G  0 part /
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0   7.9G  0 part [SWAP]

方法二还是有点复杂,但要搞明白了,对分区这块的操作部分就比较得心应手了。

在此再介绍几个相关辅助的命令:

cat /etc/fstab   #查看自动挂载磁盘文件

更多关于自动挂载文件请看分享文章;

ls -l /dev/disk/by-uuid/    #查看磁盘UUID
sudo blkid -o list          #查看磁盘UUID
sudo blkid                  #查看磁盘UUID,另外的格式

更多关于uuid的分享文章;

mkswap /dev/sda5    #格式化swap分区

更多关于swap分区的分享文章;

mkfs.ext4 /dev/sda1         #格式化linux分区

更多关于linux分区格式化的分享文章;

仔细查看了所有的deb笔记本电脑和服务器,笔记本电脑上都有这个错误,不知是什么原因,也不管是如何安装的,云服务器上都没有这个问题;有高手路过请告知缘由,不胜感激!

未解决的问题: 如何在笔记本上用parted做第一块硬盘分区?发现自己的系统都是用fdisk来分区的,不管是用自动分区还是手动分区,用U盘、CD还是网络安装。

关于为什么要分区的分享。

Linux Debian 分区出错Partition 2 does not start on physical sector boundary 解决方法 + swap相关推荐

  1. centos linux 系统上 log4j打印的时间与CST时间差8小时的解决方法

    centos linux 系统上 log4j打印的时间与CST时间差8小时的解决方法 参考文章: (1)centos linux 系统上 log4j打印的时间与CST时间差8小时的解决方法 (2)ht ...

  2. 〖Linux〗Kubuntu KDE开机后总是提示“system program problem detected”的解决方法

    [Linux]Kubuntu KDE开机后总是提示"system program problem detected"的解决方法 参考文章: (1)[Linux]Kubuntu KD ...

  3. Kali linux 2016.2(Rolling)之 Nessus安装及Plugins Download Fail 解决方法

    Kali linux 2016.2(Rolling)之 Nessus安装及Plugins Download Fail 解决方法 参考文章: (1)Kali linux 2016.2(Rolling)之 ...

  4. Linux系统中提示/usr/bin/ld: cannot find -lxxx错误的通用解决方法

    Linux系统中提示/usr/bin/ld: cannot find -lxxx错误的通用解决方法 参考文章: (1)Linux系统中提示/usr/bin/ld: cannot find -lxxx错 ...

  5. Linux中的基本命令无法使用,报Command not found的错误的解决方法

    Linux中的基本命令无法使用,报Command not found的错误的解决方法 参考文章: (1)Linux中的基本命令无法使用,报Command not found的错误的解决方法 (2)ht ...

  6. 关于“打开数据库时出错: 到主机 的 TCP/IP 连接失败。”的解决方法

    关于"打开数据库时出错: 到主机 的 TCP/IP 连接失败."的解决方法 我的电脑右键打开管理 将这"Named Pipes"和"TCP/IP&qu ...

  7. Linux | 终端显示为bash-4.1$以及提示bash:command not found的解决方法

    本文总结如何解决 Linux 终端显示为 bash-4.1 1 以及提示 bash: command not found 情形 2 ' 3 的解决方法. Updated: 2022 / 7 / 18 ...

  8. win10网络邻居看到linux,在Deepin 20系统中网络共享Windows无法访问的另类解决方法...

    本文在Deepin 20系统中实现网络共享Windows,但无法访问,以下是另类的解决方法之一. 系统环境 共享主机:Deepin 20. 访问共享:Windows7\10家庭版或专业版. 配置和出现 ...

  9. alpine linux 执行文件崩溃 报错 找不到/lib/x86_64-linux-gnu/libc.so 解决方法

    原因: 原因: 大多数 Linux 软件都与 glibc 相连接,GNU libc 库(libc 提供标准的 c 库和 POSIX API). 大多数 Linux 发行版都基于 glibc. Alpi ...

最新文章

  1. 如何管理大型呼叫中心
  2. Spring boot + Redis
  3. Linux确定命令的执行时长,Linux 历史命令显示执行时间
  4. 定义任务打印gradle下载的jar包位置
  5. python面试题总结(7)--操作类
  6. Java高级语法笔记-文件读写(2)
  7. 一加Nord 2配置细节曝光:天玑1200芯片+5000万像素旗舰主摄
  8. Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb
  9. 吴恩达机器学习作业5——偏差与方差
  10. php fastdfs扩展,php如何安装fastdfs扩展
  11. Java面试的基础题20190000
  12. 2016年工作中遇到的问题41-50:Dubbo注册中心奇葩问题,wifi热点坑了
  13. 最齐全的地面贴图素材,速来收藏
  14. Linux系统故障分析与排查
  15. 三星s8是否支持html,真正的全面屏!国行三星S8终于支持导航栏隐藏
  16. elementui表格鼠标滑轮控制横向滚动
  17. 超详细版-计算网络地址、子网、广播地址、主机数
  18. 想编程,是勤奋自学还是去培训班学习?
  19. [译] Font-size:一个意外复杂的 CSS 属性
  20. 文献阅读-用于图文检索的跨模态信息交互推理网络

热门文章

  1. 跨境电商亚马逊卖家最需要关注的四个维度的数据
  2. http中get/put/post区别
  3. scite php配置 下载,SciTE的基本配置文件
  4. gdb linux下载,GDB 7.11 发布下载,程序调试利器
  5. pandas -----变形(透视表、melt、stack、unstack),哑变量与因子变化
  6. 2014年珠宝行业下半年电商分析报告及双11销售排名
  7. 小程序空格解决文字分散对齐
  8. 快速入门pandas扩展库(上)
  9. 关注博主的博文汇总(孙志刚、贺利坚……)
  10. 曾被“霸凌”的两个孩子:电动汽车与分布式数据库