[LINUX] Create a Bootable LV

Background

In Ubuntu set up with LVM, I tried to verify what would happen if only the Bootable disk was changed to another LV.

Current partition

[email protected]:/home/moly# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <9.00 GiB / not usable 0
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               1023
  Allocated PE          1280
  PV UUID               mcw43c-b4ae-beqi-ISBZ-ZqPk-N46i-aGe5C6
  
[email protected]:/home/moly# df
Filesystem                        1K-blocks    Used Available Use% Mounted on
udev                                 472920       0    472920   0% /dev
tmpfs                                100896     944     99952   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   4062912 2079568   1757248  55% /
tmpfs                                504464       0    504464   0% /dev/shm
tmpfs                                  5120       0      5120   0% /run/lock
tmpfs                                504464       0    504464   0% /sys/fs/cgroup
/dev/loop0                            89984   89984         0 100% /snap/core/5662
/dev/loop1                            68352   68352         0 100% /snap/lxd/9239
/dev/sda2                            999320  150336    780172  17% /boot
tmpfs                                100892       0    100892   0% /run/user/1000

[email protected]:/home/moly# file -s /dev/mapper/ubuntu--vg-ubuntu--lv
/dev/mapper/ubuntu--vg-ubuntu--lv: symbolic link to ../dm-0

/dev/mapper/ubuntu--vg-ubuntu--lv: symbolic link to ../dm-0
[email protected]:/home/moly# file -s /dev/dm-0 #filesystem search
/dev/dm-0: Linux rev 1.0 ext4 filesystem data, UUID=b50c9846-9c89-44c2-b57a-1c0a00c3afa5 (needs journal recovery) (extents) (64bit) (large files) (huge files)

Make lv


[email protected]:/home/moly# lvcreate -L 1G -n  Bootable ubuntu-vg

filesystem


[email protected]:/home/moly# mkfs.ext4 /dev/ubuntu-vg/Bootable 
mke2fs 1.44.4 (18-Aug-2018)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: ef5bf14a-43fa-4dd3-9441-48e0ea4a0fbf
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

mount


[email protected]:/home/moly# mktemp -d
/tmp/tmp.GauV3uu0St
[email protected]:/home/moly# mount -t ext4 /dev/ubuntu-vg/Bootable /tmp/tmp.GauV3uu0St

gv, lv confirmation

[email protected]:/tmp/tmp.GauV3uu0St# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                oeCuCc-vFAD-p1Pa-PfDK-sk4L-w6cn-ERFBNr
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2019-04-04 15:17:09 +0000
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/Bootable
  LV Name                Bootable
  VG Name                ubuntu-vg
  LV UUID                ZPT9Lo-yY7O-WXvW-vVEa-O5xB-xIo5-9rR1qT
  LV Write Access        read/write
  LV Creation host, time yayoi, 2019-04-04 15:24:19 +0000
  LV Status              available
  # open                 1
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[email protected]:/tmp/tmp.GauV3uu0St#

Added grub menu entry

Added the following.


[email protected]:/etc/grub.d# cat 99_bootable_lvm
#!/bin/sh
set -e
echo "shitty bootable lvm" >&2

cat << EOF
menuentry "bootable lvm" {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
	insmod lvm
	set root='lvmid/Vgp9Fy-SOA4-Ff5x-sAs4-Bhfg-ppwG-gOf76f/ZPT9Lo-yY7O-WXvW-vVEa-O5xB-xIo5-9rR1qT'
        search --no-floppy --fs-uuid --set=root --hint='lvmid/Vgp9Fy-SOA4-Ff5x-sAs4-Bhfg-ppwG-gOf76f/ZPT9Lo-yY7O-WXvW-vVEa-O5xB-xIo5-9rR1qT' 3ef3a667-f4ed-4399-8f31-11c29ef994eb
        linux   /vmlinuz-4.18.0-17-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro  maybe-ubiquity
        initrd  /initrd.img-4.18.0-17-generic
}
EOF

update-grub2


[email protected]:/etc/grub.d# sudo update-grub2
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.18.0-17-generic
Found initrd image: /boot/initrd.img-4.18.0-17-generic
Found linux image: /boot/vmlinuz-4.18.0-10-generic
Found initrd image: /boot/initrd.img-4.18.0-10-generic
shitty bootable lvm
done

copy boot

[email protected]:/home/moly# cd /tmp/tmp.GauV3uu0St/
[email protected]:/tmp/tmp.GauV3uu0St# cp -r /boot/* ./

try booting

If you select from grub's menu entry, it will start normally.

Try to stop mounting / boot from fstab! w

Edit fstab and reboot


[email protected]:/tmp/tmp.GauV3uu0St# cat /etc/fstab
UUID=b50c9846-9c89-44c2-b57a-1c0a00c3afa5 / ext4 defaults 0 0
#UUID=3ef3a667-f4ed-4399-8f31-11c29ef994eb /boot ext4 defaults 0 0

result

