# migrating usb install to ssd [done]

## DaggyStyle

warning! ssd noob here (first time)

I have an gentoo install on usb which I want to migrate to ssd, the system is a home server on 24/7, running 2 vms and media server.

the system does not compile pkgs but gets bin upgrades via nfs.

will dd of the usb image to the ssd, resize the last partition (roofs), adding discard to fstab and fstrim in cron once a week will work?

or should I partition the ssd based on https://wiki.gentoo.org/wiki/SSD#Dealing_with_empty_blocks, copy the rootfs and /boot parition and run grub install?

----------

## NeddySeagoon

DaggyStyle,

I would do the latter. 

dd does a low level copy, including unallocated space. Thats extra writes that your SSD does not need.

The SSD will use a 4k physical block size. Your USB HDD may not.

Its essential that on your SSD, partitions are correctly aligned. Misalignment on a HDD makes writes slow.

On an SSD it leads to 'write amplification'. 

Use fstrim rather than discard. Discard is supposed to be an advisory to an SSD. Unfortunately many SSDs treat it as a command.

That's a bad thing for the SSD. Its good for vendors though as you will need a new one sooner. :)

fstrim in a cron job is a good compromise.

Partitiion the SSD as suits your purpose.

Then copy the filesystem content over.

Reinstall the boot loader as required.

This will give you all new PARTUUIDS and filesystem UUIDs You may need to adjust the kernel line in grub to suit and fstab.

----------

## Anon-E-moose

When I went from hd to ssd I just copied all the files from the hd to ssd, I forget whether I used cp or rsync, but I got a duplicate of all files, dir, etc with permissions, etc.

I had created the layout on the ssd the way I wanted it first (whatever size you want) then did the copy, and reran grub (v1 at that time) on the ssd.

In this case sda1, sda2, etc had stayed the same as I used the same ahci plug on the mother just removing the hd and putting the ssd in it's place.

When I went from ssd to nvme, I did a similar thing, but I swapped out handy old grub for a uefi partition instead, and made a few tweaks to point things like fstab to the nvme instead of the ssd, before mounting it live and letting go.

Edit to add:

 *NeddySeagoon wrote:*   

> The SSD will use a 4k physical block size. Your USB HDD may not.
> 
> Its essential that on your SSD, partitions are correctly aligned. Misalignment on a HDD makes writes slow.
> 
> On an SSD it leads to 'write amplification'. 

 

AFAIK most modern ssd use a 512 byte block size, like the hdd. 

But if you use parted/gparted, then it's easy enough let it align it properly, and it will check for optimum alignment. 

```
Disk model: Samsung SSD 840 

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes
```

----------

## NeddySeagoon

Anon-E-moose,

Most modern drives fake a 512b block size to keep older applications happy.

Some lie about it in the SMART data too.

----------

## DaggyStyle

thanks, will take all into account.

----------

## DaggyStyle

at last I got a chance to setup the ssd, however I don't see a 4k alignment, see:

```
Disk /dev/sda: 111.81 GiB, 120034123776 bytes, 234441648 sectors

Disk model: TS120GSSD220S   

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: 9BDCF149-D1E4-4ECB-A77D-6AF5A2D3D184
```

is this logical? can this be related to the sata port or cable?

----------

## NeddySeagoon

DaggyStyle,

Modern fdisk and parted will keep you right, it will set 4k alignment for you.

```

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes 
```

I suspect the physical / 512 bytes is faked. Using a 4k sector size and alignment is safe.

----------

## DaggyStyle

I've found this script: http://opensource.hqcodeshop.com/Parted%20calculator/parted_mkpart_calc.sh

used it to create the partition table which looks like this:

```
Model: ATA TS120GSSD220S (scsi)

Disk /dev/sda: 120GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags: 

Number  Start   End     Size    File system     Name  Flags

 1      1049kB  3146kB  2098kB  fat32           grub  bios_grub

 2      4194kB  268MB   264MB   fat16           boot  boot, esp

 3      269MB   104GB   104GB                   root

 4      104GB   120GB   16.0GB  linux-swap(v1)  swap  swap

```

parted says all the partition are optimally aligned.

question is, can I trust it?

----------

## NeddySeagoon

DaggyStyle,

There is no need to trust it. Look at the sector display.

All the Starting Sectors need to be exactly divisible by 8. parted is normally OK.

----------

## DaggyStyle

great, so the script worked, now I only need to find the Erase Block Size so I can properly format the rootfs

thanks for the assurance

----------

## NeddySeagoon

DaggyStyle,

Discovering the erase block size is difficult. Its rarely published.

You will get some write amplification anyway. In my mind it, won't matter because the drive will be too small to be useful long before its worn out.

My smart data says

```
ID# ATTRIBUTE_NAME          FLAGS    VALUE WORST THRESH FAIL RAW_VALUE

  1 Raw_Read_Error_Rate     POSR-K   100   100   000    -    0

  5 Reallocate_NAND_Blk_Cnt PO--CK   100   100   000    -    0

  9 Power_On_Hours          -O--CK   100   100   000    -    24056

 12 Power_Cycle_Count       -O--CK   100   100   000    -    2615

171 Program_Fail_Count      -O--CK   100   100   000    -    0

172 Erase_Fail_Count        -O--CK   100   100   000    -    0

173 Ave_Block-Erase_Count   -O--CK   100   100   000    -    22

...

Device Statistics (GP Log 0x04)

Page  Offset Size        Value Flags Description

0x07  0x008  1               3  N--  Percentage Used Endurance Indicator
```

