Ubuntu14.04 升级 SSD 产生的疑问

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
头像
admin_xyz
帖子: 199
注册时间: 2012-05-26 8:33
系统: Ubuntu 12.04

Ubuntu14.04 升级 SSD 产生的疑问

#1

帖子 admin_xyz » 2014-08-16 17:42

我的系统是ubuntu14.04
内核是Linux 3.13.0-33-generic
在某宝上买了块128G普科特的ssd

问题如下:

1. linux是否需要4K对齐?网上大神答案不统一.

2. 我用 fdisk -b 4096 /dev/sda 分区后, 用fdisk -lu 查看, 显示的是

root@gentoo:/dev# fdisk -lu sda

Disk sda: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 15566 cylinders, total 250069680 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2cb0e856

设备 启动 起点 终点 块数 Id 系统
sda1 256 13107455 6553600 83 Linux
sda2 13107456 26214655 6553600 5 扩展
sda5 13109504 26214654 6552575+ 83 Linux
root@gentoo:/dev#

显示的是512字节的扇区, 不是已经指定扇区的大小为4096了么... 求解

在线等...


问题3. 如何将当前机械硬盘中的ubuntu复制到ssd中, 用dd?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#2

帖子 poloshiao » 2014-08-16 18:18

linux是否需要4K对齐?网上大神答案不统一.
不是非要不可 下面的紅色字 表示 4K 对齐 的好處 藍色字 表示 沒有 4K 对齐 的壞處 特別是 紫色的裝置
http://www.thomas-krenn.com/en/wiki/Partition_Alignment
Partition alignment is understood to mean the proper alignment of partitions to the reasonable boundaries of a data storage device (such as a hard disk, solid-state drive (SSD) or RAID volume). Proper partition alignment ensures ideal performance during data access. Incorrect partition alignment will cause reduced performance, especially with regard to SSDs (with an internal page size of 4,096 or 8,192 bytes, for example), hard disks with four-kilobyte (4,096 byte) sectors and RAID volumes.
用fdisk -lu 查看
显示的是512字节的扇区, 不是已经指定扇区的大小为4096了么
http://manpages.ubuntu.com/manpages/tru ... isk.8.html
參數
-u[=unit]
When listing partition tables, show sizes in 'sectors' or in 'cylinders'. The default is to show sizes in sectors.
當你加了 -u 參數, 只能使用 sector 或 cylinder 為單位, default 是 sector, 512 bytes / sector.

試試
sudo fdisk -l -b 4096
问题3. 如何将当前机械硬盘中的ubuntu复制到ssd中, 用dd?
直接 dd 雖然可以試試 但不是 最妥善的方法
使用 fsarchiver 或 clonezilla 備存/回存 是比較妥適的方法
http://apexu.com/apexu/tw/modules/publi ... ?itemid=11
http://apexu.com/apexu/tw/modules/publi ... ?itemid=17
溫馨提示
使用 fsarchiver 或 clonezilla 備存/回存 包含 分割區的 uuid
如果 新舊分割區 還在同一台電腦 uuid 一樣 開機會引起 uuid 衝突
所以 如果 新舊分割區 還在同一台電腦 需要更改一個 分割區的 uuid 同時更改 /etc/fstab
头像
admin_xyz
帖子: 199
注册时间: 2012-05-26 8:33
系统: Ubuntu 12.04

Re: Ubuntu14.04 升级 SSD 产生的疑问

#3

帖子 admin_xyz » 2014-08-16 18:44

poloshiao 写了:
http://manpages.ubuntu.com/manpages/tru ... isk.8.html
參數
-u[=unit]
When listing partition tables, show sizes in 'sectors' or in 'cylinders'. The default is to show sizes in sectors.
當你加了 -u 參數, 只能使用 sector 或 cylinder 為單位, default 是 sector, 512 bytes / sector.

試試
sudo fdisk -l -b 4096





root@gentoo:/dev# sudo fdisk -l -b 4096
Warning: the -b (set sector size) option should be used with one specified device
Note: sector size is 4096 (not 512)

Disk /dev/sda: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 1945 cylinders, total 31258710 sectors
Units = 扇区 of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2cb0e856

设备 启动 起点 终点 块数 Id 系统
/dev/sda1 256 13107455 52428800 83 Linux
/dev/sda2 13107456 26214655 52428800 5 扩展
/dev/sda5 13107712 26214655 52427776 83 Linux


http://zhidao.baidu.com/link?url=uBQtWU ... uUf8VmSX9q

