Wednesday, July 29, 2020

Online disk resize and MBR to GPT upgrade

I'm upgrading from a 2TB drive to a 6TB drive in my home server, Gus (named for the character in Psych), which has been running since just after Christmas 2010.

In 2016 I had to rebuild the OS onto a new HDD due to disk corruption.

First, I checked the new 6TB Western Digital Blue HDD for bad blocks by plugging it into my WavLink dual-bay docking station/drive cloner (aka "the toaster") and running commands like this:

jonathan@hastings:~$ # Determine the device file for the disk I just connected.
jonathan@hastings:~$ dmesg | tail
[1429251.453182] scsi host7: uas
[1429251.453762] scsi 7:0:0:0: Direct-Access USB3.0 0101 PQ: 0 ANSI: 6
[1429251.454622] sd 7:0:0:0: Attached scsi generic sg1 type 0
[1429251.455556] sd 7:0:0:0: [sdc] 11721045168 512-byte logical blocks: (6.00 TB/5.46 TiB)
[1429251.455757] sd 7:0:0:0: [sdc] Write Protect is off
[1429251.455759] sd 7:0:0:0: [sdc] Mode Sense: 67 00 10 08
[1429251.456138] sd 7:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[1429251.478343] sdc: sdc1
[1429251.481041] sd 7:0:0:0: [sdc] Attached SCSI disk

jonathan@hastings:~$ # Note the 'sdc' above, and replace 'sdx' below with that.
jonathan@hastings:~$ sudo badblocks -sw -b 4096 -c 1024 -o ~/tmp/badblocks.out /dev/sdx

This took 3 days to run a single write/read pass, but that's my fault; I plugged it into a USB 2.0 port by accident, and then, when I realized, I figured, "How long can it take, really?" But it was definitely worth it, because this was actually the fourth drive I received; the first three were all bad, likely due to rough shipping.

Once that was complete, it was time for the copy. I unplugged the toaster from my laptop, pulled the old 2TB HDD out of Gus, and put it into the 'Source' bay, with the new 6TB HDD in the 'Target' bay. Then I turned it on, held the red button until it started flashing, and then tapped the red button again to start the copy. It took about three hours.

Next, I put the new HDD back into Gus and powered it up. This is where things got interesting, because I was unaware of MBR vs. GPT partition table formats, and the fact that an MBR table only supports disks up to 2TB. Luckily, because I was only using 2TB, Gus booted up fine.

How to upgrade from MBR to GPT

I've filtered the commands below to just the useful stuff, without including all of the wrong paths I took trying to figure out what I needed to do:

jonathan@gus:~$ # Convert from MBR to GPT:
jonathan@gus:~$ # Once you've started, DO NOT REBOOT until you have finished!
jonathan@gus:~$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3

Caution: invalid main GPT header, but valid backup; regenerating main header
from backup!

Caution! After loading partitions, the CRC doesn't check out!
Warning! Main partition table CRC mismatch! Loaded backup partition table
instead of main partition table!

Warning! One or more CRCs don't match. You should repair the disk!

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: damaged

Found valid MBR and corrupt GPT. Which do you want to use? (Using the
GPT MAY permit recovery of GPT data.)
1 - MBR
2 - GPT
3 - Create blank GPT

Your answer: 1

Command (? for help): p
Disk /dev/sda: 11721045168 sectors, 5.5 TiB
Model: WDC WD60EZAZ-00Z
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 28E343DC-CD48-47A5-BE29-82C07F3BC14E
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 11721045134
Partitions will be aligned on 2048-sector boundaries
Total free space is 7814017981 sectors (3.6 TiB)

Number Start (sector) End (sector) Size Code Name
1 2048 3907029167 1.8 TiB 8E00 Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

jonathan@gus:~$ # Resize from 2TB to 6TB, leaving a small partition at the end for Grub's second stage:
jonathan@gus:~$ sudo parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 2000GB 2000GB Linux LVM lvm

(parted) help resizepart
resizepart NUMBER END resize partition NUMBER

NUMBER is the partition number used by Linux. On MS-DOS disk labels, the primary partitions number from 1 to 4, logical partitions from 5 onwards.
END is disk location, such as 4GB or 10%. Negative value counts from the end of the disk. For example, -1s specifies exactly the last sector.
(parted) resizepart 1 6000GB
(parted) print
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 6000GB 6000GB Linux LVM lvm