so after 24000 operating hours, each block has been erased about 22 times and I've used about 3% of the drive life. The drive is about 6 years old.  Its already smaller than I would like but 3% life used over 6 year means the drive has an erase life, the way I use it, of 180 years. 

I won't be here to care when it fails :)

----------

## DaggyStyle

 *NeddySeagoon wrote:*   

> DaggyStyle,
> 
> Discovering the erase block size is difficult. Its rarely published.
> 
> You will get some write amplification anyway. In my mind it, won't matter because the drive will be too small to be useful long before its worn out.
> ...

 

so I should format it normally?

----------

## DaggyStyle

I've seen here that adding noatime,nodiratime to the partition's fstab is a good idea.

also, would it be preferable to place swap on an external usb device rather than the ssd?

----------

## NeddySeagoon

DaggyStyle,

noatime is not a default and prevents a file you read from incurring a directory write to update the atime entry.

That's a good idea anyway.

I'm not sure if nodiratime is a default or not.

One of us needs to read the man page :) 

I don't have it set explicitly and I'm still looking at a wear out duration of 180 years.

----------

## DaggyStyle

 *NeddySeagoon wrote:*   

> DaggyStyle,
> 
> noatime is not a default and prevents a file you read from incurring a directory write to update the atime entry.
> 
> That's a good idea anyway.
> ...

 

so bottom line, format as is (transcend support won't give up the magic number), add noatime, check on nodiratime.

last thing to think, swap on usb or leave it on the ssd....

----------

## szatox

 *Quote:*   

>  last thing to think, swap on usb or leave it on the ssd....

 On whichever device is faster. Most likely SSD.

SSD offers cheap IO.

HDD offers cheap capacity.

If you are not going to use the IO, there is little reason to pick an SSD in the first place (well, shock-resistance helps a bit if you want your laptop powered on when traveling)

Killing it will take some time and dedication.

Setting swappiness to some low value (e.g. 1 or even 0, down from default 60) won't hurt though.

----------

## NeddySeagoon

DaggyStyle,

If  you ever touch more than about 1M of swap, you don't have enough real RAM.

Add more RAM or fix whatever is driving swap.

If you need swap for hibernate, put it on the SSD so you get the best possible resume speed.

----------

## DaggyStyle

 *NeddySeagoon wrote:*   

> DaggyStyle,
> 
> If  you ever touch more than about 1M of swap, you don't have enough real RAM.
> 
> Add more RAM or fix whatever is driving swap.
> ...

 

the system has 12gb of ram, 2 allocated to the gpu, 8 are used by 2 vms in total and 2 are left for the host os which acts as nas server.

I remember that with 4gb, when I allocated 1gb to the host os (the rest of the 3GB was split between the vms and the gpu), it used swap. thus I'm not sure where to put swap.

as this is an home server, hibernate is not needed.

due to budget constraints, adding more ram is not an option.

----------

## DaggyStyle

I was offered this explanation:

```
The SSD220S should be a SM2258 + IMFT TLC. At smaller capacities, 256Gb/die. Typically 2304 pages per block at 16KB (user) per page, albeit in two planes. This would imply a 36MB block size, not counting ECC/spare.
```

seems logical?

----------

## szatox

I lost the train of thought.

It's an explanation to what exactly?

----------

## DaggyStyle

 *szatox wrote:*   

> I lost the train of thought.
> 
> It's an explanation to what exactly?

 

erase block size of 36MB... which seems alot to me...

----------

## DaggyStyle

migration completed, thanks for all the help.

side note, I was never a fan of sata ssd, I truly think they aren't worthwhile and prefer nvme ssd but the change is quite noticeable. especially from usb hdd

----------

## Tony0945

 *DaggyStyle wrote:*   

> migration completed, thanks for all the help.
> 
> side note, I was never a fan of sata ssd, I truly think they aren't worthwhile and prefer nvme ssd but the change is quite noticeable. especially from usb hdd

   I have an older k10 system with no NVME slots and BIOS boot only. It chainloads grub-legacy on a 10,000 RPM 500G Velociraptor from a damaged Win XP disk. There is just enough left good on the disk to chain load, not enough to actually boot Windows. The velociraptor is pretty full and the drive light runs long during searches (better after I defragged). I just happen to have a brand new 1TB SATA SSD that I just couldn't resist buying on Black Friday. So ....

Yes, there is a use for SATA SSD besides laptops.

----------

## DaggyStyle

I work with both the best ssds out there and the best nvmes out there and I'll go with nvme every time you ask.

but on this specific system, I can have only a 2.5 inch hdd so ssd was selected.

----------

## Tony0945

 *DaggyStyle wrote:*   

> I work with both the best ssds out there and the best nvmes out there and I'll go with nvme every time you ask.
> 
> but on this specific system, I can have only a 2.5 inch hdd so ssd was selected.

 

Good to know. I have an Asus NVME board, 3900X and other goodies still sitting in packages as I put my finger in the dike of these older boxes.

----------

## DaggyStyle

 *Tony0945 wrote:*   

>  *DaggyStyle wrote:*   I work with both the best ssds out there and the best nvmes out there and I'll go with nvme every time you ask.
> 
> but on this specific system, I can have only a 2.5 inch hdd so ssd was selected. 
> 
> Good to know. I have an Asus NVME board, 3900X and other goodies still sitting in packages as I put my finger in the dike of these older boxes.

 

why?

unpack and build already

----------