我的ssd是否已经4k对齐了?
百度知道上面说起始扇区和结束扇区要能被8整除...我的整队不了... 但是
Note: sector size is 4096 (not 512) 不代表已经对齐了吗?
所谓4k对齐不是把每个扇区设置为4096字节?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#4

帖子 poloshiao » 2014-08-16 18:50

Warning: the -b (set sector size) option should be used with one specified device
更正
使用 -b 參數 最好是 指定裝置
sudo fdisk -b 4096 /dev/sda
/dev/sda1 256 13107455 52428800 83 Linux
/dev/sda2 13107456 26214655 52428800 5 扩展
/dev/sda5 13107712 26214655 52427776 83 Linux
舉例
/dev/sda1
起點 512 bytes/sector x 256 sectors ÷ 4096 bytes = 32
大小 512 bytes/sector x (13107455 - 255 ) sectors ÷ 4096 bytes = 1638400 # 補充說明 255 = 256 - 1
起點 大小都是 4096 對齊 終點也一定是 4096 對齊
所以 你的 /dev/sda1 是 4096 對齊
/dev/sda2 /dev/sda3 你比照算一算
头像
admin_xyz
帖子: 199
注册时间: 2012-05-26 8:33
系统: Ubuntu 12.04

Re: Ubuntu14.04 升级 SSD 产生的疑问

#5

帖子 admin_xyz » 2014-08-16 18:58

poloshiao 写了:
Warning: the -b (set sector size) option should be used with one specified device
使用 -b 參數 最好是 指定裝置
sudo fdisk -b 4096 /dev/sda
不是一样吗

root@gentoo:/dev# fdisk -b 4096 -l sda
Note: sector size is 4096 (not 512)

Disk sda: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 1945 cylinders, total 31258710 sectors
Units = 扇区 of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2cb0e856

设备 启动 起点 终点 块数 Id 系统
sda1 256 13107455 52428800 83 Linux
sda2 13107456 26214655 52428800 5 扩展
sda5 13107712 26214655 52427776 83 Linux
root@gentoo:/dev#
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#6

帖子 poloshiao » 2014-08-16 19:01

我的现在是否已经是 4k 对齐了呢?
參見
viewtopic.php?p=3100169#p3100169

/dev/sda1
舉例
fdisk -b 4096 -l sda
最好加 sudo
-l 或 /dev/sda 選一種
sudo fdisk -b 4096 /dev/sda

sudo fdisk -l
头像
admin_xyz
帖子: 199
注册时间: 2012-05-26 8:33
系统: Ubuntu 12.04

Re: Ubuntu14.04 升级 SSD 产生的疑问

#7

帖子 admin_xyz » 2014-08-16 19:18

poloshiao 写了:
Warning: the -b (set sector size) option should be used with one specified device
sudo fdisk -b 4096 /dev/sda
/dev/sda1 256 13107455 52428800 83 Linux
/dev/sda2 13107456 26214655 52428800 5 扩展
/dev/sda5 13107712 26214655 52427776 83 Linux
舉例
/dev/sda1
起點 512 bytes/sector x 256 sectors ÷ 4096 bytes = 32
大小 512 bytes/sector x (13107455 - 255 ) sectors ÷ 4096 bytes = 1638400
起點 大小都是 4096 對齊 終點也一定是 4096 對齊
所以 你的 /dev/sda1 是 4096 對齊
/dev/sda2 /dev/sda3 你比照算一算
512字节是从哪来的?
(13107455 - 255 ) sectors ÷ 4096 bytes = 多少个4096字节的扇区
对吗?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#8

帖子 poloshiao » 2014-08-16 19:33

512字节是从哪来的?
參閱
viewtopic.php?p=3100157#p3100157
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
512 bytes / serctor
參見
http://en.wikipedia.org/wiki/Disk_sector
However, by far the majority of hard drives shipped up to the start of the 2010s still used the traditional 512-byte sector size.
(13107455 - 255 ) sectors ÷ 4096 bytes = 多少个4096字节的扇区
对吗?
不對
被除數 與 除數 單位必須相同 才有意義
头像
admin_xyz
帖子: 199
注册时间: 2012-05-26 8:33
系统: Ubuntu 12.04

Re: Ubuntu14.04 升级 SSD 产生的疑问

#9

帖子 admin_xyz » 2014-08-16 19:49

