2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2024-11-25 17:16:25 +00:00

use kpartx instead of partprobe (close #19)

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2023-02-15 10:34:32 +01:00
parent 8659907d62
commit 618b5bc861
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF
2 changed files with 6 additions and 2 deletions

View File

@ -33,6 +33,7 @@ RUN apt-get update && \
util-linux \ util-linux \
udev \ udev \
parted \ parted \
kpartx \
e2fsprogs \ e2fsprogs \
mount \ mount \
tar \ tar \

View File

@ -265,10 +265,10 @@ func (b *builder) mountImg(ctx context.Context) error {
return err return err
} }
b.loDevice = strings.TrimSuffix(o, "\n") b.loDevice = strings.TrimSuffix(o, "\n")
if err := exec.Run(ctx, "partprobe", b.loDevice); err != nil { if err := exec.Run(ctx, "kpartx", "-a", b.loDevice); err != nil {
return err return err
} }
b.loPart = fmt.Sprintf("%sp1", b.loDevice) b.loPart = fmt.Sprintf("/dev/mapper/%sp1", filepath.Base(b.loDevice))
logrus.Infof("creating raw image file system") logrus.Infof("creating raw image file system")
if err := exec.Run(ctx, "mkfs.ext4", b.loPart); err != nil { if err := exec.Run(ctx, "mkfs.ext4", b.loPart); err != nil {
return err return err
@ -285,6 +285,9 @@ func (b *builder) unmountImg(ctx context.Context) error {
if err := exec.Run(ctx, "umount", b.mntPoint); err != nil { if err := exec.Run(ctx, "umount", b.mntPoint); err != nil {
merr = multierr.Append(merr, err) merr = multierr.Append(merr, err)
} }
if err := exec.Run(ctx, "kpartx", "-d", b.loDevice); err != nil {
merr = multierr.Append(merr, err)
}
if err := exec.Run(ctx, "losetup", "-d", b.loDevice); err != nil { if err := exec.Run(ctx, "losetup", "-d", b.loDevice); err != nil {
merr = multierr.Append(merr, err) merr = multierr.Append(merr, err)
} }