(parted) help mkpart
mkpart PART-TYPE [FS-TYPE] START END make a partition

PART-TYPE is one of: primary, logical, extended
FS-TYPE is one of: zfs, btrfs, nilfs2, ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, swsusp, linux-swap(v1), linux-swap(v0), ntfs, reiserfs, freebsd-ufs,
hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0, linux-swap,
linux-swap(new), linux-swap(old)
START and END are disk locations, such as 4GB or 10%. Negative values count from the end of the disk. For example, -1s specifies exactly the last sector.

'mkpart' makes a partition without creating a new file system on the partition. FS-TYPE may be specified to set an appropriate partition ID.
(parted) mkpart primary 6000GB 100%
(parted) print
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 6000GB 6000GB Linux LVM lvm
2 6000GB 6001GB 1174MB primary

(parted) help toggle
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER

NUMBER is the partition number used by Linux. On MS-DOS disk labels, the primary partitions number from 1 to 4, logical partitions from 5 onwards.
FLAG is one of: boot, root, swap, hidden, raid, lvm, lba, hp-service, palo, prep, msftres, bios_grub, atvrecv, diag, legacy_boot, msftdata, irst, esp
(parted) toggle 2 bios_grub
(parted) print
Model: ATA WDC WD60EZAZ-00Z (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 6000GB 6000GB Linux LVM lvm
2 6000GB 6001GB 1174MB primary bios_grub

(parted) quit
Information: You may need to update /etc/fstab.

jonathan@gus:~$ # Install Grub into the new GPT and trailing drive partition:
jonathan@gus:~$ sudo grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.

jonathan@gus:~$ # It is now safe to reboot.

jonathan@gus:~$ # The remaining steps add the new bytes in the expanded partition to my LVM volume group.
jonathan@gus:~$ # Resize the physical LVM volume to take up the full partition:
jonathan@gus:~$ sudo pvresize /dev/sda1
Physical volume "/dev/sda1" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
jonathan@gus:~$ sudo vgdisplay gus_vg
--- Volume group ---
VG Name gus_vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 19
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 9
Open LV 9
Max PV 0
Cur PV 1
Act PV 1
VG Size <5.46 TiB
PE Size 4.00 MiB
Total PE 1430510
Alloc PE / Size 451584 / 1.72 TiB
Free PE / Size 978926 / 3.73 TiB
VG UUID XHTcXt-iK4c-yFt6-CGt8-rdyA-o2Jl-NW2X7r

jonathan@gus:~$ # And finally, my wife has been asking for more space in her home directory, so:
jonathan@gus:~$ sudo lvextend -L +100G /dev/gus_vg/home_sara_lv
Size of logical volume gus_vg/home_sara_lv changed from 570.00 GiB (145920 extents) to 670.00 GiB (171520 extents).
Logical volume gus_vg/home_sara_lv successfully resized.

jonathan@gus:~$ sudo resize2fs /dev/gus_vg/home_sara_lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/gus_vg/home_sara_lv is mounted on /home/sara; on-line resizing required
old_desc_blocks = 36, new_desc_blocks = 42
The filesystem on /dev/gus_vg/home_sara_lv is now 175636480 (4k) blocks long.

Note: As an Amazon associate, I may earn a commission from purchases made through links followed from this page.

Sunday, September 15, 2019

Git pre-commit hook to disallow a substring

This took way longer than it should have to figure out, so I wanted to share in case others are trying to do the same thing.

Add this snippet to your Git pre-commit hook to prevent (in this case) the substring FIXME from making it into a committed file. Since the hook includes the substring 'FIXME' you'll need to commit like this:
git add git-hooks/pre-commit
allowfixme=true git commit -m 'Disallow FIXME in committed files.'
Here's the code. Public domain, unless you really need a license, in which case use the MIT license. If you can, I'd appreciate a link, but no worries if not.
# Disallow 'FIXME' from being committed. 'TODO' is for cross-commit notes of
# pending work, but 'FIXME' is for things that need to be updated before
# committing.
# Set allowfixme=true to allow commit anyway, such as if the file contains
# 'FIXME' for a good reason (like this file), or you have some other reason
# to leave it in the repo for now.
if [ "$allowfixme" != "true" ] ; then
  found_fixme=
  for F in $(git diff --cached --name-only) ; do
    C=$(git ls-files -s "$F" | awk '{print $2}')
    if git cat-file blob "$C" | grep -q 'FIXME' ; then
      if [ -z "$found_fixme" ] ; then
        echo "COMMIT REJECTED: Found 'FIXME' in:"
        found_fixme=1
      fi
      echo "  $F"
    fi
  done
  if [ -n "$found_fixme" ] ; then
    echo "Please remove before committing."
    exit 1
  fi
fi

Saturday, September 29, 2018

Laptop Shopping: The Winner

This is a followup to my New Laptop Shopping post.

The laptop I chose to purchase is the MSI GT63 Titan-047. It was between that an the Alienware 15, which both best met the requirements I described in my original post. The only clear differences were the manufacturer, and that the Alienware was priced at $1950 (from Dell's site) and the MSI at $2100 (from Amazon).

As of this writing (and, I believe, until September 30), the MSI is available for $2200 - $150 mail-in rebate from Newegg. That makes the price difference just $100.

Two factors made me choose the MSI over the Alienware: First, my current laptop is an MSI, and I didn't even consider looking at replacements until more than five years after purchase. Second, Newegg's return policy explicitly mentions installing additional operating systems being accepted, as long as the recovery partition is retained (you should check their wording before relying on my account, though).

So I bought the MSI from Newegg. It arrived Thursday (today is Saturday), and I am loving it so far. Being so new, it's got a couple glitches under Ubuntu, but nothing serious. My main (unstated) requirement was that it could run Fallout 4 at top settings, and it is managing that with flying colors. The screen is beautiful and smooth, the keyboard is a delight to type on (although MSI is still doing that obnoxious thing where they put the Home and End keys both out of reach, and require Fn-activation for them), and the trackpad supports my desired scrolling and tapping (although Windows is scrolling in reverse, and does not seem to provide an option to fix it).

I wholeheartedly recommend the MSI GT63 Titan 047 (Amazon link).

And if you have trouble with your WiFi under Linux, try this:

git clone https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/backport-iwlwifi.git
cd backport-iwlwifi
make
sudo make install

Note: As an Amazon associate, I may earn a commission from purchases made through links followed from this page.

Laptop Shopping: MSI GS65 Stealth Thin

This is a followup to my New Laptop Shopping post.

Since all three lists I consulted for the "best gaming laptops of 2018" mentioned the MSI GS65 Stealth Thin, I decided I should take a look at it before making my decision between my top two choices (the Alienware 15 and the MSI GT63 Titan 047).

I had initially discarded the GS65 from consideration because of its use of NVidia's "Max-Q" branding, which is intended to be positive, but actually labels laptops that are too thin to effectively deal with the heat produced by an over-powered video card. That is, they are lap-burners, not lap-tops.

But to be fair, let's take a look at the specs:

  • Display: 15-inch FHD 144Hz IPS
  • CPU: Intel eighth-gen i7
  • GPU: NVidia 1070 Max-Q
  • RAM: 16g
  • Storage: 512g SSD, no HDD
  • Price: $2000
This meets or beats most of my requirements -- Good CPU, RAM, and Display (once I decided I was okay with an FHD with a high-refresh-rate), and a better GPU than I really need.

But I have two issues with this design: First, there is no spare storage. 512g is more than enough for just running Ubuntu (and might suffice for an exclusive Windows user), but I know I would have issues trying to split it between Ubuntu and Windows.

Second, it is branded Max-Q, which I see as a big negative. And don't just take my word for it that Max-Q has heat issues: LaptopMag says the keyboard got up to 101*F after 15 minutes gaming, and CNet's own review said the Esc and W keys, wrist rest, and touchpad all got uncomfortably hot within an hour.



Oh, and it's $2000, which is intended to be the top of my budget for a computer that actually meets my requirements. So... no.

Sunday, September 23, 2018

Laptop Shopping: Top Gaming Laptops of 2018

This is a followup to my New Laptop Shopping post.

Today I'm going to look at three lists of the top gaming laptops of 2018, hoping to pick out some models worth further research.

CNet
Let's start with CNet's Best Gaming Laptops for 2018, since I already mentioned it in my post researching the Razer Blade 15. I'm not going to list the full models (copyright and all that; go read through the list!), just the brand names (and when one appears multiple times on the same list, whether it's the first, second, etc. appearance):

Eliminated due to Max-Q: The Razer (first), MSI, Asus, Digital Storm, and Dell models.

Eliminated due to CPU model: The Acer, Lenovo, and Razer (second) models.

Eliminated due to being made by HP: The HP model.

Interesting... That was all of them.

TechRadar
Turns out CNet isn't the only publication with a Best Laptops list, so let's check out the one from TechRadar!

Eliminated due to being on the CNet list: The MSI and Razer models.

Eliminated due to screen size (I want 15-inch): The Asus (second) and Alienware (first and second) models.

Eliminated due to using an old-model CPU: The Asus (first and third), Acer, and Gigabyte models.

Eliminated due to using a Radeon card: The Dell model.

Okay, so that was their entire list too...

PC Gamer
Maybe the list from PC Gamer will be more fruitful?

Eliminated to being on the CNet and TechRadar lists: The MSI and Razer models (makes me wonder if they're worth another look, though...)

Eliminated due to using an old-model CPU: The Asus, Acer (first and second), and Dell models.

Eliminated due to screen size (I want 15-inch): The MSI model. But I notice this is a Titan, and probably helped lead me towards the GT63 Titan I looked at the other day.

Eliminated due to Max-Q: The Gigabyte model.

I guess that's everything. Either I'm being to picky, or the Top Laptops lists just suck. I will take a closer look at the MSI GS65 since it was on all three lists. The Razer Blade 15 is still out because I couldn't get it with an NVidia 1070 at a reasonable price, and it's branded Max-Q.

Saturday, September 22, 2018

Laptop Shopping: MSI GT63 Titan 047

This is a followup to my New Laptop Shopping post.

Although the MSI GT63 Titan-047 (wow, that's a mouthful of a model designation) is not on the CNet list, I found it by narrowing down the options on MSI's site. I specifically chose the GT series (I have no idea what GT means in comparison to GS, GE, GP, GL, wtf how many of these do they have?), but my current laptop is a GT and I like it. So I figured I'd try to get something similar.

The Titan, for short, has many of the features I want. Here's a rundown:

  • 15.6 inch FHD 120Hz display
  • 8th gen i7 CPU
  • 16g RAM, support for 64g
  • NVidia 1070 GPU (with no mention of Max-Q!)
  • 1t HDD + 256g SSD
  • 3x USB-A 3.1, 1x USB-C 3.1, 1x USB-A 2.0
  • HDMI (supporting 4k at 60Hz), and a mini-DisplayPort
  • "Multi touch" trackpad (no details)
  • Price: $2200 at Newegg, $2100 at Amazon
So it's a little above my target price range, and the display resolution isn't as high as I want... But it has everything else. And it's an MSI, and I know from my current GT683 they know how to deal with heat.

I'm starting to think that I'll end up with an FHD screen no matter what...

This laptop is in the running. Now looking at this and the Alienware 15.

Note: As an Amazon associate, I may earn a commission from purchases made through links followed from this page.

Laptop Shopping: 2018 Razer Blade 15

This is a followup to my New Laptop Shopping post.

According to CNet's Best Gaming Laptops of 2018 article, the Razer Blade comes out on top. I expect to work my way down the list in later posts, but there is a conspicuous absence: Alienware. Weren't they once the top gaming laptop manufacturer? I guess that was before Dell took over...

Anyway, let's take a look at the Razer Blade 15. Scanning through CNet's review, I already see some problems: It has an FHD display (I want QHD or better), and is marketed with NVidia Max-Q (a big no-no for me).

I am skeptical. But let's take a closer look anyway!

Visiting Razer's page for the Razer Blade 15 ("New!" like I care), they provide a few choices:
  • FHD 60Hz display:
    • Only options are NVidia 1060 and 256g SSD: $1900
  • FHD 144Hz display:
    • NVidia 1060 and 512g SSD: $2100
    • NVidia 1070 and 256g SSD: $2400
    • NVidia 1070 and 512g SSD: $2600
  • 4k 60Hz display (oh, and it's a touch-screen, ugh):
    • NVidia 1070 and 512g SSD: $2900
So the only one in my price range has a 60Hz display and an NVidia 1060, neither of which I want. Oh, and it's branded Max-Q. "Yes, Razer, I do want to burn my legs, thanks!"

Even with a bit of flexibility on the price (the $2100 option), it's still only got an NVidia 1060.

Oh, and let's also add touch-screens as a feature I'd prefer to avoid. All they do is confuse me when I accidentally touch the screen and something stupid happens.

So the Razer Blade is not in the running. Still just looking at the Alienware 15.