I don't know who made grubenv, but for the time being, I couldn't see / boot. ** Best **


[email protected]:/home/moly# df
Filesystem                        1K-blocks    Used Available Use% Mounted on
udev                                 472920       0    472920   0% /dev
tmpfs                                100896     932     99964   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   4062912 2105112   1731704  55% /
tmpfs                                504464       0    504464   0% /dev/shm
tmpfs                                  5120       0      5120   0% /run/lock
tmpfs                                504464       0    504464   0% /sys/fs/cgroup
/dev/loop0                            89984   89984         0 100% /snap/core/5662
/dev/loop1                            68352   68352         0 100% /snap/lxd/9239
tmpfs                                100892       0    100892   0% /run/user/1000
[email protected]:/home/moly# tree /boot
/boot
└── grub
    └── grubenv

1 directory, 1 file
[email protected]:/home/moly# cat /boot/grub/grubenv
# GRUB Environment Block
#######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################[email protected]:/home/moly#

Mount the newly created Bootable LV on / boot

Change fstab and reboot


[email protected]:/home/moly# blkid
/dev/sda2: UUID="3ef3a667-f4ed-4399-8f31-11c29ef994eb" TYPE="ext4" PARTUUID="c0289df7-8720-4474-ae2d-66ed85f9b9a3"
/dev/sda3: UUID="mcw43c-b4ae-beqi-ISBZ-ZqPk-N46i-aGe5C6" TYPE="LVM2_member" PARTUUID="9a3e5412-0c8e-4623-a7ef-9143918a416e"
/dev/mapper/ubuntu--vg-ubuntu--lv: UUID="b50c9846-9c89-44c2-b57a-1c0a00c3afa5" TYPE="ext4"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/mapper/ubuntu--vg-Bootable: UUID="ef5bf14a-43fa-4dd3-9441-48e0ea4a0fbf" TYPE="ext4"
/dev/sda1: PARTUUID="184382b2-05c6-4aa2-9ed6-d350573bfe9f"
[email protected]:/home/moly# cat /etc/fstab
UUID=b50c9846-9c89-44c2-b57a-1c0a00c3afa5 / ext4 defaults 0 0
#UUID=3ef3a667-f4ed-4399-8f31-11c29ef994eb /boot ext4 defaults 0 0
UUID=ef5bf14a-43fa-4dd3-9441-48e0ea4a0fbf /boot ext4 defaults 0 0

result

/ boot is mounted with / dev / mapper / ubuntu--vg-Bootable

[email protected]:/home/moly# df
Filesystem                        1K-blocks    Used Available Use% Mounted on
udev                                 472920       0    472920   0% /dev
tmpfs                                100896     940     99956   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   4062912 2155104   1681712  57% /
tmpfs                                504464       0    504464   0% /dev/shm
tmpfs                                  5120       0      5120   0% /run/lock
tmpfs                                504464       0    504464   0% /sys/fs/cgroup
/dev/loop0                            89984   89984         0 100% /snap/core/5662
/dev/loop1                            68352   68352         0 100% /snap/lxd/9239
/dev/mapper/ubuntu--vg-Bootable      999320  150328    780180  17% /boot
tmpfs                                100892       0    100892   0% /run/user/1000

Recommended Posts

Create a Bootable LV
Create a Django schedule
Create a Python module
Create a Python environment
Create a slack bot
Create a Wox plugin (Python)
Create a local pypi repository
Create a function in Python
Create a dictionary in Python
Create a (simple) REST server
Create a homepage with django
Create a python numpy array
Create a dummy data file
Create a Django login screen
Create a heatmap with pyqtgraph
Create a classroom on Jupyterhub
Create a simple textlint server
Create a directory with python
Create a rudimentary ELF packer
Create a CSV reader in Flask
Create a python GUI using tkinter
Create a DI Container in Python
Steps to create a Django project
Create a pandas Dataframe from a string.
Create a Python environment on Mac (2017/4)
Create a nested dictionary using defaultdict
How to create a Conda package
Create a virtual environment with Python!
Create a binary file in Python
How to create a virtual bridge
Create a SlackBot service on Pepper
Create a Linux environment on Windows 10
How to create a Dockerfile (basic)
Create a Unix Domain Socket server
Create a 1MByte random number file
Create a Python general-purpose decorator framework
Create a Kubernetes Operator in Python
5 Ways to Create a Python Chatbot
Create a CRUD API using FastAPI
Create a poisson stepper with numpy.random
Create a random string in Python
How to create a config file
Create a C wrapper using Boost.Python
Create a file uploader with Django
Create a LINE Bot in Django
I tried to create a linebot (implementation)
How to create a clone from Github
Create a Python function decorator with Class
Create a bot to retweet coronavirus information
Create a new Python numerical calculation project
How to create a git clone folder
I tried to create a linebot (preparation)
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
Create a model for your Django schedule
Create a python environment on your Mac
Create a simple GUI app in Python
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a JSON object mapper in Python