惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Know Your Adversary
Know Your Adversary
小众软件
小众软件
L
LangChain Blog
月光博客
月光博客
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
Recorded Future
Recorded Future
V
Visual Studio Blog
TaoSecurity Blog
TaoSecurity Blog
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
L
LINUX DO - 热门话题
C
Check Point Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
博客园 - 司徒正美
T
Threatpost
P
Palo Alto Networks Blog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
Engineering at Meta
Engineering at Meta
N
News | PayPal Newsroom
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
Blog — PlanetScale
Blog — PlanetScale
A
Arctic Wolf
量子位
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Google Online Security Blog
Google Online Security Blog
Google DeepMind News
Google DeepMind News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Vulnerabilities – Threatpost
H
Hacker News: Front Page

blog.smartere

Floppy Disks: the best TV remote for kids Upgrading the Olimex A20 LIME2 to 2GB RAM, by learning to BGA solder and deep diving into the U-Boot bootloader process Making a too cheap LED lamp safe to use Giv mig nu bare elprisen.somjson.dk! (en historie om det måske værste datasæt i åbne energidata) World’s Longest Multi-Cutter Blade: 30 cm Reparation af Nordlux IP S12 badeværelseslampe der ikke lyser længere Fantus-button part 2: the physical button build and the network communication Fantus-button part 1: Reverse engineering the DRTV Chromecast App Floating Solid Wood Alcove Shelves Quick and dirty guide to Lithium battery-powered Wemos D1 Mini Olimex A20-OLinuXino-LIME2 – 8 years in service, 2 PSUs and 1 SD-card down Grundfos Alpha 2 pumpe går i stykker og flimrer: reparer den med en kondensator til nogle få kr Reparation af Aduro-tronic II Sniffing Philips Hue Zigbee traffic with Wireshark Dør jeg af partikelforurening fra min moderne brændeovn? 18650 Lithium-ion battery packs – 1S80P Olimex A20-OLinuXino-LIME2 – A review after 4 years in service Reparation af DUKA/PAX Passad 30 Ventilator der kører uregelmæssigt Ford 3000 Tractor Instrument Voltage Stabilizer – Mechanical PWM! Reverse engineering Aduro Smart Response Hvorfor korrelerer min DC-spænding med solen? Measuring high DC supply voltage with an Arduino Roomba 500-series Easy Scheduling using an Arduino Brother DS-620 on Linux Making objdump -S find your source code Et lille slag for ytringsfriheden WordPress – mildly impressed
Stupid sys-admin’ing, and hooray for LVM and unnecessary partitions
Mads Chr. Ol · 2014-01-31 · via blog.smartere

Posted on fredag, januar 31, 2014 in Planet Ubuntu-DK, Planets, Sysadmin'ing, Ubuntu

The scenario is: almost finished migrating from an old server to a new server. Only a few steps remain, namely

  • change DNS to point to new server
  • wipe disks on old server

Done in this order, one might be unlucky that ssh’ing in to wipe the disks lands you on the new server. If you don’t discover this and run the command
dd if=/dev/zero of=/dev/md2
to wipe the disks you might run it on the new server instead. BAM: you just wiped the data of your new server. Fortunately, I realised my mistake after a few seconds, and was able to recover from this with only unimportant data loss, and a little panic.

/dev/md2 is actually a LVM physical partition, of which the first part now only contains zeroes; hereunder all the meta-data. LVM reported no volumes of any kind:
root@server# pvs -v
Scanning for physical volume names
root@server# lvs -v
Finding all logical volumes
No volume groups found
root@server # vgs -v
Finding all volume groups
No volume groups found

After a bit of Google’ing while panicking I found out LVM keeps a backup of all its metadata in /etc/lvm/backup, and that it could be rewritten to the physical volume using:
pvcreate -ff -u XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX --restorefile /etc/lvm/backup/vg0 /dev/md2
where XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX is the physical UUID from the backup file:
...
physical_volumes {
pv0 {
id = "XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX"
device = "/dev/md2" # Hint only ... 

Unfortunately, I got an error:
root@server# pvcreate -ff -u XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX --restorefile /etc/lvm/backup/vg0 /dev/md2
Couldn't find device with uuid XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX.
Can't open /dev/md2 exclusively. Mounted filesystem?

lsof showed nothing accessing md2, but I guess something still had references to the logical volumes. I was unable to get it to work, so I decided to reboot (while making sure the system would come up, and nothing would try to mount the (non-existent) LVM volumes). After a reboot the command worked, but still no logical volumes:
root@server # pvcreate -ff -u XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX --restorefile /etc/lvm/backup/vg0 /dev/md2
Couldn't find device with uuid XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX.
Physical volume "/dev/md2" successfully created
root@server # sudo pvs
PV VG Fmt Attr PSize PFree
/dev/md2 lvm2 a- 648.51g 648.51g
root@server # sudo lvs
No volume groups found

Now I had a physical volume, and could use the vgcfgrestore command:
root@server # vgcfgrestore -f /etc/lvm/backup/vg0 /dev/vg0
Restored volume group vg0
root@server # sudo lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
...
home vg0 -wi-a- 20.00g

I now had my logical volumes back! Now to assess the data loss… The backup file /etc/lvm/backup/vg0 lists which order the logical volumes are stored. The first volume in my case was the “home” volume. Sure enough, it would no longer mount:
root@server # mount /dev/vg0/home /home
mount: wrong fs type, bad option, bad superblock on /dev/mapper/vg0-home,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

I actually had no important information on that file system, so I re-created it. Luckily the next volume was intact, and I could bring up the rest of the system without problems.

So to sum up: LVM keeps a backup of all it’s metadata that can be restored (after a reboot), but if your keyboard is faster than your brain it can be a good idea to keep an unused volume as the first logical volume 🙂