poloshiao 写了:
512字节是从哪来的?
參閱
viewtopic.php?p=3100157#p3100157
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
512 bytes / serctor
參見
http://en.wikipedia.org/wiki/Disk_sector
However, by far the majority of hard drives shipped up to the start of the 2010s still used the traditional 512-byte sector size.
(13107455 - 255 ) sectors ÷ 4096 bytes = 多少个4096字节的扇区
对吗?
不對
被除數 與 除數 單位必須相同 才有意義

起点和终点是以扇区为单位的是吧
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#10

帖子 poloshiao » 2014-08-16 20:18

起点和终点是以扇区为单位的是吧
無論是
sudo fdisk /dev/sda -l
sudo parted /dev/sda print
sudo gdisk /dev/sda -l
等等
都是 顯示出來時 臨時指定 起點/終點/大小 的基本單位
還可以增加參數 指定 顯示的基本單位
不是 分割當下 原生的基本單位
cao627
帖子: 992
注册时间: 2007-12-05 10:57
系统: ubuntu14.04
来自: 金山

Re: Ubuntu14.04 升级 SSD 产生的疑问

#11

帖子 cao627 » 2014-08-16 23:13

root@gentoo:/dev# fdisk -lu sda

Disk sda: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 15566 cylinders, total 250069680 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2cb0e856

你的逻辑扇区和物理扇区大小都是512字节
设备 启动 起点 终点 块数 Id 系统
sda1 256 13107455 6553600 83 Linux
sda2 13107456 26214655 6553600 5 扩展
sda5 13109504 26214654 6552575+ 83 Linux
256 13107455说明你的第一个分区的起始位置于第256号扇区,结束于第13107455号扇区
由于每个扇区为512字节,所以第一个分区大小正好为4096的整数倍(正如4楼为你算的):
512 bytes/sector x (13107455 - 255 ) sectors ÷ 4096 bytes = 1638400

我是这么理解的:
操作系统是安块(block)存取文件的,格式化文件系统时指定块的大小,块的概念是:比如指定了块的大小为4096byte,那么一个4097byte大小的文件只能用两个块即8192个字节来存,其中一个块中只存了一个字节,并且这个块中剩下的4095个字节只能浪费而不能别的文件利用了。

分区的时候必须考虑不能让一个块跨在两个分区上,这样造成跨区读写,读写次数放大,从而影响读写速度。即一个扇区的bytes x (分区结束扇区号 - 分区开始扇区号 ) ÷ 一个block的bytes要是一个整数。我觉得这是4k或nk对齐的概念和意义(可能不对)。

至于物理扇区和逻辑扇区Sector size (logical/physical),到底是个什么东东我也不太理解,感觉物理physical的应该是硬盘固有的属性,不能倍软件改变大小。又或是physical就是block?而logical只是个虚拟玩意没有实际意义?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#12

帖子 poloshiao » 2014-08-17 0:58

起点和终点是以扇区为单位的是吧
這是早期 (2002 年以前)對於硬盤定址的理解
http://en.wikipedia.org/wiki/Cylinder-head-sector

這是最近 (2002 年以後)對於硬盤定址的理解
http://en.wikipedia.org/wiki/Logical_block_addressing
在 LBA 定址的概念 要實體去找出 cylinder / head / sector 的精確位置 是沒有意義的 所以 扇區為單位 只存在你的想像中 幫助你理解 實體硬盤上 是沒有的
npxywml
帖子: 206
注册时间: 2009-08-29 14:44

Re: Ubuntu14.04 升级 SSD 产生的疑问

#13

帖子 npxywml » 2014-08-17 11:36

前一段也买了块SSD,分别安装了win8.1和ubuntu14.04。其中win是重新安装,ubuntu是采用分区助手的复制分区的方式将两分区(我的ubuntu只有两分区)搬到SSD上的。然后用U盘重建引导。
头像
admin_xyz
帖子: 199
注册时间: 2012-05-26 8:33
系统: Ubuntu 12.04

Re: Ubuntu14.04 升级 SSD 产生的疑问

#14

帖子 admin_xyz » 2014-08-17 14:46

poloshiao 写了:
起点和终点是以扇区为单位的是吧
這是早期 (2002 年以前)對於硬盤定址的理解
http://en.wikipedia.org/wiki/Cylinder-head-sector

這是最近 (2002 年以後)對於硬盤定址的理解
http://en.wikipedia.org/wiki/Logical_block_addressing
在 LBA 定址的概念 要實體去找出 cylinder / head / sector 的精確位置 是沒有意義的 所以 扇區為單位 只存在你的想像中 幫助你理解 實體硬盤上 是沒有的
还有一点小问题没有理解,
问题1
fdisk -b 4096 /dev/sda
这不就是指定扇区大小为4096byte吗,为什么显示的还是512byte呢
问题2
fdisk -b 4096 /dev/sda 这个是指定sector size的
mkfs.ext4 -b 4096 /dev/sda1 这个是指定block size的
两者有什么关系吗
4K对齐需要把block大小设置为4096?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: Ubuntu14.04 升级 SSD 产生的疑问

#15

帖子 poloshiao » 2014-08-17 18:09

问题1
fdisk -b 4096 /dev/sda
这不就是指定扇区大小为4096byte吗,为什么显示的还是512byte呢
1. viewtopic.php?p=3100178#p3100178
by far the majority of hard drives shipped up to the start of the 2010s still used the traditional 512-byte sector size.
現在硬盤出廠時使用的最小基本單位就是 512 bytes / seector

2. http://www.tomshardware.com/forum/26424 ... kb#5972460
All current drives use 512-byte sectors, even the "Advanced Format" drives. From the point of view of the OS the advanced format drives "look" like they record 512-byte sectors, but the drive actually records eight 512-byte "logical" sectors into a single 4096-byte "physical" sector. The internal format of the drive with it's larger sectors is completely hidden to everything except the firmware in the drive itself.
所謂 4096byte 是說 硬盤一次寫入 8 個連續的 sectors = 512 x 8 = 4096 bytes 但是 硬盤最小基本單位還是 512 bytes / sector

3. http://ubuntuforums.org/showthread.php? ... st10869301
You should NOT attempt to adjust the sector size using fdisk's -b option! Doing so will produce a completely unusable partition table. Advanced Format disks lie about their sector size and "translate" themselves, so trying to do the "translation" yourself in fdisk would be like doing an English-to-metric conversion twice.
不應該使用 -b 參數 想要改變 sector size

4. http://manpages.ubuntu.com/manpages/tru ... isk.8.html
-b sectorsize
Specify the sector size of the disk. Valid values are 512,
1024, 2048 or 4096. (Recent kernels know the sector size. Use
this only on old kernels or to override the kernel's ideas.)
Since util-linux-2.17, fdisk differentiates between logical and
physical sector size. This option changes both sector sizes to
sectorsize.
自從 Linux kernel 2.17 以後的版本 fdisk 可以識別 logical and
physical sector size
只有早期的 linux kernel 才需要使用 -b 參數 現在的 linux kernel 自己會識別 不必增加 -b 參數
问题2
fdisk -b 4096 /dev/sda 这个是指定sector size的
mkfs.ext4 -b 4096 /dev/sda1 这个是指定block size的
两者有什么关系吗
4K对齐需要把block大小设置为4096?
5. fdisk -b 4096 /dev/sda 这个是指定sector size的
請見 1 --> 4

6. 這是最近 (2002 年以後)對於硬盤定址的理解
http://en.wikipedia.org/wiki/Logical_block_addressing

7. 甚麼是 block ? block 與 數據存取
http://en.wikipedia.org/wiki/Block_%28data_storage%29

8. http://manpages.ubuntu.com/manpages/tru ... xt4.8.html
mke2fs - create an ext2/ext3/ext4 filesystem
-b block-size
Specify the size of blocks in bytes. Valid block-size values
are 1024, 2048 and 4096 bytes per block.
1024=512x2
2048=512x4
4096=512x8
表示指定 block 的大小是 512 的整數倍
最小基本單位 還是 512 bytes / sector

9. 舉例說明
sudo fdisk /dev/sdb -l
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 磁頭,63 磁區/磁軌,60801 磁柱,總計 976773168 磁區
單位 = 磁區 之於 1 * 512 = 512 位元組
磁區大小 (邏輯/實體):512 位元組 / 512 位元組
I/O 大小 (最小/最佳化):512 位元組 / 512 位元組
磁碟識別碼:0x0005a4ea
所用裝置 開機 開始 結束 區塊 識別號 系統
/dev/sdb1 * 2048 204802047 102400000 83 Linux
... 以下省略
204802047 - 2047 = 204800000 sectors
204800000 ÷ 102400000 = 2 sectors/block
512 bytes/sector x 2 sectors/block = 1024 bytes / block

9-1. 1024 bytes / block 預設值 見
http://manpages.ubuntu.com/manpages/tru ... onf.5.html
small = {
blocksize = 1024
inode_ratio = 4096
}
回复